From be15ac06badbea6b11390ad7d9c2ddd4aea73480 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 16 Jan 2022 18:44:28 +0800 Subject: feat(statusline): support multibyte fillchar This includes a partial port of Vim patch 8.2.2569 and some changes to nvim_eval_statusline() to allow a multibyte fillchar. Literally every line of C code touched by that patch has been refactored in Nvim, and that patch contains some irrelevant foldcolumn tests I'm not sure how to port (as Nvim's foldcolumn behavior has diverged from Vim's). --- src/nvim/api/vim.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 59db12f2c0..7ef8faa67e 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -19,6 +19,7 @@ #include "nvim/ascii.h" #include "nvim/buffer.h" #include "nvim/buffer_defs.h" +#include "nvim/charset.h" #include "nvim/context.h" #include "nvim/decoration.h" #include "nvim/edit.h" @@ -2234,7 +2235,7 @@ Dictionary nvim_eval_statusline(String str, Dict(eval_statusline) *opts, Error * Dictionary result = ARRAY_DICT_INIT; int maxwidth; - char fillchar = 0; + int fillchar = 0; Window window = 0; bool use_tabline = false; bool highlights = false; @@ -2249,12 +2250,12 @@ Dictionary nvim_eval_statusline(String str, Dict(eval_statusline) *opts, Error * } if (HAS_KEY(opts->fillchar)) { - if (opts->fillchar.type != kObjectTypeString || opts->fillchar.data.string.size > 1) { - api_set_error(err, kErrorTypeValidation, "fillchar must be an ASCII character"); + if (opts->fillchar.type != kObjectTypeString || opts->fillchar.data.string.size == 0 + || char2cells(fillchar = utf_ptr2char((char_u *)opts->fillchar.data.string.data)) != 1 + || (size_t)utf_char2len(fillchar) != opts->fillchar.data.string.size) { + api_set_error(err, kErrorTypeValidation, "fillchar must be a single-width character"); return result; } - - fillchar = opts->fillchar.data.string.data[0]; } if (HAS_KEY(opts->highlights)) { @@ -2285,7 +2286,7 @@ Dictionary nvim_eval_statusline(String str, Dict(eval_statusline) *opts, Error * if (fillchar == 0) { int attr; - fillchar = (char)fillchar_status(&attr, wp); + fillchar = fillchar_status(&attr, wp); } } @@ -2313,7 +2314,7 @@ Dictionary nvim_eval_statusline(String str, Dict(eval_statusline) *opts, Error * sizeof(buf), (char_u *)str.data, false, - (char_u)fillchar, + fillchar, maxwidth, hltab_ptr, NULL); -- cgit From e850a929864508864ee52abcbac9579a6a2d2f28 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Wed, 19 Jan 2022 21:53:49 -0500 Subject: fix(coverity/340720): error if nvim_eval_statusline given invalid winid --- src/nvim/api/vim.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 59db12f2c0..88a3577de3 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -2281,6 +2281,11 @@ Dictionary nvim_eval_statusline(String str, Dict(eval_statusline) *opts, Error * fillchar = ' '; } else { wp = find_window_by_handle(window, err); + + if (wp == NULL) { + api_set_error(err, kErrorTypeException, "unknown winid %d", window); + return result; + } ewp = wp; if (fillchar == 0) { -- cgit From 6e69a3c3e79fd78b31753343213e68e73b0048c4 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 21 Jan 2022 18:08:56 +0800 Subject: refactor: remove CSI unescaping and clean up related names and comments --- src/nvim/api/vim.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 59db12f2c0..cc622a00dc 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -187,21 +187,23 @@ static void on_redraw_event(void **argv) /// On execution error: does not fail, but updates v:errmsg. /// /// To input sequences like use |nvim_replace_termcodes()| (typically -/// with escape_csi=true) to replace |keycodes|, then pass the result to +/// with escape_ks=false) to replace |keycodes|, then pass the result to /// nvim_feedkeys(). /// /// Example: ///
 ///     :let key = nvim_replace_termcodes("", v:true, v:false, v:true)
-///     :call nvim_feedkeys(key, 'n', v:true)
+///     :call nvim_feedkeys(key, 'n', v:false)
 /// 
/// /// @param keys to be typed /// @param mode behavior flags, see |feedkeys()| -/// @param escape_csi If true, escape K_SPECIAL/CSI 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() -/// @see vim_strsave_escape_csi -void nvim_feedkeys(String keys, String mode, Boolean escape_csi) +/// @see vim_strsave_escape_ks +void nvim_feedkeys(String keys, String mode, Boolean escape_ks) FUNC_API_SINCE(1) { bool remap = true; @@ -232,10 +234,10 @@ void nvim_feedkeys(String keys, String mode, Boolean escape_csi) } char *keys_esc; - if (escape_csi) { - // Need to escape K_SPECIAL and CSI before putting the string in the + if (escape_ks) { + // Need to escape K_SPECIAL before putting the string in the // typeahead buffer. - keys_esc = (char *)vim_strsave_escape_csi((char_u *)keys.data); + keys_esc = (char *)vim_strsave_escape_ks((char_u *)keys.data); } else { keys_esc = keys.data; } @@ -245,7 +247,7 @@ void nvim_feedkeys(String keys, String mode, Boolean escape_csi) typebuf_was_filled = true; } - if (escape_csi) { + if (escape_ks) { xfree(keys_esc); } -- cgit From 4aa0cdd3aa117e032325edeb755107acd4ecbf84 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Mon, 24 Jan 2022 09:36:15 +0000 Subject: feat(highlight): ns=0 to set :highlight namespace Passing ns=0 to nvim_set_hl will alter the `:highlight` namespace. --- src/nvim/api/vim.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 7c194935ce..af743eb63c 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -31,6 +31,7 @@ #include "nvim/fileio.h" #include "nvim/getchar.h" #include "nvim/highlight.h" +#include "nvim/highlight_defs.h" #include "nvim/lua/executor.h" #include "nvim/mark.h" #include "nvim/memline.h" @@ -121,7 +122,9 @@ Dictionary nvim__get_hl_defs(Integer ns_id, Error *err) /// Set a highlight group. /// -/// @param ns_id number of namespace for this highlight +/// @param ns_id number of namespace for this highlight. Use value 0 +/// to set a highlight group in the global (`:highlight`) +/// namespace. /// @param name highlight group name, like ErrorMsg /// @param val highlight definition map, like |nvim_get_hl_by_name|. /// in addition the following keys are also recognized: @@ -135,18 +138,23 @@ Dictionary nvim__get_hl_defs(Integer ns_id, Error *err) /// same as attributes of gui color /// @param[out] err Error details, if any /// -/// TODO: ns_id = 0, should modify :highlight namespace -/// TODO val should take update vs reset flag +// TODO(bfredl): val should take update vs reset flag void nvim_set_hl(Integer ns_id, String name, Dictionary val, Error *err) FUNC_API_SINCE(7) { int hl_id = syn_check_group(name.data, (int)name.size); int link_id = -1; - HlAttrs attrs = dict2hlattrs(val, true, &link_id, err); + HlAttrNames *names = NULL; // Only used when setting global namespace + if (ns_id == 0) { + names = xmalloc(sizeof(*names)); + *names = HLATTRNAMES_INIT; + } + HlAttrs attrs = dict2hlattrs(val, true, &link_id, names, err); if (!ERROR_SET(err)) { - ns_hl_def((NS)ns_id, hl_id, attrs, link_id); + ns_hl_def((NS)ns_id, hl_id, attrs, link_id, names); } + xfree(names); } /// Set active namespace for highlights. -- cgit From 0bafa44f8b9c4ad2a1cf5233bc207cba522a5dfe Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Wed, 2 Feb 2022 22:01:52 +0100 Subject: refactor(api): use a keyset for highlight dicts --- src/nvim/api/vim.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index e9182fde7f..ada041bab2 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -140,22 +140,16 @@ Dictionary nvim__get_hl_defs(Integer ns_id, Error *err) /// @param[out] err Error details, if any /// // TODO(bfredl): val should take update vs reset flag -void nvim_set_hl(Integer ns_id, String name, Dictionary val, Error *err) +void nvim_set_hl(Integer ns_id, String name, Dict(highlight) *val, Error *err) FUNC_API_SINCE(7) { int hl_id = syn_check_group(name.data, (int)name.size); int link_id = -1; - HlAttrNames *names = NULL; // Only used when setting global namespace - if (ns_id == 0) { - names = xmalloc(sizeof(*names)); - *names = HLATTRNAMES_INIT; - } - HlAttrs attrs = dict2hlattrs(val, true, &link_id, names, err); + HlAttrs attrs = dict2hlattrs(val, true, &link_id, err); if (!ERROR_SET(err)) { - ns_hl_def((NS)ns_id, hl_id, attrs, link_id, names); + ns_hl_def((NS)ns_id, hl_id, attrs, link_id, val); } - xfree(names); } /// Set active namespace for highlights. -- cgit From 23c3f7f572d3a1f3816a9a9ae1b3632c53856923 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 10 Feb 2022 09:41:25 +0800 Subject: fix(api): use changedir_func() in nvim_set_current_dir() Co-Authored-By: smolck <46855713+smolck@users.noreply.github.com> --- src/nvim/api/vim.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index ada041bab2..f7c55344f5 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -31,6 +31,7 @@ #include "nvim/file_search.h" #include "nvim/fileio.h" #include "nvim/getchar.h" +#include "nvim/globals.h" #include "nvim/highlight.h" #include "nvim/highlight_defs.h" #include "nvim/lua/executor.h" @@ -545,20 +546,19 @@ void nvim_set_current_dir(String dir, Error *err) return; } - char string[MAXPATHL]; + char_u string[MAXPATHL]; memcpy(string, dir.data, dir.size); string[dir.size] = NUL; try_start(); - if (vim_chdir((char_u *)string)) { + if (!changedir_func(string, kCdScopeGlobal)) { if (!try_end(err)) { api_set_error(err, kErrorTypeException, "Failed to change directory"); } return; } - post_chdir(kCdScopeGlobal, true); try_end(err); } -- cgit From f292dd2126f8dacd6446799ac750ab368b852f81 Mon Sep 17 00:00:00 2001 From: shadmansaleh <13149513+shadmansaleh@users.noreply.github.com> Date: Sat, 12 Feb 2022 10:54:25 +0600 Subject: fix: autoload variables not loaded with vim.g & nvim_get_var --- src/nvim/api/vim.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index f7c55344f5..f4909b0801 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -601,7 +601,19 @@ void nvim_del_current_line(Error *err) Object nvim_get_var(String name, Error *err) FUNC_API_SINCE(1) { - return dict_get_value(&globvardict, name, err); + dictitem_T *di = tv_dict_find(&globvardict, name.data, (ptrdiff_t)name.size); + if (di == NULL) { // try to autoload script + if (!script_autoload(name.data, name.size, false) || aborting()) { + api_set_error(err, kErrorTypeValidation, "Key not found: %s", name.data); + return (Object)OBJECT_INIT; + } + di = tv_dict_find(&globvardict, name.data, (ptrdiff_t)name.size); + } + if (di == NULL) { + api_set_error(err, kErrorTypeValidation, "Key not found: %s", name.data); + return (Object)OBJECT_INIT; + } + return vim_to_object(&di->di_tv); } /// Sets a global (g:) variable. -- cgit From d512be55a2ea54dd83914ff25f57c02d703f93b4 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Thu, 16 Dec 2021 11:40:23 +0000 Subject: fix(api): re-route nvim_get_runtime_file errors This allows nvim_get_runtime_file to be properly used via pcall --- src/nvim/api/vim.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index f4909b0801..0c11ea7e6e 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -497,8 +497,12 @@ ArrayOf(String) nvim_get_runtime_file(String name, Boolean all, Error *err) int flags = DIP_DIRFILE | (all ? DIP_ALL : 0); - do_in_runtimepath((char_u *)(name.size ? name.data : ""), - flags, find_runtime_cb, &rv); + TRY_WRAP({ + try_start(); + do_in_runtimepath((char_u *)(name.size ? name.data : ""), + flags, find_runtime_cb, &rv); + try_end(err); + }); return rv; } -- cgit From cc81a8253be032aa12f05730e8a2f1b5d94fd08c Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 16 Feb 2022 16:58:32 +0800 Subject: docs: minor changes related to mapping description --- src/nvim/api/vim.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index f4909b0801..565015cada 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -1584,7 +1584,7 @@ ArrayOf(Dictionary) nvim_get_keymap(uint64_t channel_id, String mode) /// @param rhs Right-hand-side |{rhs}| of the mapping. /// @param opts Optional parameters map. Accepts all |:map-arguments| /// as keys excluding || but including |noremap| and "desc". -/// |desc| can be used to give a description to keymap. +/// "desc" can be used to give a description to keymap. /// When called from Lua, also accepts a "callback" key that takes /// a Lua function to call when the mapping is executed. /// Values are Booleans. Unknown key is an error. -- cgit From 1e7cb2dcd975aadeb91b913f117b21c7775c3374 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Mon, 21 Feb 2022 20:17:36 +0000 Subject: fix(highlight): accept NONE as a color name (#17487) ... for when `ns=0`. Also update the documentation of nvim_set_hl to clarify the set behaviour. Fixes #17478 --- src/nvim/api/vim.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 11bb1750e4..4dc599564f 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -124,6 +124,10 @@ Dictionary nvim__get_hl_defs(Integer ns_id, Error *err) /// Set a highlight group. /// +/// Note: unlike the `:highlight` command which can update a highlight group, +/// this function completely replaces the definition. For example: +/// `nvim_set_hl(0, 'Visual', {})` will clear the highlight group 'Visual'. +/// /// @param ns_id number of namespace for this highlight. Use value 0 /// to set a highlight group in the global (`:highlight`) /// namespace. -- cgit From b87867e69e94d9784468a126f21c721446f080de Mon Sep 17 00:00:00 2001 From: erw7 Date: Sat, 11 Sep 2021 11:48:58 +0900 Subject: feat(lua): add proper support of luv threads --- src/nvim/api/vim.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 4dc599564f..cd9d61ed24 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -1955,7 +1955,7 @@ Dictionary nvim__stats(void) Dictionary rv = ARRAY_DICT_INIT; PUT(rv, "fsync", INTEGER_OBJ(g_stats.fsync)); PUT(rv, "redraw", INTEGER_OBJ(g_stats.redraw)); - PUT(rv, "lua_refcount", INTEGER_OBJ(nlua_refcount)); + PUT(rv, "lua_refcount", INTEGER_OBJ(nlua_get_global_ref_count())); return rv; } -- cgit From 1b5767aa3480c0cdc43f7a4b78f36a14e85a182f Mon Sep 17 00:00:00 2001 From: Javier Lopez Date: Sun, 27 Feb 2022 14:35:06 -0500 Subject: feat(lua): add to user commands callback (#17522) Works similar to ex . It only splits the arguments if the command has more than one posible argument. In cases were the command can only have 1 argument opts.fargs = { opts.args } --- src/nvim/api/vim.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index cd9d61ed24..302dccbde7 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -2415,6 +2415,8 @@ Dictionary nvim_eval_statusline(String str, Dict(eval_statusline) *opts, Error * /// from Lua, the command can also be a Lua function. The function is called with a /// single table argument that contains the following keys: /// - 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 || /// - bang: (boolean) "true" if the command was executed with a ! modifier || /// - line1: (number) The starting line of the command range || /// - line2: (number) The final line of the command range || -- cgit From ebfe083337701534887ac3ea3d8e7ad47f7a206a Mon Sep 17 00:00:00 2001 From: shadmansaleh <13149513+shadmansaleh@users.noreply.github.com> Date: Sat, 8 Jan 2022 00:39:44 +0600 Subject: feat(lua): show proper verbose output for lua configuration `:verbose` didn't work properly with lua configs (For example: options or keymaps are set from lua, just say that they were set from lua, doesn't say where they were set at. This fixes that issue. Now `:verbose` will provide filename and line no when option/keymap is set from lua. Changes: - compiles lua/vim/keymap.lua as vim/keymap.lua - When souring a lua file current_sctx.sc_sid is set to SID_LUA - Moved finding scripts SID out of `do_source()` to `get_current_script_id()`. So it can be reused for lua files. - Added new function `nlua_get_sctx` that extracts current lua scripts name and line no with debug library. And creates a sctx for it. NOTE: This function ignores C functions and blacklist which currently contains only vim/_meta.lua so vim.o/opt wrappers aren't targeted. - Added function `nlua_set_sctx` that changes provided sctx to current lua scripts sctx if a lua file is being executed. - Added tests in tests/functional/lua/verbose_spec.lua - add primary support for additional types (:autocmd, :function, :syntax) to lua verbose Note: These can't yet be directly set from lua but once that's possible :verbose should work for them hopefully :D - add :verbose support for nvim_exec & nvim_command within lua Currently auto commands/commands/functions ... can only be defined by nvim_exec/nvim_command this adds support for them. Means if those Are defined within lua with vim.cmd/nvim_exec :verbose will show their location . Though note it'll show the line no on which nvim_exec call was made. --- src/nvim/api/vim.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 302dccbde7..9d0b096a36 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -1586,6 +1586,7 @@ ArrayOf(Dictionary) nvim_get_keymap(uint64_t channel_id, String mode) /// nmap /// /// +/// @param channel_id /// @param mode Mode short-name (map command prefix: "n", "i", "v", "x", …) /// or "!" for |:map!|, or empty string for |:map|. /// @param lhs Left-hand-side |{lhs}| of the mapping. @@ -1597,10 +1598,11 @@ ArrayOf(Dictionary) nvim_get_keymap(uint64_t channel_id, String mode) /// a Lua function to call when the mapping is executed. /// Values are Booleans. Unknown key is an error. /// @param[out] err Error details, if any. -void nvim_set_keymap(String mode, String lhs, String rhs, Dict(keymap) *opts, Error *err) +void nvim_set_keymap(uint64_t channel_id, String mode, String lhs, String rhs, Dict(keymap) *opts, + Error *err) FUNC_API_SINCE(6) { - modify_keymap(-1, false, mode, lhs, rhs, opts, err); + modify_keymap(channel_id, -1, false, mode, lhs, rhs, opts, err); } /// Unmaps a global |mapping| for the given mode. @@ -1608,10 +1610,10 @@ void nvim_set_keymap(String mode, String lhs, String rhs, Dict(keymap) *opts, Er /// To unmap a buffer-local mapping, use |nvim_buf_del_keymap()|. /// /// @see |nvim_set_keymap()| -void nvim_del_keymap(String mode, String lhs, Error *err) +void nvim_del_keymap(uint64_t channel_id, String mode, String lhs, Error *err) FUNC_API_SINCE(6) { - nvim_buf_del_keymap(-1, mode, lhs, err); + nvim_buf_del_keymap(channel_id, -1, mode, lhs, err); } /// Gets a map of global (non-buffer-local) Ex commands. -- cgit From 045422e4a081e9dedff014346cc32eaef45e04e1 Mon Sep 17 00:00:00 2001 From: Charlie Groves Date: Tue, 1 Mar 2022 15:58:42 -0500 Subject: fix: respect os_proc_children rv of pid not found os_proc_children returns 2 if there's a failure in the underlying syscall. Only shell out to pgrep in that case. It returns 1 if the pid isn't found. In that case, we can roll forward with returning an empty list. --- src/nvim/api/vim.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 9d0b096a36..c37df45c14 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -1991,7 +1991,7 @@ Array nvim_get_proc_children(Integer pid, Error *err) size_t proc_count; int rv = os_proc_children((int)pid, &proc_list, &proc_count); - if (rv != 0) { + if (rv == 2) { // syscall failed (possibly because of kernel options), try shelling out. DLOG("fallback to vim._os_proc_children()"); Array a = ARRAY_DICT_INIT; -- cgit From 3011794c8600f529bc049983a64ca99ae03908df Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 10 Mar 2022 07:18:49 +0800 Subject: feat(api): relax statusline fillchar width check Treat fillchar as single-width even if it isn't. --- src/nvim/api/vim.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index c37df45c14..1a324bfaa5 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -2241,7 +2241,7 @@ Array nvim_get_mark(String name, Dictionary opts, Error *err) /// - winid: (number) |window-ID| of the window to use as context for statusline. /// - maxwidth: (number) Maximum width of statusline. /// - fillchar: (string) Character to fill blank spaces in the statusline (see -/// 'fillchars'). +/// 'fillchars'). Treated as single-width even if it isn't. /// - highlights: (boolean) Return highlight information. /// - use_tabline: (boolean) Evaluate tabline instead of statusline. When |TRUE|, {winid} /// is ignored. @@ -2277,11 +2277,12 @@ Dictionary nvim_eval_statusline(String str, Dict(eval_statusline) *opts, Error * if (HAS_KEY(opts->fillchar)) { if (opts->fillchar.type != kObjectTypeString || opts->fillchar.data.string.size == 0 - || char2cells(fillchar = utf_ptr2char((char_u *)opts->fillchar.data.string.data)) != 1 - || (size_t)utf_char2len(fillchar) != opts->fillchar.data.string.size) { - api_set_error(err, kErrorTypeValidation, "fillchar must be a single-width character"); + || ((size_t)utf_ptr2len((char_u *)opts->fillchar.data.string.data) + != opts->fillchar.data.string.size)) { + api_set_error(err, kErrorTypeValidation, "fillchar must be a single character"); return result; } + fillchar = utf_ptr2char((char_u *)opts->fillchar.data.string.data); } if (HAS_KEY(opts->highlights)) { -- cgit From 7e3bdc75e44b9139d8afaea4381b53ae78b15746 Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Wed, 9 Mar 2022 21:19:37 +0100 Subject: refactor(uncrustify): format all c files --- src/nvim/api/vim.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 1a324bfaa5..b2d866ae0e 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -722,15 +722,15 @@ Object nvim_get_option_value(String name, Dict(option) *opts, Error *err) break; case 2: switch (numval) { - case 0: - case 1: - rv = BOOLEAN_OBJ(numval); - break; - default: - // Boolean options that return something other than 0 or 1 should return nil. Currently this - // only applies to 'autoread' which uses -1 as a local value to indicate "unset" - rv = NIL; - break; + case 0: + case 1: + rv = BOOLEAN_OBJ(numval); + break; + default: + // Boolean options that return something other than 0 or 1 should return nil. Currently this + // only applies to 'autoread' which uses -1 as a local value to indicate "unset" + rv = NIL; + break; } break; default: -- cgit From 1b054119ec1a7208b49feeaa496c2e1d55252989 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Thu, 10 Mar 2022 15:17:06 +0000 Subject: refactor(decorations): move provider code Move decoration provider code to a separate file. --- src/nvim/api/vim.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 1a324bfaa5..1573c6e0e3 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -22,6 +22,7 @@ #include "nvim/charset.h" #include "nvim/context.h" #include "nvim/decoration.h" +#include "nvim/decoration_provider.h" #include "nvim/edit.h" #include "nvim/eval.h" #include "nvim/eval/typval.h" -- cgit From 5862176764c7a86d5fdd2685122810e14a3d5b02 Mon Sep 17 00:00:00 2001 From: Charlie Groves Date: Wed, 16 Feb 2022 17:11:50 -0500 Subject: feat(remote): add basic --remote support This is starting from @geekodour's work at https://github.com/neovim/neovim/pull/8326 --- src/nvim/api/vim.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index ebf4f65c91..b82a7553cb 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -1997,7 +1997,7 @@ Array nvim_get_proc_children(Integer pid, Error *err) DLOG("fallback to vim._os_proc_children()"); Array a = ARRAY_DICT_INIT; ADD(a, INTEGER_OBJ(pid)); - String s = cstr_to_string("return vim._os_proc_children(select(1, ...))"); + String s = cstr_to_string("return vim._os_proc_children(select(...))"); Object o = nlua_exec(s, a, err); api_free_string(s); api_free_array(a); -- cgit From 039e94f491d2f8576cbef1aeacd5ea1f7bc0982a Mon Sep 17 00:00:00 2001 From: Charlie Groves Date: Thu, 24 Feb 2022 10:47:41 -0500 Subject: test(remote): add tests for --remote This also fixes a fair number of issues found in running the tests --- src/nvim/api/vim.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index b82a7553cb..b691dee2ef 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -1997,7 +1997,7 @@ Array nvim_get_proc_children(Integer pid, Error *err) DLOG("fallback to vim._os_proc_children()"); Array a = ARRAY_DICT_INIT; ADD(a, INTEGER_OBJ(pid)); - String s = cstr_to_string("return vim._os_proc_children(select(...))"); + String s = cstr_to_string("return vim._os_proc_children(...)"); Object o = nlua_exec(s, a, err); api_free_string(s); api_free_array(a); -- cgit From 5051510ade5f171c1239906c8638e804356186fe Mon Sep 17 00:00:00 2001 From: erw7 Date: Fri, 12 Nov 2021 00:07:03 +0900 Subject: fix(channel): fix channel consistency - Fix the problem that chanclose() does not work for channel created by nvim_open_term(). - Fix the problem that the loopback channel is not released. - Fix the error message when sending raw data to the loopback channel. --- src/nvim/api/vim.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index b691dee2ef..c7ccc6bfeb 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -1140,6 +1140,7 @@ Integer nvim_open_term(Buffer buffer, DictionaryOf(LuaRef) opts, Error *err) TerminalOptions topts; Channel *chan = channel_alloc(kChannelStreamInternal); chan->stream.internal.cb = cb; + chan->stream.internal.closed = false; topts.data = chan; // NB: overridden in terminal_check_size if a window is already // displaying the buffer -- cgit From 3a12737e6c13e9be774483f34655e7ac96e36c09 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Sat, 2 Nov 2019 15:06:32 +0100 Subject: refactor(main): separate connection code from --remote execution code --- src/nvim/api/vim.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index b691dee2ef..a942c94f46 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -1997,9 +1997,8 @@ Array nvim_get_proc_children(Integer pid, Error *err) DLOG("fallback to vim._os_proc_children()"); Array a = ARRAY_DICT_INIT; ADD(a, INTEGER_OBJ(pid)); - String s = cstr_to_string("return vim._os_proc_children(...)"); + String s = STATIC_CSTR_AS_STRING("return vim._os_proc_children(...)"); Object o = nlua_exec(s, a, err); - api_free_string(s); api_free_array(a); if (o.type == kObjectTypeArray) { rvobj = o.data.array; -- cgit From 9e6bc228ec58b787c0985a65139d1959c9d889f0 Mon Sep 17 00:00:00 2001 From: adrian5 Date: Sun, 13 Mar 2022 13:42:12 +0100 Subject: docs(api): improve section on nvim_set_hl (#17692) --- src/nvim/api/vim.c | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index b8c66a034c..80fa677485 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -123,26 +123,24 @@ Dictionary nvim__get_hl_defs(Integer ns_id, Error *err) abort(); } -/// Set a highlight group. +/// Sets a highlight group. /// -/// Note: unlike the `:highlight` command which can update a highlight group, +/// Note: Unlike the `:highlight` command which can update a highlight group, /// this function completely replaces the definition. For example: /// `nvim_set_hl(0, 'Visual', {})` will clear the highlight group 'Visual'. /// -/// @param ns_id number of namespace for this highlight. Use value 0 -/// to set a highlight group in the global (`:highlight`) -/// namespace. -/// @param name highlight group name, like ErrorMsg -/// @param val highlight definition map, like |nvim_get_hl_by_name|. -/// in addition the following keys are also recognized: -/// `default`: don't override existing definition, -/// like `hi default` -/// `ctermfg`: sets foreground of cterm color -/// `ctermbg`: sets background of cterm color -/// `cterm` : cterm attribute map. sets attributed for -/// cterm colors. similer to `hi cterm` -/// Note: by default cterm attributes are -/// same as attributes of gui color +/// @param ns_id Namespace id for this highlight |nvim_create_namespace()|. +/// Use 0 to set a highlight group globally |:highlight|. +/// @param name Highlight group name, e.g. "ErrorMsg" +/// @param val Highlight definition map, like |synIDattr()|. In +/// addition, the following keys are recognized: +/// - default: Don't override existing definition |:hi-default| +/// - ctermfg: Sets foreground of cterm color |highlight-ctermfg| +/// - ctermbg: Sets background of cterm color |highlight-ctermbg| +/// - cterm: cterm attribute map, like +/// |highlight-args|. +/// Note: Attributes default to those set for `gui` +/// if not set. /// @param[out] err Error details, if any /// // TODO(bfredl): val should take update vs reset flag -- cgit From 4ba12b3dda34472c193c9fa8ffd7d3bd5b6c04d6 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sun, 13 Mar 2022 15:11:17 +0100 Subject: refactor: fix clint warnings (#17682) --- src/nvim/api/vim.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 80fa677485..3292ee2ef8 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -219,7 +219,7 @@ void nvim_feedkeys(String keys, String mode, Boolean escape_ks) bool execute = false; bool dangerous = false; - for (size_t i = 0; i < mode.size; ++i) { + for (size_t i = 0; i < mode.size; i++) { switch (mode.data[i]) { case 'n': remap = false; break; @@ -1880,7 +1880,7 @@ static void write_msg(String message, bool to_err) } \ line_buf[pos++] = message.data[i]; - ++no_wait_return; + no_wait_return++; for (uint32_t i = 0; i < message.size; i++) { if (got_int) { break; @@ -1891,7 +1891,7 @@ static void write_msg(String message, bool to_err) PUSH_CHAR(i, out_pos, out_line_buf, msg); } } - --no_wait_return; + no_wait_return--; msg_end(); } -- cgit From d238b8f6003d34cae7f65ff7585b48a2cd9449fb Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Thu, 17 Mar 2022 06:21:24 +0100 Subject: chore: fix typos (#17670) Co-authored-by: zeertzjq --- src/nvim/api/vim.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 3292ee2ef8..0bdccf7a0b 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -127,7 +127,7 @@ Dictionary nvim__get_hl_defs(Integer ns_id, Error *err) /// /// Note: Unlike the `:highlight` command which can update a highlight group, /// this function completely replaces the definition. For example: -/// `nvim_set_hl(0, 'Visual', {})` will clear the highlight group 'Visual'. +/// ``nvim_set_hl(0, 'Visual', {})`` will clear the highlight group 'Visual'. /// /// @param ns_id Namespace id for this highlight |nvim_create_namespace()|. /// Use 0 to set a highlight group globally |:highlight|. -- cgit From 5ab122917474b3f9e88be4ee88bc6d627980cfe0 Mon Sep 17 00:00:00 2001 From: Famiu Haque Date: Sun, 30 Jan 2022 11:57:41 +0600 Subject: feat: add support for global statusline Ref: #9342 Adds the option to have a single global statusline for the current window at the bottom of the screen instead of a statusline at the bottom of every window. Enabled by setting `laststatus = 3`. Due to the fact that statuslines at the bottom of windows are removed when global statusline is enabled, horizontal separators are used instead to separate horizontal splits. The horizontal separator character is configurable through the`horiz` item in `'fillchars'`. Separator connector characters are also used to connect the horizontal and vertical separators together, which are also configurable through the `horizup`, `horizdown`, `vertleft`, `vertright` and `verthoriz` items in `fillchars`. The window separators are highlighted using the `WinSeparator` highlight group, which supersedes `VertSplit` and is linked to `VertSplit` by default in order to maintain backwards compatibility. --- src/nvim/api/vim.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index f4909b0801..2e3d99cdad 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -2319,7 +2319,7 @@ Dictionary nvim_eval_statusline(String str, Dict(eval_statusline) *opts, Error * maxwidth = (int)opts->maxwidth.data.integer; } else { - maxwidth = use_tabline ? Columns : wp->w_width; + maxwidth = (use_tabline || global_stl_height() > 0) ? Columns : wp->w_width; } char buf[MAXPATHL]; -- cgit From 00effff56944d5b59440dcdb5e3496d49a76d3e2 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 18 Mar 2022 04:47:08 +0000 Subject: vim-patch:8.1.1693: syntax coloring and highlighting is in one big file (#17721) Problem: Syntax coloring and highlighting is in one big file. Solution: Move the highlighting to a separate file. (Yegappan Lakshmanan, closes vim/vim#4674) https://github.com/vim/vim/commit/f9cc9f209ede9f15959e4c2351e970477c139614 Name the new file highlight_group.c instead. Co-authored-by: zeertzjq --- src/nvim/api/vim.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index d1ca7662f6..bdeac1a9f4 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -35,6 +35,7 @@ #include "nvim/globals.h" #include "nvim/highlight.h" #include "nvim/highlight_defs.h" +#include "nvim/highlight_group.h" #include "nvim/lua/executor.h" #include "nvim/mark.h" #include "nvim/memline.h" @@ -50,7 +51,6 @@ #include "nvim/popupmnu.h" #include "nvim/screen.h" #include "nvim/state.h" -#include "nvim/syntax.h" #include "nvim/types.h" #include "nvim/ui.h" #include "nvim/vim.h" @@ -112,7 +112,7 @@ Dictionary nvim_get_hl_by_id(Integer hl_id, Boolean rgb, Error *err) Integer nvim_get_hl_id_by_name(String name) FUNC_API_SINCE(7) { - return syn_check_group(name.data, (int)name.size); + return syn_check_group(name.data, name.size); } Dictionary nvim__get_hl_defs(Integer ns_id, Error *err) @@ -147,7 +147,7 @@ Dictionary nvim__get_hl_defs(Integer ns_id, Error *err) void nvim_set_hl(Integer ns_id, String name, Dict(highlight) *val, Error *err) FUNC_API_SINCE(7) { - int hl_id = syn_check_group(name.data, (int)name.size); + int hl_id = syn_check_group(name.data, name.size); int link_id = -1; HlAttrs attrs = dict2hlattrs(val, true, &link_id, err); -- cgit From 4a11c7e56fa23c92f5ddd09007a7838dcfca9b02 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 24 Mar 2022 19:40:00 +0800 Subject: chore(nvim_paste): assert the correct String (#17752) --- src/nvim/api/vim.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index bdeac1a9f4..7c7ada55a2 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -1328,7 +1328,7 @@ Boolean nvim_paste(String data, Boolean crlf, Integer phase, Error *err) if (!cancel && !(State & CMDLINE)) { // Dot-repeat. for (size_t i = 0; i < lines.size; i++) { String s = lines.items[i].data.string; - assert(data.size <= INT_MAX); + assert(s.size <= INT_MAX); AppendToRedobuffLit((char_u *)s.data, (int)s.size); // readfile()-style: "\n" is indicated by presence of N+1 item. if (i + 1 < lines.size) { -- cgit From 263a7fde35f2341f526a536690122b927300021a Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 10 Apr 2022 07:20:35 +0800 Subject: vim-patch:8.2.4723: the ModeChanged autocmd event is inefficient Problem: The ModeChanged autocmd event is inefficient. Solution: Avoid allocating memory. (closes vim/vim#10134) Rename trigger_modechanged() to may_trigger_modechanged(). https://github.com/vim/vim/commit/2bf52dd065495cbf28e28792f2c2d50d44546d9f Make v:event readonly for ModeChanged. --- src/nvim/api/vim.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 7c7ada55a2..503a1c9f23 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -1549,10 +1549,11 @@ Dictionary nvim_get_mode(void) FUNC_API_SINCE(2) FUNC_API_FAST { Dictionary rv = ARRAY_DICT_INIT; - char *modestr = get_mode(); + char modestr[MODE_MAX_LENGTH]; + get_mode(modestr); bool blocked = input_blocking(); - PUT(rv, "mode", STRING_OBJ(cstr_as_string(modestr))); + PUT(rv, "mode", STRING_OBJ(cstr_to_string(modestr))); PUT(rv, "blocking", BOOLEAN_OBJ(blocked)); return rv; -- cgit From f94f75dc0512def7fbfdfe100eea2dab3352d61f Mon Sep 17 00:00:00 2001 From: Gregory Anders Date: Sun, 10 Apr 2022 19:12:41 -0600 Subject: refactor!: rename nvim_add_user_command to nvim_create_user_command --- src/nvim/api/vim.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 503a1c9f23..626f7dc3eb 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -2408,7 +2408,7 @@ Dictionary nvim_eval_statusline(String str, Dict(eval_statusline) *opts, Error * /// /// Example: ///
-///    :call nvim_add_user_command('SayHello', 'echo "Hello world!"', {})
+///    :call nvim_create_user_command('SayHello', 'echo "Hello world!"', {})
 ///    :SayHello
 ///    Hello world!
 /// 
@@ -2436,10 +2436,10 @@ Dictionary nvim_eval_statusline(String str, Dict(eval_statusline) *opts, Error * /// {command}. /// - force: (boolean, default true) Override any previous definition. /// @param[out] err Error details, if any. -void nvim_add_user_command(String name, Object command, Dict(user_command) *opts, Error *err) +void nvim_create_user_command(String name, Object command, Dict(user_command) *opts, Error *err) FUNC_API_SINCE(9) { - add_user_command(name, command, opts, 0, err); + create_user_command(name, command, opts, 0, err); } /// Delete a user-defined command. -- cgit From 92f7286377cb077cb42484a83740a8c95f8ae7f1 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sun, 24 Apr 2022 02:01:01 +0200 Subject: docs: make docstring consistent with parameters #18178 Closes: https://github.com/neovim/neovim/issues/12691 --- src/nvim/api/vim.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 626f7dc3eb..7a966777af 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -526,8 +526,7 @@ String nvim__get_lib_dir(void) /// /// @param pat pattern of files to search for /// @param all whether to return all matches or only the first -/// @param options -/// is_lua: only search lua subdirs +/// @param opts is_lua: only search lua subdirs /// @return list of absolute paths to the found files ArrayOf(String) nvim__get_runtime(Array pat, Boolean all, Dict(runtime) *opts, Error *err) FUNC_API_SINCE(8) -- cgit From 5f3018fa1a7a97d1f961f4c33e5ae418c19202ef Mon Sep 17 00:00:00 2001 From: erw7 Date: Wed, 27 Apr 2022 13:17:06 +0900 Subject: refactor(terminal)!: drop winpty, require Windows 10 #18253 Problem: winpty is only needed for Windows 8.1. Removing it reduces our build and code complexity. Solution: - Remove winpty. - Require Windows 10. closes #18252 --- src/nvim/api/vim.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 7a966777af..0f9a4a0e0d 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -1740,7 +1740,7 @@ void nvim_set_client_info(uint64_t channel_id, String name, Dictionary version, /// - "pty" (optional) Name of pseudoterminal. On a POSIX system this /// is a device path like "/dev/pts/1". If the name is unknown, /// the key will still be present if a pty is used (e.g. for -/// winpty on Windows). +/// conpty on Windows). /// - "buffer" (optional) Buffer with connected |terminal| instance. /// - "client" (optional) Info about the peer (client on the other end of /// the RPC channel), if provided by it via -- cgit From dde4f09f51ffaf8df5cc2a81eed935e31e1f94ba Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 31 Mar 2022 15:47:53 +0800 Subject: vim-patch:8.1.2145: cannot map when modifyOtherKeys is enabled Problem: Cannot map when modifyOtherKeys is enabled. Solution: Add the mapping twice, both with modifier and as 0x08. Use only the first one when modifyOtherKeys has been detected. https://github.com/vim/vim/commit/459fd785e4a8d044147a3f83a5fca8748528aa84 Add REPTERM_NO_SPECIAL instead of REPTERM_SPECIAL because the meaning of "special" is different between Vim and Nvim. Omit seenModifyOtherKeys as Nvim supports attaching multiple UIs. Omit tests as they send terminal codes. Keep the behavior of API functions. --- src/nvim/api/vim.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 0f9a4a0e0d..2174cd1620 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -403,9 +403,19 @@ String nvim_replace_termcodes(String str, Boolean from_part, Boolean do_lt, Bool return (String) { .data = NULL, .size = 0 }; } + int flags = 0; + if (from_part) { + flags |= REPTERM_FROM_PART; + } + if (do_lt) { + flags |= REPTERM_DO_LT; + } + if (!special) { + flags |= REPTERM_NO_SPECIAL; + } + char *ptr = NULL; - replace_termcodes((char_u *)str.data, str.size, (char_u **)&ptr, - from_part, do_lt, special, CPO_TO_CPO_FLAGS); + replace_termcodes((char_u *)str.data, str.size, (char_u **)&ptr, flags, NULL, CPO_TO_CPO_FLAGS); return cstr_as_string(ptr); } -- cgit From 3c23100130725bb79c04e933c505bbeda96fb3bb Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sat, 30 Apr 2022 16:48:00 +0200 Subject: refactor: replace char_u variables and functions with char (#18288) Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/api/vim.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 2174cd1620..ac2fc09056 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -568,7 +568,7 @@ void nvim_set_current_dir(String dir, Error *err) try_start(); - if (!changedir_func(string, kCdScopeGlobal)) { + if (!changedir_func((char *)string, kCdScopeGlobal)) { if (!try_end(err)) { api_set_error(err, kErrorTypeException, "Failed to change directory"); } -- cgit From 8dbb11ebf633e40cb57568e77c7168deffc8bd7f Mon Sep 17 00:00:00 2001 From: Famiu Haque Date: Sat, 23 Apr 2022 10:21:59 +0600 Subject: feat(api): add `nvim_parse_cmdline` Adds an API function to parse a command line string and get command information from it. --- src/nvim/api/vim.c | 201 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 201 insertions(+) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index ac2fc09056..3d1b5eade4 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -28,6 +28,7 @@ #include "nvim/eval/typval.h" #include "nvim/eval/userfunc.h" #include "nvim/ex_cmds2.h" +#include "nvim/ex_cmds_defs.h" #include "nvim/ex_docmd.h" #include "nvim/file_search.h" #include "nvim/fileio.h" @@ -2460,3 +2461,203 @@ void nvim_del_user_command(String name, Error *err) { nvim_buf_del_user_command(-1, name, err); } + +/// Parse command line. +/// +/// Doesn't check the validity of command arguments. +/// +/// @param str Command line string to parse. Cannot contain "\n". +/// @param opts Optional parameters. Reserved for future use. +/// @param[out] err Error details, if any. +/// @return Dictionary containing command information, with these keys: +/// - cmd: (string) Command name. +/// - line1: (number) Starting line of command range. Only applicable if command can take a +/// range. +/// - line2: (number) Final line of command range. Only applicable if command can take a +/// range. +/// - bang: (boolean) Whether command contains a bang (!) modifier. +/// - args: (array) Command arguments. +/// - addr: (string) Value of |:command-addr|. Uses short name. +/// - 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. +/// - magic: (dictionary) Which characters have special meaning in the command arguments. +/// - file: (boolean) The command expands filenames. Which means characters such as "%", +/// "#" and wildcards are expanded. +/// - bar: (boolean) The "|" character is treated as a command separator and the double +/// quote character (\") is treated as the start of a comment. +/// - mods: (dictionary) |:command-modifiers|. +/// - silent: (boolean) |:silent|. +/// - emsg_silent: (boolean) |:silent!|. +/// - sandbox: (boolean) |:sandbox|. +/// - noautocmd: (boolean) |:noautocmd|. +/// - browse: (boolean) |:browse|. +/// - confirm: (boolean) |:confirm|. +/// - hide: (boolean) |:hide|. +/// - keepalt: (boolean) |:keepalt|. +/// - keepjumps: (boolean) |:keepjumps|. +/// - keepmarks: (boolean) |:keepmarks|. +/// - keeppatterns: (boolean) |:keeppatterns|. +/// - lockmarks: (boolean) |:lockmarks|. +/// - noswapfile: (boolean) |:noswapfile|. +/// - tab: (integer) |:tab|. +/// - verbose: (integer) |:verbose|. +/// - vertical: (boolean) |:vertical|. +/// - split: (string) Split modifier string, is an empty string when there's no split +/// modifier. If there is a split modifier it can be one of: +/// - "aboveleft": |:aboveleft|. +/// - "belowright": |:belowright|. +/// - "topleft": |:topleft|. +/// - "botright": |:botright|. +Dictionary nvim_parse_cmd(String str, Dictionary opts, Error *err) + FUNC_API_SINCE(10) FUNC_API_FAST +{ + Dictionary result = ARRAY_DICT_INIT; + + if (opts.size > 0) { + api_set_error(err, kErrorTypeValidation, "opts dict isn't empty"); + return result; + } + + // Parse command line + exarg_T ea; + CmdParseInfo cmdinfo; + char_u *cmdline = vim_strsave((char_u *)str.data); + + if (!parse_cmdline(cmdline, &ea, &cmdinfo)) { + api_set_error(err, kErrorTypeException, "Error while parsing command line"); + goto end; + } + + // Parse arguments + Array args = ARRAY_DICT_INIT; + size_t length = STRLEN(ea.arg); + + // For nargs = 1 or '?', pass the entire argument list as a single argument, + // otherwise split arguments by whitespace. + if (ea.argt & EX_NOSPC) { + if (*ea.arg != NUL) { + ADD(args, STRING_OBJ(cstrn_to_string((char *)ea.arg, length))); + } + } else { + size_t end = 0; + size_t len = 0; + char *buf = xcalloc(length, sizeof(char)); + bool done = false; + + while (!done) { + done = uc_split_args_iter(ea.arg, length, &end, buf, &len); + if (len > 0) { + ADD(args, STRING_OBJ(cstrn_to_string(buf, len))); + } + } + + xfree(buf); + } + + if (ea.cmdidx == CMD_USER) { + PUT(result, "cmd", CSTR_TO_OBJ((char *)USER_CMD(ea.useridx)->uc_name)); + } else if (ea.cmdidx == CMD_USER_BUF) { + PUT(result, "cmd", CSTR_TO_OBJ((char *)USER_CMD_GA(&curbuf->b_ucmds, ea.useridx)->uc_name)); + } else { + PUT(result, "cmd", CSTR_TO_OBJ((char *)get_command_name(NULL, ea.cmdidx))); + } + PUT(result, "line1", INTEGER_OBJ(ea.line1)); + PUT(result, "line2", INTEGER_OBJ(ea.line2)); + PUT(result, "bang", BOOLEAN_OBJ(ea.forceit)); + PUT(result, "args", ARRAY_OBJ(args)); + + char nargs[2]; + if (ea.argt & EX_EXTRA) { + if (ea.argt & EX_NOSPC) { + if (ea.argt & EX_NEEDARG) { + nargs[0] = '1'; + } else { + nargs[0] = '?'; + } + } else if (ea.argt & EX_NEEDARG) { + nargs[0] = '+'; + } else { + nargs[0] = '*'; + } + } else { + nargs[0] = '0'; + } + nargs[1] = '\0'; + PUT(result, "nargs", CSTR_TO_OBJ(nargs)); + + const char *addr; + switch (ea.addr_type) { + case ADDR_LINES: + addr = "line"; + break; + case ADDR_ARGUMENTS: + addr = "arg"; + break; + case ADDR_BUFFERS: + addr = "buf"; + break; + case ADDR_LOADED_BUFFERS: + addr = "load"; + break; + case ADDR_WINDOWS: + addr = "win"; + break; + case ADDR_TABS: + addr = "tab"; + break; + case ADDR_QUICKFIX: + addr = "qf"; + break; + case ADDR_NONE: + addr = "none"; + break; + default: + addr = "?"; + break; + } + PUT(result, "addr", CSTR_TO_OBJ(addr)); + PUT(result, "nextcmd", CSTR_TO_OBJ((char *)ea.nextcmd)); + + Dictionary mods = ARRAY_DICT_INIT; + PUT(mods, "silent", BOOLEAN_OBJ(cmdinfo.silent)); + PUT(mods, "emsg_silent", BOOLEAN_OBJ(cmdinfo.emsg_silent)); + PUT(mods, "sandbox", BOOLEAN_OBJ(cmdinfo.sandbox)); + PUT(mods, "noautocmd", BOOLEAN_OBJ(cmdinfo.noautocmd)); + PUT(mods, "tab", INTEGER_OBJ(cmdmod.tab)); + PUT(mods, "verbose", INTEGER_OBJ(cmdinfo.verbose)); + PUT(mods, "browse", BOOLEAN_OBJ(cmdmod.browse)); + PUT(mods, "confirm", BOOLEAN_OBJ(cmdmod.confirm)); + PUT(mods, "hide", BOOLEAN_OBJ(cmdmod.hide)); + PUT(mods, "keepalt", BOOLEAN_OBJ(cmdmod.keepalt)); + PUT(mods, "keepjumps", BOOLEAN_OBJ(cmdmod.keepjumps)); + PUT(mods, "keepmarks", BOOLEAN_OBJ(cmdmod.keepmarks)); + PUT(mods, "keeppatterns", BOOLEAN_OBJ(cmdmod.keeppatterns)); + PUT(mods, "lockmarks", BOOLEAN_OBJ(cmdmod.lockmarks)); + PUT(mods, "noswapfile", BOOLEAN_OBJ(cmdmod.noswapfile)); + PUT(mods, "vertical", BOOLEAN_OBJ(cmdmod.split & WSP_VERT)); + + const char *split; + if (cmdmod.split & WSP_BOT) { + split = "botright"; + } else if (cmdmod.split & WSP_TOP) { + split = "topleft"; + } else if (cmdmod.split & WSP_BELOW) { + split = "belowright"; + } else if (cmdmod.split & WSP_ABOVE) { + split = "aboveleft"; + } else { + split = ""; + } + PUT(mods, "split", CSTR_TO_OBJ(split)); + + PUT(result, "mods", DICTIONARY_OBJ(mods)); + + Dictionary magic = ARRAY_DICT_INIT; + PUT(magic, "file", BOOLEAN_OBJ(cmdinfo.magic.file)); + PUT(magic, "bar", BOOLEAN_OBJ(cmdinfo.magic.bar)); + PUT(result, "magic", DICTIONARY_OBJ(magic)); +end: + xfree(cmdline); + return result; +} -- cgit From bfb72f637b9d8dc9e4a05479c2b1a0fe1fbc5e36 Mon Sep 17 00:00:00 2001 From: Famiu Haque Date: Mon, 2 May 2022 11:23:16 +0600 Subject: fix(api): preserve `cmdmod` on `nvim_parse_cmd` --- src/nvim/api/vim.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 3d1b5eade4..061653c5af 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -2624,27 +2624,27 @@ Dictionary nvim_parse_cmd(String str, Dictionary opts, Error *err) PUT(mods, "emsg_silent", BOOLEAN_OBJ(cmdinfo.emsg_silent)); PUT(mods, "sandbox", BOOLEAN_OBJ(cmdinfo.sandbox)); PUT(mods, "noautocmd", BOOLEAN_OBJ(cmdinfo.noautocmd)); - PUT(mods, "tab", INTEGER_OBJ(cmdmod.tab)); + PUT(mods, "tab", INTEGER_OBJ(cmdinfo.cmdmod.tab)); PUT(mods, "verbose", INTEGER_OBJ(cmdinfo.verbose)); - PUT(mods, "browse", BOOLEAN_OBJ(cmdmod.browse)); - PUT(mods, "confirm", BOOLEAN_OBJ(cmdmod.confirm)); - PUT(mods, "hide", BOOLEAN_OBJ(cmdmod.hide)); - PUT(mods, "keepalt", BOOLEAN_OBJ(cmdmod.keepalt)); - PUT(mods, "keepjumps", BOOLEAN_OBJ(cmdmod.keepjumps)); - PUT(mods, "keepmarks", BOOLEAN_OBJ(cmdmod.keepmarks)); - PUT(mods, "keeppatterns", BOOLEAN_OBJ(cmdmod.keeppatterns)); - PUT(mods, "lockmarks", BOOLEAN_OBJ(cmdmod.lockmarks)); - PUT(mods, "noswapfile", BOOLEAN_OBJ(cmdmod.noswapfile)); - PUT(mods, "vertical", BOOLEAN_OBJ(cmdmod.split & WSP_VERT)); + PUT(mods, "browse", BOOLEAN_OBJ(cmdinfo.cmdmod.browse)); + PUT(mods, "confirm", BOOLEAN_OBJ(cmdinfo.cmdmod.confirm)); + PUT(mods, "hide", BOOLEAN_OBJ(cmdinfo.cmdmod.hide)); + PUT(mods, "keepalt", BOOLEAN_OBJ(cmdinfo.cmdmod.keepalt)); + PUT(mods, "keepjumps", BOOLEAN_OBJ(cmdinfo.cmdmod.keepjumps)); + PUT(mods, "keepmarks", BOOLEAN_OBJ(cmdinfo.cmdmod.keepmarks)); + PUT(mods, "keeppatterns", BOOLEAN_OBJ(cmdinfo.cmdmod.keeppatterns)); + PUT(mods, "lockmarks", BOOLEAN_OBJ(cmdinfo.cmdmod.lockmarks)); + PUT(mods, "noswapfile", BOOLEAN_OBJ(cmdinfo.cmdmod.noswapfile)); + PUT(mods, "vertical", BOOLEAN_OBJ(cmdinfo.cmdmod.split & WSP_VERT)); const char *split; - if (cmdmod.split & WSP_BOT) { + if (cmdinfo.cmdmod.split & WSP_BOT) { split = "botright"; - } else if (cmdmod.split & WSP_TOP) { + } else if (cmdinfo.cmdmod.split & WSP_TOP) { split = "topleft"; - } else if (cmdmod.split & WSP_BELOW) { + } else if (cmdinfo.cmdmod.split & WSP_BELOW) { split = "belowright"; - } else if (cmdmod.split & WSP_ABOVE) { + } else if (cmdinfo.cmdmod.split & WSP_ABOVE) { split = "aboveleft"; } else { split = ""; -- cgit From 13520aae163bfc243fc050cf16b89082c0896eaf Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 3 May 2022 09:29:55 +0800 Subject: fix(coverity): use xstrndup() instead of vim_strsave() (#18363) --- src/nvim/api/vim.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 061653c5af..d9ab097316 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -2522,7 +2522,7 @@ Dictionary nvim_parse_cmd(String str, Dictionary opts, Error *err) // Parse command line exarg_T ea; CmdParseInfo cmdinfo; - char_u *cmdline = vim_strsave((char_u *)str.data); + char_u *cmdline = (char_u *)string_to_cstr(str); if (!parse_cmdline(cmdline, &ea, &cmdinfo)) { api_set_error(err, kErrorTypeException, "Error while parsing command line"); -- cgit From 3ec93ca92cb08faed342586e86a6f21b35264376 Mon Sep 17 00:00:00 2001 From: Famiu Haque Date: Wed, 4 May 2022 18:04:01 +0600 Subject: feat(nvim_parse_cmd): add range, count, reg #18383 Adds range, count and reg to the return values of nvim_parse_cmd. Also makes line1 and line2 be -1 if the command does not take a range. Also moves nvim_parse_cmd to vimscript.c because it fits better there. --- src/nvim/api/vim.c | 200 ----------------------------------------------------- 1 file changed, 200 deletions(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index d9ab097316..3f0cfb82a6 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -2461,203 +2461,3 @@ void nvim_del_user_command(String name, Error *err) { nvim_buf_del_user_command(-1, name, err); } - -/// Parse command line. -/// -/// Doesn't check the validity of command arguments. -/// -/// @param str Command line string to parse. Cannot contain "\n". -/// @param opts Optional parameters. Reserved for future use. -/// @param[out] err Error details, if any. -/// @return Dictionary containing command information, with these keys: -/// - cmd: (string) Command name. -/// - line1: (number) Starting line of command range. Only applicable if command can take a -/// range. -/// - line2: (number) Final line of command range. Only applicable if command can take a -/// range. -/// - bang: (boolean) Whether command contains a bang (!) modifier. -/// - args: (array) Command arguments. -/// - addr: (string) Value of |:command-addr|. Uses short name. -/// - 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. -/// - magic: (dictionary) Which characters have special meaning in the command arguments. -/// - file: (boolean) The command expands filenames. Which means characters such as "%", -/// "#" and wildcards are expanded. -/// - bar: (boolean) The "|" character is treated as a command separator and the double -/// quote character (\") is treated as the start of a comment. -/// - mods: (dictionary) |:command-modifiers|. -/// - silent: (boolean) |:silent|. -/// - emsg_silent: (boolean) |:silent!|. -/// - sandbox: (boolean) |:sandbox|. -/// - noautocmd: (boolean) |:noautocmd|. -/// - browse: (boolean) |:browse|. -/// - confirm: (boolean) |:confirm|. -/// - hide: (boolean) |:hide|. -/// - keepalt: (boolean) |:keepalt|. -/// - keepjumps: (boolean) |:keepjumps|. -/// - keepmarks: (boolean) |:keepmarks|. -/// - keeppatterns: (boolean) |:keeppatterns|. -/// - lockmarks: (boolean) |:lockmarks|. -/// - noswapfile: (boolean) |:noswapfile|. -/// - tab: (integer) |:tab|. -/// - verbose: (integer) |:verbose|. -/// - vertical: (boolean) |:vertical|. -/// - split: (string) Split modifier string, is an empty string when there's no split -/// modifier. If there is a split modifier it can be one of: -/// - "aboveleft": |:aboveleft|. -/// - "belowright": |:belowright|. -/// - "topleft": |:topleft|. -/// - "botright": |:botright|. -Dictionary nvim_parse_cmd(String str, Dictionary opts, Error *err) - FUNC_API_SINCE(10) FUNC_API_FAST -{ - Dictionary result = ARRAY_DICT_INIT; - - if (opts.size > 0) { - api_set_error(err, kErrorTypeValidation, "opts dict isn't empty"); - return result; - } - - // Parse command line - exarg_T ea; - CmdParseInfo cmdinfo; - char_u *cmdline = (char_u *)string_to_cstr(str); - - if (!parse_cmdline(cmdline, &ea, &cmdinfo)) { - api_set_error(err, kErrorTypeException, "Error while parsing command line"); - goto end; - } - - // Parse arguments - Array args = ARRAY_DICT_INIT; - size_t length = STRLEN(ea.arg); - - // For nargs = 1 or '?', pass the entire argument list as a single argument, - // otherwise split arguments by whitespace. - if (ea.argt & EX_NOSPC) { - if (*ea.arg != NUL) { - ADD(args, STRING_OBJ(cstrn_to_string((char *)ea.arg, length))); - } - } else { - size_t end = 0; - size_t len = 0; - char *buf = xcalloc(length, sizeof(char)); - bool done = false; - - while (!done) { - done = uc_split_args_iter(ea.arg, length, &end, buf, &len); - if (len > 0) { - ADD(args, STRING_OBJ(cstrn_to_string(buf, len))); - } - } - - xfree(buf); - } - - if (ea.cmdidx == CMD_USER) { - PUT(result, "cmd", CSTR_TO_OBJ((char *)USER_CMD(ea.useridx)->uc_name)); - } else if (ea.cmdidx == CMD_USER_BUF) { - PUT(result, "cmd", CSTR_TO_OBJ((char *)USER_CMD_GA(&curbuf->b_ucmds, ea.useridx)->uc_name)); - } else { - PUT(result, "cmd", CSTR_TO_OBJ((char *)get_command_name(NULL, ea.cmdidx))); - } - PUT(result, "line1", INTEGER_OBJ(ea.line1)); - PUT(result, "line2", INTEGER_OBJ(ea.line2)); - PUT(result, "bang", BOOLEAN_OBJ(ea.forceit)); - PUT(result, "args", ARRAY_OBJ(args)); - - char nargs[2]; - if (ea.argt & EX_EXTRA) { - if (ea.argt & EX_NOSPC) { - if (ea.argt & EX_NEEDARG) { - nargs[0] = '1'; - } else { - nargs[0] = '?'; - } - } else if (ea.argt & EX_NEEDARG) { - nargs[0] = '+'; - } else { - nargs[0] = '*'; - } - } else { - nargs[0] = '0'; - } - nargs[1] = '\0'; - PUT(result, "nargs", CSTR_TO_OBJ(nargs)); - - const char *addr; - switch (ea.addr_type) { - case ADDR_LINES: - addr = "line"; - break; - case ADDR_ARGUMENTS: - addr = "arg"; - break; - case ADDR_BUFFERS: - addr = "buf"; - break; - case ADDR_LOADED_BUFFERS: - addr = "load"; - break; - case ADDR_WINDOWS: - addr = "win"; - break; - case ADDR_TABS: - addr = "tab"; - break; - case ADDR_QUICKFIX: - addr = "qf"; - break; - case ADDR_NONE: - addr = "none"; - break; - default: - addr = "?"; - break; - } - PUT(result, "addr", CSTR_TO_OBJ(addr)); - PUT(result, "nextcmd", CSTR_TO_OBJ((char *)ea.nextcmd)); - - Dictionary mods = ARRAY_DICT_INIT; - PUT(mods, "silent", BOOLEAN_OBJ(cmdinfo.silent)); - PUT(mods, "emsg_silent", BOOLEAN_OBJ(cmdinfo.emsg_silent)); - PUT(mods, "sandbox", BOOLEAN_OBJ(cmdinfo.sandbox)); - PUT(mods, "noautocmd", BOOLEAN_OBJ(cmdinfo.noautocmd)); - PUT(mods, "tab", INTEGER_OBJ(cmdinfo.cmdmod.tab)); - PUT(mods, "verbose", INTEGER_OBJ(cmdinfo.verbose)); - PUT(mods, "browse", BOOLEAN_OBJ(cmdinfo.cmdmod.browse)); - PUT(mods, "confirm", BOOLEAN_OBJ(cmdinfo.cmdmod.confirm)); - PUT(mods, "hide", BOOLEAN_OBJ(cmdinfo.cmdmod.hide)); - PUT(mods, "keepalt", BOOLEAN_OBJ(cmdinfo.cmdmod.keepalt)); - PUT(mods, "keepjumps", BOOLEAN_OBJ(cmdinfo.cmdmod.keepjumps)); - PUT(mods, "keepmarks", BOOLEAN_OBJ(cmdinfo.cmdmod.keepmarks)); - PUT(mods, "keeppatterns", BOOLEAN_OBJ(cmdinfo.cmdmod.keeppatterns)); - PUT(mods, "lockmarks", BOOLEAN_OBJ(cmdinfo.cmdmod.lockmarks)); - PUT(mods, "noswapfile", BOOLEAN_OBJ(cmdinfo.cmdmod.noswapfile)); - PUT(mods, "vertical", BOOLEAN_OBJ(cmdinfo.cmdmod.split & WSP_VERT)); - - const char *split; - if (cmdinfo.cmdmod.split & WSP_BOT) { - split = "botright"; - } else if (cmdinfo.cmdmod.split & WSP_TOP) { - split = "topleft"; - } else if (cmdinfo.cmdmod.split & WSP_BELOW) { - split = "belowright"; - } else if (cmdinfo.cmdmod.split & WSP_ABOVE) { - split = "aboveleft"; - } else { - split = ""; - } - PUT(mods, "split", CSTR_TO_OBJ(split)); - - PUT(result, "mods", DICTIONARY_OBJ(mods)); - - Dictionary magic = ARRAY_DICT_INIT; - PUT(magic, "file", BOOLEAN_OBJ(cmdinfo.magic.file)); - PUT(magic, "bar", BOOLEAN_OBJ(cmdinfo.magic.bar)); - PUT(result, "magic", DICTIONARY_OBJ(magic)); -end: - xfree(cmdline); - return result; -} -- cgit From 5576d30e89153c817fb1a8d23c30cfc0432bc7c6 Mon Sep 17 00:00:00 2001 From: Dundar Goc Date: Tue, 3 May 2022 11:06:27 +0200 Subject: refactor: replace char_u variables and functions with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/api/vim.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 3f0cfb82a6..2323b8db47 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -2210,7 +2210,7 @@ Array nvim_get_mark(String name, Dictionary opts, Error *err) allocated = true; // Marks comes from shada } else { - filename = (char *)mark.fname; + filename = mark.fname; bufnr = 0; } -- cgit From 9a671e6a24243a5ff2879599d91ab5aec8b4e77d Mon Sep 17 00:00:00 2001 From: Dundar Goc Date: Wed, 4 May 2022 18:27:22 +0200 Subject: refactor: replace char_u variables and functions with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/api/vim.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 2323b8db47..7f4fafa71b 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -474,7 +474,7 @@ Integer nvim_strwidth(String text, Error *err) return 0; } - return (Integer)mb_string2cells((char_u *)text.data); + return (Integer)mb_string2cells(text.data); } /// Gets the paths contained in 'runtimepath'. -- cgit From 2a378e6e82cececb12339f2df51ffe107039d867 Mon Sep 17 00:00:00 2001 From: Dundar Goc Date: Wed, 4 May 2022 22:35:50 +0200 Subject: refactor: replace char_u variables and functions with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/api/vim.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 7f4fafa71b..185c043b06 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -2287,12 +2287,12 @@ Dictionary nvim_eval_statusline(String str, Dict(eval_statusline) *opts, Error * if (HAS_KEY(opts->fillchar)) { if (opts->fillchar.type != kObjectTypeString || opts->fillchar.data.string.size == 0 - || ((size_t)utf_ptr2len((char_u *)opts->fillchar.data.string.data) + || ((size_t)utf_ptr2len(opts->fillchar.data.string.data) != opts->fillchar.data.string.size)) { api_set_error(err, kErrorTypeValidation, "fillchar must be a single character"); return result; } - fillchar = utf_ptr2char((char_u *)opts->fillchar.data.string.data); + fillchar = utf_ptr2char(opts->fillchar.data.string.data); } if (HAS_KEY(opts->highlights)) { -- cgit From e31b32a293f6ba8708499a176234f8be1df6a145 Mon Sep 17 00:00:00 2001 From: Dundar Goc Date: Thu, 5 May 2022 13:36:14 +0200 Subject: refactor: replace char_u variables and functions with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/api/vim.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 185c043b06..5e7e51762a 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -245,11 +245,11 @@ void nvim_feedkeys(String keys, String mode, Boolean escape_ks) if (escape_ks) { // Need to escape K_SPECIAL before putting the string in the // typeahead buffer. - keys_esc = (char *)vim_strsave_escape_ks((char_u *)keys.data); + keys_esc = vim_strsave_escape_ks(keys.data); } else { keys_esc = keys.data; } - ins_typebuf((char_u *)keys_esc, (remap ? REMAP_YES : REMAP_NONE), + ins_typebuf(keys_esc, (remap ? REMAP_YES : REMAP_NONE), insert ? 0 : typebuf.tb_len, !typed, false); if (vgetc_busy) { typebuf_was_filled = true; @@ -416,7 +416,7 @@ String nvim_replace_termcodes(String str, Boolean from_part, Boolean do_lt, Bool } char *ptr = NULL; - replace_termcodes((char_u *)str.data, str.size, (char_u **)&ptr, flags, NULL, CPO_TO_CPO_FLAGS); + replace_termcodes(str.data, str.size, &ptr, flags, NULL, CPO_TO_CPO_FLAGS); return cstr_as_string(ptr); } @@ -513,14 +513,13 @@ ArrayOf(String) nvim_get_runtime_file(String name, Boolean all, Error *err) TRY_WRAP({ try_start(); - do_in_runtimepath((char_u *)(name.size ? name.data : ""), - flags, find_runtime_cb, &rv); + do_in_runtimepath((name.size ? name.data : ""), flags, find_runtime_cb, &rv); try_end(err); }); return rv; } -static void find_runtime_cb(char_u *fname, void *cookie) +static void find_runtime_cb(char *fname, void *cookie) { Array *rv = (Array *)cookie; if (fname != NULL) { @@ -563,13 +562,13 @@ void nvim_set_current_dir(String dir, Error *err) return; } - char_u string[MAXPATHL]; + char string[MAXPATHL]; memcpy(string, dir.data, dir.size); string[dir.size] = NUL; try_start(); - if (!changedir_func((char *)string, kCdScopeGlobal)) { + if (!changedir_func(string, kCdScopeGlobal)) { if (!try_end(err)) { api_set_error(err, kErrorTypeException, "Failed to change directory"); } @@ -722,7 +721,7 @@ Object nvim_get_option_value(String name, Dict(option) *opts, Error *err) long numval = 0; char *stringval = NULL; - switch (get_option_value(name.data, &numval, (char_u **)&stringval, scope)) { + switch (get_option_value(name.data, &numval, &stringval, scope)) { case 0: rv = STRING_OBJ(cstr_as_string(stringval)); break; @@ -1339,7 +1338,7 @@ Boolean nvim_paste(String data, Boolean crlf, Integer phase, Error *err) for (size_t i = 0; i < lines.size; i++) { String s = lines.items[i].data.string; assert(s.size <= INT_MAX); - AppendToRedobuffLit((char_u *)s.data, (int)s.size); + AppendToRedobuffLit(s.data, (int)s.size); // readfile()-style: "\n" is indicated by presence of N+1 item. if (i + 1 < lines.size) { AppendCharToRedobuff(NL); @@ -1392,7 +1391,7 @@ void nvim_put(ArrayOf(String) lines, String type, Boolean after, Boolean follow, goto cleanup; } String line = lines.items[i].data.string; - reg->y_array[i] = (char_u *)xmemdupz(line.data, line.size); + reg->y_array[i] = xmemdupz(line.data, line.size); memchrsub(reg->y_array[i], NUL, NL, line.size); } @@ -2352,9 +2351,9 @@ Dictionary nvim_eval_statusline(String str, Dict(eval_statusline) *opts, Error * ewp->w_p_crb = false; int width = build_stl_str_hl(ewp, - (char_u *)buf, + buf, sizeof(buf), - (char_u *)str.data, + str.data, false, fillchar, maxwidth, -- cgit From 9aa5647e686e5420e5b9b51828ec7d55631f98ed Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 10 May 2022 07:58:58 +0800 Subject: vim-patch:8.2.4911: the mode #defines are not clearly named (#18499) Problem: The mode #defines are not clearly named. Solution: Prepend MODE_. Renumber them to put the mapped modes first. https://github.com/vim/vim/commit/249591057b4840785c50e41dd850efb8a8faf435 A hunk from the patch depends on patch 8.2.4861, which hasn't been ported yet, but that should be easy to notice. --- src/nvim/api/vim.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 5e7e51762a..09bf032daa 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -1327,14 +1327,14 @@ Boolean nvim_paste(String data, Boolean crlf, Integer phase, Error *err) draining = true; goto theend; } - if (!(State & (CMDLINE | INSERT)) && (phase == -1 || phase == 1)) { + if (!(State & (MODE_CMDLINE | MODE_INSERT)) && (phase == -1 || phase == 1)) { ResetRedobuff(); AppendCharToRedobuff('a'); // Dot-repeat. } // vim.paste() decides if client should cancel. Errors do NOT cancel: we // want to drain remaining chunks (rather than divert them to main input). cancel = (rv.type == kObjectTypeBoolean && !rv.data.boolean); - if (!cancel && !(State & CMDLINE)) { // Dot-repeat. + if (!cancel && !(State & MODE_CMDLINE)) { // Dot-repeat. for (size_t i = 0; i < lines.size; i++) { String s = lines.items[i].data.string; assert(s.size <= INT_MAX); @@ -1345,7 +1345,7 @@ Boolean nvim_paste(String data, Boolean crlf, Integer phase, Error *err) } } } - if (!(State & (CMDLINE | INSERT)) && (phase == -1 || phase == 3)) { + if (!(State & (MODE_CMDLINE | MODE_INSERT)) && (phase == -1 || phase == 3)) { AppendCharToRedobuff(ESC); // Dot-repeat. } theend: -- cgit From 0a66c4a72a9912f71cc8c3b1795ac2797dd5dbb9 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sun, 15 May 2022 10:44:48 +0200 Subject: docs(nvim_set_keymap): specify that optional arguments defaults to false (#18177) Closes: https://github.com/neovim/neovim/issues/16919 --- src/nvim/api/vim.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 09bf032daa..d1da3312e1 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -1601,12 +1601,13 @@ ArrayOf(Dictionary) nvim_get_keymap(uint64_t channel_id, String mode) /// or "!" for |:map!|, or empty string for |:map|. /// @param lhs Left-hand-side |{lhs}| of the mapping. /// @param rhs Right-hand-side |{rhs}| of the mapping. -/// @param opts Optional parameters map. Accepts all |:map-arguments| -/// as keys excluding || but including |noremap| and "desc". -/// "desc" can be used to give a description to keymap. -/// When called from Lua, also accepts a "callback" key that takes -/// a Lua function to call when the mapping is executed. -/// Values are Booleans. Unknown key is an error. +/// @param opts Optional parameters map: keys are |:map-arguments|, values +/// are booleans (default false). Accepts all |:map-arguments| as +/// keys excluding || but including |noremap| and "desc". +/// Unknown key is an error. "desc" can be used to give a +/// description to the mapping. When called from Lua, also accepts a +/// "callback" key that takes a Lua function to call when the +/// mapping is executed. /// @param[out] err Error details, if any. void nvim_set_keymap(uint64_t channel_id, String mode, String lhs, String rhs, Dict(keymap) *opts, Error *err) -- cgit From 0a3d615b1ca17cda978b89d66acef39b90ee7c81 Mon Sep 17 00:00:00 2001 From: deforde <7503504+deforde@users.noreply.github.com> Date: Sun, 15 May 2022 22:06:23 +0200 Subject: fix(api): nvim_eval_statusline should validate input #18347 Fix #18112 Make an exception for strings starting with "%!". --- src/nvim/api/vim.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index d1da3312e1..fca86fe440 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -2276,6 +2276,14 @@ 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)) { + const char *const errmsg = check_stl_option((char_u *)str.data); + if (errmsg) { + api_set_error(err, kErrorTypeValidation, "%s", errmsg); + return result; + } + } + if (HAS_KEY(opts->winid)) { if (opts->winid.type != kObjectTypeInteger) { api_set_error(err, kErrorTypeValidation, "winid must be an integer"); -- cgit From 5e3b16836a333d48f8977fc201c5e666767d61f1 Mon Sep 17 00:00:00 2001 From: Oliver Marriott Date: Mon, 16 May 2022 07:06:06 +1000 Subject: docs(api): nvim_set_hl attributes #18558 --- src/nvim/api/vim.c | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index fca86fe440..a257dd6478 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -126,22 +126,43 @@ Dictionary nvim__get_hl_defs(Integer ns_id, Error *err) /// Sets a highlight group. /// -/// Note: Unlike the `:highlight` command which can update a highlight group, -/// this function completely replaces the definition. For example: -/// ``nvim_set_hl(0, 'Visual', {})`` will clear the highlight group 'Visual'. +/// @note Unlike the `:highlight` command which can update a highlight group, +/// this function completely replaces the definition. For example: +/// ``nvim_set_hl(0, 'Visual', {})`` will clear the highlight group +/// 'Visual'. +/// +/// @note The fg and bg keys also accept the string values `"fg"` or `"bg"` +/// which act as aliases to the corresponding foreground and background +/// values of the Normal group. If the Normal group has not been defined, +/// using these values results in an error. /// /// @param ns_id Namespace id for this highlight |nvim_create_namespace()|. /// Use 0 to set a highlight group globally |:highlight|. /// @param name Highlight group name, e.g. "ErrorMsg" -/// @param val Highlight definition map, like |synIDattr()|. In -/// addition, the following keys are recognized: +/// @param val Highlight definition map, accepts the following keys: +/// - fg (or foreground): color name or "#RRGGBB", see note. +/// - bg (or background): color name or "#RRGGBB", see note. +/// - sp (or special): color name or "#RRGGBB" +/// - blend: integer between 0 and 100 +/// - bold: boolean +/// - standout: boolean +/// - underline: boolean +/// - underlineline: boolean +/// - undercurl: boolean +/// - underdot: boolean +/// - underdash: boolean +/// - strikethrough: boolean +/// - italic: boolean +/// - reverse: boolean +/// - nocombine: boolean +/// - link: name of another highlight group to link to, see |:hi-link|. +/// Additionally, the following keys are recognized: /// - default: Don't override existing definition |:hi-default| /// - ctermfg: Sets foreground of cterm color |highlight-ctermfg| /// - ctermbg: Sets background of cterm color |highlight-ctermbg| -/// - cterm: cterm attribute map, like -/// |highlight-args|. -/// Note: Attributes default to those set for `gui` -/// if not set. +/// - cterm: cterm attribute map, like |highlight-args|. If not set, +/// cterm attributes will match those from the attribute map +/// documented above. /// @param[out] err Error details, if any /// // TODO(bfredl): val should take update vs reset flag -- cgit From 6219331c4d333e5a76129746021f972c21a040db Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Wed, 11 May 2022 13:49:43 +0100 Subject: feat(api): add win and buf to nvim_set_option_value Co-authored-by: Gregory Anders <8965202+gpanders@users.noreply.github.com> --- src/nvim/api/vim.c | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index a257dd6478..f6ca5a5e00 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -775,11 +775,15 @@ end: /// |:set|: for global-local options, both the global and local value are set /// unless otherwise specified with {scope}. /// +/// Note the options {win} and {buf} cannot be used together. +/// /// @param name Option name /// @param value New option value /// @param opts Optional parameters /// - scope: One of 'global' or 'local'. Analogous to /// |:setglobal| and |:setlocal|, respectively. +/// - win: |window-ID|. Used for setting window local option. +/// - buf: Buffer number. Used for setting buffer local option. /// @param[out] err Error details, if any void nvim_set_option_value(String name, Object value, Dict(option) *opts, Error *err) FUNC_API_SINCE(9) @@ -799,6 +803,36 @@ void nvim_set_option_value(String name, Object value, Dict(option) *opts, Error return; } + int opt_type = SREQ_GLOBAL; + void *to = NULL; + + if (opts->win.type == kObjectTypeInteger) { + opt_type = SREQ_WIN; + to = find_window_by_handle((int)opts->win.data.integer, err); + } else if (HAS_KEY(opts->win)) { + api_set_error(err, kErrorTypeValidation, "invalid value for key: win"); + return; + } + + if (opts->buf.type == kObjectTypeInteger) { + scope = OPT_LOCAL; + opt_type = SREQ_BUF; + to = find_buffer_by_handle((int)opts->buf.data.integer, err); + } else if (HAS_KEY(opts->buf)) { + api_set_error(err, kErrorTypeValidation, "invalid value for key: buf"); + return; + } + + if (HAS_KEY(opts->scope) && HAS_KEY(opts->buf)) { + api_set_error(err, kErrorTypeValidation, "scope and buf cannot be used together"); + return; + } + + if (HAS_KEY(opts->win) && HAS_KEY(opts->buf)) { + api_set_error(err, kErrorTypeValidation, "buf and win cannot be used together"); + return; + } + long numval = 0; char *stringval = NULL; @@ -820,10 +854,7 @@ void nvim_set_option_value(String name, Object value, Dict(option) *opts, Error return; } - char *e = set_option_value(name.data, numval, stringval, scope); - if (e) { - api_set_error(err, kErrorTypeException, "%s", e); - } + set_option_value_for(name.data, numval, stringval, scope, opt_type, to, err); } /// Gets the option information for all options. -- cgit From e1bdb2a258cbe6c5cb981acc6bac82cd9e7706fb Mon Sep 17 00:00:00 2001 From: Famiu Haque Date: Fri, 13 May 2022 20:47:11 +0600 Subject: feat(ui): add `'winbar'` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds support for a bar at the top of each window, enabled through the `'winbar'` option. Co-authored-by: Björn Linse --- src/nvim/api/vim.c | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index a257dd6478..3c378e73e1 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -2274,8 +2274,9 @@ Array nvim_get_mark(String name, Dictionary opts, Error *err) /// - fillchar: (string) Character to fill blank spaces in the statusline (see /// 'fillchars'). Treated as single-width even if it isn't. /// - highlights: (boolean) Return highlight information. +/// - use_winbar: (boolean) Evaluate winbar instead of statusline. /// - use_tabline: (boolean) Evaluate tabline instead of statusline. When |TRUE|, {winid} -/// is ignored. +/// is ignored. Mutually exclusive with {use_winbar}. /// /// @param[out] err Error details, if any. /// @return Dictionary containing statusline information, with these keys: @@ -2294,6 +2295,7 @@ Dictionary nvim_eval_statusline(String str, Dict(eval_statusline) *opts, Error * int maxwidth; int fillchar = 0; Window window = 0; + bool use_winbar = false; bool use_tabline = false; bool highlights = false; @@ -2313,7 +2315,6 @@ Dictionary nvim_eval_statusline(String str, Dict(eval_statusline) *opts, Error * window = (Window)opts->winid.data.integer; } - if (HAS_KEY(opts->fillchar)) { if (opts->fillchar.type != kObjectTypeString || opts->fillchar.data.string.size == 0 || ((size_t)utf_ptr2len(opts->fillchar.data.string.data) @@ -2323,7 +2324,6 @@ Dictionary nvim_eval_statusline(String str, Dict(eval_statusline) *opts, Error * } fillchar = utf_ptr2char(opts->fillchar.data.string.data); } - if (HAS_KEY(opts->highlights)) { highlights = api_object_to_bool(opts->highlights, "highlights", false, err); @@ -2331,7 +2331,13 @@ Dictionary nvim_eval_statusline(String str, Dict(eval_statusline) *opts, Error * return result; } } + if (HAS_KEY(opts->use_winbar)) { + use_winbar = api_object_to_bool(opts->use_winbar, "use_winbar", false, err); + if (ERROR_SET(err)) { + return result; + } + } if (HAS_KEY(opts->use_tabline)) { use_tabline = api_object_to_bool(opts->use_tabline, "use_tabline", false, err); @@ -2339,6 +2345,10 @@ Dictionary nvim_eval_statusline(String str, Dict(eval_statusline) *opts, Error * return result; } } + if (use_winbar && use_tabline) { + api_set_error(err, kErrorTypeValidation, "use_winbar and use_tabline are mutually exclusive"); + return result; + } win_T *wp, *ewp; @@ -2348,7 +2358,6 @@ Dictionary nvim_eval_statusline(String str, Dict(eval_statusline) *opts, Error * fillchar = ' '; } else { wp = find_window_by_handle(window, err); - if (wp == NULL) { api_set_error(err, kErrorTypeException, "unknown winid %d", window); return result; @@ -2356,8 +2365,12 @@ Dictionary nvim_eval_statusline(String str, Dict(eval_statusline) *opts, Error * ewp = wp; if (fillchar == 0) { - int attr; - fillchar = fillchar_status(&attr, wp); + if (use_winbar) { + fillchar = wp->w_p_fcs_chars.wbr; + } else { + int attr; + fillchar = fillchar_status(&attr, wp); + } } } @@ -2369,7 +2382,7 @@ Dictionary nvim_eval_statusline(String str, Dict(eval_statusline) *opts, Error * maxwidth = (int)opts->maxwidth.data.integer; } else { - maxwidth = (use_tabline || global_stl_height() > 0) ? Columns : wp->w_width; + maxwidth = (use_tabline || (!use_winbar && global_stl_height() > 0)) ? Columns : wp->w_width; } char buf[MAXPATHL]; @@ -2404,7 +2417,7 @@ Dictionary nvim_eval_statusline(String str, Dict(eval_statusline) *opts, Error * // add the default highlight at the beginning of the highlight list if (hltab->start == NULL || ((char *)hltab->start - buf) != 0) { Dictionary hl_info = ARRAY_DICT_INIT; - grpname = get_default_stl_hl(wp); + grpname = get_default_stl_hl(wp, use_winbar); PUT(hl_info, "start", INTEGER_OBJ(0)); PUT(hl_info, "group", CSTR_TO_OBJ(grpname)); @@ -2418,22 +2431,18 @@ Dictionary nvim_eval_statusline(String str, Dict(eval_statusline) *opts, Error * PUT(hl_info, "start", INTEGER_OBJ((char *)sp->start - buf)); if (sp->userhl == 0) { - grpname = get_default_stl_hl(wp); + grpname = get_default_stl_hl(wp, use_winbar); } else if (sp->userhl < 0) { grpname = (char *)syn_id2name(-sp->userhl); } else { snprintf(user_group, sizeof(user_group), "User%d", sp->userhl); grpname = user_group; } - PUT(hl_info, "group", CSTR_TO_OBJ(grpname)); - ADD(hl_values, DICTIONARY_OBJ(hl_info)); } - PUT(result, "highlights", ARRAY_OBJ(hl_values)); } - PUT(result, "str", CSTR_TO_OBJ((char *)buf)); return result; -- cgit From 028329850e4a4fc9171518566ba7947d9e435f83 Mon Sep 17 00:00:00 2001 From: bfredl Date: Wed, 18 May 2022 13:06:02 +0200 Subject: refactor: grid->rows and grid->cols --- src/nvim/api/vim.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 3c378e73e1..15992a98be 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -2140,8 +2140,8 @@ Array nvim__inspect_cell(Integer grid, Integer row, Integer col, Error *err) } } - if (row < 0 || row >= g->Rows - || col < 0 || col >= g->Columns) { + if (row < 0 || row >= g->rows + || col < 0 || col >= g->cols) { return ret; } size_t off = g->line_offset[(size_t)row] + (size_t)col; -- cgit From 9fec6dc9a25b5cf9c9a444ac2bd0728e8af3229e Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Wed, 25 May 2022 20:31:14 +0200 Subject: refactor(uncrustify): set maximum number of consecutive newlines to 2 (#18695) --- src/nvim/api/vim.c | 5 ----- 1 file changed, 5 deletions(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 8e216c2031..7ca0912f82 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -209,7 +209,6 @@ static void on_redraw_event(void **argv) redraw_all_later(NOT_VALID); } - /// Sends input-keys to Nvim, subject to various quirks controlled by `mode` /// flags. This is a blocking call, unlike |nvim_input()|. /// @@ -441,7 +440,6 @@ String nvim_replace_termcodes(String str, Boolean from_part, Boolean do_lt, Bool return cstr_as_string(ptr); } - /// Execute Lua code. Parameters (if any) are available as `...` inside the /// chunk. The chunk can return a value. /// @@ -570,7 +568,6 @@ ArrayOf(String) nvim__get_runtime(Array pat, Boolean all, Dict(runtime) *opts, E return runtime_get_named(is_lua, pat, all); } - /// Changes the global working directory. /// /// @param dir Directory path @@ -1245,7 +1242,6 @@ static void term_close(void *data) channel_decref(chan); } - /// Send data to channel `id`. For a job, it writes it to the /// stdin of the process. For the stdio channel |channel-stdio|, /// it writes to Nvim's stdout. For an internal terminal instance @@ -2192,7 +2188,6 @@ void nvim__screenshot(String path) ui_call_screenshot(path); } - /// Deletes an uppercase/file named mark. See |mark-motions|. /// /// @note fails with error if a lowercase or buffer local named mark is used. -- cgit From 7b952793d5c46e862a9cdec3d6ac4762370296ed Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Thu, 26 May 2022 04:49:25 +0200 Subject: refactor: missing parenthesis may cause unexpected problems (#17443) related vim-8.2.{4402,4639} --- src/nvim/api/vim.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 7ca0912f82..dd0b75bbfb 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -1931,13 +1931,13 @@ static void write_msg(String message, bool to_err) static char out_line_buf[LINE_BUFFER_SIZE], err_line_buf[LINE_BUFFER_SIZE]; #define PUSH_CHAR(i, pos, line_buf, msg) \ - if (message.data[i] == NL || pos == LINE_BUFFER_SIZE - 1) { \ - line_buf[pos] = NUL; \ + if (message.data[i] == NL || (pos) == LINE_BUFFER_SIZE - 1) { \ + (line_buf)[pos] = NUL; \ msg(line_buf); \ - pos = 0; \ + (pos) = 0; \ continue; \ } \ - line_buf[pos++] = message.data[i]; + (line_buf)[(pos)++] = message.data[i]; no_wait_return++; for (uint32_t i = 0; i < message.size; i++) { -- cgit From 9988d2f214963b3cac70026d6ad4bb058837afd9 Mon Sep 17 00:00:00 2001 From: Famiu Haque Date: Sun, 29 May 2022 10:42:00 +0600 Subject: feat(nvim_create_user_command): pass structured modifiers to commands Adds an `smods` key to `nvim_create_user_command` Lua command callbacks, which has command modifiers but in a structured format. This removes the need to manually parse command modifiers. It also reduces friction in using `nvim_cmd` inside a Lua command callback. --- src/nvim/api/vim.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index dd0b75bbfb..5c3c16d6b0 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -2501,6 +2501,8 @@ Dictionary nvim_eval_statusline(String str, Dict(eval_statusline) *opts, Error * /// - count: (number) Any count supplied || /// - reg: (string) The optional register, if specified || /// - mods: (string) Command modifiers, if any || +/// - smods: (table) Command modifiers in a structured format. Has the same +/// structure as the "mods" key of |nvim_parse_cmd()|. /// @param opts Optional command attributes. See |command-attributes| for more details. To use /// boolean attributes (such as |:command-bang| or |:command-bar|) set the value to /// "true". In addition to the string options listed in |:command-complete|, the -- cgit From d404d68c929a272eb7ccbc3cc370673e005e2a4b Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 31 May 2022 07:06:34 +0800 Subject: docs: clarify that nvim_strwidth counts control characters as one cell (#18802) --- src/nvim/api/vim.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 5c3c16d6b0..fc3d0549b9 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -480,7 +480,7 @@ Object nvim_notify(String msg, Integer log_level, Dictionary opts, Error *err) } /// Calculates the number of display cells occupied by `text`. -/// counts as one cell. +/// Control characters including count as one cell. /// /// @param text Some text /// @param[out] err Error details, if any -- cgit From 46536f53e82967dcac8d030ee3394cdb156f9603 Mon Sep 17 00:00:00 2001 From: Famiu Haque Date: Wed, 20 Apr 2022 17:02:18 +0600 Subject: feat: add preview functionality to user commands Adds a Lua-only `preview` flag to user commands which allows the command to be incrementally previewed like `:substitute` when 'inccommand' is set. --- src/nvim/api/vim.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 5c3c16d6b0..8555d1bb71 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -2511,6 +2511,7 @@ Dictionary nvim_eval_statusline(String str, Dict(eval_statusline) *opts, Error * /// - desc: (string) Used for listing the command when a Lua function is used for /// {command}. /// - force: (boolean, default true) Override any previous definition. +/// - preview: (function) Preview callback for 'inccommand' |:command-preview| /// @param[out] err Error details, if any. void nvim_create_user_command(String name, Object command, Dict(user_command) *opts, Error *err) FUNC_API_SINCE(9) -- cgit From d5f047bee04a42f40425c34061c84b39af846e1f Mon Sep 17 00:00:00 2001 From: bfredl Date: Mon, 23 May 2022 19:53:19 +0200 Subject: refactor(api): use a unpacker based on libmpack instead of msgpack-c Currently this is more or less a straight off reimplementation, but this allow further optimizations down the line, especially for avoiding memory allocations of rpc objects. Current score for "make functionaltest; make oldtest" on a -DEXITFREE build: is 117 055 352 xfree(ptr != NULL) calls (that's NUMBERWANG!). --- src/nvim/api/vim.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 228d114376..2320ae62af 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -45,6 +45,7 @@ #include "nvim/move.h" #include "nvim/msgpack_rpc/channel.h" #include "nvim/msgpack_rpc/helpers.h" +#include "nvim/msgpack_rpc/unpacker.h" #include "nvim/ops.h" #include "nvim/option.h" #include "nvim/os/input.h" @@ -2188,6 +2189,12 @@ void nvim__screenshot(String path) ui_call_screenshot(path); } +Object nvim__unpack(String str, Error *err) + FUNC_API_FAST +{ + return unpack(str.data, str.size, err); +} + /// Deletes an uppercase/file named mark. See |mark-motions|. /// /// @note fails with error if a lowercase or buffer local named mark is used. -- cgit From ff20d40321399fa187bd350f9619cf6418d7eb6e Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sat, 4 Jun 2022 05:56:36 +0200 Subject: docs: fix typos (#18269) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: zeertzjq Co-authored-by: Dan Sully Co-authored-by: saher Co-authored-by: Stephan Seitz Co-authored-by: Benedikt Müller Co-authored-by: Andrey Mishchenko Co-authored-by: Famiu Haque Co-authored-by: Oliver Marriott --- src/nvim/api/vim.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 2320ae62af..9430a37d27 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -157,7 +157,6 @@ Dictionary nvim__get_hl_defs(Integer ns_id, Error *err) /// - reverse: boolean /// - nocombine: boolean /// - link: name of another highlight group to link to, see |:hi-link|. -/// Additionally, the following keys are recognized: /// - default: Don't override existing definition |:hi-default| /// - ctermfg: Sets foreground of cterm color |highlight-ctermfg| /// - ctermbg: Sets background of cterm color |highlight-ctermbg| -- cgit From e92fcdbab204f49c542ba4cf330aba1258fb2968 Mon Sep 17 00:00:00 2001 From: bfredl Date: Thu, 5 May 2022 12:33:35 +0200 Subject: feat(api): nvim__get_runtime do_source --- src/nvim/api/vim.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 9430a37d27..1e44250ec3 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -562,10 +562,25 @@ ArrayOf(String) nvim__get_runtime(Array pat, Boolean all, Dict(runtime) *opts, E FUNC_API_FAST { bool is_lua = api_object_to_bool(opts->is_lua, "is_lua", false, err); + bool source = api_object_to_bool(opts->do_source, "do_source", false, err); + if (source && !nlua_is_deferred_safe()) { + api_set_error(err, kErrorTypeValidation, "'do_source' cannot be used in fast callback"); + } + if (ERROR_SET(err)) { return (Array)ARRAY_DICT_INIT; } - return runtime_get_named(is_lua, pat, all); + + ArrayOf(String) res = runtime_get_named(is_lua, pat, all); + + if (source) { + for (size_t i = 0; i < res.size; i++) { + String name = res.items[i].data.string; + (void)do_source(name.data, false, DOSO_NONE); + } + } + + return res; } /// Changes the global working directory. -- cgit From f4121c52b95d4b79c0de95412c8447614a2f8960 Mon Sep 17 00:00:00 2001 From: bfredl Date: Fri, 10 Jun 2022 11:23:17 +0200 Subject: fix(messages): add color when showing nvim_echo in :messages history --- src/nvim/api/vim.c | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 1e44250ec3..5f7162cdd6 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -942,26 +942,15 @@ void nvim_echo(Array chunks, Boolean history, Dictionary opts, Error *err) goto error; } - no_wait_return++; - msg_start(); - msg_clr_eos(); - bool need_clear = false; - for (uint32_t i = 0; i < kv_size(hl_msg); i++) { - HlMessageChunk chunk = kv_A(hl_msg, i); - msg_multiline_attr((const char *)chunk.text.data, chunk.attr, - true, &need_clear); - } + msg_multiattr(hl_msg, history ? "echomsg" : "echo", history); + if (history) { - msg_ext_set_kind("echomsg"); - add_hl_msg_hist(hl_msg); - } else { - msg_ext_set_kind("echo"); + // history takes ownership + return; } - no_wait_return--; - msg_end(); error: - clear_hl_msg(&hl_msg); + hl_msg_free(hl_msg); } /// Writes a message to the Vim output buffer. Does not append "\n", the -- cgit From 4a275e3291d3eade38490801d9842640df3de202 Mon Sep 17 00:00:00 2001 From: bfredl Date: Sun, 12 Jun 2022 00:37:39 +0200 Subject: refactor(api): move option code to own file --- src/nvim/api/vim.c | 214 ----------------------------------------------------- 1 file changed, 214 deletions(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 5f7162cdd6..f4a6c5e9e3 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -708,220 +708,6 @@ void nvim_set_vvar(String name, Object value, Error *err) dict_set_var(&vimvardict, name, value, false, false, err); } -/// Gets the global value of an option. -/// -/// @param name Option name -/// @param[out] err Error details, if any -/// @return Option value (global) -Object nvim_get_option(String name, Error *err) - FUNC_API_SINCE(1) -{ - return get_option_from(NULL, SREQ_GLOBAL, name, err); -} - -/// Gets the value of an option. The behavior of this function matches that of -/// |:set|: the local value of an option is returned if it exists; otherwise, -/// the global value is returned. Local values always correspond to the current -/// buffer or window. To get a buffer-local or window-local option for a -/// specific buffer or window, use |nvim_buf_get_option()| or -/// |nvim_win_get_option()|. -/// -/// @param name Option name -/// @param opts Optional parameters -/// - scope: One of 'global' or 'local'. Analogous to -/// |:setglobal| and |:setlocal|, respectively. -/// @param[out] err Error details, if any -/// @return Option value -Object nvim_get_option_value(String name, Dict(option) *opts, Error *err) - FUNC_API_SINCE(9) -{ - Object rv = OBJECT_INIT; - - int scope = 0; - if (opts->scope.type == kObjectTypeString) { - if (!strcmp(opts->scope.data.string.data, "local")) { - scope = OPT_LOCAL; - } else if (!strcmp(opts->scope.data.string.data, "global")) { - scope = OPT_GLOBAL; - } else { - api_set_error(err, kErrorTypeValidation, "invalid scope: must be 'local' or 'global'"); - goto end; - } - } else if (HAS_KEY(opts->scope)) { - api_set_error(err, kErrorTypeValidation, "invalid value for key: scope"); - goto end; - } - - long numval = 0; - char *stringval = NULL; - switch (get_option_value(name.data, &numval, &stringval, scope)) { - case 0: - rv = STRING_OBJ(cstr_as_string(stringval)); - break; - case 1: - rv = INTEGER_OBJ(numval); - break; - case 2: - switch (numval) { - case 0: - case 1: - rv = BOOLEAN_OBJ(numval); - break; - default: - // Boolean options that return something other than 0 or 1 should return nil. Currently this - // only applies to 'autoread' which uses -1 as a local value to indicate "unset" - rv = NIL; - break; - } - break; - default: - api_set_error(err, kErrorTypeValidation, "unknown option '%s'", name.data); - goto end; - } - -end: - return rv; -} - -/// Sets the value of an option. The behavior of this function matches that of -/// |:set|: for global-local options, both the global and local value are set -/// unless otherwise specified with {scope}. -/// -/// Note the options {win} and {buf} cannot be used together. -/// -/// @param name Option name -/// @param value New option value -/// @param opts Optional parameters -/// - scope: One of 'global' or 'local'. Analogous to -/// |:setglobal| and |:setlocal|, respectively. -/// - win: |window-ID|. Used for setting window local option. -/// - buf: Buffer number. Used for setting buffer local option. -/// @param[out] err Error details, if any -void nvim_set_option_value(String name, Object value, Dict(option) *opts, Error *err) - FUNC_API_SINCE(9) -{ - int scope = 0; - if (opts->scope.type == kObjectTypeString) { - if (!strcmp(opts->scope.data.string.data, "local")) { - scope = OPT_LOCAL; - } else if (!strcmp(opts->scope.data.string.data, "global")) { - scope = OPT_GLOBAL; - } else { - api_set_error(err, kErrorTypeValidation, "invalid scope: must be 'local' or 'global'"); - return; - } - } else if (HAS_KEY(opts->scope)) { - api_set_error(err, kErrorTypeValidation, "invalid value for key: scope"); - return; - } - - int opt_type = SREQ_GLOBAL; - void *to = NULL; - - if (opts->win.type == kObjectTypeInteger) { - opt_type = SREQ_WIN; - to = find_window_by_handle((int)opts->win.data.integer, err); - } else if (HAS_KEY(opts->win)) { - api_set_error(err, kErrorTypeValidation, "invalid value for key: win"); - return; - } - - if (opts->buf.type == kObjectTypeInteger) { - scope = OPT_LOCAL; - opt_type = SREQ_BUF; - to = find_buffer_by_handle((int)opts->buf.data.integer, err); - } else if (HAS_KEY(opts->buf)) { - api_set_error(err, kErrorTypeValidation, "invalid value for key: buf"); - return; - } - - if (HAS_KEY(opts->scope) && HAS_KEY(opts->buf)) { - api_set_error(err, kErrorTypeValidation, "scope and buf cannot be used together"); - return; - } - - if (HAS_KEY(opts->win) && HAS_KEY(opts->buf)) { - api_set_error(err, kErrorTypeValidation, "buf and win cannot be used together"); - return; - } - - long numval = 0; - char *stringval = NULL; - - switch (value.type) { - case kObjectTypeInteger: - numval = value.data.integer; - break; - case kObjectTypeBoolean: - numval = value.data.boolean ? 1 : 0; - break; - case kObjectTypeString: - stringval = value.data.string.data; - break; - case kObjectTypeNil: - scope |= OPT_CLEAR; - break; - default: - api_set_error(err, kErrorTypeValidation, "invalid value for option"); - return; - } - - set_option_value_for(name.data, numval, stringval, scope, opt_type, to, err); -} - -/// Gets the option information for all options. -/// -/// The dictionary has the full option names as keys and option metadata -/// dictionaries as detailed at |nvim_get_option_info|. -/// -/// @return dictionary of all options -Dictionary nvim_get_all_options_info(Error *err) - FUNC_API_SINCE(7) -{ - return get_all_vimoptions(); -} - -/// Gets the option information for one option -/// -/// Resulting dictionary has keys: -/// - name: Name of the option (like 'filetype') -/// - shortname: Shortened name of the option (like 'ft') -/// - type: type of option ("string", "number" or "boolean") -/// - default: The default value for the option -/// - was_set: Whether the option was set. -/// -/// - last_set_sid: Last set script id (if any) -/// - last_set_linenr: line number where option was set -/// - last_set_chan: Channel where option was set (0 for local) -/// -/// - scope: one of "global", "win", or "buf" -/// - global_local: whether win or buf option has a global value -/// -/// - commalist: List of comma separated values -/// - flaglist: List of single char flags -/// -/// -/// @param name Option name -/// @param[out] err Error details, if any -/// @return Option Information -Dictionary nvim_get_option_info(String name, Error *err) - FUNC_API_SINCE(7) -{ - return get_vimoption(name, err); -} - -/// Sets the global value of an option. -/// -/// @param channel_id -/// @param name Option name -/// @param value New option value -/// @param[out] err Error details, if any -void nvim_set_option(uint64_t channel_id, String name, Object value, Error *err) - FUNC_API_SINCE(1) -{ - set_option_to(channel_id, NULL, SREQ_GLOBAL, name, value, err); -} - /// Echo a message. /// /// @param chunks A list of [text, hl_group] arrays, each representing a -- cgit From 0d63fafcda3847a6ec8a9da42db7bf10ac917d14 Mon Sep 17 00:00:00 2001 From: bfredl Date: Sun, 12 Jun 2022 16:38:31 +0200 Subject: refactor(api): move command related API to separate file --- src/nvim/api/vim.c | 70 ------------------------------------------------------ 1 file changed, 70 deletions(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index f4a6c5e9e3..77b4900f4f 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -1465,21 +1465,6 @@ void nvim_del_keymap(uint64_t channel_id, String mode, String lhs, Error *err) nvim_buf_del_keymap(channel_id, -1, mode, lhs, err); } -/// Gets a map of global (non-buffer-local) Ex commands. -/// -/// Currently only |user-commands| are supported, not builtin Ex commands. -/// -/// @param opts Optional parameters. Currently only supports -/// {"builtin":false} -/// @param[out] err Error details, if any. -/// -/// @returns Map of maps describing commands. -Dictionary nvim_get_commands(Dict(get_commands) *opts, Error *err) - FUNC_API_SINCE(4) -{ - return nvim_buf_get_commands(-1, opts, err); -} - /// Returns a 2-tuple (Array), where item 0 is the current channel id and item /// 1 is the |api-metadata| map (Dictionary). /// @@ -2269,58 +2254,3 @@ Dictionary nvim_eval_statusline(String str, Dict(eval_statusline) *opts, Error * return result; } - -/// Create a new user command |user-commands| -/// -/// {name} is the name of the new command. The name must begin with an uppercase letter. -/// -/// {command} is the replacement text or Lua function to execute. -/// -/// Example: -///
-///    :call nvim_create_user_command('SayHello', 'echo "Hello world!"', {})
-///    :SayHello
-///    Hello world!
-/// 
-/// -/// @param name Name of the new user command. Must begin with an uppercase letter. -/// @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: -/// - 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 || -/// - bang: (boolean) "true" if the command was executed with a ! modifier || -/// - line1: (number) The starting line of the command range || -/// - line2: (number) The final line of the command range || -/// - range: (number) The number of items in the command range: 0, 1, or 2 || -/// - count: (number) Any count supplied || -/// - reg: (string) The optional register, if specified || -/// - mods: (string) Command modifiers, if any || -/// - smods: (table) Command modifiers in a structured format. Has the same -/// structure as the "mods" key of |nvim_parse_cmd()|. -/// @param opts Optional command attributes. See |command-attributes| for more details. To use -/// boolean attributes (such as |:command-bang| or |:command-bar|) set the value to -/// "true". In addition to the string options listed in |:command-complete|, the -/// "complete" key also accepts a Lua function which works like the "customlist" -/// completion mode |:command-completion-customlist|. Additional parameters: -/// - desc: (string) Used for listing the command when a Lua function is used for -/// {command}. -/// - force: (boolean, default true) Override any previous definition. -/// - preview: (function) Preview callback for 'inccommand' |:command-preview| -/// @param[out] err Error details, if any. -void nvim_create_user_command(String name, Object command, Dict(user_command) *opts, Error *err) - FUNC_API_SINCE(9) -{ - create_user_command(name, command, opts, 0, err); -} - -/// Delete a user-defined command. -/// -/// @param name Name of the command to delete. -/// @param[out] err Error details, if any. -void nvim_del_user_command(String name, Error *err) - FUNC_API_SINCE(9) -{ - nvim_buf_del_user_command(-1, name, err); -} -- cgit From 8f065205946844d87f00d6c55517521e3809f821 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Mon, 23 May 2022 21:44:15 -0700 Subject: feat(logging): include test-id in log messages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: 1. Log messages (especially in CI) are hard to correlate with tests. 2. Since b353a5c05f02 #11886, dumplog() prints the logs next to test failures. This is noisy and gets in the way of the test results. Solution: 1. Associate an incrementing id with each test and include it in log messages. - FUTURE: add v:name so Nvim instances can be formally "named"? 2. Mention "child" in log messages if the current Nvim is a child (based on the presence of $NVIM). BEFORE: DBG … 12345 UI: event DBG … 12345 log_server_msg:722: RPC ->ch 1: … DBG … 12345 UI: flush DBG … 12345 inbuf_poll:444: blocking... events_enabled=1 events_pending=0 DBG … 23454 UI: stop INF … 23454 os_exit:594: Nvim exit: 0 AFTER: DBG … T57 UI: event DBG … T57 log_server_msg:722: RPC ->ch 1: … DBG … T57 UI: flush DBG … T57 inbuf_poll:444: blocking... events_enabled=1 events_pending=0 DBG … T57/child UI: stop INF … T57/child os_exit:594: Nvim exit: 0 --- src/nvim/api/vim.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 77b4900f4f..a60a069fae 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -1790,8 +1790,9 @@ Dictionary nvim__stats(void) { Dictionary rv = ARRAY_DICT_INIT; PUT(rv, "fsync", INTEGER_OBJ(g_stats.fsync)); - PUT(rv, "redraw", INTEGER_OBJ(g_stats.redraw)); + PUT(rv, "log_skip", INTEGER_OBJ(g_stats.log_skip)); PUT(rv, "lua_refcount", INTEGER_OBJ(nlua_get_global_ref_count())); + PUT(rv, "redraw", INTEGER_OBJ(g_stats.redraw)); return rv; } -- cgit From ff6b8f54359037790b300cb06a025f84f11d829a Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sat, 18 Jun 2022 18:53:12 +0200 Subject: fix(terminal): coverity USE_AFTER_FREE #18978 Problem: Coverity reports use after free: *** CID 352784: Memory - illegal accesses (USE_AFTER_FREE) /src/nvim/buffer.c: 1508 in set_curbuf() 1502 if (old_tw != curbuf->b_p_tw) { 1503 check_colorcolumn(curwin); 1504 } 1505 } 1506 1507 if (bufref_valid(&prevbufref) && prevbuf->terminal != NULL) { >>> CID 352784: Memory - illegal accesses (USE_AFTER_FREE) >>> Calling "terminal_check_size" dereferences freed pointer "prevbuf->terminal". 1508 terminal_check_size(prevbuf->terminal); 1509 } 1510 } 1511 1512 /// Enter a new current buffer. 1513 /// Old curbuf must have been abandoned already! This also means "curbuf" may Solution: Change terminal_destroy and terminal_close to set caller storage to NULL, similar to XFREE_CLEAR. This aligns with the pattern found already in: terminal_destroy e897ccad3eb1e term_delayed_free 3e59c1e20d605 --- src/nvim/api/vim.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index a60a069fae..3a24f2b405 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -1025,8 +1025,7 @@ static void term_resize(uint16_t width, uint16_t height, void *data) static void term_close(void *data) { Channel *chan = data; - terminal_destroy(chan->term); - chan->term = NULL; + terminal_destroy(&chan->term); api_free_luaref(chan->stream.internal.cb); chan->stream.internal.cb = LUA_NOREF; channel_decref(chan); -- cgit From 374e0b6678b21105bd5a26265e483cc4d9dbcaad Mon Sep 17 00:00:00 2001 From: bfredl Date: Tue, 21 Jun 2022 12:29:49 +0200 Subject: perf(highlight): don't allocate duplicates for color names --- src/nvim/api/vim.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 3a24f2b405..b7df1398f5 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -1293,7 +1293,8 @@ void nvim_unsubscribe(uint64_t channel_id, String event) Integer nvim_get_color_by_name(String name) FUNC_API_SINCE(1) { - return name_to_color(name.data); + int dummy; + return name_to_color(name.data, &dummy); } /// Returns a map of color names and RGB values. -- cgit From 7718b758461265d8966468c104ce5454538471e2 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 23 Jun 2022 21:17:11 +0800 Subject: refactor: move some mapping-related code to a separate file (#19061) This marks the following Vim patches as ported: vim-patch:8.1.1785: map functionality mixed with character input Problem: Map functionality mixed with character input. Solution: Move the map functionality to a separate file. (Yegappan Lakshmanan, closes vim/vim#4740) Graduate the +localmap feature. https://github.com/vim/vim/commit/b66bab381c8ba71fd6e92327d1d34c6f8a65f2a7 vim-patch:8.2.3643: header for source file is outdated Problem: Header for source file is outdated. Solution: Make the header more accurate. (closes vim/vim#9186) https://github.com/vim/vim/commit/a3f83feb63eae5464a620ae793c002eb45f7a838 Also cherry-pick a change for mappings from patch 8.2.0807. Rename map_clear_mode() to do_mapclear(). --- src/nvim/api/vim.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index b7df1398f5..c5881dbc5f 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -38,6 +38,7 @@ #include "nvim/highlight_defs.h" #include "nvim/highlight_group.h" #include "nvim/lua/executor.h" +#include "nvim/mapping.h" #include "nvim/mark.h" #include "nvim/memline.h" #include "nvim/memory.h" -- cgit From 014a88799a1d175ad121c520c9cc5bd0bb2d8813 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Tue, 28 Jun 2022 11:31:54 +0200 Subject: refactor: replace char_u #18429 Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/api/vim.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index c5881dbc5f..bf3fb04a18 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -2109,7 +2109,7 @@ Dictionary nvim_eval_statusline(String str, Dict(eval_statusline) *opts, Error * bool highlights = false; if (str.size < 2 || memcmp(str.data, "%!", 2)) { - const char *const errmsg = check_stl_option((char_u *)str.data); + const char *const errmsg = check_stl_option(str.data); if (errmsg) { api_set_error(err, kErrorTypeValidation, "%s", errmsg); return result; -- cgit From 995e4879153d0f4ea72dff446c175754a1873425 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 30 Jun 2022 16:57:44 +0800 Subject: refactor(highlight)!: rename attributes to match Vim (#19159) Ref: https://github.com/vim/vim/commit/84f546363068e4ddfe14a8a2a2322bb8d3a25417 Rename: - `underlineline` to `underdouble` - `underdot` to `underdotted` - `underdash` to `underdashed` `underdouble` also now takes higher precedence than `undercurl`. --- src/nvim/api/vim.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index bf3fb04a18..f91b74cd31 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -149,10 +149,10 @@ Dictionary nvim__get_hl_defs(Integer ns_id, Error *err) /// - bold: boolean /// - standout: boolean /// - underline: boolean -/// - underlineline: boolean /// - undercurl: boolean -/// - underdot: boolean -/// - underdash: boolean +/// - underdouble: boolean +/// - underdotted: boolean +/// - underdashed: boolean /// - strikethrough: boolean /// - italic: boolean /// - reverse: boolean -- cgit From 565f72b9689e0c440ff72c712a090224aaf7631b Mon Sep 17 00:00:00 2001 From: Javier Lopez Date: Thu, 30 Jun 2022 07:59:52 -0500 Subject: feat(marks): restore viewport on jump #15831 ** Refactor Previously most functions used to "get" a mark returned a position, changed the line number and sometimes changed even the current buffer. Now functions return a {x}fmark_T making calling context aware whether the mark is in another buffer without arcane casting. A new function is provided for switching to the mark buffer and returning a flag style Enum to convey what happen in the movement. If the cursor changed, line, columns, if it changed buffer, etc. The function to get named mark was split into multiple functions. - mark_get() -> fmark_T - mark_get_global() -> xfmark_T - mark_get_local() -> fmark_T - mark_get_motion() -> fmark_T - mark_get_visual() -> fmark_T Functions that manage the changelist and jumplist were also modified to return mark types. - get_jumplist -> fmark_T - get_changelist -> fmark_T The refactor is also seen mainly on normal.c, where all the mark movement has been siphoned through one function nv_gomark, while the other functions handle getting the mark and setting their movement flags. To handle whether context marks should be left, etc. ** Mark View While doing the refactor the concept of a mark view was also implemented: The view of a mark currently implemented as the number of lines between the mark position on creation and the window topline. This allows for moving not only back to the position of a mark but having the window look similar to when the mark was defined. This is done by carrying and extra element in the fmark_T struct, which can be extended later to also restore horizontal shift. *** User space features 1. There's a new option, jumpoptions+=view enables the mark view restoring automatically when using the jumplist, changelist, alternate-file and mark motions. g; g, '[mark] `[mark] ** Limitations - The view information is not saved in shada. - Calls to get_mark should copy the value in the pointer since we are using pos_to_mark() to wrap and provide a homogeneous interfaces. This was also a limitation in the previous state of things. --- src/nvim/api/vim.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index f91b74cd31..56516b2ac7 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -2027,20 +2027,20 @@ Array nvim_get_mark(String name, Dictionary opts, Error *err) return rv; } - xfmark_T mark = get_global_mark(*name.data); - pos_T pos = mark.fmark.mark; + xfmark_T *mark = mark_get_global(false, *name.data); // false avoids loading the mark buffer + pos_T pos = mark->fmark.mark; bool allocated = false; int bufnr; char *filename; // Marks are from an open buffer it fnum is non zero - if (mark.fmark.fnum != 0) { - bufnr = mark.fmark.fnum; + if (mark->fmark.fnum != 0) { + bufnr = mark->fmark.fnum; filename = (char *)buflist_nr2name(bufnr, true, true); allocated = true; // Marks comes from shada } else { - filename = mark.fname; + filename = mark->fname; bufnr = 0; } -- cgit