From 637ab296cba9e37e7374a8c076342487398605ee Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 17 Oct 2022 21:00:50 +0800 Subject: feat(api): nvim_select_popupmenu_item support cmdline pum (#20652) --- src/nvim/api/vim.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index fa8d26914a..0c0c71b694 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -1908,19 +1908,20 @@ Object nvim_get_proc(Integer pid, Error *err) return rvobj; } -/// Selects an item in the completion popupmenu. -/// -/// If |ins-completion| is not active this API call is silently ignored. -/// Useful for an external UI using |ui-popupmenu| to control the popupmenu -/// with the mouse. Can also be used in a mapping; use |:map-cmd| to -/// ensure the mapping doesn't end completion mode. -/// -/// @param item Index (zero-based) of the item to select. Value of -1 selects -/// nothing and restores the original text. -/// @param insert Whether the selection should be inserted in the buffer. -/// @param finish Finish the completion and dismiss the popupmenu. Implies -/// `insert`. -/// @param opts Optional parameters. Reserved for future use. +/// Selects an item in the completion popup menu. +/// +/// If neither |ins-completion| nor |cmdline-completion| popup menu is active +/// this API call is silently ignored. +/// Useful for an external UI using |ui-popupmenu| to control the popup menu with the mouse. +/// Can also be used in a mapping; use |:map-cmd| or a Lua mapping to ensure the mapping +/// doesn't end completion mode. +/// +/// @param item Index (zero-based) of the item to select. Value of -1 selects nothing +/// and restores the original text. +/// @param insert For |ins-completion|, whether the selection should be inserted in the buffer. +/// Ignored for |cmdline-completion|. +/// @param finish Finish the completion and dismiss the popup menu. Implies {insert}. +/// @param opts Optional parameters. Reserved for future use. /// @param[out] err Error details, if any void nvim_select_popupmenu_item(Integer item, Boolean insert, Boolean finish, Dictionary opts, Error *err) -- cgit From 784e498c4a9c1f03266ced5ec3f55c3a6c94b80d Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Fri, 21 Oct 2022 14:47:44 +0200 Subject: refactor: clang-tidy fixes to silence clangd warning (#20683) * refactor: readability-uppercase-literal-suffix * refactor: readability-named-parameter * refactor: bugprone-suspicious-string-compare * refactor: google-readability-casting * refactor: readability-redundant-control-flow * refactor: bugprone-too-small-loop-variable * refactor: readability-non-const-parameter * refactor: readability-avoid-const-params-in-decls * refactor: google-readability-todo * refactor: readability-inconsistent-declaration-parameter-name * refactor: bugprone-suspicious-missing-comma * refactor: remove noisy or slow warnings --- src/nvim/api/private/defs.h | 2 +- src/nvim/api/ui.c | 2 +- src/nvim/api/vim.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/private/defs.h b/src/nvim/api/private/defs.h index 2ae3ee6c7c..8693751c97 100644 --- a/src/nvim/api/private/defs.h +++ b/src/nvim/api/private/defs.h @@ -48,7 +48,7 @@ typedef enum { /// Internal call from lua code #define LUA_INTERNAL_CALL (VIML_INTERNAL_CALL + 1) -static inline bool is_internal_call(const uint64_t channel_id) +static inline bool is_internal_call(uint64_t channel_id) REAL_FATTR_ALWAYS_INLINE REAL_FATTR_CONST; /// Check whether call is internal diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c index e6d8cb2fdb..f251e0043f 100644 --- a/src/nvim/api/ui.c +++ b/src/nvim/api/ui.c @@ -845,7 +845,7 @@ static void remote_ui_raw_line(UI *ui, Integer grid, Integer row, Integer startc for (size_t i = 0; i < ncells; i++) { repeat++; if (i == ncells - 1 || attrs[i] != attrs[i + 1] - || strcmp(chunk[i], chunk[i + 1])) { + || strcmp(chunk[i], chunk[i + 1]) != 0) { if (UI_BUF_SIZE - BUF_POS(data) < 2 * (1 + 2 + sizeof(schar_T) + 5 + 5)) { // close to overflowing the redraw buffer. finish this event, // flush, and start a new "grid_line" event at the current position. diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 0c0c71b694..32d52bef46 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -1012,7 +1012,7 @@ Integer nvim_open_term(Buffer buffer, DictionaryOf(LuaRef) opts, Error *err) return (Integer)chan->id; } -static void term_write(char *buf, size_t size, void *data) +static void term_write(char *buf, size_t size, void *data) // NOLINT(readability-non-const-parameter) { Channel *chan = data; LuaRef cb = chan->stream.internal.cb; @@ -2125,7 +2125,7 @@ Dictionary nvim_eval_statusline(String str, Dict(eval_statusline) *opts, Error * bool use_tabline = false; bool highlights = false; - if (str.size < 2 || memcmp(str.data, "%!", 2)) { + if (str.size < 2 || memcmp(str.data, "%!", 2) != 0) { const char *const errmsg = check_stl_option(str.data); if (errmsg) { api_set_error(err, kErrorTypeValidation, "%s", errmsg); -- cgit From 6ff245732a5a8ab821598a38fb0c5805e6bd3779 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Fri, 14 Oct 2022 17:04:28 +0200 Subject: refactor(uncrustify): improved formatting rules --- src/nvim/api/private/dispatch.h | 5 +---- src/nvim/api/ui_events.in.h | 43 +++++++++++++++++------------------------ 2 files changed, 19 insertions(+), 29 deletions(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/private/dispatch.h b/src/nvim/api/private/dispatch.h index f92b205531..f0161a53a8 100644 --- a/src/nvim/api/private/dispatch.h +++ b/src/nvim/api/private/dispatch.h @@ -3,10 +3,7 @@ #include "nvim/api/private/defs.h" -typedef Object (*ApiDispatchWrapper)(uint64_t channel_id, - Array args, - Arena *arena, - Error *error); +typedef Object (*ApiDispatchWrapper)(uint64_t channel_id, Array args, Arena *arena, Error *error); /// The rpc_method_handlers table, used in msgpack_rpc_dispatch(), stores /// functions of this type. diff --git a/src/nvim/api/ui_events.in.h b/src/nvim/api/ui_events.in.h index 17930dca85..21400862b9 100644 --- a/src/nvim/api/ui_events.in.h +++ b/src/nvim/api/ui_events.in.h @@ -69,11 +69,10 @@ void scroll(Integer count) FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY; // Second revision of the grid protocol, used with ext_linegrid ui option -void default_colors_set(Integer rgb_fg, Integer rgb_bg, Integer rgb_sp, - Integer cterm_fg, Integer cterm_bg) +void default_colors_set(Integer rgb_fg, Integer rgb_bg, Integer rgb_sp, Integer cterm_fg, + Integer cterm_bg) FUNC_API_SINCE(4) FUNC_API_REMOTE_IMPL; -void hl_attr_define(Integer id, HlAttrs rgb_attrs, HlAttrs cterm_attrs, - Array info) +void hl_attr_define(Integer id, HlAttrs rgb_attrs, HlAttrs cterm_attrs, Array info) FUNC_API_SINCE(5) FUNC_API_REMOTE_IMPL FUNC_API_BRIDGE_IMPL; void hl_group_set(String name, Integer id) FUNC_API_SINCE(6) FUNC_API_BRIDGE_IMPL; @@ -85,8 +84,8 @@ void grid_cursor_goto(Integer grid, Integer row, Integer col) FUNC_API_SINCE(5) FUNC_API_REMOTE_IMPL FUNC_API_COMPOSITOR_IMPL; void grid_line(Integer grid, Integer row, Integer col_start, Array data) FUNC_API_SINCE(5) FUNC_API_REMOTE_ONLY FUNC_API_CLIENT_IMPL; -void grid_scroll(Integer grid, Integer top, Integer bot, - Integer left, Integer right, Integer rows, Integer cols) +void grid_scroll(Integer grid, Integer top, Integer bot, Integer left, Integer right, Integer rows, + Integer cols) FUNC_API_SINCE(5) FUNC_API_REMOTE_IMPL FUNC_API_COMPOSITOR_IMPL; void grid_destroy(Integer grid) FUNC_API_SINCE(6) FUNC_API_REMOTE_ONLY; @@ -94,20 +93,18 @@ void grid_destroy(Integer grid) // For performance and simplicity, we use the dense screen representation // in internal code, such as compositor and TUI. The remote_ui module will // translate this in to the public grid_line format. -void raw_line(Integer grid, Integer row, Integer startcol, - Integer endcol, Integer clearcol, Integer clearattr, - LineFlags flags, const schar_T *chunk, const sattr_T *attrs) +void raw_line(Integer grid, Integer row, Integer startcol, Integer endcol, Integer clearcol, + Integer clearattr, LineFlags flags, const schar_T *chunk, const sattr_T *attrs) FUNC_API_NOEXPORT FUNC_API_COMPOSITOR_IMPL; void event(char *name, Array args) FUNC_API_NOEXPORT FUNC_API_COMPOSITOR_IMPL; -void win_pos(Integer grid, Window win, Integer startrow, - Integer startcol, Integer width, Integer height) +void win_pos(Integer grid, Window win, Integer startrow, Integer startcol, Integer width, + Integer height) FUNC_API_SINCE(6) FUNC_API_REMOTE_ONLY; -void win_float_pos(Integer grid, Window win, String anchor, Integer anchor_grid, - Float anchor_row, Float anchor_col, Boolean focusable, - Integer zindex) +void win_float_pos(Integer grid, Window win, String anchor, Integer anchor_grid, Float anchor_row, + Float anchor_col, Boolean focusable, Integer zindex) FUNC_API_SINCE(6) FUNC_API_REMOTE_ONLY; void win_external_pos(Integer grid, Window win) FUNC_API_SINCE(6) FUNC_API_REMOTE_ONLY; @@ -118,29 +115,25 @@ 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, - Integer line_count) +void win_viewport(Integer grid, Window win, Integer topline, Integer botline, Integer curline, + Integer curcol, Integer line_count) FUNC_API_SINCE(7) FUNC_API_BRIDGE_IMPL; -void win_extmark(Integer grid, Window win, Integer ns_id, Integer mark_id, - Integer row, Integer col) +void win_extmark(Integer grid, Window win, Integer ns_id, Integer mark_id, Integer row, Integer col) FUNC_API_SINCE(10) FUNC_API_REMOTE_ONLY; -void popupmenu_show(Array items, Integer selected, - Integer row, Integer col, Integer grid) +void popupmenu_show(Array items, Integer selected, Integer row, Integer col, Integer grid) FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY; void popupmenu_hide(void) FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY; void popupmenu_select(Integer selected) FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY; -void tabline_update(Tabpage current, Array tabs, - Buffer current_buffer, Array buffers) +void tabline_update(Tabpage current, Array tabs, Buffer current_buffer, Array buffers) FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY; -void cmdline_show(Array content, Integer pos, String firstc, String prompt, - Integer indent, Integer level) +void cmdline_show(Array content, Integer pos, String firstc, String prompt, Integer indent, + Integer level) FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY; void cmdline_pos(Integer pos, Integer level) FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY; -- cgit From 1887d8d7d0dd619fa90fe11182c436bc3c71c9d5 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sun, 23 Oct 2022 03:45:39 +0200 Subject: docs: fix typos (#20724) Co-authored-by: Marco Lehmann --- 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 32d52bef46..beb48b8d7d 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -1685,7 +1685,7 @@ Array nvim_call_atomic(uint64_t channel_id, Array calls, Arena *arena, Error *er // error handled after loop break; } - // TODO(bfredl): wastefull copy. It could be avoided to encoding to msgpack + // TODO(bfredl): wasteful copy. It could be avoided to encoding to msgpack // directly here. But `result` might become invalid when next api function // is called in the loop. ADD_C(results, copy_object(result, arena)); -- cgit From f44ad753801d881f5352c9182167ced18e79e456 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Thu, 27 Oct 2022 22:31:58 +0200 Subject: docs(api): pattern is not expanded for autocommands (#20812) Problem: Unlike `:autocmd`, `nvim_create_autocommand()` does not expand environment variables in the `pattern`, which is unexpected. Solution: Add a note to the documentation explaining this and suggesting using `expand()` explicitly. --- src/nvim/api/autocmd.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/autocmd.c b/src/nvim/api/autocmd.c index b5c695b9ce..3dfe77ba38 100644 --- a/src/nvim/api/autocmd.c +++ b/src/nvim/api/autocmd.c @@ -401,6 +401,13 @@ cleanup: /// pattern = { "*.py", "*.pyi" } /// /// +/// Note: The `pattern` is passed to callbacks and commands as a literal string; environment +/// variables like `$HOME` and `~` are not automatically expanded as they are by |:autocmd|. +/// Instead, |expand()| such variables explicitly: +///
+///   pattern = vim.fn.expand("~") .. "/some/path/*.py"
+/// 
+/// /// Example values for event: ///
 ///   "BufWritePre"
@@ -411,7 +418,7 @@ cleanup:
 /// @param opts Dictionary of autocommand options:
 ///             - group (string|integer) optional: the autocommand group name or
 ///             id to match against.
-///             - pattern (string|array) optional: pattern or patterns to match
+///             - pattern (string|array) optional: pattern or patterns to match literally
 ///             against |autocmd-pattern|.
 ///             - buffer (integer) optional: buffer number for buffer local autocommands
 ///             |autocmd-buflocal|. Cannot be used with {pattern}.
-- 
cgit 


From 731cdde28ea8d48cc23ba2752a08c261c87eee92 Mon Sep 17 00:00:00 2001
From: dundargoc 
Date: Sat, 22 Oct 2022 12:36:38 +0200
Subject: refactor: fix clang-tidy warnings

Enable and fix bugprone-misplaced-widening-cast warning.

Fix some modernize-macro-to-enum and readability-else-after-return
warnings, but don't enable them. While the warnings can be useful, they
are in general too noisy to enable.
---
 src/nvim/api/extmark.c   |  3 +--
 src/nvim/api/tabpage.c   | 13 ++++++-------
 src/nvim/api/vimscript.c |  2 +-
 3 files changed, 8 insertions(+), 10 deletions(-)

(limited to 'src/nvim/api')

diff --git a/src/nvim/api/extmark.c b/src/nvim/api/extmark.c
index 3b1b470629..fee6876469 100644
--- a/src/nvim/api/extmark.c
+++ b/src/nvim/api/extmark.c
@@ -833,9 +833,8 @@ uint32_t src2ns(Integer *src_id)
   }
   if (*src_id < 0) {
     return (((uint32_t)1) << 31) - 1;
-  } else {
-    return (uint32_t)(*src_id);
   }
+  return (uint32_t)(*src_id);
 }
 
 /// Adds a highlight to buffer.
diff --git a/src/nvim/api/tabpage.c b/src/nvim/api/tabpage.c
index b81fc3b7d7..31f9fab82a 100644
--- a/src/nvim/api/tabpage.c
+++ b/src/nvim/api/tabpage.c
@@ -110,15 +110,14 @@ Window nvim_tabpage_get_win(Tabpage tabpage, Error *err)
 
   if (tab == curtab) {
     return nvim_get_current_win();
-  } else {
-    FOR_ALL_WINDOWS_IN_TAB(wp, tab) {
-      if (wp == tab->tp_curwin) {
-        return wp->handle;
-      }
+  }
+  FOR_ALL_WINDOWS_IN_TAB(wp, tab) {
+    if (wp == tab->tp_curwin) {
+      return wp->handle;
     }
-    // There should always be a current window for a tabpage
-    abort();
   }
+  // There should always be a current window for a tabpage
+  abort();
 }
 
 /// Gets the tabpage number
diff --git a/src/nvim/api/vimscript.c b/src/nvim/api/vimscript.c
index 71209c9ab6..dccc2d42d8 100644
--- a/src/nvim/api/vimscript.c
+++ b/src/nvim/api/vimscript.c
@@ -532,7 +532,7 @@ Dictionary nvim_parse_expression(String expr, String flags, Boolean highlight, E
       kv_drop(ast_conv_stack, 1);
     } else {
       if (cur_item.ret_node_p->type == kObjectTypeNil) {
-        size_t items_size = (size_t)(3  // "type", "start" and "len"
+        size_t items_size = (size_t)(3  // "type", "start" and "len"  // NOLINT(bugprone-misplaced-widening-cast)
                                      + (node->children != NULL)  // "children"
                                      + (node->type == kExprNodeOption
                                         || node->type == kExprNodePlainIdentifier)  // "scope"
-- 
cgit 


From 1af4bd04f9ad157edbfea30642250e854c5cb5d2 Mon Sep 17 00:00:00 2001
From: Raphael 
Date: Sun, 6 Nov 2022 18:59:43 +0800
Subject: feat(ui): add support to display a title in the border of a float
 (#20184)

add "title" and "title_pos" keys to win config dict.
---
 src/nvim/api/keysets.lua  |   2 +
 src/nvim/api/win_config.c | 118 +++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 119 insertions(+), 1 deletion(-)

(limited to 'src/nvim/api')

diff --git a/src/nvim/api/keysets.lua b/src/nvim/api/keysets.lua
index ea8949bd2c..7e0d399573 100644
--- a/src/nvim/api/keysets.lua
+++ b/src/nvim/api/keysets.lua
@@ -81,6 +81,8 @@ return {
     "focusable";
     "zindex";
     "border";
+    "title";
+    "title_pos";
     "style";
     "noautocmd";
   };
diff --git a/src/nvim/api/win_config.c b/src/nvim/api/win_config.c
index 636b9566ce..9f15e5a85b 100644
--- a/src/nvim/api/win_config.c
+++ b/src/nvim/api/win_config.c
@@ -2,14 +2,17 @@
 // it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
 
 #include 
+#include 
 #include 
 #include 
 #include 
 
+#include "nvim/api/extmark.h"
 #include "nvim/api/private/defs.h"
 #include "nvim/api/private/helpers.h"
 #include "nvim/api/win_config.h"
 #include "nvim/ascii.h"
+#include "nvim/buffer_defs.h"
 #include "nvim/drawscreen.h"
 #include "nvim/highlight_group.h"
 #include "nvim/option.h"
@@ -134,6 +137,11 @@
 ///     By default, `FloatBorder` highlight is used, which links to `WinSeparator`
 ///     when not defined.  It could also be specified by character:
 ///       [ {"+", "MyCorner"}, {"x", "MyBorder"} ].
+///   - title: Title (optional) in window border, String or list.
+///     List is [text, highlight] tuples. if is string the default
+///     highlight group is `FloatBorderTitle`.
+///   - title_pos: Title position must set with title option.
+///     value can be of `left` `center` `right` default is left.
 ///   - noautocmd: If true then no buffer-related autocommand events such as
 ///                  |BufEnter|, |BufLeave| or |BufWinEnter| may fire from
 ///                  calling this function.
@@ -273,6 +281,21 @@ Dictionary nvim_win_get_config(Window window, Error *err)
         }
       }
       PUT(rv, "border", ARRAY_OBJ(border));
+      if (config->title) {
+        Array titles = ARRAY_DICT_INIT;
+        VirtText title_datas = config->title_chunks;
+        for (size_t i = 0; i < title_datas.size; i++) {
+          Array tuple = ARRAY_DICT_INIT;
+          ADD(tuple, CSTR_TO_OBJ((const char *)title_datas.items[i].text));
+          if (title_datas.items[i].hl_id > 0) {
+            ADD(tuple,
+                STRING_OBJ(cstr_to_string((const char *)syn_id2name(title_datas.items[i].hl_id))));
+          }
+          ADD(titles, ARRAY_OBJ(tuple));
+        }
+        PUT(rv, "title", ARRAY_OBJ(titles));
+        PUT(rv, "title_pos", INTEGER_OBJ(config->title_pos));
+      }
     }
   }
 
@@ -330,7 +353,75 @@ static bool parse_float_bufpos(Array bufpos, lpos_T *out)
   return true;
 }
 
-static void parse_border_style(Object style, FloatConfig *fconfig, Error *err)
+static void parse_border_title(Object title, Object title_pos, FloatConfig *fconfig, Error *err)
+{
+  if (!parse_title_pos(title_pos, fconfig, err)) {
+    return;
+  }
+
+  if (title.type == kObjectTypeString) {
+    if (title.data.string.size == 0) {
+      fconfig->title = false;
+      return;
+    }
+    int hl_id = syn_check_group(S_LEN("FloatBorderTitle"));
+    kv_push(fconfig->title_chunks, ((VirtTextChunk){ .text = xstrdup(title.data.string.data),
+                                                     .hl_id = hl_id }));
+    fconfig->title_width = (int)mb_string2cells(title.data.string.data);
+    fconfig->title = true;
+    return;
+  }
+
+  if (title.type != kObjectTypeArray) {
+    api_set_error(err, kErrorTypeValidation, "title must be string or array");
+    return;
+  }
+
+  if (title.type == kObjectTypeArray && title.data.array.size == 0) {
+    api_set_error(err, kErrorTypeValidation, "title cannot be an empty array");
+    return;
+  }
+
+  fconfig->title_width = 0;
+  fconfig->title_chunks = parse_virt_text(title.data.array, err, &fconfig->title_width);
+
+  fconfig->title = true;
+  return;
+}
+
+static bool parse_title_pos(Object title_pos, FloatConfig *fconfig, Error *err)
+{
+  if (!HAS_KEY(title_pos)) {
+    fconfig->title_pos = kAlignLeft;
+    return true;
+  }
+
+  if (title_pos.type != kObjectTypeString) {
+    api_set_error(err, kErrorTypeValidation, "title_pos must be string");
+    return false;
+  }
+
+  if (title_pos.data.string.size == 0) {
+    fconfig->title_pos = kAlignLeft;
+    return true;
+  }
+
+  char *pos = title_pos.data.string.data;
+
+  if (strequal(pos, "left")) {
+    fconfig->title_pos = kAlignLeft;
+  } else if (strequal(pos, "center")) {
+    fconfig->title_pos = kAlignCenter;
+  } else if (strequal(pos, "right")) {
+    fconfig->title_pos = kAlignRight;
+  } else {
+    api_set_error(err, kErrorTypeValidation, "invalid title_pos value");
+    return false;
+  }
+  return true;
+}
+
+static void parse_border_style(Object style,  FloatConfig *fconfig, Error *err)
 {
   struct {
     const char *name;
@@ -414,6 +505,8 @@ static void parse_border_style(Object style, FloatConfig *fconfig, Error *err)
     String str = style.data.string;
     if (str.size == 0 || strequal(str.data, "none")) {
       fconfig->border = false;
+      // title does not work with border equal none
+      fconfig->title = false;
       return;
     }
     for (size_t i = 0; defaults[i].name; i++) {
@@ -603,6 +696,29 @@ static bool parse_float_config(Dict(float_config) *config, FloatConfig *fconfig,
     return false;
   }
 
+  if (HAS_KEY(config->title_pos)) {
+    if (!HAS_KEY(config->title)) {
+      api_set_error(err, kErrorTypeException, "title_pos requires title to be set");
+      return false;
+    }
+  }
+
+  if (HAS_KEY(config->title)) {
+    // title only work with border
+    if (!HAS_KEY(config->border) && !fconfig->border) {
+      api_set_error(err, kErrorTypeException, "title requires border to be set");
+      return false;
+    }
+
+    if (fconfig->title) {
+      clear_virttext(&fconfig->title_chunks);
+    }
+    parse_border_title(config->title, config->title_pos, fconfig, err);
+    if (ERROR_SET(err)) {
+      return false;
+    }
+  }
+
   if (HAS_KEY(config->border)) {
     parse_border_style(config->border, fconfig, err);
     if (ERROR_SET(err)) {
-- 
cgit 


From 42e44d6d334bda8b97afe9e34a819ab293e5e10a Mon Sep 17 00:00:00 2001
From: zeertzjq 
Date: Mon, 7 Nov 2022 10:26:54 +0800
Subject: vim-patch:8.2.3751: cannot assign a lambda to an option that takes a
 function

Problem:    Cannot assign a lambda to an option that takes a function.
Solution:   Automatically convert the lambda to a string. (Yegappan
            Lakshmanan, closes vim/vim#9286)

https://github.com/vim/vim/commit/6409553b6e3b4de4e1d72b8ee5445595214581ff

Co-authored-by: Yegappan Lakshmanan 
---
 src/nvim/api/options.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(limited to 'src/nvim/api')

diff --git a/src/nvim/api/options.c b/src/nvim/api/options.c
index ec1f19cf6a..92f20fff48 100644
--- a/src/nvim/api/options.c
+++ b/src/nvim/api/options.c
@@ -487,7 +487,7 @@ static getoption_T access_option_value(char *key, long *numval, char **stringval
                                        bool get, Error *err)
 {
   if (get) {
-    return get_option_value(key, numval, stringval, opt_flags);
+    return get_option_value(key, numval, stringval, NULL, opt_flags);
   } else {
     char *errmsg;
     if ((errmsg = set_option_value(key, *numval, *stringval, opt_flags))) {
-- 
cgit 


From 3435cdfb94b6f3c72e7f0f16fef9ff2660377cb2 Mon Sep 17 00:00:00 2001
From: Raphael 
Date: Mon, 7 Nov 2022 20:02:00 +0800
Subject: refactor(highlight): rename FloatBorderTitle #20988

requested in https://github.com/neovim/neovim/pull/20184
---
 src/nvim/api/win_config.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

(limited to 'src/nvim/api')

diff --git a/src/nvim/api/win_config.c b/src/nvim/api/win_config.c
index 9f15e5a85b..648048e970 100644
--- a/src/nvim/api/win_config.c
+++ b/src/nvim/api/win_config.c
@@ -139,7 +139,7 @@
 ///       [ {"+", "MyCorner"}, {"x", "MyBorder"} ].
 ///   - title: Title (optional) in window border, String or list.
 ///     List is [text, highlight] tuples. if is string the default
-///     highlight group is `FloatBorderTitle`.
+///     highlight group is `FloatTitle`.
 ///   - title_pos: Title position must set with title option.
 ///     value can be of `left` `center` `right` default is left.
 ///   - noautocmd: If true then no buffer-related autocommand events such as
@@ -364,7 +364,7 @@ static void parse_border_title(Object title, Object title_pos, FloatConfig *fcon
       fconfig->title = false;
       return;
     }
-    int hl_id = syn_check_group(S_LEN("FloatBorderTitle"));
+    int hl_id = syn_check_group(S_LEN("FloatTitle"));
     kv_push(fconfig->title_chunks, ((VirtTextChunk){ .text = xstrdup(title.data.string.data),
                                                      .hl_id = hl_id }));
     fconfig->title_width = (int)mb_string2cells(title.data.string.data);
-- 
cgit 


From c022140ec6a66402e405152054b6ab0141940419 Mon Sep 17 00:00:00 2001
From: Famiu Haque 
Date: Mon, 7 Nov 2022 22:27:37 +0600
Subject: feat(api): add command name to Lua command callback opts

Adds a `name` key to the opts dict passed to Lua command callbacks
created using `nvim_create_user_command()`. This is useful for when
multiple commands use the same callback.

Note that this kind of behavior is not as strange as one might think,
even some internal Neovim commands reuse the same internal C function,
differing their behavior by checking the command name. `substitute`,
`smagic` and `snomagic` are examples of that.

This will also be useful for generalized Lua command preview functions
that can preview a wide range of commands, in which case knowing the
command name is necessary for the preview function to actually be able
to execute the command that it's supposed to preview.
---
 src/nvim/api/command.c | 1 +
 1 file changed, 1 insertion(+)

(limited to 'src/nvim/api')

diff --git a/src/nvim/api/command.c b/src/nvim/api/command.c
index 8cd2c0f8b8..752d3868d5 100644
--- a/src/nvim/api/command.c
+++ b/src/nvim/api/command.c
@@ -884,6 +884,7 @@ static void build_cmdline_str(char **cmdlinep, exarg_T *eap, CmdParseInfo *cmdin
 /// @param  command Replacement command to execute when this user command is executed. When called
 ///                 from Lua, the command can also be a Lua function. The function is called with a
 ///                 single table argument that contains the following keys:
+///                 - name: (string) Command name
 ///                 - args: (string) The args passed to the command, if any ||
 ///                 - fargs: (table) The args split by unescaped whitespace (when more than one
 ///                 argument is allowed), if any ||
-- 
cgit 


From 8147d3df284a075f89746f9d5e948b5220c45f0b Mon Sep 17 00:00:00 2001
From: luukvbaal <31730729+luukvbaal@users.noreply.github.com>
Date: Tue, 8 Nov 2022 00:21:22 +0100
Subject: vim-patch:9.0.0844: handling 'statusline' errors is spread out
 (#20992)

Problem:    Handling 'statusline' errors is spread out.
Solution:   Pass the option name to the lower levels so the option can be
            reset there when an error is encountered. (Luuk van Baal,
            closes vim/vim#11467)

https://github.com/vim/vim/commit/7b224fdf4a29f115567d4fc8629c1cef92d8444a
---
 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 beb48b8d7d..d3f8c768a0 100644
--- a/src/nvim/api/vim.c
+++ b/src/nvim/api/vim.c
@@ -2223,7 +2223,8 @@ Dictionary nvim_eval_statusline(String str, Dict(eval_statusline) *opts, Error *
                                buf,
                                sizeof(buf),
                                str.data,
-                               false,
+                               NULL,
+                               0,
                                fillchar,
                                maxwidth,
                                hltab_ptr,
-- 
cgit 


From 7e6d785d19926714615758e75c4d43e856d13a6f Mon Sep 17 00:00:00 2001
From: Thomas Vigouroux 
Date: Tue, 13 Sep 2022 09:44:24 +0200
Subject: feat(extmarks): allow preventing spellchecking with spell = false

---
 src/nvim/api/extmark.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

(limited to 'src/nvim/api')

diff --git a/src/nvim/api/extmark.c b/src/nvim/api/extmark.c
index fee6876469..54eb7d9b6b 100644
--- a/src/nvim/api/extmark.c
+++ b/src/nvim/api/extmark.c
@@ -721,8 +721,12 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, Integer line, Integer
   bool ephemeral = false;
   OPTION_TO_BOOL(ephemeral, ephemeral, false);
 
-  OPTION_TO_BOOL(decor.spell, spell, false);
-  if (decor.spell) {
+  if (opts->spell.type == kObjectTypeNil) {
+    decor.spell = kNone;
+  } else {
+    bool spell = false;
+    OPTION_TO_BOOL(spell, spell, false);
+    decor.spell = spell ? kTrue : kFalse;
     has_decor = true;
   }
 
-- 
cgit 


From f8c671827710c6e9cca3bfd60c32098b2be8239a Mon Sep 17 00:00:00 2001
From: Lewis Russell 
Date: Mon, 14 Nov 2022 18:04:36 +0000
Subject: feat(lua-api): avoid unnecessary allocations (#19877)

Lua makes (or reuses) an internal copy of strings, so we can safely push
buf pointers onto the stack.
---
 src/nvim/api/buffer.c          | 131 ++++++++++++++++++++++++++++++++++-------
 src/nvim/api/buffer.h          |   3 +
 src/nvim/api/deprecated.c      |   4 +-
 src/nvim/api/options.c         |  11 ++--
 src/nvim/api/private/helpers.c |  55 +++--------------
 5 files changed, 130 insertions(+), 74 deletions(-)

(limited to 'src/nvim/api')

diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c
index 51fedb302a..29c2ed6028 100644
--- a/src/nvim/api/buffer.c
+++ b/src/nvim/api/buffer.c
@@ -271,6 +271,7 @@ ArrayOf(String) nvim_buf_get_lines(uint64_t channel_id,
                                    Integer start,
                                    Integer end,
                                    Boolean strict_indexing,
+                                   lua_State *lstate,
                                    Error *err)
   FUNC_API_SINCE(1)
 {
@@ -300,21 +301,18 @@ ArrayOf(String) nvim_buf_get_lines(uint64_t channel_id,
     return rv;
   }
 
-  rv.size = (size_t)(end - start);
-  rv.items = xcalloc(rv.size, sizeof(Object));
+  size_t size = (size_t)(end - start);
 
-  if (!buf_collect_lines(buf, rv.size, start,
-                         (channel_id != VIML_INTERNAL_CALL), &rv, err)) {
+  init_line_array(lstate, &rv, size);
+
+  if (!buf_collect_lines(buf, size, (linenr_T)start, (channel_id != VIML_INTERNAL_CALL), &rv,
+                         lstate, err)) {
     goto end;
   }
 
 end:
   if (ERROR_SET(err)) {
-    for (size_t i = 0; i < rv.size; i++) {
-      xfree(rv.items[i].data.string.data);
-    }
-
-    xfree(rv.items);
+    api_free_array(rv);
     rv.items = NULL;
   }
 
@@ -790,7 +788,8 @@ early_end:
 ArrayOf(String) nvim_buf_get_text(uint64_t channel_id, Buffer buffer,
                                   Integer start_row, Integer start_col,
                                   Integer end_row, Integer end_col,
-                                  Dictionary opts, Error *err)
+                                  Dictionary opts, lua_State *lstate,
+                                  Error *err)
   FUNC_API_SINCE(9)
 {
   Array rv = ARRAY_DICT_INIT;
@@ -830,33 +829,38 @@ ArrayOf(String) nvim_buf_get_text(uint64_t channel_id, Buffer buffer,
 
   bool replace_nl = (channel_id != VIML_INTERNAL_CALL);
 
+  size_t size = (size_t)(end_row - start_row) + 1;
+
+  init_line_array(lstate, &rv, size);
+
   if (start_row == end_row) {
-    String line = buf_get_text(buf, start_row, start_col, end_col, replace_nl, err);
+    String line = buf_get_text(buf, start_row, start_col, end_col, err);
     if (ERROR_SET(err)) {
-      return rv;
+      goto end;
     }
-
-    ADD(rv, STRING_OBJ(line));
+    push_linestr(lstate, &rv, line.data, line.size, 0, replace_nl);
     return rv;
   }
 
-  rv.size = (size_t)(end_row - start_row) + 1;
-  rv.items = xcalloc(rv.size, sizeof(Object));
+  String str = buf_get_text(buf, start_row, start_col, MAXCOL - 1, err);
+
+  push_linestr(lstate, &rv, str.data, str.size, 0, replace_nl);
 
-  rv.items[0] = STRING_OBJ(buf_get_text(buf, start_row, start_col, MAXCOL - 1, replace_nl, err));
   if (ERROR_SET(err)) {
     goto end;
   }
 
-  if (rv.size > 2) {
+  if (size > 2) {
     Array tmp = ARRAY_DICT_INIT;
     tmp.items = &rv.items[1];
-    if (!buf_collect_lines(buf, rv.size - 2, start_row + 1, replace_nl, &tmp, err)) {
+    if (!buf_collect_lines(buf, size - 2, (linenr_T)start_row + 1, replace_nl, &tmp, lstate, err)) {
       goto end;
     }
   }
 
-  rv.items[rv.size - 1] = STRING_OBJ(buf_get_text(buf, end_row, 0, end_col, replace_nl, err));
+  str = buf_get_text(buf, end_row, 0, end_col, err);
+  push_linestr(lstate, &rv, str.data, str.size, (int)(size - 1), replace_nl);
+
   if (ERROR_SET(err)) {
     goto end;
   }
@@ -1390,3 +1394,90 @@ static int64_t normalize_index(buf_T *buf, int64_t index, bool end_exclusive, bo
   index++;
   return index;
 }
+
+/// Initialise a string array either:
+/// - on the Lua stack (as a table) (if lstate is not NULL)
+/// - as an API array object (if lstate is NULL).
+///
+/// @param lstate  Lua state. When NULL the Array is initialized instead.
+/// @param a       Array to initialize
+/// @param size    Size of array
+static inline void init_line_array(lua_State *lstate, Array *a, size_t size)
+{
+  if (lstate) {
+    lua_createtable(lstate, (int)size, 0);
+  } else {
+    a->size = size;
+    a->items = xcalloc(a->size, sizeof(Object));
+  }
+}
+
+/// Push a string onto either the Lua stack (as a table element) or an API array object.
+///
+/// For Lua, a table of the correct size must be created first.
+/// API array objects must be pre allocated.
+///
+/// @param lstate      Lua state. When NULL the Array is pushed to instead.
+/// @param a           Array to push onto when not using Lua
+/// @param s           String to push
+/// @param len         Size of string
+/// @param idx         0-based index to place s
+/// @param replace_nl  Replace newlines ('\n') with null ('\0')
+static void push_linestr(lua_State *lstate, Array *a, const char *s, size_t len, int idx,
+                         bool replace_nl)
+{
+  if (lstate) {
+    // Vim represents NULs as NLs
+    if (s && replace_nl && strchr(s, '\n')) {
+      char *tmp = xmemdupz(s, len);
+      strchrsub(tmp, '\n', '\0');
+      lua_pushlstring(lstate, tmp, len);
+      xfree(tmp);
+    } else {
+      lua_pushlstring(lstate, s, len);
+    }
+    lua_rawseti(lstate, -2, idx + 1);
+  } else {
+    String str = STRING_INIT;
+    if (s) {
+      str = cbuf_to_string(s, len);
+      if (replace_nl) {
+        // Vim represents NULs as NLs, but this may confuse clients.
+        strchrsub(str.data, '\n', '\0');
+      }
+    }
+
+    a->items[idx] = STRING_OBJ(str);
+  }
+}
+
+/// Collects `n` buffer lines into array `l` and/or lua_State `lstate`, optionally replacing
+/// newlines with NUL.
+///
+/// @param buf Buffer to get lines from
+/// @param n Number of lines to collect
+/// @param replace_nl Replace newlines ("\n") with NUL
+/// @param start Line number to start from
+/// @param[out] l If not NULL, Lines are copied here
+/// @param[out] lstate If not NULL, Lines are pushed into a table onto the stack
+/// @param err[out] Error, if any
+/// @return true unless `err` was set
+bool buf_collect_lines(buf_T *buf, size_t n, linenr_T start, bool replace_nl, Array *l,
+                       lua_State *lstate, Error *err)
+{
+  for (size_t i = 0; i < n; i++) {
+    linenr_T lnum = start + (linenr_T)i;
+
+    if (lnum >= MAXLNUM) {
+      if (err != NULL) {
+        api_set_error(err, kErrorTypeValidation, "Line index is too high");
+      }
+      return false;
+    }
+
+    char *bufstr = ml_get_buf(buf, lnum, false);
+    push_linestr(lstate, l, bufstr, strlen(bufstr), (int)i, replace_nl);
+  }
+
+  return true;
+}
diff --git a/src/nvim/api/buffer.h b/src/nvim/api/buffer.h
index 1c4a93a587..0814da63cd 100644
--- a/src/nvim/api/buffer.h
+++ b/src/nvim/api/buffer.h
@@ -1,7 +1,10 @@
 #ifndef NVIM_API_BUFFER_H
 #define NVIM_API_BUFFER_H
 
+#include 
+
 #include "nvim/api/private/defs.h"
+#include "nvim/buffer_defs.h"
 
 #ifdef INCLUDE_GENERATED_DECLARATIONS
 # include "api/buffer.h.generated.h"
diff --git a/src/nvim/api/deprecated.c b/src/nvim/api/deprecated.c
index abaac07755..8e1a615bbb 100644
--- a/src/nvim/api/deprecated.c
+++ b/src/nvim/api/deprecated.c
@@ -190,7 +190,7 @@ String buffer_get_line(Buffer buffer, Integer index, Error *err)
   String rv = { .size = 0 };
 
   index = convert_index(index);
-  Array slice = nvim_buf_get_lines(0, buffer, index, index + 1, true, err);
+  Array slice = nvim_buf_get_lines(0, buffer, index, index + 1, true, NULL, err);
 
   if (!ERROR_SET(err) && slice.size) {
     rv = slice.items[0].data.string;
@@ -263,7 +263,7 @@ ArrayOf(String) buffer_get_line_slice(Buffer buffer,
 {
   start = convert_index(start) + !include_start;
   end = convert_index(end) + include_end;
-  return nvim_buf_get_lines(0, buffer, start, end, false, err);
+  return nvim_buf_get_lines(0, buffer, start, end, false, NULL, err);
 }
 
 /// Replaces a line range on the buffer
diff --git a/src/nvim/api/options.c b/src/nvim/api/options.c
index 92f20fff48..1b04392d47 100644
--- a/src/nvim/api/options.c
+++ b/src/nvim/api/options.c
@@ -256,7 +256,7 @@ void nvim_set_option(uint64_t channel_id, String name, Object value, Error *err)
 /// @param name     Option name
 /// @param[out] err Error details, if any
 /// @return         Option value (global)
-Object nvim_get_option(String name, Error *err)
+Object nvim_get_option(String name, Arena *arena, Error *err)
   FUNC_API_SINCE(1)
 {
   return get_option_from(NULL, SREQ_GLOBAL, name, err);
@@ -268,7 +268,7 @@ Object nvim_get_option(String name, Error *err)
 /// @param name       Option name
 /// @param[out] err   Error details, if any
 /// @return Option value
-Object nvim_buf_get_option(Buffer buffer, String name, Error *err)
+Object nvim_buf_get_option(Buffer buffer, String name, Arena *arena, Error *err)
   FUNC_API_SINCE(1)
 {
   buf_T *buf = find_buffer_by_handle(buffer, err);
@@ -306,7 +306,7 @@ void nvim_buf_set_option(uint64_t channel_id, Buffer buffer, String name, Object
 /// @param name     Option name
 /// @param[out] err Error details, if any
 /// @return Option value
-Object nvim_win_get_option(Window window, String name, Error *err)
+Object nvim_win_get_option(Window window, String name, Arena *arena, Error *err)
   FUNC_API_SINCE(1)
 {
   win_T *win = find_window_by_handle(window, err);
@@ -346,7 +346,7 @@ void nvim_win_set_option(uint64_t channel_id, Window window, String name, Object
 /// @param name The option name
 /// @param[out] err Details of an error that may have occurred
 /// @return the option value
-Object get_option_from(void *from, int type, String name, Error *err)
+static Object get_option_from(void *from, int type, String name, Error *err)
 {
   Object rv = OBJECT_INIT;
 
@@ -358,8 +358,7 @@ Object get_option_from(void *from, int type, String name, Error *err)
   // Return values
   int64_t numval;
   char *stringval = NULL;
-  int flags = get_option_value_strict(name.data, &numval, &stringval,
-                                      type, from);
+  int flags = get_option_value_strict(name.data, &numval, &stringval, type, from);
 
   if (!flags) {
     api_set_error(err, kErrorTypeValidation, "Invalid option name: '%s'",
diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c
index 73b5489d5c..d10d17c88d 100644
--- a/src/nvim/api/private/helpers.c
+++ b/src/nvim/api/private/helpers.c
@@ -394,6 +394,12 @@ String cstrn_to_string(const char *str, size_t maxsize)
   return cbuf_to_string(str, STRNLEN(str, maxsize));
 }
 
+String cstrn_as_string(char *str, size_t maxsize)
+  FUNC_ATTR_NONNULL_ALL
+{
+  return cbuf_as_string(str, STRNLEN(str, maxsize));
+}
+
 /// Creates a String using the given C string. Unlike
 /// cstr_to_string this function DOES NOT copy the C string.
 ///
@@ -462,53 +468,15 @@ Array string_to_array(const String input, bool crlf)
   return ret;
 }
 
-/// Collects `n` buffer lines into array `l`, optionally replacing newlines
-/// with NUL.
-///
-/// @param buf Buffer to get lines from
-/// @param n Number of lines to collect
-/// @param replace_nl Replace newlines ("\n") with NUL
-/// @param start Line number to start from
-/// @param[out] l Lines are copied here
-/// @param err[out] Error, if any
-/// @return true unless `err` was set
-bool buf_collect_lines(buf_T *buf, size_t n, int64_t start, bool replace_nl, Array *l, Error *err)
-{
-  for (size_t i = 0; i < n; i++) {
-    int64_t lnum = start + (int64_t)i;
-
-    if (lnum >= MAXLNUM) {
-      if (err != NULL) {
-        api_set_error(err, kErrorTypeValidation, "Line index is too high");
-      }
-      return false;
-    }
-
-    const char *bufstr = ml_get_buf(buf, (linenr_T)lnum, false);
-    Object str = STRING_OBJ(cstr_to_string(bufstr));
-
-    if (replace_nl) {
-      // Vim represents NULs as NLs, but this may confuse clients.
-      strchrsub(str.data.string.data, '\n', '\0');
-    }
-
-    l->items[i] = str;
-  }
-
-  return true;
-}
-
 /// Returns a substring of a buffer line
 ///
 /// @param buf          Buffer handle
 /// @param lnum         Line number (1-based)
 /// @param start_col    Starting byte offset into line (0-based)
 /// @param end_col      Ending byte offset into line (0-based, exclusive)
-/// @param replace_nl   Replace newlines ('\n') with null ('\0')
 /// @param err          Error object
 /// @return The text between start_col and end_col on line lnum of buffer buf
-String buf_get_text(buf_T *buf, int64_t lnum, int64_t start_col, int64_t end_col, bool replace_nl,
-                    Error *err)
+String buf_get_text(buf_T *buf, int64_t lnum, int64_t start_col, int64_t end_col, Error *err)
 {
   String rv = STRING_INIT;
 
@@ -517,7 +485,7 @@ String buf_get_text(buf_T *buf, int64_t lnum, int64_t start_col, int64_t end_col
     return rv;
   }
 
-  const char *bufstr = ml_get_buf(buf, (linenr_T)lnum, false);
+  char *bufstr = ml_get_buf(buf, (linenr_T)lnum, false);
   size_t line_length = strlen(bufstr);
 
   start_col = start_col < 0 ? (int64_t)line_length + start_col + 1 : start_col;
@@ -537,12 +505,7 @@ String buf_get_text(buf_T *buf, int64_t lnum, int64_t start_col, int64_t end_col
     return rv;
   }
 
-  rv = cstrn_to_string(&bufstr[start_col], (size_t)(end_col - start_col));
-  if (replace_nl) {
-    strchrsub(rv.data, '\n', '\0');
-  }
-
-  return rv;
+  return cstrn_as_string((char *)&bufstr[start_col], (size_t)(end_col - start_col));
 }
 
 void api_free_string(String value)
-- 
cgit 


From 66360675cf4d091b7460e4a8e1435c13216c1929 Mon Sep 17 00:00:00 2001
From: dundargoc 
Date: Sun, 11 Sep 2022 17:12:44 +0200
Subject: build: allow IWYU to fix includes for all .c files

Allow Include What You Use to remove unnecessary includes and only
include what is necessary. This helps with reducing compilation times
and makes it easier to visualise which dependencies are actually
required.

Work on https://github.com/neovim/neovim/issues/549, but doesn't close
it since this only works fully for .c files and not headers.
---
 src/nvim/api/autocmd.c           |  9 +++++++++
 src/nvim/api/buffer.c            | 16 +++++++++++-----
 src/nvim/api/command.c           | 21 ++++++++++++++++++---
 src/nvim/api/deprecated.c        |  8 ++++++--
 src/nvim/api/extmark.c           | 13 +++++++++++--
 src/nvim/api/extmark.h           |  3 +++
 src/nvim/api/options.c           | 12 ++++++------
 src/nvim/api/private/converter.c |  9 ++++++++-
 src/nvim/api/private/dispatch.c  | 29 +----------------------------
 src/nvim/api/private/dispatch.h  |  5 +++++
 src/nvim/api/private/helpers.c   | 18 +++++++++---------
 src/nvim/api/private/helpers.h   |  6 ++++++
 src/nvim/api/tabpage.c           |  3 ++-
 src/nvim/api/ui.c                | 16 ++++++++++++----
 src/nvim/api/vim.c               | 31 ++++++++++++++++---------------
 src/nvim/api/vimscript.c         | 17 +++++++++++------
 src/nvim/api/win_config.c        | 15 ++++++++++-----
 src/nvim/api/window.c            |  9 +++++----
 18 files changed, 149 insertions(+), 91 deletions(-)

(limited to 'src/nvim/api')

diff --git a/src/nvim/api/autocmd.c b/src/nvim/api/autocmd.c
index 3dfe77ba38..af185c50c9 100644
--- a/src/nvim/api/autocmd.c
+++ b/src/nvim/api/autocmd.c
@@ -1,8 +1,12 @@
 // This is an open source non-commercial project. Dear PVS-Studio, please check
 // it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
 
+#include 
 #include 
+#include 
 #include 
+#include 
+#include 
 
 #include "lauxlib.h"
 #include "nvim/api/autocmd.h"
@@ -12,7 +16,12 @@
 #include "nvim/autocmd.h"
 #include "nvim/buffer.h"
 #include "nvim/eval/typval.h"
+#include "nvim/eval/typval_defs.h"
+#include "nvim/ex_cmds_defs.h"
+#include "nvim/globals.h"
 #include "nvim/lua/executor.h"
+#include "nvim/memory.h"
+#include "nvim/vim.h"
 
 #ifdef INCLUDE_GENERATED_DECLARATIONS
 # include "api/autocmd.c.generated.h"
diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c
index 29c2ed6028..1101689391 100644
--- a/src/nvim/api/buffer.c
+++ b/src/nvim/api/buffer.c
@@ -3,25 +3,30 @@
 
 // Some of this code was adapted from 'if_py_both.h' from the original
 // vim source
+
+#include 
 #include 
-#include 
 #include 
+#include 
 #include 
-#include 
+#include 
 
+#include "klib/kvec.h"
+#include "lua.h"
 #include "nvim/api/buffer.h"
 #include "nvim/api/private/defs.h"
 #include "nvim/api/private/helpers.h"
+#include "nvim/ascii.h"
 #include "nvim/autocmd.h"
 #include "nvim/buffer.h"
+#include "nvim/buffer_defs.h"
 #include "nvim/buffer_updates.h"
 #include "nvim/change.h"
 #include "nvim/cursor.h"
-#include "nvim/decoration.h"
 #include "nvim/drawscreen.h"
 #include "nvim/ex_cmds.h"
-#include "nvim/ex_docmd.h"
 #include "nvim/extmark.h"
+#include "nvim/globals.h"
 #include "nvim/lua/executor.h"
 #include "nvim/mapping.h"
 #include "nvim/mark.h"
@@ -29,9 +34,10 @@
 #include "nvim/memory.h"
 #include "nvim/move.h"
 #include "nvim/ops.h"
+#include "nvim/pos.h"
+#include "nvim/types.h"
 #include "nvim/undo.h"
 #include "nvim/vim.h"
-#include "nvim/window.h"
 
 #ifdef INCLUDE_GENERATED_DECLARATIONS
 # include "api/buffer.c.generated.h"
diff --git a/src/nvim/api/command.c b/src/nvim/api/command.c
index 752d3868d5..8a7abf0845 100644
--- a/src/nvim/api/command.c
+++ b/src/nvim/api/command.c
@@ -1,21 +1,36 @@
 // This is an open source non-commercial project. Dear PVS-Studio, please check
 // it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
 
+#include 
 #include 
-#include 
-#include 
+#include 
+#include 
 
+#include "klib/kvec.h"
+#include "lauxlib.h"
 #include "nvim/api/command.h"
-#include "nvim/api/private/converter.h"
 #include "nvim/api/private/defs.h"
 #include "nvim/api/private/helpers.h"
+#include "nvim/ascii.h"
 #include "nvim/autocmd.h"
+#include "nvim/buffer_defs.h"
+#include "nvim/decoration.h"
+#include "nvim/ex_cmds.h"
 #include "nvim/ex_docmd.h"
 #include "nvim/ex_eval.h"
+#include "nvim/garray.h"
+#include "nvim/globals.h"
 #include "nvim/lua/executor.h"
+#include "nvim/macros.h"
+#include "nvim/mbyte.h"
+#include "nvim/memory.h"
 #include "nvim/ops.h"
+#include "nvim/pos.h"
 #include "nvim/regexp.h"
+#include "nvim/strings.h"
+#include "nvim/types.h"
 #include "nvim/usercmd.h"
+#include "nvim/vim.h"
 #include "nvim/window.h"
 
 #ifdef INCLUDE_GENERATED_DECLARATIONS
diff --git a/src/nvim/api/deprecated.c b/src/nvim/api/deprecated.c
index 8e1a615bbb..332e2b5fc3 100644
--- a/src/nvim/api/deprecated.c
+++ b/src/nvim/api/deprecated.c
@@ -1,7 +1,6 @@
 // This is an open source non-commercial project. Dear PVS-Studio, please check
 // it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
 
-#include 
 #include 
 #include 
 #include 
@@ -11,10 +10,15 @@
 #include "nvim/api/extmark.h"
 #include "nvim/api/private/defs.h"
 #include "nvim/api/private/helpers.h"
-#include "nvim/api/vim.h"
 #include "nvim/api/vimscript.h"
+#include "nvim/buffer_defs.h"
+#include "nvim/decoration.h"
 #include "nvim/extmark.h"
+#include "nvim/globals.h"
 #include "nvim/lua/executor.h"
+#include "nvim/memory.h"
+#include "nvim/pos.h"
+#include "nvim/types.h"
 
 #ifdef INCLUDE_GENERATED_DECLARATIONS
 # include "api/deprecated.c.generated.h"
diff --git a/src/nvim/api/extmark.c b/src/nvim/api/extmark.c
index 54eb7d9b6b..3a96c42dba 100644
--- a/src/nvim/api/extmark.c
+++ b/src/nvim/api/extmark.c
@@ -1,20 +1,29 @@
 // This is an open source non-commercial project. Dear PVS-Studio, please check
 // it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
 
+#include 
 #include 
 #include 
-#include 
+#include 
 
+#include "klib/kvec.h"
+#include "lauxlib.h"
 #include "nvim/api/extmark.h"
 #include "nvim/api/private/defs.h"
 #include "nvim/api/private/helpers.h"
+#include "nvim/buffer_defs.h"
 #include "nvim/charset.h"
+#include "nvim/decoration.h"
 #include "nvim/decoration_provider.h"
 #include "nvim/drawscreen.h"
 #include "nvim/extmark.h"
 #include "nvim/highlight_group.h"
-#include "nvim/lua/executor.h"
+#include "nvim/mbyte.h"
 #include "nvim/memline.h"
+#include "nvim/memory.h"
+#include "nvim/pos.h"
+#include "nvim/strings.h"
+#include "nvim/vim.h"
 
 #ifdef INCLUDE_GENERATED_DECLARATIONS
 # include "api/extmark.c.generated.h"
diff --git a/src/nvim/api/extmark.h b/src/nvim/api/extmark.h
index 74802c6efb..0a627a889c 100644
--- a/src/nvim/api/extmark.h
+++ b/src/nvim/api/extmark.h
@@ -3,7 +3,10 @@
 
 #include "nvim/api/private/defs.h"
 #include "nvim/decoration.h"
+#include "nvim/macros.h"
 #include "nvim/map.h"
+#include "nvim/map_defs.h"
+#include "nvim/types.h"
 
 EXTERN Map(String, handle_T) namespace_ids INIT(= MAP_INIT);
 EXTERN handle_T next_namespace_id INIT(= 1);
diff --git a/src/nvim/api/options.c b/src/nvim/api/options.c
index 1b04392d47..d705636479 100644
--- a/src/nvim/api/options.c
+++ b/src/nvim/api/options.c
@@ -1,20 +1,20 @@
 // This is an open source non-commercial project. Dear PVS-Studio, please check
 // it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
 
-#include 
 #include 
+#include 
 #include 
-#include 
-#include 
 #include 
 
 #include "nvim/api/options.h"
-#include "nvim/api/private/converter.h"
+#include "nvim/api/private/defs.h"
 #include "nvim/api/private/helpers.h"
 #include "nvim/autocmd.h"
-#include "nvim/buffer.h"
+#include "nvim/buffer_defs.h"
+#include "nvim/globals.h"
+#include "nvim/memory.h"
 #include "nvim/option.h"
-#include "nvim/option_defs.h"
+#include "nvim/vim.h"
 #include "nvim/window.h"
 
 #ifdef INCLUDE_GENERATED_DECLARATIONS
diff --git a/src/nvim/api/private/converter.c b/src/nvim/api/private/converter.c
index b6b3c83f3c..7770ba39d8 100644
--- a/src/nvim/api/private/converter.c
+++ b/src/nvim/api/private/converter.c
@@ -2,17 +2,24 @@
 // it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
 
 #include 
+#include 
 #include 
+#include 
 #include 
 
+#include "klib/kvec.h"
 #include "nvim/api/private/converter.h"
 #include "nvim/api/private/defs.h"
 #include "nvim/api/private/helpers.h"
 #include "nvim/assert.h"
 #include "nvim/eval/typval.h"
+#include "nvim/eval/typval_defs.h"
 #include "nvim/eval/userfunc.h"
-#include "nvim/lua/converter.h"
+#include "nvim/garray.h"
 #include "nvim/lua/executor.h"
+#include "nvim/memory.h"
+#include "nvim/types.h"
+#include "nvim/vim.h"
 
 /// Helper structure for vim_to_object
 typedef struct {
diff --git a/src/nvim/api/private/dispatch.c b/src/nvim/api/private/dispatch.c
index d6a6fc1219..f427bba00e 100644
--- a/src/nvim/api/private/dispatch.c
+++ b/src/nvim/api/private/dispatch.c
@@ -1,38 +1,11 @@
 // This is an open source non-commercial project. Dear PVS-Studio, please check
 // it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
 
-#include 
-#include 
-#include 
-#include 
+#include 
 
-#include "nvim/api/deprecated.h"
 #include "nvim/api/private/defs.h"
 #include "nvim/api/private/dispatch.h"
 #include "nvim/api/private/helpers.h"
-#include "nvim/log.h"
-#include "nvim/map.h"
-#include "nvim/msgpack_rpc/helpers.h"
-#include "nvim/vim.h"
-
-// ===========================================================================
-// NEW API FILES MUST GO HERE.
-//
-//  When creating a new API file, you must include it here,
-//  so that the dispatcher can find the C functions that you are creating!
-// ===========================================================================
-#include "nvim/api/autocmd.h"
-#include "nvim/api/buffer.h"
-#include "nvim/api/command.h"
-#include "nvim/api/extmark.h"
-#include "nvim/api/options.h"
-#include "nvim/api/tabpage.h"
-#include "nvim/api/ui.h"
-#include "nvim/api/vim.h"
-#include "nvim/api/vimscript.h"
-#include "nvim/api/win_config.h"
-#include "nvim/api/window.h"
-#include "nvim/ui_client.h"
 
 #ifdef INCLUDE_GENERATED_DECLARATIONS
 # include "api/private/dispatch_wrappers.generated.h"
diff --git a/src/nvim/api/private/dispatch.h b/src/nvim/api/private/dispatch.h
index f0161a53a8..4ae61b2bfb 100644
--- a/src/nvim/api/private/dispatch.h
+++ b/src/nvim/api/private/dispatch.h
@@ -1,7 +1,12 @@
 #ifndef NVIM_API_PRIVATE_DISPATCH_H
 #define NVIM_API_PRIVATE_DISPATCH_H
 
+#include 
+#include 
+
 #include "nvim/api/private/defs.h"
+#include "nvim/memory.h"
+#include "nvim/types.h"
 
 typedef Object (*ApiDispatchWrapper)(uint64_t channel_id, Array args, Arena *arena, Error *error);
 
diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c
index d10d17c88d..b7cd0c82fb 100644
--- a/src/nvim/api/private/helpers.c
+++ b/src/nvim/api/private/helpers.c
@@ -3,8 +3,12 @@
 
 #include 
 #include 
+#include 
+#include 
+#include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -12,28 +16,24 @@
 #include "nvim/api/private/converter.h"
 #include "nvim/api/private/defs.h"
 #include "nvim/api/private/helpers.h"
-#include "nvim/api/vim.h"
 #include "nvim/ascii.h"
-#include "nvim/assert.h"
-#include "nvim/buffer.h"
-#include "nvim/charset.h"
-#include "nvim/eval.h"
+#include "nvim/buffer_defs.h"
 #include "nvim/eval/typval.h"
-#include "nvim/ex_cmds_defs.h"
+#include "nvim/eval/typval_defs.h"
 #include "nvim/ex_eval.h"
-#include "nvim/extmark.h"
+#include "nvim/garray.h"
 #include "nvim/highlight_group.h"
 #include "nvim/lua/executor.h"
 #include "nvim/map.h"
-#include "nvim/map_defs.h"
 #include "nvim/mark.h"
 #include "nvim/memline.h"
 #include "nvim/memory.h"
+#include "nvim/message.h"
 #include "nvim/msgpack_rpc/helpers.h"
+#include "nvim/pos.h"
 #include "nvim/ui.h"
 #include "nvim/version.h"
 #include "nvim/vim.h"
-#include "nvim/window.h"
 
 #ifdef INCLUDE_GENERATED_DECLARATIONS
 # include "api/private/funcs_metadata.generated.h"
diff --git a/src/nvim/api/private/helpers.h b/src/nvim/api/private/helpers.h
index 65215fa8c8..ec97ba9ec6 100644
--- a/src/nvim/api/private/helpers.h
+++ b/src/nvim/api/private/helpers.h
@@ -1,11 +1,17 @@
 #ifndef NVIM_API_PRIVATE_HELPERS_H
 #define NVIM_API_PRIVATE_HELPERS_H
 
+#include 
+#include 
+
 #include "klib/kvec.h"
 #include "nvim/api/private/defs.h"
 #include "nvim/decoration.h"
 #include "nvim/ex_eval_defs.h"
 #include "nvim/getchar.h"
+#include "nvim/globals.h"
+#include "nvim/macros.h"
+#include "nvim/map.h"
 #include "nvim/memory.h"
 #include "nvim/vim.h"
 
diff --git a/src/nvim/api/tabpage.c b/src/nvim/api/tabpage.c
index 31f9fab82a..21eb326c3b 100644
--- a/src/nvim/api/tabpage.c
+++ b/src/nvim/api/tabpage.c
@@ -2,13 +2,14 @@
 // it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
 
 #include 
-#include 
 #include 
 
 #include "nvim/api/private/defs.h"
 #include "nvim/api/private/helpers.h"
 #include "nvim/api/tabpage.h"
 #include "nvim/api/vim.h"
+#include "nvim/buffer_defs.h"
+#include "nvim/globals.h"
 #include "nvim/memory.h"
 #include "nvim/window.h"
 
diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c
index f251e0043f..aeccddb9ea 100644
--- a/src/nvim/api/ui.c
+++ b/src/nvim/api/ui.c
@@ -2,26 +2,34 @@
 // it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
 
 #include 
+#include 
+#include 
 #include 
-#include 
 #include 
+#include 
+#include 
 
+#include "klib/kvec.h"
 #include "nvim/api/private/defs.h"
 #include "nvim/api/private/helpers.h"
 #include "nvim/api/ui.h"
 #include "nvim/channel.h"
-#include "nvim/cursor_shape.h"
+#include "nvim/event/loop.h"
+#include "nvim/event/wstream.h"
+#include "nvim/globals.h"
 #include "nvim/grid.h"
 #include "nvim/highlight.h"
+#include "nvim/main.h"
 #include "nvim/map.h"
+#include "nvim/mbyte.h"
 #include "nvim/memory.h"
 #include "nvim/msgpack_rpc/channel.h"
+#include "nvim/msgpack_rpc/channel_defs.h"
 #include "nvim/msgpack_rpc/helpers.h"
 #include "nvim/option.h"
-#include "nvim/popupmenu.h"
+#include "nvim/types.h"
 #include "nvim/ui.h"
 #include "nvim/vim.h"
-#include "nvim/window.h"
 
 typedef struct {
   uint64_t channel_id;
diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c
index d3f8c768a0..7a5ea7aa95 100644
--- a/src/nvim/api/vim.c
+++ b/src/nvim/api/vim.c
@@ -5,9 +5,13 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 #include 
 #include 
 
+#include "klib/kvec.h"
+#include "lauxlib.h"
 #include "nvim/api/buffer.h"
 #include "nvim/api/deprecated.h"
 #include "nvim/api/private/converter.h"
@@ -15,55 +19,52 @@
 #include "nvim/api/private/dispatch.h"
 #include "nvim/api/private/helpers.h"
 #include "nvim/api/vim.h"
-#include "nvim/api/window.h"
 #include "nvim/ascii.h"
+#include "nvim/autocmd.h"
 #include "nvim/buffer.h"
-#include "nvim/buffer_defs.h"
-#include "nvim/charset.h"
+#include "nvim/channel.h"
 #include "nvim/context.h"
-#include "nvim/decoration.h"
-#include "nvim/decoration_provider.h"
 #include "nvim/drawscreen.h"
-#include "nvim/edit.h"
 #include "nvim/eval.h"
 #include "nvim/eval/typval.h"
-#include "nvim/eval/userfunc.h"
-#include "nvim/ex_cmds_defs.h"
+#include "nvim/eval/typval_defs.h"
 #include "nvim/ex_docmd.h"
 #include "nvim/ex_eval.h"
-#include "nvim/file_search.h"
-#include "nvim/fileio.h"
 #include "nvim/getchar.h"
 #include "nvim/globals.h"
 #include "nvim/grid.h"
 #include "nvim/highlight.h"
-#include "nvim/highlight_defs.h"
 #include "nvim/highlight_group.h"
-#include "nvim/insexpand.h"
+#include "nvim/keycodes.h"
+#include "nvim/log.h"
 #include "nvim/lua/executor.h"
+#include "nvim/macros.h"
 #include "nvim/mapping.h"
 #include "nvim/mark.h"
+#include "nvim/mbyte.h"
 #include "nvim/memline.h"
 #include "nvim/memory.h"
 #include "nvim/message.h"
 #include "nvim/move.h"
 #include "nvim/msgpack_rpc/channel.h"
-#include "nvim/msgpack_rpc/helpers.h"
+#include "nvim/msgpack_rpc/channel_defs.h"
 #include "nvim/msgpack_rpc/unpacker.h"
 #include "nvim/ops.h"
 #include "nvim/option.h"
 #include "nvim/optionstr.h"
 #include "nvim/os/input.h"
+#include "nvim/os/os_defs.h"
 #include "nvim/os/process.h"
 #include "nvim/popupmenu.h"
+#include "nvim/pos.h"
 #include "nvim/runtime.h"
 #include "nvim/state.h"
 #include "nvim/statusline.h"
+#include "nvim/strings.h"
+#include "nvim/terminal.h"
 #include "nvim/types.h"
 #include "nvim/ui.h"
 #include "nvim/vim.h"
-#include "nvim/viml/parser/expressions.h"
-#include "nvim/viml/parser/parser.h"
 #include "nvim/window.h"
 
 #define LINE_BUFFER_MIN_SIZE 4096
diff --git a/src/nvim/api/vimscript.c b/src/nvim/api/vimscript.c
index dccc2d42d8..af1b23b712 100644
--- a/src/nvim/api/vimscript.c
+++ b/src/nvim/api/vimscript.c
@@ -2,26 +2,31 @@
 // it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
 
 #include 
-#include 
-#include 
+#include 
+#include 
+#include 
+#include 
 
+#include "klib/kvec.h"
 #include "nvim/api/private/converter.h"
 #include "nvim/api/private/defs.h"
 #include "nvim/api/private/helpers.h"
 #include "nvim/api/vimscript.h"
 #include "nvim/ascii.h"
-#include "nvim/autocmd.h"
+#include "nvim/buffer_defs.h"
 #include "nvim/eval.h"
 #include "nvim/eval/typval.h"
+#include "nvim/eval/typval_defs.h"
 #include "nvim/eval/userfunc.h"
 #include "nvim/ex_docmd.h"
-#include "nvim/ops.h"
+#include "nvim/garray.h"
+#include "nvim/globals.h"
+#include "nvim/memory.h"
+#include "nvim/pos.h"
 #include "nvim/runtime.h"
-#include "nvim/strings.h"
 #include "nvim/vim.h"
 #include "nvim/viml/parser/expressions.h"
 #include "nvim/viml/parser/parser.h"
-#include "nvim/window.h"
 
 #ifdef INCLUDE_GENERATED_DECLARATIONS
 # include "api/vimscript.c.generated.h"
diff --git a/src/nvim/api/win_config.c b/src/nvim/api/win_config.c
index 648048e970..532052f9b0 100644
--- a/src/nvim/api/win_config.c
+++ b/src/nvim/api/win_config.c
@@ -1,22 +1,27 @@
 // This is an open source non-commercial project. Dear PVS-Studio, please check
 // it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
 
-#include 
-#include 
 #include 
-#include 
-#include 
+#include 
 
+#include "klib/kvec.h"
 #include "nvim/api/extmark.h"
 #include "nvim/api/private/defs.h"
 #include "nvim/api/private/helpers.h"
 #include "nvim/api/win_config.h"
 #include "nvim/ascii.h"
 #include "nvim/buffer_defs.h"
+#include "nvim/decoration.h"
 #include "nvim/drawscreen.h"
+#include "nvim/extmark_defs.h"
+#include "nvim/globals.h"
+#include "nvim/grid_defs.h"
 #include "nvim/highlight_group.h"
+#include "nvim/macros.h"
+#include "nvim/mbyte.h"
+#include "nvim/memory.h"
 #include "nvim/option.h"
-#include "nvim/strings.h"
+#include "nvim/pos.h"
 #include "nvim/syntax.h"
 #include "nvim/ui.h"
 #include "nvim/window.h"
diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c
index 08dcc113da..3f7c734cd1 100644
--- a/src/nvim/api/window.c
+++ b/src/nvim/api/window.c
@@ -10,16 +10,17 @@
 #include "nvim/api/private/helpers.h"
 #include "nvim/api/window.h"
 #include "nvim/ascii.h"
-#include "nvim/buffer.h"
+#include "nvim/buffer_defs.h"
 #include "nvim/cursor.h"
 #include "nvim/drawscreen.h"
 #include "nvim/ex_docmd.h"
+#include "nvim/gettext.h"
 #include "nvim/globals.h"
 #include "nvim/lua/executor.h"
+#include "nvim/memline_defs.h"
 #include "nvim/move.h"
-#include "nvim/option.h"
-#include "nvim/syntax.h"
-#include "nvim/vim.h"
+#include "nvim/pos.h"
+#include "nvim/types.h"
 #include "nvim/window.h"
 
 /// Gets the current buffer in a window
-- 
cgit 


From fa7e1e26019112ff9e2ea42626995f04e2a4e032 Mon Sep 17 00:00:00 2001
From: Lewis Russell 
Date: Tue, 15 Nov 2022 21:27:42 +0000
Subject: fix(api): nvim_buf_get_text regression (#21071)

---
 src/nvim/api/buffer.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

(limited to 'src/nvim/api')

diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c
index 1101689391..0a31286df7 100644
--- a/src/nvim/api/buffer.c
+++ b/src/nvim/api/buffer.c
@@ -311,7 +311,7 @@ ArrayOf(String) nvim_buf_get_lines(uint64_t channel_id,
 
   init_line_array(lstate, &rv, size);
 
-  if (!buf_collect_lines(buf, size, (linenr_T)start, (channel_id != VIML_INTERNAL_CALL), &rv,
+  if (!buf_collect_lines(buf, size, (linenr_T)start, 0, (channel_id != VIML_INTERNAL_CALL), &rv,
                          lstate, err)) {
     goto end;
   }
@@ -857,9 +857,8 @@ ArrayOf(String) nvim_buf_get_text(uint64_t channel_id, Buffer buffer,
   }
 
   if (size > 2) {
-    Array tmp = ARRAY_DICT_INIT;
-    tmp.items = &rv.items[1];
-    if (!buf_collect_lines(buf, size - 2, (linenr_T)start_row + 1, replace_nl, &tmp, lstate, err)) {
+    if (!buf_collect_lines(buf, size - 2, (linenr_T)start_row + 1, 1, replace_nl, &rv, lstate,
+                           err)) {
       goto end;
     }
   }
@@ -1464,12 +1463,13 @@ static void push_linestr(lua_State *lstate, Array *a, const char *s, size_t len,
 /// @param n Number of lines to collect
 /// @param replace_nl Replace newlines ("\n") with NUL
 /// @param start Line number to start from
+/// @param start_idx First index to push to
 /// @param[out] l If not NULL, Lines are copied here
 /// @param[out] lstate If not NULL, Lines are pushed into a table onto the stack
 /// @param err[out] Error, if any
 /// @return true unless `err` was set
-bool buf_collect_lines(buf_T *buf, size_t n, linenr_T start, bool replace_nl, Array *l,
-                       lua_State *lstate, Error *err)
+bool buf_collect_lines(buf_T *buf, size_t n, linenr_T start, int start_idx, bool replace_nl,
+                       Array *l, lua_State *lstate, Error *err)
 {
   for (size_t i = 0; i < n; i++) {
     linenr_T lnum = start + (linenr_T)i;
@@ -1482,7 +1482,7 @@ bool buf_collect_lines(buf_T *buf, size_t n, linenr_T start, bool replace_nl, Ar
     }
 
     char *bufstr = ml_get_buf(buf, lnum, false);
-    push_linestr(lstate, l, bufstr, strlen(bufstr), (int)i, replace_nl);
+    push_linestr(lstate, l, bufstr, strlen(bufstr), start_idx + (int)i, replace_nl);
   }
 
   return true;
-- 
cgit 


From fedf002cb34d0d7a50c54f84a2f161984db2a4c2 Mon Sep 17 00:00:00 2001
From: Jlll1 
Date: Thu, 17 Nov 2022 00:18:31 +0100
Subject: fix(api): nvim_win_set_cursor redraw cursorcolumn for non-current
 window (#21072)

fix #19063
this fixes the cursorcolumn not being redrawn for non-current windows in `nvim_win_set_cursor()`
---
 src/nvim/api/window.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

(limited to 'src/nvim/api')

diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c
index 3f7c734cd1..8d17570077 100644
--- a/src/nvim/api/window.c
+++ b/src/nvim/api/window.c
@@ -118,8 +118,13 @@ void nvim_win_set_cursor(Window window, ArrayOf(Integer, 2) pos, Error *err)
   // Make sure we stick in this column.
   win->w_set_curswant = true;
 
-  // make sure cursor is in visible range even if win != curwin
-  update_topline_win(win);
+  // make sure cursor is in visible range and
+  // cursorcolumn and cursorline are updated even if win != curwin
+  switchwin_T switchwin;
+  switch_win(&switchwin, win, NULL, true);
+  update_topline(curwin);
+  validate_cursor();
+  restore_win(&switchwin, true);
 
   redraw_later(win, UPD_VALID);
   win->w_redr_status = true;
-- 
cgit 


From 40f3f75867bf03abfd90e0389a38197a00d37af1 Mon Sep 17 00:00:00 2001
From: Dundar Göc 
Date: Fri, 26 Aug 2022 23:11:25 +0200
Subject: refactor: replace char_u with char

Work on https://github.com/neovim/neovim/issues/459
---
 src/nvim/api/private/helpers.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(limited to 'src/nvim/api')

diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c
index b7cd0c82fb..ca8ad16cbf 100644
--- a/src/nvim/api/private/helpers.c
+++ b/src/nvim/api/private/helpers.c
@@ -505,7 +505,7 @@ String buf_get_text(buf_T *buf, int64_t lnum, int64_t start_col, int64_t end_col
     return rv;
   }
 
-  return cstrn_as_string((char *)&bufstr[start_col], (size_t)(end_col - start_col));
+  return cstrn_as_string(&bufstr[start_col], (size_t)(end_col - start_col));
 }
 
 void api_free_string(String value)
-- 
cgit 


From 0cbc23d3cc327109176c0a9c0f8a48fc5196a6cd Mon Sep 17 00:00:00 2001
From: dundargoc <33953936+dundargoc@users.noreply.github.com>
Date: Tue, 22 Nov 2022 01:07:45 +0100
Subject: fix: pvs warnings (#21145)

* fix(PVS/V009): start file with special comment

* fix(PVS/V501): identical sub-expressions for comparison

* fix(PVS/V560): part of conditional expression is always true/false

* fix(PVS/V593): review expression of type A = B < C

* fix(PVS/V614): potentially uninitialized variable used
---
 src/nvim/api/win_config.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

(limited to 'src/nvim/api')

diff --git a/src/nvim/api/win_config.c b/src/nvim/api/win_config.c
index 532052f9b0..cfe887d762 100644
--- a/src/nvim/api/win_config.c
+++ b/src/nvim/api/win_config.c
@@ -382,7 +382,7 @@ static void parse_border_title(Object title, Object title_pos, FloatConfig *fcon
     return;
   }
 
-  if (title.type == kObjectTypeArray && title.data.array.size == 0) {
+  if (title.data.array.size == 0) {
     api_set_error(err, kErrorTypeValidation, "title cannot be an empty array");
     return;
   }
@@ -391,7 +391,6 @@ static void parse_border_title(Object title, Object title_pos, FloatConfig *fcon
   fconfig->title_chunks = parse_virt_text(title.data.array, err, &fconfig->title_width);
 
   fconfig->title = true;
-  return;
 }
 
 static bool parse_title_pos(Object title_pos, FloatConfig *fconfig, Error *err)
-- 
cgit 


From 3b96ccf7d35be90e49029dec76344d3d92ad91dc Mon Sep 17 00:00:00 2001
From: dundargoc 
Date: Sat, 26 Nov 2022 18:57:46 +0100
Subject: refactor: replace char_u with char

Work on https://github.com/neovim/neovim/issues/459
---
 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 ca8ad16cbf..4ff600618d 100644
--- a/src/nvim/api/private/helpers.c
+++ b/src/nvim/api/private/helpers.c
@@ -391,13 +391,13 @@ String cbuf_to_string(const char *buf, size_t size)
 String cstrn_to_string(const char *str, size_t maxsize)
   FUNC_ATTR_NONNULL_ALL
 {
-  return cbuf_to_string(str, STRNLEN(str, maxsize));
+  return cbuf_to_string(str, strnlen(str, maxsize));
 }
 
 String cstrn_as_string(char *str, size_t maxsize)
   FUNC_ATTR_NONNULL_ALL
 {
-  return cbuf_as_string(str, STRNLEN(str, maxsize));
+  return cbuf_as_string(str, strnlen(str, maxsize));
 }
 
 /// Creates a String using the given C string. Unlike
-- 
cgit 


From 615f124003376c007442319b31a172360796974c Mon Sep 17 00:00:00 2001
From: dundargoc <33953936+dundargoc@users.noreply.github.com>
Date: Tue, 29 Nov 2022 02:45:48 +0100
Subject: docs: fix typos (#21196)

Co-authored-by: zeertzjq 
Co-authored-by: Raphael 
Co-authored-by: Gregory Anders 
---
 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 7a5ea7aa95..c3f71cc625 100644
--- a/src/nvim/api/vim.c
+++ b/src/nvim/api/vim.c
@@ -236,7 +236,7 @@ void nvim_set_hl_ns_fast(Integer ns_id, Error *err)
 ///
 /// @param keys         to be typed
 /// @param mode         behavior flags, see |feedkeys()|
-/// @param escape_ks    If true, escape K_SPECIAL bytes in `keys`
+/// @param escape_ks    If true, escape K_SPECIAL bytes in `keys`.
 ///                     This should be false if you already used
 ///                     |nvim_replace_termcodes()|, and true otherwise.
 /// @see feedkeys()
-- 
cgit 


From 0b79137c59fbe44bded76f123602e552dc6f7b03 Mon Sep 17 00:00:00 2001
From: zeertzjq 
Date: Tue, 29 Nov 2022 16:47:29 +0800
Subject: vim-patch:8.1.2001: some source files are too big (#21231)

Problem:    Some source files are too big.
Solution:   Move buffer and window related functions to evalbuffer.c and
            evalwindow.c. (Yegappan Lakshmanan, closes vim/vim#4898)

https://github.com/vim/vim/commit/261f346f8154c0ec7094a4a211c653c74e9f7c2e
---
 src/nvim/api/options.c | 1 +
 src/nvim/api/window.c  | 1 +
 2 files changed, 2 insertions(+)

(limited to 'src/nvim/api')

diff --git a/src/nvim/api/options.c b/src/nvim/api/options.c
index d705636479..bfcb99754f 100644
--- a/src/nvim/api/options.c
+++ b/src/nvim/api/options.c
@@ -11,6 +11,7 @@
 #include "nvim/api/private/helpers.h"
 #include "nvim/autocmd.h"
 #include "nvim/buffer_defs.h"
+#include "nvim/eval/window.h"
 #include "nvim/globals.h"
 #include "nvim/memory.h"
 #include "nvim/option.h"
diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c
index 8d17570077..60fbc55363 100644
--- a/src/nvim/api/window.c
+++ b/src/nvim/api/window.c
@@ -13,6 +13,7 @@
 #include "nvim/buffer_defs.h"
 #include "nvim/cursor.h"
 #include "nvim/drawscreen.h"
+#include "nvim/eval/window.h"
 #include "nvim/ex_docmd.h"
 #include "nvim/gettext.h"
 #include "nvim/globals.h"
-- 
cgit 


From 282dda643ae598d5c8e9f34c379d931563b4891b Mon Sep 17 00:00:00 2001
From: Andrew Willette 
Date: Wed, 30 Nov 2022 14:32:57 -0600
Subject: fix(ui-ext): log and clear error in ui_comp_event (#21147)

* fix: log and clear error in ui_comp_event

* fix: handling error in each map_foreach_value iteration

* fix: handling error decl in for_each loop

* fix: updating initerr to const, removing initerr free-ing

* fix: using ERROR_SET for error check

* fix: wrapping ERROR_INIT in parens to allow for including inside macro
---
 src/nvim/api/private/defs.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(limited to 'src/nvim/api')

diff --git a/src/nvim/api/private/defs.h b/src/nvim/api/private/defs.h
index 8693751c97..8acbf0d9de 100644
--- a/src/nvim/api/private/defs.h
+++ b/src/nvim/api/private/defs.h
@@ -12,7 +12,7 @@
 #define ARRAY_DICT_INIT KV_INITIAL_VALUE
 #define STRING_INIT { .data = NULL, .size = 0 }
 #define OBJECT_INIT { .type = kObjectTypeNil }
-#define ERROR_INIT { .type = kErrorTypeNone, .msg = NULL }
+#define ERROR_INIT ((Error) { .type = kErrorTypeNone, .msg = NULL })
 #define REMOTE_TYPE(type) typedef handle_T type
 
 #define ERROR_SET(e) ((e)->type != kErrorTypeNone)
-- 
cgit 


From 0b05bd87c04f9cde5c84a062453619349e370795 Mon Sep 17 00:00:00 2001
From: Christian Clason 
Date: Wed, 23 Nov 2022 12:31:49 +0100
Subject: docs(gen): support language annotation in docstrings

---
 src/nvim/api/autocmd.c    | 21 ++++++++++-----------
 src/nvim/api/buffer.c     |  2 +-
 src/nvim/api/command.c    |  2 +-
 src/nvim/api/extmark.c    |  6 ++----
 src/nvim/api/vim.c        |  8 ++++----
 src/nvim/api/win_config.c |  4 ++--
 6 files changed, 20 insertions(+), 23 deletions(-)

(limited to 'src/nvim/api')

diff --git a/src/nvim/api/autocmd.c b/src/nvim/api/autocmd.c
index af185c50c9..db84ecb5d8 100644
--- a/src/nvim/api/autocmd.c
+++ b/src/nvim/api/autocmd.c
@@ -47,7 +47,7 @@ static int64_t next_autocmd_id = 1;
 /// Get all autocommands that match the corresponding {opts}.
 ///
 /// These examples will get autocommands matching ALL the given criteria:
-/// 
+/// 
lua
 ///   -- Matches all criteria
 ///   autocommands = vim.api.nvim_get_autocmds({
 ///     group = "MyGroup",
@@ -367,7 +367,7 @@ cleanup:
 /// triggers: a callback function (Lua or Vimscript), or a command (like regular autocommands).
 ///
 /// Example using callback:
-/// 
+/// 
lua
 ///     -- Lua function
 ///     local myluafun = function() print("This buffer enters") end
 ///
@@ -383,8 +383,7 @@ cleanup:
 /// Lua functions receive a table with information about the autocmd event as an argument. To use
 /// a function which itself accepts another (optional) parameter, wrap the function
 /// in a lambda:
-///
-/// 
+/// 
lua
 ///     -- Lua function with an optional parameter.
 ///     -- The autocmd callback would pass a table as argument but this
 ///     -- function expects number|nil
@@ -397,7 +396,7 @@ cleanup:
 /// 
/// /// Example using command: -///
+/// 
lua
 ///     vim.api.nvim_create_autocmd({"BufEnter", "BufWinEnter"}, {
 ///       pattern = {"*.c", "*.h"},
 ///       command = "echo 'Entering a C or C++ file'",
@@ -405,7 +404,7 @@ cleanup:
 /// 
/// /// Example values for pattern: -///
+/// 
lua
 ///   pattern = "*.py"
 ///   pattern = { "*.py", "*.pyi" }
 /// 
@@ -413,14 +412,14 @@ cleanup: /// Note: The `pattern` is passed to callbacks and commands as a literal string; environment /// variables like `$HOME` and `~` are not automatically expanded as they are by |:autocmd|. /// Instead, |expand()| such variables explicitly: -///
+/// 
lua
 ///   pattern = vim.fn.expand("~") .. "/some/path/*.py"
 /// 
/// /// Example values for event: -///
-///   "BufWritePre"
-///   {"CursorHold", "BufWritePre", "BufWritePost"}
+/// 
lua
+///   event = "BufWritePre"
+///   event = {"CursorHold", "BufWritePre", "BufWritePost"}
 /// 
/// /// @param event (string|array) The event or events to register this autocommand @@ -703,7 +702,7 @@ cleanup: /// Create or get an autocommand group |autocmd-groups|. /// /// To get an existing group id, do: -///
+/// 
lua
 ///     local id = vim.api.nvim_create_augroup("MyGroup", {
 ///         clear = false
 ///     })
diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c
index 0a31286df7..fe9e6077d6 100644
--- a/src/nvim/api/buffer.c
+++ b/src/nvim/api/buffer.c
@@ -84,7 +84,7 @@ Integer nvim_buf_line_count(Buffer buffer, Error *err)
 ///
 /// Example (Lua): capture buffer updates in a global `events` variable
 /// (use "print(vim.inspect(events))" to see its contents):
-/// 
+/// 
lua
 ///   events = {}
 ///   vim.api.nvim_buf_attach(0, false, {
 ///     on_lines=function(...) table.insert(events, {...}) end})
diff --git a/src/nvim/api/command.c b/src/nvim/api/command.c
index 8a7abf0845..416dbc0e5d 100644
--- a/src/nvim/api/command.c
+++ b/src/nvim/api/command.c
@@ -889,7 +889,7 @@ static void build_cmdline_str(char **cmdlinep, exarg_T *eap, CmdParseInfo *cmdin
 /// {command} is the replacement text or Lua function to execute.
 ///
 /// Example:
-/// 
+/// 
vim
 ///    :call nvim_create_user_command('SayHello', 'echo "Hello world!"', {})
 ///    :SayHello
 ///    Hello world!
diff --git a/src/nvim/api/extmark.c b/src/nvim/api/extmark.c
index 3a96c42dba..b406672aa5 100644
--- a/src/nvim/api/extmark.c
+++ b/src/nvim/api/extmark.c
@@ -255,8 +255,7 @@ ArrayOf(Integer) nvim_buf_get_extmark_by_id(Buffer buffer, Integer ns_id,
 /// 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:
-///
-/// 
+/// 
lua
 ///   nvim_buf_get_extmarks(0, my_ns, 0, -1, {})
 ///   nvim_buf_get_extmarks(0, my_ns, [0,0], [-1,-1], {})
 /// 
@@ -265,8 +264,7 @@ ArrayOf(Integer) nvim_buf_get_extmark_by_id(Buffer buffer, Integer ns_id, /// with `limit`, to get the first marks prior to a given position.) /// /// Example: -/// -///
+/// 
lua
 ///   local a   = vim.api
 ///   local pos = a.nvim_win_get_cursor(0)
 ///   local ns  = a.nvim_create_namespace('my-plugin')
diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c
index c3f71cc625..857c03eb27 100644
--- a/src/nvim/api/vim.c
+++ b/src/nvim/api/vim.c
@@ -229,7 +229,7 @@ void nvim_set_hl_ns_fast(Integer ns_id, Error *err)
 /// nvim_feedkeys().
 ///
 /// Example:
-/// 
+/// 
vim
 ///     :let key = nvim_replace_termcodes("", v:true, v:false, v:true)
 ///     :call nvim_feedkeys(key, 'n', v:false)
 /// 
@@ -1295,7 +1295,7 @@ void nvim_unsubscribe(uint64_t channel_id, String event) /// "#rrggbb" hexadecimal string. /// /// Example: -///
+/// 
vim
 ///     :echo nvim_get_color_by_name("Pink")
 ///     :echo nvim_get_color_by_name("#cbcbcb")
 /// 
@@ -1437,12 +1437,12 @@ ArrayOf(Dictionary) nvim_get_keymap(String mode) /// Empty {rhs} is ||. |keycodes| are replaced as usual. /// /// Example: -///
+/// 
vim
 ///     call nvim_set_keymap('n', ' ', '', {'nowait': v:true})
 /// 
/// /// is equivalent to: -///
+/// 
vim
 ///     nmap   
 /// 
/// diff --git a/src/nvim/api/win_config.c b/src/nvim/api/win_config.c index cfe887d762..828ef2f0eb 100644 --- a/src/nvim/api/win_config.c +++ b/src/nvim/api/win_config.c @@ -55,13 +55,13 @@ /// this should not be used to specify arbitrary WM screen positions. /// /// Example (Lua): window-relative float -///
+/// 
lua
 ///     vim.api.nvim_open_win(0, false,
 ///       {relative='win', row=3, col=3, width=12, height=3})
 /// 
/// /// Example (Lua): buffer-relative float (travels as buffer is scrolled) -///
+/// 
lua
 ///     vim.api.nvim_open_win(0, false,
 ///       {relative='win', width=12, height=3, bufpos={100,10}})
 /// 
-- cgit From 707df880545703bc6f4db1af6e46820becbcd911 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 5 Dec 2022 21:09:31 +0800 Subject: docs: add missing docs from some Vim patches (#21296) This is cherry-picked from these Vim patches: Only applicable change outside vi_diff.txt in patch 8.1.1226: https://github.com/vim/vim/commit/6c60f47fb9251e686217d51cf81847e14d0dd26d Most changes outside starting.txt and vi_diff.txt in patch 8.1.1280: https://github.com/vim/vim/commit/25c9c680ec4dfbb51f4ef21c3460a48d3c67ffc8 Missing docs for 'mousemoveevent': https://github.com/vim/vim/commit/cbaff5e06ec525d31dc44093125c42029e01d508 --- src/nvim/api/command.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/command.c b/src/nvim/api/command.c index 416dbc0e5d..ac1927eeb1 100644 --- a/src/nvim/api/command.c +++ b/src/nvim/api/command.c @@ -57,7 +57,7 @@ /// Omitted if command cannot take a register. /// - bang: (boolean) Whether command contains a || (!) modifier. /// - args: (array) Command arguments. -/// - addr: (string) Value of |:command-addr|. Uses short name. +/// - addr: (string) Value of |:command-addr|. Uses short name or "line" for -addr=lines. /// - nargs: (string) Value of |:command-nargs|. /// - nextcmd: (string) Next command if there are multiple commands separated by a |:bar|. /// Empty if there isn't a next command. -- cgit From 224473546c95f17c45afc54fe8b4ef5f0e000974 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 10 Dec 2022 20:13:40 +0800 Subject: fix(api): set correct curbuf when temporarily changing curwin (#21371) This is the same code change as https://github.com/vim/vim/commit/6c87bbb4e45515e70ac1728cabd1451063bf427d --- src/nvim/api/window.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/nvim/api') diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c index 60fbc55363..df8ad165ba 100644 --- a/src/nvim/api/window.c +++ b/src/nvim/api/window.c @@ -169,9 +169,11 @@ void nvim_win_set_height(Window window, Integer height, Error *err) win_T *savewin = curwin; curwin = win; + curbuf = curwin->w_buffer; try_start(); win_setheight((int)height); curwin = savewin; + curbuf = curwin->w_buffer; try_end(err); } @@ -214,9 +216,11 @@ void nvim_win_set_width(Window window, Integer width, Error *err) win_T *savewin = curwin; curwin = win; + curbuf = curwin->w_buffer; try_start(); win_setwidth((int)width); curwin = savewin; + curbuf = curwin->w_buffer; try_end(err); } -- cgit From b12bb97feeb84df47d672d39b2de170061c37f45 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Mon, 12 Dec 2022 01:53:07 +0100 Subject: docs: fix typos (#21328) --- 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 857c03eb27..70b07dabe8 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -1825,7 +1825,7 @@ Dictionary nvim__stats(void) /// - "width" Requested width of the UI /// - "rgb" true if the UI uses RGB colors (false implies |cterm-colors|) /// - "ext_..." Requested UI extensions, see |ui-option| -/// - "chan" Channel id of remote UI (not present for TUI) +/// - "chan" Channel id of remote UI or 0 for TUI Array nvim_list_uis(void) FUNC_API_SINCE(4) { -- cgit From 1c324cb1927e03b5a3584a8982e3d5029498f14e Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 11 Dec 2022 21:41:26 -0500 Subject: docs #20986 - https://github.com/neovim/tree-sitter-vimdoc v1.2.4 eliminates most errors in pi_netrw.txt, so we can remove that workaround from ignore_parse_error(). - improved codeblock --- src/nvim/api/autocmd.c | 92 ++++++++++++++------------------------------------ 1 file changed, 26 insertions(+), 66 deletions(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/autocmd.c b/src/nvim/api/autocmd.c index db84ecb5d8..ada042e654 100644 --- a/src/nvim/api/autocmd.c +++ b/src/nvim/api/autocmd.c @@ -361,41 +361,20 @@ cleanup: return autocmd_list; } -/// Create an |autocommand| +/// Creates an |autocommand| event handler, defined by `callback` (Lua function or Vimscript +/// function _name_ string) or `command` (Ex command string). /// -/// The API allows for two (mutually exclusive) types of actions to be executed when the autocommand -/// triggers: a callback function (Lua or Vimscript), or a command (like regular autocommands). -/// -/// Example using callback: -///
lua
-///     -- Lua function
-///     local myluafun = function() print("This buffer enters") end
-///
-///     -- Vimscript function name (as a string)
-///     local myvimfun = "g:MyVimFunction"
-///
-///     vim.api.nvim_create_autocmd({"BufEnter", "BufWinEnter"}, {
-///       pattern = {"*.c", "*.h"},
-///       callback = myluafun,  -- Or myvimfun
-///     })
-/// 
-/// -/// Lua functions receive a table with information about the autocmd event as an argument. To use -/// a function which itself accepts another (optional) parameter, wrap the function -/// in a lambda: +/// Example using Lua callback: ///
lua
-///     -- Lua function with an optional parameter.
-///     -- The autocmd callback would pass a table as argument but this
-///     -- function expects number|nil
-///     local myluafun = function(bufnr) bufnr = bufnr or vim.api.nvim_get_current_buf() end
-///
 ///     vim.api.nvim_create_autocmd({"BufEnter", "BufWinEnter"}, {
 ///       pattern = {"*.c", "*.h"},
-///       callback = function() myluafun() end,
+///       callback = function(ev)
+///         print(string.format('event fired: %s', vim.inspect(ev)))
+///       end
 ///     })
 /// 
/// -/// Example using command: +/// Example using an Ex command as the handler: ///
lua
 ///     vim.api.nvim_create_autocmd({"BufEnter", "BufWinEnter"}, {
 ///       pattern = {"*.c", "*.h"},
@@ -403,46 +382,28 @@ cleanup:
 ///     })
 /// 
/// -/// Example values for pattern: -///
lua
-///   pattern = "*.py"
-///   pattern = { "*.py", "*.pyi" }
-/// 
-/// -/// Note: The `pattern` is passed to callbacks and commands as a literal string; environment -/// variables like `$HOME` and `~` are not automatically expanded as they are by |:autocmd|. -/// Instead, |expand()| such variables explicitly: +/// Note: `pattern` is NOT automatically expanded (unlike with |:autocmd|), thus names like "$HOME" +/// and "~" must be expanded explicitly: ///
lua
 ///   pattern = vim.fn.expand("~") .. "/some/path/*.py"
 /// 
/// -/// Example values for event: -///
lua
-///   event = "BufWritePre"
-///   event = {"CursorHold", "BufWritePre", "BufWritePost"}
-/// 
-/// -/// @param event (string|array) The event or events to register this autocommand -/// @param opts Dictionary of autocommand options: -/// - group (string|integer) optional: the autocommand group name or -/// id to match against. -/// - pattern (string|array) optional: pattern or patterns to match literally -/// against |autocmd-pattern|. -/// - buffer (integer) optional: buffer number for buffer local autocommands +/// @param event (string|array) Event(s) that will trigger the handler (`callback` or `command`). +/// @param opts Options dict: +/// - group (string|integer) optional: autocommand group name or id to match against. +/// - pattern (string|array) optional: pattern(s) to match literally |autocmd-pattern|. +/// - buffer (integer) optional: buffer number for buffer-local autocommands /// |autocmd-buflocal|. Cannot be used with {pattern}. -/// - desc (string) optional: description of the autocommand. -/// - callback (function|string) optional: if a string, the name of a Vimscript function -/// to call when this autocommand is triggered. Otherwise, a Lua function which is -/// called when this autocommand is triggered. Cannot be used with {command}. Lua -/// callbacks can return true to delete the autocommand; in addition, they accept a -/// single table argument with the following keys: -/// - id: (number) the autocommand id -/// - event: (string) the name of the event that triggered the autocommand -/// |autocmd-events| -/// - group: (number|nil) the autocommand group id, if it exists -/// - match: (string) the expanded value of || -/// - buf: (number) the expanded value of || -/// - file: (string) the expanded value of || +/// - desc (string) optional: description (for documentation and troubleshooting). +/// - callback (function|string) optional: Lua function (or Vimscript function name, if +/// string) called when the event(s) is triggered. Lua callback can return true to +/// delete the autocommand, and receives a table argument with these keys: +/// - id: (number) autocommand id +/// - event: (string) name of the triggered event |autocmd-events| +/// - group: (number|nil) autocommand group id, if any +/// - match: (string) expanded value of || +/// - buf: (number) expanded value of || +/// - file: (string) expanded value of || /// - data: (any) arbitrary data passed to |nvim_exec_autocmds()| /// - command (string) optional: Vim command to execute on event. Cannot be used with /// {callback} @@ -451,7 +412,7 @@ cleanup: /// - nested (boolean) optional: defaults to false. Run nested /// autocommands |autocmd-nested|. /// -/// @return Integer id of the created autocommand. +/// @return Autocommand id (number) /// @see |autocommand| /// @see |nvim_del_autocmd()| Integer nvim_create_autocmd(uint64_t channel_id, Object event, Dict(create_autocmd) *opts, @@ -472,8 +433,7 @@ Integer nvim_create_autocmd(uint64_t channel_id, Object event, Dict(create_autoc } if (opts->callback.type != kObjectTypeNil && opts->command.type != kObjectTypeNil) { - api_set_error(err, kErrorTypeValidation, - "cannot pass both: 'callback' and 'command' for the same autocmd"); + api_set_error(err, kErrorTypeValidation, "specify either 'callback' or 'command', not both"); goto cleanup; } else if (opts->callback.type != kObjectTypeNil) { // TODO(tjdevries): It's possible we could accept callable tables, -- cgit From 49c240d3a2a783f3b62954d3e9153dbd07eb5f46 Mon Sep 17 00:00:00 2001 From: ii14 <59243201+ii14@users.noreply.github.com> Date: Mon, 12 Dec 2022 16:15:31 +0100 Subject: docs: add links to extmarks and namespaces (#21378) Co-authored-by: ii14 --- src/nvim/api/extmark.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/extmark.c b/src/nvim/api/extmark.c index b406672aa5..bdc0900dd9 100644 --- a/src/nvim/api/extmark.c +++ b/src/nvim/api/extmark.c @@ -66,7 +66,7 @@ Integer nvim_create_namespace(String name) return (Integer)id; } -/// Gets existing, non-anonymous namespaces. +/// Gets existing, non-anonymous |namespace|s. /// /// @return dict that maps from names to namespace ids. Dictionary nvim_get_namespaces(void) @@ -195,7 +195,7 @@ static Array extmark_to_array(const ExtmarkInfo *extmark, bool id, bool add_dict return rv; } -/// Gets the position (0-indexed) of an extmark. +/// Gets the position (0-indexed) of an |extmark|. /// /// @param buffer Buffer handle, or 0 for current buffer /// @param ns_id Namespace id from |nvim_create_namespace()| @@ -249,7 +249,7 @@ ArrayOf(Integer) nvim_buf_get_extmark_by_id(Buffer buffer, Integer ns_id, return extmark_to_array(&extmark, false, details); } -/// Gets extmarks in "traversal order" from a |charwise| region defined by +/// 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 @@ -368,7 +368,7 @@ Array nvim_buf_get_extmarks(Buffer buffer, Integer ns_id, Object start, Object e return rv; } -/// Creates or updates an extmark. +/// Creates or updates an |extmark|. /// /// By default a new extmark is created when no id is passed in, but it is also /// possible to create a new mark by passing in a previously unused id or move @@ -814,7 +814,7 @@ error: return 0; } -/// Removes an extmark. +/// Removes an |extmark|. /// /// @param buffer Buffer handle, or 0 for current buffer /// @param ns_id Namespace id from |nvim_create_namespace()| @@ -929,7 +929,7 @@ Integer nvim_buf_add_highlight(Buffer buffer, Integer ns_id, String hl_group, In return ns_id; } -/// Clears namespaced objects (highlights, extmarks, virtual text) from +/// Clears |namespace|d objects (highlights, |extmarks|, virtual text) from /// a region. /// /// Lines are 0-indexed. |api-indexing| To clear the namespace in the entire @@ -962,12 +962,12 @@ void nvim_buf_clear_namespace(Buffer buffer, Integer ns_id, Integer line_start, (int)line_end - 1, MAXCOL); } -/// Set or change decoration provider for a namespace +/// Set or change decoration provider for a |namespace| /// /// This is a very general purpose interface for having lua callbacks /// being triggered during the redraw code. /// -/// The expected usage is to set extmarks for the currently +/// The expected usage is to set |extmarks| for the currently /// redrawn buffer. |nvim_buf_set_extmark()| can be called to add marks /// on a per-window or per-lines basis. Use the `ephemeral` key to only /// use the mark for the current screen redraw (the callback will be called @@ -1051,7 +1051,7 @@ error: decor_provider_clear(p); } -/// Gets the line and column of an extmark. +/// Gets the line and column of an |extmark|. /// /// Extmarks may be queried by position, name or even special names /// in the future such as "cursor". -- cgit From 72a19b2ffe93ab20f6ff1825e11b43da4e44842a Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 16 Dec 2022 08:54:13 +0800 Subject: fix(api): "emsg_silent" should imply "silent" in nvim_cmd (#21438) --- src/nvim/api/command.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/nvim/api') diff --git a/src/nvim/api/command.c b/src/nvim/api/command.c index ac1927eeb1..abd265f2cf 100644 --- a/src/nvim/api/command.c +++ b/src/nvim/api/command.c @@ -660,6 +660,12 @@ String nvim_cmd(uint64_t channel_id, Dict(cmd) *cmd, Dict(cmd_opts) *opts, Error OBJ_TO_CMOD_FLAG(CMOD_LOCKMARKS, mods.lockmarks, false, "'mods.lockmarks'"); OBJ_TO_CMOD_FLAG(CMOD_NOSWAPFILE, mods.noswapfile, false, "'mods.noswapfile'"); + if (cmdinfo.cmdmod.cmod_flags & CMOD_ERRSILENT) { + // CMOD_ERRSILENT must imply CMOD_SILENT, otherwise apply_cmdmod() and undo_cmdmod() won't + // work properly. + cmdinfo.cmdmod.cmod_flags |= CMOD_SILENT; + } + if ((cmdinfo.cmdmod.cmod_flags & CMOD_SANDBOX) && !(ea.argt & EX_SBOXOK)) { VALIDATION_ERROR("Command cannot be run in sandbox"); } -- cgit From ef91146efcece1b6d97152251e7137d301146189 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Wed, 14 Dec 2022 10:46:54 +0100 Subject: feat: `vim.inspect_pos`, `vim.show_pos`, `:Inspect` --- src/nvim/api/extmark.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/extmark.c b/src/nvim/api/extmark.c index bdc0900dd9..f7c6b398d5 100644 --- a/src/nvim/api/extmark.c +++ b/src/nvim/api/extmark.c @@ -40,7 +40,7 @@ void api_extmark_free_all_mem(void) map_destroy(String, handle_T)(&namespace_ids); } -/// Creates a new \*namespace\* or gets an existing one. +/// Creates a new namespace or gets an existing one. \*namespace\* /// /// Namespaces are used for buffer highlights and virtual text, see /// |nvim_buf_add_highlight()| and |nvim_buf_set_extmark()|. -- cgit From b42d8a43b9f1b3316e73108ebefc4850b1a2c65b Mon Sep 17 00:00:00 2001 From: bfredl Date: Fri, 16 Dec 2022 13:50:12 +0100 Subject: refactor(tui): use nvim_echo() for verbose terminfo This is needed for #18375 for the obvious reasons. note: verbose_terminfo_event is only temporarily needed until the full TUI process refactor is merged. --- src/nvim/api/keysets.lua | 3 +++ src/nvim/api/vim.c | 19 ++++++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/keysets.lua b/src/nvim/api/keysets.lua index 7e0d399573..8ded9cfa5d 100644 --- a/src/nvim/api/keysets.lua +++ b/src/nvim/api/keysets.lua @@ -219,5 +219,8 @@ return { cmd_opts = { "output"; }; + echo_opts = { + "verbose"; + }; } diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 70b07dabe8..83c9d54725 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -726,8 +726,11 @@ void nvim_set_vvar(String name, Object value, Error *err) /// text chunk with specified highlight. `hl_group` element /// can be omitted for no highlight. /// @param history if true, add to |message-history|. -/// @param opts Optional parameters. Reserved for future use. -void nvim_echo(Array chunks, Boolean history, Dictionary opts, Error *err) +/// @param opts Optional parameters. +/// - verbose: Message was printed as a result of 'verbose' option +/// if Nvim was invoked with -V3log_file, the message will be +/// redirected to the log_file and surpressed from direct output. +void nvim_echo(Array chunks, Boolean history, Dict(echo_opts) *opts, Error *err) FUNC_API_SINCE(7) { HlMessage hl_msg = parse_hl_msg(chunks, err); @@ -735,13 +738,19 @@ void nvim_echo(Array chunks, Boolean history, Dictionary opts, Error *err) goto error; } - if (opts.size > 0) { - api_set_error(err, kErrorTypeValidation, "opts dict isn't empty"); - goto error; + bool verbose = api_object_to_bool(opts->verbose, "verbose", false, err); + + if (verbose) { + verbose_enter(); } msg_multiattr(hl_msg, history ? "echomsg" : "echo", history); + if (verbose) { + verbose_leave(); + verbose_stop(); // flush now + } + if (history) { // history takes ownership return; -- cgit From 24488169564c39a506c235bf6a33b8e23a8cb528 Mon Sep 17 00:00:00 2001 From: hlpr98 Date: Mon, 27 May 2019 22:04:24 +0530 Subject: feat(tui): run TUI as external process --- src/nvim/api/ui.c | 35 ++++++++++++++++++++++++++++++++--- src/nvim/api/ui_events.in.h | 17 +++++++++-------- 2 files changed, 41 insertions(+), 11 deletions(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c index aeccddb9ea..ef6ced1ee0 100644 --- a/src/nvim/api/ui.c +++ b/src/nvim/api/ui.c @@ -14,9 +14,6 @@ #include "nvim/api/private/helpers.h" #include "nvim/api/ui.h" #include "nvim/channel.h" -#include "nvim/event/loop.h" -#include "nvim/event/wstream.h" -#include "nvim/globals.h" #include "nvim/grid.h" #include "nvim/highlight.h" #include "nvim/main.h" @@ -30,6 +27,7 @@ #include "nvim/types.h" #include "nvim/ui.h" #include "nvim/vim.h" +#include "nvim/window.h" typedef struct { uint64_t channel_id; @@ -285,6 +283,19 @@ void ui_attach(uint64_t channel_id, Integer width, Integer height, Boolean enabl api_free_dictionary(opts); } +/// Tells the nvim server if focus was gained by the GUI or not +void nvim_ui_set_focus(uint64_t channel_id, Boolean gained, Error *error) + FUNC_API_SINCE(6) FUNC_API_REMOTE_ONLY +{ + if (!pmap_has(uint64_t)(&connected_uis, channel_id)) { + api_set_error(error, kErrorTypeException, + "UI not attached to channel: %" PRId64, channel_id); + return; + } + + autocmd_schedule_focusgained((bool)gained); +} + /// Deactivates UI events on the channel. /// /// Removes the client from the list of UIs. |nvim_list_uis()| @@ -404,6 +415,24 @@ static void ui_set_option(UI *ui, bool init, String name, Object value, Error *e return; } + if (strequal(name.data, "term_ttyin")) { + if (value.type != kObjectTypeInteger) { + api_set_error(error, kErrorTypeValidation, "term_ttyin must be a Integer"); + return; + } + stdin_isatty = (int)value.data.integer; + return; + } + + if (strequal(name.data, "term_ttyout")) { + if (value.type != kObjectTypeInteger) { + api_set_error(error, kErrorTypeValidation, "term_ttyout must be a Integer"); + return; + } + stdout_isatty = (int)value.data.integer; + return; + } + // LEGACY: Deprecated option, use `ext_cmdline` instead. bool is_popupmenu = strequal(name.data, "popupmenu_external"); diff --git a/src/nvim/api/ui_events.in.h b/src/nvim/api/ui_events.in.h index 21400862b9..d5c79272b7 100644 --- a/src/nvim/api/ui_events.in.h +++ b/src/nvim/api/ui_events.in.h @@ -31,7 +31,7 @@ void visual_bell(void) void flush(void) FUNC_API_SINCE(3) FUNC_API_REMOTE_IMPL; void suspend(void) - FUNC_API_SINCE(3) FUNC_API_BRIDGE_IMPL; + FUNC_API_SINCE(3); void set_title(String title) FUNC_API_SINCE(3); void set_icon(String icon) @@ -39,7 +39,7 @@ void set_icon(String icon) void screenshot(String path) FUNC_API_SINCE(7) FUNC_API_REMOTE_IMPL; void option_set(String name, Object value) - FUNC_API_SINCE(4) FUNC_API_BRIDGE_IMPL; + FUNC_API_SINCE(4); // Stop event is not exported as such, represented by EOF in the msgpack stream. void stop(void) FUNC_API_NOEXPORT; @@ -73,9 +73,9 @@ void default_colors_set(Integer rgb_fg, Integer rgb_bg, Integer rgb_sp, Integer Integer cterm_bg) FUNC_API_SINCE(4) FUNC_API_REMOTE_IMPL; void hl_attr_define(Integer id, HlAttrs rgb_attrs, HlAttrs cterm_attrs, Array info) - FUNC_API_SINCE(5) FUNC_API_REMOTE_IMPL FUNC_API_BRIDGE_IMPL; + FUNC_API_SINCE(5) FUNC_API_REMOTE_IMPL; void hl_group_set(String name, Integer id) - FUNC_API_SINCE(6) FUNC_API_BRIDGE_IMPL; + FUNC_API_SINCE(6); void grid_resize(Integer grid, Integer width, Integer height) FUNC_API_SINCE(5) FUNC_API_REMOTE_IMPL FUNC_API_COMPOSITOR_IMPL FUNC_API_CLIENT_IMPL; void grid_clear(Integer grid) @@ -112,8 +112,9 @@ void win_hide(Integer grid) FUNC_API_SINCE(6) FUNC_API_REMOTE_ONLY; void win_close(Integer grid) FUNC_API_SINCE(6) FUNC_API_REMOTE_ONLY; + 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; + FUNC_API_SINCE(6) FUNC_API_COMPOSITOR_IMPL; void win_viewport(Integer grid, Window win, Integer topline, Integer botline, Integer curline, Integer curcol, Integer line_count) @@ -149,11 +150,11 @@ void cmdline_block_hide(void) FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY; void wildmenu_show(Array items) - FUNC_API_SINCE(3) FUNC_API_REMOTE_IMPL FUNC_API_BRIDGE_IMPL; + FUNC_API_SINCE(3) FUNC_API_REMOTE_IMPL; void wildmenu_select(Integer selected) - FUNC_API_SINCE(3) FUNC_API_REMOTE_IMPL FUNC_API_BRIDGE_IMPL; + FUNC_API_SINCE(3) FUNC_API_REMOTE_IMPL; void wildmenu_hide(void) - FUNC_API_SINCE(3) FUNC_API_REMOTE_IMPL FUNC_API_BRIDGE_IMPL; + FUNC_API_SINCE(3) FUNC_API_REMOTE_IMPL; void msg_show(String kind, Array content, Boolean replace_last) FUNC_API_SINCE(6) FUNC_API_REMOTE_ONLY; -- cgit From 43e8ec92de9e0850e7d202cb7ff9051bc408447e Mon Sep 17 00:00:00 2001 From: bfredl Date: Mon, 2 May 2022 21:10:01 +0200 Subject: fix(tui): more work in the TUI --- src/nvim/api/keysets.lua | 2 ++ src/nvim/api/ui.c | 22 +++++++++++----------- 2 files changed, 13 insertions(+), 11 deletions(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/keysets.lua b/src/nvim/api/keysets.lua index 8ded9cfa5d..8f909e937f 100644 --- a/src/nvim/api/keysets.lua +++ b/src/nvim/api/keysets.lua @@ -126,6 +126,8 @@ return { "global_link"; "fallback"; "blend"; + "fg_indexed"; + "bg_indexed"; }; highlight_cterm = { "bold"; diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c index ef6ced1ee0..e4134133ac 100644 --- a/src/nvim/api/ui.c +++ b/src/nvim/api/ui.c @@ -283,9 +283,9 @@ void ui_attach(uint64_t channel_id, Integer width, Integer height, Boolean enabl api_free_dictionary(opts); } -/// Tells the nvim server if focus was gained by the GUI or not +/// Tells the nvim server if focus was gained or lost by the GUI void nvim_ui_set_focus(uint64_t channel_id, Boolean gained, Error *error) - FUNC_API_SINCE(6) FUNC_API_REMOTE_ONLY + FUNC_API_SINCE(11) FUNC_API_REMOTE_ONLY { if (!pmap_has(uint64_t)(&connected_uis, channel_id)) { api_set_error(error, kErrorTypeException, @@ -293,7 +293,7 @@ void nvim_ui_set_focus(uint64_t channel_id, Boolean gained, Error *error) return; } - autocmd_schedule_focusgained((bool)gained); + do_autocmd_focusgained((bool)gained); } /// Deactivates UI events on the channel. @@ -415,21 +415,21 @@ static void ui_set_option(UI *ui, bool init, String name, Object value, Error *e return; } - if (strequal(name.data, "term_ttyin")) { - if (value.type != kObjectTypeInteger) { - api_set_error(error, kErrorTypeValidation, "term_ttyin must be a Integer"); + if (strequal(name.data, "stdin_tty")) { + if (value.type != kObjectTypeBoolean) { + api_set_error(error, kErrorTypeValidation, "stdin_tty must be a Boolean"); return; } - stdin_isatty = (int)value.data.integer; + stdin_isatty = value.data.boolean; return; } - if (strequal(name.data, "term_ttyout")) { - if (value.type != kObjectTypeInteger) { - api_set_error(error, kErrorTypeValidation, "term_ttyout must be a Integer"); + if (strequal(name.data, "stdout_tty")) { + if (value.type != kObjectTypeBoolean) { + api_set_error(error, kErrorTypeValidation, "stdout_tty must be a Boolean"); return; } - stdout_isatty = (int)value.data.integer; + stdout_isatty = value.data.boolean; return; } -- cgit From 9cc37e057a7afa02dcb9f384aa43217d82b9d479 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Wed, 28 Dec 2022 14:08:17 +0100 Subject: docs(api): fix treesitter parsing errors --- src/nvim/api/extmark.c | 4 ++-- src/nvim/api/win_config.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/extmark.c b/src/nvim/api/extmark.c index f7c6b398d5..992c134a0f 100644 --- a/src/nvim/api/extmark.c +++ b/src/nvim/api/extmark.c @@ -256,8 +256,8 @@ ArrayOf(Integer) nvim_buf_get_extmark_by_id(Buffer buffer, Integer ns_id, /// positions define the bounds). 0 and -1 are understood as (0,0) and (-1,-1) /// respectively, thus the following are equivalent: ///
lua
-///   nvim_buf_get_extmarks(0, my_ns, 0, -1, {})
-///   nvim_buf_get_extmarks(0, my_ns, [0,0], [-1,-1], {})
+///   vim.api.nvim_buf_get_extmarks(0, my_ns, 0, -1, {})
+///   vim.api.nvim_buf_get_extmarks(0, my_ns, {0,0}, {-1,-1}, {})
 /// 
/// /// If `end` is less than `start`, traversal works backwards. (Useful diff --git a/src/nvim/api/win_config.c b/src/nvim/api/win_config.c index 828ef2f0eb..56d5f8fb16 100644 --- a/src/nvim/api/win_config.c +++ b/src/nvim/api/win_config.c @@ -141,7 +141,7 @@ /// will only make vertical borders but not horizontal ones. /// By default, `FloatBorder` highlight is used, which links to `WinSeparator` /// when not defined. It could also be specified by character: -/// [ {"+", "MyCorner"}, {"x", "MyBorder"} ]. +/// [ ["+", "MyCorner"], ["x", "MyBorder"] ]. /// - title: Title (optional) in window border, String or list. /// List is [text, highlight] tuples. if is string the default /// highlight group is `FloatTitle`. -- cgit From 936e191fef9865600af211c29ea4959ffbce81dd Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Wed, 4 Jan 2023 00:38:48 +0100 Subject: docs: fix typos (#21427) Co-authored-by: Gustavo Sampaio Co-authored-by: C.D. MacEachern Co-authored-by: Sean Dewar Co-authored-by: Tomas Nemec --- src/nvim/api/extmark.c | 2 +- src/nvim/api/vim.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/extmark.c b/src/nvim/api/extmark.c index 992c134a0f..44e7ed3986 100644 --- a/src/nvim/api/extmark.c +++ b/src/nvim/api/extmark.c @@ -271,7 +271,7 @@ ArrayOf(Integer) nvim_buf_get_extmark_by_id(Buffer buffer, Integer ns_id, /// -- Create new extmark at line 1, column 1. /// local m1 = a.nvim_buf_set_extmark(0, ns, 0, 0, {}) /// -- Create new extmark at line 3, column 1. -/// local m2 = a.nvim_buf_set_extmark(0, ns, 0, 2, {}) +/// local m2 = a.nvim_buf_set_extmark(0, ns, 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. diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 83c9d54725..1e8964d912 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -729,7 +729,7 @@ void nvim_set_vvar(String name, Object value, Error *err) /// @param opts Optional parameters. /// - verbose: Message was printed as a result of 'verbose' option /// if Nvim was invoked with -V3log_file, the message will be -/// redirected to the log_file and surpressed from direct output. +/// redirected to the log_file and suppressed from direct output. void nvim_echo(Array chunks, Boolean history, Dict(echo_opts) *opts, Error *err) FUNC_API_SINCE(7) { -- cgit From 47ba78f89a1f0bba8168b4408bc55a3024d5ab97 Mon Sep 17 00:00:00 2001 From: bfredl Date: Fri, 30 Dec 2022 22:17:01 +0100 Subject: refactor(ui): devirtualize the ui layer - The defined interface for the UI is only the RPC protocol. The original UI interface as an array of function pointers fill no function. - On the server, all the UI:s are all RPC channels. - ui.c is only used on the server. - The compositor is a preprocessing step for single-grid UI:s - on the client, ui_client and tui talk directly to each other - we still do module separation, as ui_client.c could form the basis of a libnvim client module later. Items for later PR:s - vim.ui_attach is still an unhappy child, reconsider based on plugin experience. - the flags in ui_events.in.h are still a mess. Can be simplified now. - UX for remote attachment needs more work. - startup for client can be simplified further (think of the millisecs we can save) --- src/nvim/api/ui.c | 108 ++++++++++---------------------------------- src/nvim/api/ui.h | 2 + src/nvim/api/ui_events.in.h | 17 +++---- 3 files changed, 33 insertions(+), 94 deletions(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c index e4134133ac..32b294c0ce 100644 --- a/src/nvim/api/ui.c +++ b/src/nvim/api/ui.c @@ -29,41 +29,6 @@ #include "nvim/vim.h" #include "nvim/window.h" -typedef struct { - uint64_t channel_id; - -#define UI_BUF_SIZE 4096 ///< total buffer size for pending msgpack data. - /// guaranteed size available for each new event (so packing of simple events - /// and the header of grid_line will never fail) -#define EVENT_BUF_SIZE 256 - char buf[UI_BUF_SIZE]; ///< buffer of packed but not yet sent msgpack data - char *buf_wptr; ///< write head of buffer - const char *cur_event; ///< name of current event (might get multiple arglists) - Array call_buf; ///< buffer for constructing a single arg list (max 16 elements!) - - // state for write_cb, while packing a single arglist to msgpack. This - // might fail due to buffer overflow. - size_t pack_totlen; - bool buf_overflow; - char *temp_buf; - - // We start packing the two outermost msgpack arrays before knowing the total - // number of elements. Thus track the location where array size will need - // to be written in the msgpack buffer, once the specific array is finished. - char *nevents_pos; - char *ncalls_pos; - uint32_t nevents; ///< number of distinct events (top-level args to "redraw" - uint32_t ncalls; ///< number of calls made to the current event (plus one for the name!) - bool flushed_events; ///< events where sent to client without "flush" event - - int hl_id; // Current highlight for legacy put event. - Integer cursor_row, cursor_col; // Intended visible cursor position. - - // Position of legacy cursor, used both for drawing and visible user cursor. - Integer client_row, client_col; - bool wildmenu_active; -} UIData; - #define BUF_POS(data) ((size_t)((data)->buf_wptr - (data)->buf)) #ifdef INCLUDE_GENERATED_DECLARATIONS @@ -143,8 +108,6 @@ void remote_ui_disconnect(uint64_t channel_id) UIData *data = ui->data; kv_destroy(data->call_buf); pmap_del(uint64_t)(&connected_uis, channel_id); - xfree(data); - ui->data = NULL; // Flag UI as "stopped". ui_detach_impl(ui, channel_id); xfree(ui); } @@ -204,32 +167,6 @@ void nvim_ui_attach(uint64_t channel_id, Integer width, Integer height, Dictiona ui->pum_col = -1.0; ui->rgb = true; ui->override = false; - ui->grid_resize = remote_ui_grid_resize; - ui->grid_clear = remote_ui_grid_clear; - ui->grid_cursor_goto = remote_ui_grid_cursor_goto; - ui->mode_info_set = remote_ui_mode_info_set; - ui->update_menu = remote_ui_update_menu; - ui->busy_start = remote_ui_busy_start; - ui->busy_stop = remote_ui_busy_stop; - ui->mouse_on = remote_ui_mouse_on; - ui->mouse_off = remote_ui_mouse_off; - ui->mode_change = remote_ui_mode_change; - ui->grid_scroll = remote_ui_grid_scroll; - ui->hl_attr_define = remote_ui_hl_attr_define; - ui->hl_group_set = remote_ui_hl_group_set; - ui->raw_line = remote_ui_raw_line; - ui->bell = remote_ui_bell; - ui->visual_bell = remote_ui_visual_bell; - ui->default_colors_set = remote_ui_default_colors_set; - ui->flush = remote_ui_flush; - ui->suspend = remote_ui_suspend; - ui->set_title = remote_ui_set_title; - ui->set_icon = remote_ui_set_icon; - ui->option_set = remote_ui_option_set; - ui->msg_set_pos = remote_ui_msg_set_pos; - ui->event = remote_ui_event; - ui->inspect = remote_ui_inspect; - ui->win_viewport = remote_ui_win_viewport; CLEAR_FIELD(ui->ui_ext); @@ -252,7 +189,7 @@ void nvim_ui_attach(uint64_t channel_id, Integer width, Integer height, Dictiona ui->ui_ext[kUICmdline] = true; } - UIData *data = xmalloc(sizeof(UIData)); + UIData *data = ui->data; data->channel_id = channel_id; data->cur_event = NULL; data->hl_id = 0; @@ -267,7 +204,6 @@ void nvim_ui_attach(uint64_t channel_id, Integer width, Integer height, Dictiona data->wildmenu_active = false; data->call_buf = (Array)ARRAY_DICT_INIT; kv_ensure_space(data->call_buf, 16); - ui->data = data; pmap_put(uint64_t)(&connected_uis, channel_id, ui); ui_attach_impl(ui, channel_id); @@ -313,6 +249,10 @@ void nvim_ui_detach(uint64_t channel_id, Error *err) remote_ui_disconnect(channel_id); } +// TODO(bfredl): use me to detach a specifc ui from the server +void remote_ui_stop(UI *ui) +{} + void nvim_ui_try_resize(uint64_t channel_id, Integer width, Integer height, Error *err) FUNC_API_SINCE(1) FUNC_API_REMOTE_ONLY { @@ -684,7 +624,7 @@ static void push_call(UI *ui, const char *name, Array args) data->ncalls++; } -static void remote_ui_grid_clear(UI *ui, Integer grid) +void remote_ui_grid_clear(UI *ui, Integer grid) { UIData *data = ui->data; Array args = data->call_buf; @@ -695,7 +635,7 @@ static void remote_ui_grid_clear(UI *ui, Integer grid) push_call(ui, name, args); } -static void remote_ui_grid_resize(UI *ui, Integer grid, Integer width, Integer height) +void remote_ui_grid_resize(UI *ui, Integer grid, Integer width, Integer height) { UIData *data = ui->data; Array args = data->call_buf; @@ -708,8 +648,8 @@ static void remote_ui_grid_resize(UI *ui, Integer grid, Integer width, Integer h push_call(ui, name, args); } -static void remote_ui_grid_scroll(UI *ui, Integer grid, Integer top, Integer bot, Integer left, - Integer right, Integer rows, Integer cols) +void remote_ui_grid_scroll(UI *ui, Integer grid, Integer top, Integer bot, Integer left, + Integer right, Integer rows, Integer cols) { UIData *data = ui->data; if (ui->ui_ext[kUILinegrid]) { @@ -745,8 +685,8 @@ static void remote_ui_grid_scroll(UI *ui, Integer grid, Integer top, Integer bot } } -static void remote_ui_default_colors_set(UI *ui, Integer rgb_fg, Integer rgb_bg, Integer rgb_sp, - Integer cterm_fg, Integer cterm_bg) +void remote_ui_default_colors_set(UI *ui, Integer rgb_fg, Integer rgb_bg, Integer rgb_sp, + Integer cterm_fg, Integer cterm_bg) { if (!ui->ui_ext[kUITermColors]) { HL_SET_DEFAULT_COLORS(rgb_fg, rgb_bg, rgb_sp); @@ -776,8 +716,8 @@ static void remote_ui_default_colors_set(UI *ui, Integer rgb_fg, Integer rgb_bg, } } -static void remote_ui_hl_attr_define(UI *ui, Integer id, HlAttrs rgb_attrs, HlAttrs cterm_attrs, - Array info) +void remote_ui_hl_attr_define(UI *ui, Integer id, HlAttrs rgb_attrs, HlAttrs cterm_attrs, + Array info) { if (!ui->ui_ext[kUILinegrid]) { return; @@ -802,7 +742,7 @@ static void remote_ui_hl_attr_define(UI *ui, Integer id, HlAttrs rgb_attrs, HlAt push_call(ui, "hl_attr_define", args); } -static void remote_ui_highlight_set(UI *ui, int id) +void remote_ui_highlight_set(UI *ui, int id) { UIData *data = ui->data; Array args = data->call_buf; @@ -818,7 +758,7 @@ static void remote_ui_highlight_set(UI *ui, int id) } /// "true" cursor used only for input focus -static void remote_ui_grid_cursor_goto(UI *ui, Integer grid, Integer row, Integer col) +void remote_ui_grid_cursor_goto(UI *ui, Integer grid, Integer row, Integer col) { if (ui->ui_ext[kUILinegrid]) { UIData *data = ui->data; @@ -836,7 +776,7 @@ static void remote_ui_grid_cursor_goto(UI *ui, Integer grid, Integer row, Intege } /// emulated cursor used both for drawing and for input focus -static void remote_ui_cursor_goto(UI *ui, Integer row, Integer col) +void remote_ui_cursor_goto(UI *ui, Integer row, Integer col) { UIData *data = ui->data; if (data->client_row == row && data->client_col == col) { @@ -850,7 +790,7 @@ static void remote_ui_cursor_goto(UI *ui, Integer row, Integer col) push_call(ui, "cursor_goto", args); } -static void remote_ui_put(UI *ui, const char *cell) +void remote_ui_put(UI *ui, const char *cell) { UIData *data = ui->data; data->client_col++; @@ -859,9 +799,9 @@ static void remote_ui_put(UI *ui, const char *cell) push_call(ui, "put", args); } -static void remote_ui_raw_line(UI *ui, Integer grid, Integer row, Integer startcol, Integer endcol, - Integer clearcol, Integer clearattr, LineFlags flags, - const schar_T *chunk, const sattr_T *attrs) +void remote_ui_raw_line(UI *ui, Integer grid, Integer row, Integer startcol, Integer endcol, + Integer clearcol, Integer clearattr, LineFlags flags, const schar_T *chunk, + const sattr_T *attrs) { UIData *data = ui->data; if (ui->ui_ext[kUILinegrid]) { @@ -953,7 +893,7 @@ static void remote_ui_raw_line(UI *ui, Integer grid, Integer row, Integer startc /// /// This might happen multiple times before the actual ui_flush, if the /// total redraw size is large! -static void remote_ui_flush_buf(UI *ui) +void remote_ui_flush_buf(UI *ui) { UIData *data = ui->data; if (!data->nevents_pos) { @@ -980,7 +920,7 @@ static void remote_ui_flush_buf(UI *ui) /// /// Clients can know this happened by a final "flush" event at the end of the /// "redraw" batch. -static void remote_ui_flush(UI *ui) +void remote_ui_flush(UI *ui) { UIData *data = ui->data; if (data->nevents > 0 || data->flushed_events) { @@ -1025,7 +965,7 @@ static Array translate_firstarg(UI *ui, Array args, Arena *arena) return new_args; } -static void remote_ui_event(UI *ui, char *name, Array args) +void remote_ui_event(UI *ui, char *name, Array args) { Arena arena = ARENA_EMPTY; UIData *data = ui->data; @@ -1092,7 +1032,7 @@ free_ret: arena_mem_free(arena_finish(&arena)); } -static void remote_ui_inspect(UI *ui, Dictionary *info) +void remote_ui_inspect(UI *ui, Dictionary *info) { UIData *data = ui->data; PUT(*info, "chan", INTEGER_OBJ((Integer)data->channel_id)); diff --git a/src/nvim/api/ui.h b/src/nvim/api/ui.h index bc70406acb..b3fe0fa2bb 100644 --- a/src/nvim/api/ui.h +++ b/src/nvim/api/ui.h @@ -5,8 +5,10 @@ #include "nvim/api/private/defs.h" #include "nvim/map.h" +#include "nvim/ui.h" #ifdef INCLUDE_GENERATED_DECLARATIONS # include "api/ui.h.generated.h" +# include "ui_events_remote.h.generated.h" #endif #endif // NVIM_API_UI_H diff --git a/src/nvim/api/ui_events.in.h b/src/nvim/api/ui_events.in.h index d5c79272b7..a08e8dbfeb 100644 --- a/src/nvim/api/ui_events.in.h +++ b/src/nvim/api/ui_events.in.h @@ -37,7 +37,7 @@ void set_title(String title) void set_icon(String icon) FUNC_API_SINCE(3); void screenshot(String path) - FUNC_API_SINCE(7) FUNC_API_REMOTE_IMPL; + FUNC_API_SINCE(7); void option_set(String name, Object value) FUNC_API_SINCE(4); // Stop event is not exported as such, represented by EOF in the msgpack stream. @@ -75,7 +75,7 @@ void default_colors_set(Integer rgb_fg, Integer rgb_bg, Integer rgb_sp, Integer void hl_attr_define(Integer id, HlAttrs rgb_attrs, HlAttrs cterm_attrs, Array info) FUNC_API_SINCE(5) FUNC_API_REMOTE_IMPL; void hl_group_set(String name, Integer id) - FUNC_API_SINCE(6); + FUNC_API_SINCE(6) FUNC_API_CLIENT_IGNORE; void grid_resize(Integer grid, Integer width, Integer height) FUNC_API_SINCE(5) FUNC_API_REMOTE_IMPL FUNC_API_COMPOSITOR_IMPL FUNC_API_CLIENT_IMPL; void grid_clear(Integer grid) @@ -97,9 +97,6 @@ void raw_line(Integer grid, Integer row, Integer startcol, Integer endcol, Integ Integer clearattr, LineFlags flags, const schar_T *chunk, const sattr_T *attrs) FUNC_API_NOEXPORT FUNC_API_COMPOSITOR_IMPL; -void event(char *name, Array args) - FUNC_API_NOEXPORT FUNC_API_COMPOSITOR_IMPL; - void win_pos(Integer grid, Window win, Integer startrow, Integer startcol, Integer width, Integer height) FUNC_API_SINCE(6) FUNC_API_REMOTE_ONLY; @@ -114,11 +111,11 @@ void win_close(Integer grid) FUNC_API_SINCE(6) FUNC_API_REMOTE_ONLY; void msg_set_pos(Integer grid, Integer row, Boolean scrolled, String sep_char) - FUNC_API_SINCE(6) FUNC_API_COMPOSITOR_IMPL; + FUNC_API_SINCE(6) FUNC_API_COMPOSITOR_IMPL FUNC_API_CLIENT_IGNORE; void win_viewport(Integer grid, Window win, Integer topline, Integer botline, Integer curline, Integer curcol, Integer line_count) - FUNC_API_SINCE(7) FUNC_API_BRIDGE_IMPL; + FUNC_API_SINCE(7) FUNC_API_CLIENT_IGNORE; void win_extmark(Integer grid, Window win, Integer ns_id, Integer mark_id, Integer row, Integer col) FUNC_API_SINCE(10) FUNC_API_REMOTE_ONLY; @@ -150,11 +147,11 @@ void cmdline_block_hide(void) FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY; void wildmenu_show(Array items) - FUNC_API_SINCE(3) FUNC_API_REMOTE_IMPL; + FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY; void wildmenu_select(Integer selected) - FUNC_API_SINCE(3) FUNC_API_REMOTE_IMPL; + FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY; void wildmenu_hide(void) - FUNC_API_SINCE(3) FUNC_API_REMOTE_IMPL; + FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY; void msg_show(String kind, Array content, Boolean replace_last) FUNC_API_SINCE(6) FUNC_API_REMOTE_ONLY; -- cgit From 1f18c27404f15a3344d6f2f3992e71b3efd0923c Mon Sep 17 00:00:00 2001 From: Raphael Date: Mon, 9 Jan 2023 13:57:46 +0800 Subject: fix(ui): convert title_pos string in nvim_win_get_config --- src/nvim/api/win_config.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/win_config.c b/src/nvim/api/win_config.c index 56d5f8fb16..25bae725fc 100644 --- a/src/nvim/api/win_config.c +++ b/src/nvim/api/win_config.c @@ -299,7 +299,15 @@ Dictionary nvim_win_get_config(Window window, Error *err) ADD(titles, ARRAY_OBJ(tuple)); } PUT(rv, "title", ARRAY_OBJ(titles)); - PUT(rv, "title_pos", INTEGER_OBJ(config->title_pos)); + char *title_pos; + if (config->title_pos == 0) { + title_pos = "left"; + } else if (config->title_pos == 1){ + title_pos = "center"; + }else { + title_pos = "right"; + } + PUT(rv, "title_pos", CSTR_TO_OBJ(title_pos)); } } } -- cgit From ad34ab38dbe5ac89c7018097a4dbed033fc38f22 Mon Sep 17 00:00:00 2001 From: Raphael Date: Mon, 9 Jan 2023 14:22:10 +0800 Subject: fix: format --- src/nvim/api/win_config.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/win_config.c b/src/nvim/api/win_config.c index 25bae725fc..4e8a9015c8 100644 --- a/src/nvim/api/win_config.c +++ b/src/nvim/api/win_config.c @@ -302,9 +302,9 @@ Dictionary nvim_win_get_config(Window window, Error *err) char *title_pos; if (config->title_pos == 0) { title_pos = "left"; - } else if (config->title_pos == 1){ + } else if (config->title_pos == 1) { title_pos = "center"; - }else { + } else { title_pos = "right"; } PUT(rv, "title_pos", CSTR_TO_OBJ(title_pos)); -- cgit From 3a8be82175c3bcc26640ecfe7d13c7d8bdc06632 Mon Sep 17 00:00:00 2001 From: Raphael Date: Mon, 9 Jan 2023 17:00:32 +0800 Subject: fix: use enum type --- src/nvim/api/win_config.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/win_config.c b/src/nvim/api/win_config.c index 4e8a9015c8..602802d651 100644 --- a/src/nvim/api/win_config.c +++ b/src/nvim/api/win_config.c @@ -300,9 +300,9 @@ Dictionary nvim_win_get_config(Window window, Error *err) } PUT(rv, "title", ARRAY_OBJ(titles)); char *title_pos; - if (config->title_pos == 0) { + if (config->title_pos == kAlignLeft) { title_pos = "left"; - } else if (config->title_pos == 1) { + } else if (config->title_pos == kAlignCenter) { title_pos = "center"; } else { title_pos = "right"; -- cgit From 364b131f42509326c912c9b0fef5dfc94ed23b41 Mon Sep 17 00:00:00 2001 From: luukvbaal <31730729+luukvbaal@users.noreply.github.com> Date: Mon, 9 Jan 2023 18:12:06 +0100 Subject: feat(ui): add 'statuscolumn' option Problem: Unable to customize the column next to a window ('gutter'). Solution: Add 'statuscolumn' option that follows the 'statusline' syntax, allowing to customize the status column. Also supporting the %@ click execute function label. Adds new items @C and @s which will print the fold and sign columns. Line numbers and signs can be clicked, highlighted, aligned, transformed, margined etc. --- 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 1e8964d912..65b08ecade 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -2238,6 +2238,7 @@ Dictionary nvim_eval_statusline(String str, Dict(eval_statusline) *opts, Error * fillchar, maxwidth, hltab_ptr, + NULL, NULL); PUT(result, "width", INTEGER_OBJ(width)); -- cgit From 87cfe50944ef2c84de98eb6b124fe312eef31313 Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 10 Jan 2023 17:36:48 +0800 Subject: fix(ui): set stc to empty in floatwin with minimal style (#21720) fix(ui): set stc to emtpy in floatwin with minimal style --- src/nvim/api/win_config.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/win_config.c b/src/nvim/api/win_config.c index 602802d651..3fdd062ef0 100644 --- a/src/nvim/api/win_config.c +++ b/src/nvim/api/win_config.c @@ -114,8 +114,9 @@ /// float where the text should not be edited. Disables /// 'number', 'relativenumber', 'cursorline', 'cursorcolumn', /// 'foldcolumn', 'spell' and 'list' options. 'signcolumn' -/// is changed to `auto` and 'colorcolumn' is cleared. The -/// end-of-buffer region is hidden by setting `eob` flag of +/// is changed to `auto` and 'colorcolumn' is cleared. +/// 'statuscolumn' is changed to empty. The end-of-buffer +/// region is hidden by setting `eob` flag of /// 'fillchars' to a space char, and clearing the /// |hl-EndOfBuffer| region in 'winhighlight'. /// - border: Style of (optional) window border. This can either be a string -- cgit From 870ca1de52b240926b88f01afa697cd9b119bdac Mon Sep 17 00:00:00 2001 From: Sebastian Lyng Johansen Date: Tue, 10 Jan 2023 11:22:41 +0100 Subject: feat(float): open float relative to mouse #21531 Problem: No easy way to position a LSP hover window relative to mouse. Solution: Introduce another option to the `relative` key in `nvim_open_win()`. With this PR it should be possible to override the handler and do something similar to this https://github.com/neovim/neovim/pull/19481#issuecomment-1193248674 to have hover information displayed from the mouse. Test case: ```lua local util = require('vim.lsp.util') local function make_position_param(window, offset_encoding) window = window or 0 local buf = vim.api.nvim_win_get_buf(window) local row, col local mouse = vim.fn.getmousepos() row = mouse.line col = mouse.column offset_encoding = offset_encoding or util._get_offset_encoding(buf) row = row - 1 local line = vim.api.nvim_buf_get_lines(buf, row, row + 1, true)[1] if not line then return { line = 0, character = 0 } end if #line < col then return { line = 0, character = 0 } end col = util._str_utfindex_enc(line, col, offset_encoding) return { line = row, character = col } end local make_params = function(window, offset_encoding) window = window or 0 local buf = vim.api.nvim_win_get_buf(window) offset_encoding = offset_encoding or util._get_offset_encoding(buf) return { textDocument = util.make_text_document_params(buf), position = make_position_param(window, offset_encoding), } end local hover_timer = nil vim.o.mousemoveevent = true vim.keymap.set({ '', 'i' }, '', function() if hover_timer then hover_timer:close() end hover_timer = vim.defer_fn(function() hover_timer = nil local params = make_params() vim.lsp.buf_request( 0, 'textDocument/hover', params, vim.lsp.with(vim.lsp.handlers.hover, { silent = true, focusable = false, relative = 'mouse', }) ) end, 500) return '' end, { expr = true }) ``` --- src/nvim/api/win_config.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/nvim/api') diff --git a/src/nvim/api/win_config.c b/src/nvim/api/win_config.c index 3fdd062ef0..f81d26b486 100644 --- a/src/nvim/api/win_config.c +++ b/src/nvim/api/win_config.c @@ -74,6 +74,7 @@ /// - "editor" The global editor grid /// - "win" Window given by the `win` field, or current window. /// - "cursor" Cursor position in current window. +/// - "mouse" Mouse position /// - win: |window-ID| for relative="win". /// - anchor: Decides which corner of the float to place at (row,col): /// - "NW" northwest (default) @@ -349,6 +350,8 @@ static bool parse_float_relative(String relative, FloatRelative *out) *out = kFloatRelativeWindow; } else if (striequal(str, "cursor")) { *out = kFloatRelativeCursor; + } else if (striequal(str, "mouse")) { + *out = kFloatRelativeMouse; } else { return false; } -- cgit From 921e634119c14b03f9611f1602df171c9ffc9559 Mon Sep 17 00:00:00 2001 From: ii14 <59243201+ii14@users.noreply.github.com> Date: Thu, 12 Jan 2023 16:25:44 +0100 Subject: fix(api): nvim_create_autocmd crash on invalid types inside pattern array Co-authored-by: ii14 --- src/nvim/api/autocmd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/autocmd.c b/src/nvim/api/autocmd.c index ada042e654..931363e199 100644 --- a/src/nvim/api/autocmd.c +++ b/src/nvim/api/autocmd.c @@ -940,7 +940,7 @@ static bool get_patterns_from_pattern_or_buf(Array *patterns, Object pattern, Ob patlen = aucmd_pattern_length(pat); } } else if (v->type == kObjectTypeArray) { - if (!check_autocmd_string_array(*patterns, "pattern", err)) { + if (!check_autocmd_string_array(v->data.array, "pattern", err)) { return false; } -- cgit From 7af2c52ef051ebe801f153a2775966fb3c69b439 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 15 Jan 2023 05:24:19 +0800 Subject: docs: builtin TUI is no longer channel 0 (#21794) --- 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 65b08ecade..13c8e162b6 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -1834,7 +1834,7 @@ Dictionary nvim__stats(void) /// - "width" Requested width of the UI /// - "rgb" true if the UI uses RGB colors (false implies |cterm-colors|) /// - "ext_..." Requested UI extensions, see |ui-option| -/// - "chan" Channel id of remote UI or 0 for TUI +/// - "chan" |channel-id| of remote UI Array nvim_list_uis(void) FUNC_API_SINCE(4) { -- cgit From 3269902a13df3bccf8705db73488c0a47f495514 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sun, 15 Jan 2023 14:16:33 +0100 Subject: refactor: fix IWYU mapping file and use IWYU (#21802) Also add the EXITFREE definition to main_lib rather than the nvim target, as the header generation needs the EXITFREE flag to work properly. --- src/nvim/api/private/helpers.c | 1 - src/nvim/api/ui.c | 7 +++++-- 2 files changed, 5 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 4ff600618d..bf19c8c395 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -33,7 +33,6 @@ #include "nvim/pos.h" #include "nvim/ui.h" #include "nvim/version.h" -#include "nvim/vim.h" #ifdef INCLUDE_GENERATED_DECLARATIONS # include "api/private/funcs_metadata.generated.h" diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c index 32b294c0ce..e67607a7e4 100644 --- a/src/nvim/api/ui.c +++ b/src/nvim/api/ui.c @@ -13,7 +13,11 @@ #include "nvim/api/private/defs.h" #include "nvim/api/private/helpers.h" #include "nvim/api/ui.h" +#include "nvim/autocmd.h" #include "nvim/channel.h" +#include "nvim/event/loop.h" +#include "nvim/event/wstream.h" +#include "nvim/globals.h" #include "nvim/grid.h" #include "nvim/highlight.h" #include "nvim/main.h" @@ -27,13 +31,12 @@ #include "nvim/types.h" #include "nvim/ui.h" #include "nvim/vim.h" -#include "nvim/window.h" #define BUF_POS(data) ((size_t)((data)->buf_wptr - (data)->buf)) #ifdef INCLUDE_GENERATED_DECLARATIONS # include "api/ui.c.generated.h" -# include "ui_events_remote.generated.h" +# include "ui_events_remote.generated.h" // IWYU pragma: export #endif static PMap(uint64_t) connected_uis = MAP_INIT; -- cgit From ce66f158b55287924b33451b272de847ab75b332 Mon Sep 17 00:00:00 2001 From: erw7 Date: Sat, 5 Nov 2022 19:40:02 +0900 Subject: feat(api): show more exception info --- src/nvim/api/private/helpers.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index bf19c8c395..519f2cc5bf 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -150,7 +150,18 @@ bool try_end(Error *err) xfree(msg); } } else if (did_throw) { - api_set_error(err, kErrorTypeException, "%s", current_exception->value); + if (*current_exception->throw_name != NUL) { + if (current_exception->throw_lnum != 0) { + api_set_error(err, kErrorTypeException, "%s, line %" PRIdLINENR ": %s", + current_exception->throw_name, current_exception->throw_lnum, + current_exception->value); + } else { + api_set_error(err, kErrorTypeException, "%s: %s", + current_exception->throw_name, current_exception->value); + } + } else { + api_set_error(err, kErrorTypeException, "%s", current_exception->value); + } discard_current_exception(); } -- cgit From 2c1e7242f9bed345e520e9060e5e13fe48a023eb Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Wed, 18 Jan 2023 11:52:19 +0100 Subject: refactor: replace char_u with char 23 (#21798) Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/api/vim.c | 2 +- src/nvim/api/win_config.c | 2 +- 2 files 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 13c8e162b6..a53b30dd8a 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -2271,7 +2271,7 @@ Dictionary nvim_eval_statusline(String str, Dict(eval_statusline) *opts, Error * if (sp->userhl == 0) { grpname = get_default_stl_hl(wp, use_winbar); } else if (sp->userhl < 0) { - grpname = (char *)syn_id2name(-sp->userhl); + grpname = syn_id2name(-sp->userhl); } else { snprintf(user_group, sizeof(user_group), "User%d", sp->userhl); grpname = user_group; diff --git a/src/nvim/api/win_config.c b/src/nvim/api/win_config.c index f81d26b486..0ffeac1bff 100644 --- a/src/nvim/api/win_config.c +++ b/src/nvim/api/win_config.c @@ -278,7 +278,7 @@ Dictionary nvim_win_get_config(Window window, Error *err) String s = cstrn_to_string((const char *)config->border_chars[i], sizeof(schar_T)); int hi_id = config->border_hl_ids[i]; - char *hi_name = (char *)syn_id2name(hi_id); + char *hi_name = syn_id2name(hi_id); if (hi_name[0]) { ADD(tuple, STRING_OBJ(s)); ADD(tuple, STRING_OBJ(cstr_to_string((const char *)hi_name))); -- cgit From 8a4285d5637c146a0ae606918a8e77063c6a5f0d Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Wed, 18 Jan 2023 14:17:11 +0100 Subject: refactor: replace char_u with char 24 (#21823) refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/api/extmark.c | 2 +- src/nvim/api/private/converter.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/extmark.c b/src/nvim/api/extmark.c index 44e7ed3986..ab3b3485e4 100644 --- a/src/nvim/api/extmark.c +++ b/src/nvim/api/extmark.c @@ -698,7 +698,7 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, Integer line, Integer } if (opts->sign_text.type == kObjectTypeString) { - if (!init_sign_text((char **)&decor.sign_text, + if (!init_sign_text(&decor.sign_text, opts->sign_text.data.string.data)) { api_set_error(err, kErrorTypeValidation, "sign_text is not a valid value"); goto error; diff --git a/src/nvim/api/private/converter.c b/src/nvim/api/private/converter.c index 7770ba39d8..58ff552ab7 100644 --- a/src/nvim/api/private/converter.c +++ b/src/nvim/api/private/converter.c @@ -358,7 +358,7 @@ bool object_to_vim(Object obj, typval_T *tv, Error *err) } case kObjectTypeLuaRef: { - char *name = (char *)register_luafunc(api_new_luaref(obj.data.luaref)); + char *name = register_luafunc(api_new_luaref(obj.data.luaref)); tv->v_type = VAR_FUNC; tv->vval.v_string = xstrdup(name); break; -- cgit From cb757f2663e6950e655c6306d713338dfa66b18d Mon Sep 17 00:00:00 2001 From: Arnout Engelen Date: Mon, 23 Jan 2023 10:26:46 +0100 Subject: build: make generated source files reproducible #21586 Problem: Build is not reproducible, because generated source files (.c/.h/) are not deterministic, mostly because Lua pairs() is unordered by design (for security). https://github.com/LuaJIT/LuaJIT/issues/626#issuecomment-707005671 https://www.lua.org/manual/5.1/manual.html#pdf-next > The order in which the indices are enumerated is not specified [...] > >> The hardening of the VM deliberately randomizes string hashes. This in >> turn randomizes the iteration order of tables with string keys. Solution: - Update the code generation scripts to be deterministic. - That is only a partial solution: the exported function (funcs_metadata.generated.h) and ui event (ui_events_metadata.generated.h) metadata have some mpack'ed tables, which are not serialized deterministically. - As a workaround, introduce `PRG_GEN_LUA` cmake setting, so you can inject a modified build of luajit (with LUAJIT_SECURITY_PRN=0) that preserves table order. - Longer-term we should change the mpack'ed data structure so it no longer uses tables keyed by strings. Closes #20124 Co-Authored-By: dundargoc Co-Authored-By: Arnout Engelen --- src/nvim/api/keysets.lua | 93 ++++++++++++++++++++++++------------------------ 1 file changed, 46 insertions(+), 47 deletions(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/keysets.lua b/src/nvim/api/keysets.lua index 8f909e937f..bd709b7b25 100644 --- a/src/nvim/api/keysets.lua +++ b/src/nvim/api/keysets.lua @@ -1,8 +1,8 @@ return { - context = { + { 'context', { "types"; - }; - set_decoration_provider = { + }}; + { 'set_decoration_provider', { "on_start"; "on_buf"; "on_win"; @@ -10,8 +10,8 @@ return { "on_end"; "_on_hl_def"; "_on_spell_nav"; - }; - set_extmark = { + }}; + { 'set_extmark', { "id"; "end_line"; "end_row"; @@ -39,8 +39,8 @@ return { "conceal"; "spell"; "ui_watched"; - }; - keymap = { + }}; + { 'keymap', { "noremap"; "nowait"; "silent"; @@ -50,11 +50,11 @@ return { "callback"; "desc"; "replace_keycodes"; - }; - get_commands = { + }}; + { 'get_commands', { "builtin"; - }; - user_command = { + }}; + { 'user_command', { "addr"; "bang"; "bar"; @@ -67,8 +67,8 @@ return { "preview"; "range"; "register"; - }; - float_config = { + }}; + { 'float_config', { "row"; "col"; "width"; @@ -85,25 +85,25 @@ return { "title_pos"; "style"; "noautocmd"; - }; - runtime = { + }}; + { 'runtime', { "is_lua"; "do_source"; - }; - eval_statusline = { + }}; + { 'eval_statusline', { "winid"; "maxwidth"; "fillchar"; "highlights"; "use_winbar"; "use_tabline"; - }; - option = { + }}; + { 'option', { "scope"; "win"; "buf"; - }; - highlight = { + }}; + { 'highlight', { "bold"; "standout"; "strikethrough"; @@ -128,8 +128,8 @@ return { "blend"; "fg_indexed"; "bg_indexed"; - }; - highlight_cterm = { + }}; + { 'highlight_cterm', { "bold"; "standout"; "strikethrough"; @@ -141,15 +141,15 @@ return { "italic"; "reverse"; "nocombine"; - }; + }}; -- Autocmds - clear_autocmds = { + { 'clear_autocmds', { "buffer"; "event"; "group"; "pattern"; - }; - create_autocmd = { + }}; + { 'create_autocmd', { "buffer"; "callback"; "command"; @@ -158,24 +158,24 @@ return { "nested"; "once"; "pattern"; - }; - exec_autocmds = { + }}; + { 'exec_autocmds', { "buffer"; "group"; "modeline"; "pattern"; "data"; - }; - get_autocmds = { + }}; + { 'get_autocmds', { "event"; "group"; "pattern"; "buffer"; - }; - create_augroup = { + }}; + { 'create_augroup', { "clear"; - }; - cmd = { + }}; + { 'cmd', { "cmd"; "range"; "count"; @@ -187,12 +187,12 @@ return { "nargs"; "addr"; "nextcmd"; - }; - cmd_magic = { + }}; + { 'cmd_magic', { "file"; "bar"; - }; - cmd_mods = { + }}; + { 'cmd_mods', { "silent"; "emsg_silent"; "unsilent"; @@ -213,16 +213,15 @@ return { "verbose"; "vertical"; "split"; - }; - cmd_mods_filter = { + }}; + { 'cmd_mods_filter', { "pattern"; "force"; - }; - cmd_opts = { + }}; + { 'cmd_opts', { "output"; - }; - echo_opts = { + }}; + { 'echo_opts', { "verbose"; - }; + }}; } - -- cgit From 0371d0f7afa5e01dd2ac8bbd3abcf0f7454872b3 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 23 Jan 2023 18:55:11 +0800 Subject: refactor(win_close): remove "force", don't pass on "free_buf" (#21921) Problem: The "force" flag of win_close() complicates the code and adds edge cases where it is not clear what the correct behavior should be. The "free_buf" flag of win_close() is passed on to float windows when closing the last window of a tabpage, which doesn't make much sense. Solution: Remove the "force" flag and always close float windows as if :close! is used when closing the last window of a tabpage, and set the "free_buf" flag for a float window based on whether its buffer can be freed. As 'hidden' is on by default, this change shouldn't affect many people. --- src/nvim/api/window.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c index df8ad165ba..76ea4b6d7f 100644 --- a/src/nvim/api/window.c +++ b/src/nvim/api/window.c @@ -370,7 +370,7 @@ void nvim_win_hide(Window window, Error *err) TryState tstate; try_enter(&tstate); if (tabpage == curtab) { - win_close(win, false, false); + win_close(win, false); } else { win_close_othertab(win, false, tabpage); } -- cgit From fca39eeabba84853960fb514edf402fbf8f586e3 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 24 Jan 2023 15:39:43 +0800 Subject: fix(api): don't allow hiding aucmd_win from another tabpage (#21975) --- src/nvim/api/window.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c index 76ea4b6d7f..17cc1447ac 100644 --- a/src/nvim/api/window.c +++ b/src/nvim/api/window.c @@ -369,11 +369,16 @@ void nvim_win_hide(Window window, Error *err) tabpage_T *tabpage = win_find_tabpage(win); TryState tstate; try_enter(&tstate); - if (tabpage == curtab) { + + // Never close the autocommand window. + if (is_aucmd_win(win)) { + emsg(_(e_autocmd_close)); + } else if (tabpage == curtab) { win_close(win, false); } else { win_close_othertab(win, false, tabpage); } + vim_ignored = try_leave(&tstate, err); } -- cgit From c6ab8dfc15e0f6f1a805ce2145e2b4f0072b33d1 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 24 Jan 2023 18:31:07 +0800 Subject: revert: "refactor(win_close): remove "force", don't pass on "free_buf" (#21921)" (#21979) This reverts commit 0371d0f7afa5e01dd2ac8bbd3abcf0f7454872b3. > 'bufhidden' option exists. I don't think we should assume autoclosing windows are fine just because 'hidden' is set. --- src/nvim/api/window.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c index 17cc1447ac..e2c234ab29 100644 --- a/src/nvim/api/window.c +++ b/src/nvim/api/window.c @@ -374,7 +374,7 @@ void nvim_win_hide(Window window, Error *err) if (is_aucmd_win(win)) { emsg(_(e_autocmd_close)); } else if (tabpage == curtab) { - win_close(win, false); + win_close(win, false, false); } else { win_close_othertab(win, false, tabpage); } -- cgit From f3039ce531f49a63f8fd07317c1f957fb28fc6a7 Mon Sep 17 00:00:00 2001 From: "Paul \"LeoNerd\" Evans" Date: Thu, 19 Jan 2023 23:18:21 +0000 Subject: feat(highlight): define the concept of altfont as a (c)term rendering attribute --- src/nvim/api/keysets.lua | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/nvim/api') diff --git a/src/nvim/api/keysets.lua b/src/nvim/api/keysets.lua index bd709b7b25..30dcef6127 100644 --- a/src/nvim/api/keysets.lua +++ b/src/nvim/api/keysets.lua @@ -114,6 +114,7 @@ return { "underdashed"; "italic"; "reverse"; + "altfont"; "nocombine"; "default"; "cterm"; @@ -140,6 +141,7 @@ return { "underdashed"; "italic"; "reverse"; + "altfont"; "nocombine"; }}; -- Autocmds -- cgit