From 9408f2dcf7cade2631688300e9b58eed6bc5219a Mon Sep 17 00:00:00 2001 From: ii14 <59243201+ii14@users.noreply.github.com> Date: Fri, 7 Apr 2023 19:40:57 +0200 Subject: refactor: remove redundant const char * casts --- src/nvim/api/win_config.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src/nvim/api/win_config.c') diff --git a/src/nvim/api/win_config.c b/src/nvim/api/win_config.c index 0ffeac1bff..23bd5d2f48 100644 --- a/src/nvim/api/win_config.c +++ b/src/nvim/api/win_config.c @@ -275,13 +275,13 @@ Dictionary nvim_win_get_config(Window window, Error *err) for (size_t i = 0; i < 8; i++) { Array tuple = ARRAY_DICT_INIT; - String s = cstrn_to_string((const char *)config->border_chars[i], sizeof(schar_T)); + String s = cstrn_to_string(config->border_chars[i], sizeof(schar_T)); int hi_id = config->border_hl_ids[i]; char *hi_name = syn_id2name(hi_id); if (hi_name[0]) { ADD(tuple, STRING_OBJ(s)); - ADD(tuple, STRING_OBJ(cstr_to_string((const char *)hi_name))); + ADD(tuple, STRING_OBJ(cstr_to_string(hi_name))); ADD(border, ARRAY_OBJ(tuple)); } else { ADD(border, STRING_OBJ(s)); @@ -293,10 +293,9 @@ Dictionary nvim_win_get_config(Window window, Error *err) VirtText title_datas = config->title_chunks; for (size_t i = 0; i < title_datas.size; i++) { Array tuple = ARRAY_DICT_INIT; - ADD(tuple, CSTR_TO_OBJ((const char *)title_datas.items[i].text)); + ADD(tuple, CSTR_TO_OBJ(title_datas.items[i].text)); if (title_datas.items[i].hl_id > 0) { - ADD(tuple, - STRING_OBJ(cstr_to_string((const char *)syn_id2name(title_datas.items[i].hl_id)))); + ADD(tuple, STRING_OBJ(cstr_to_string(syn_id2name(title_datas.items[i].hl_id)))); } ADD(titles, ARRAY_OBJ(tuple)); } -- cgit From da979ae04b7a8c56586ed0233957600ad6af99f0 Mon Sep 17 00:00:00 2001 From: Munif Tanjim Date: Sun, 2 Apr 2023 23:01:10 +0600 Subject: fix(api): do not re-apply win_config.style when missing --- src/nvim/api/win_config.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src/nvim/api/win_config.c') diff --git a/src/nvim/api/win_config.c b/src/nvim/api/win_config.c index 0ffeac1bff..b2b2b51005 100644 --- a/src/nvim/api/win_config.c +++ b/src/nvim/api/win_config.c @@ -108,8 +108,8 @@ /// The default value for floats are 50. In general, values below 100 are /// recommended, unless there is a good reason to overshadow builtin /// elements. -/// - style: Configure the appearance of the window. Currently only takes -/// one non-empty value: +/// - style: (optional) Configure the appearance of the window. Currently +/// only supports one value: /// - "minimal" Nvim will display the window with many UI options /// disabled. This is useful when displaying a temporary /// float where the text should not be edited. Disables @@ -222,9 +222,11 @@ void nvim_win_set_config(Window window, Dict(float_config) *config, Error *err) win_config_float(win, fconfig); win->w_pos_changed = true; } - if (fconfig.style == kWinStyleMinimal) { - win_set_minimal_style(win); - didset_window_options(win, true); + if (HAS_KEY(config->style)) { + if (fconfig.style == kWinStyleMinimal) { + win_set_minimal_style(win); + didset_window_options(win, true); + } } } -- cgit From cfd4fdfea4d0e68ea50ad412b88b5289ded6fd6f Mon Sep 17 00:00:00 2001 From: Famiu Haque Date: Tue, 23 May 2023 14:25:10 +0600 Subject: refactor(api): new helper macros Adds new API helper macros `CSTR_AS_OBJ()`, `STATIC_CSTR_AS_OBJ()`, and `STATIC_CSTR_TO_OBJ()`, which cleans up a lot of the current code. These macros will also be used extensively in the upcoming option refactor PRs because then API Objects will be used to get/set options. This PR also modifies pre-existing code to use old API helper macros like `CSTR_TO_OBJ()` to make them cleaner. --- src/nvim/api/win_config.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim/api/win_config.c') diff --git a/src/nvim/api/win_config.c b/src/nvim/api/win_config.c index c267fee39a..8e4fbb6779 100644 --- a/src/nvim/api/win_config.c +++ b/src/nvim/api/win_config.c @@ -267,7 +267,7 @@ Dictionary nvim_win_get_config(Window window, Error *err) PUT(rv, "bufpos", ARRAY_OBJ(pos)); } } - PUT(rv, "anchor", STRING_OBJ(cstr_to_string(float_anchor_str[config->anchor]))); + PUT(rv, "anchor", CSTR_TO_OBJ(float_anchor_str[config->anchor])); PUT(rv, "row", FLOAT_OBJ(config->row)); PUT(rv, "col", FLOAT_OBJ(config->col)); PUT(rv, "zindex", INTEGER_OBJ(config->zindex)); @@ -283,7 +283,7 @@ Dictionary nvim_win_get_config(Window window, Error *err) char *hi_name = syn_id2name(hi_id); if (hi_name[0]) { ADD(tuple, STRING_OBJ(s)); - ADD(tuple, STRING_OBJ(cstr_to_string(hi_name))); + ADD(tuple, CSTR_TO_OBJ(hi_name)); ADD(border, ARRAY_OBJ(tuple)); } else { ADD(border, STRING_OBJ(s)); @@ -297,7 +297,7 @@ Dictionary nvim_win_get_config(Window window, Error *err) Array tuple = ARRAY_DICT_INIT; ADD(tuple, CSTR_TO_OBJ(title_datas.items[i].text)); if (title_datas.items[i].hl_id > 0) { - ADD(tuple, STRING_OBJ(cstr_to_string(syn_id2name(title_datas.items[i].hl_id)))); + ADD(tuple, CSTR_TO_OBJ(syn_id2name(title_datas.items[i].hl_id))); } ADD(titles, ARRAY_OBJ(tuple)); } @@ -317,7 +317,7 @@ Dictionary nvim_win_get_config(Window window, Error *err) const char *rel = (wp->w_floating && !config->external ? float_relative_str[config->relative] : ""); - PUT(rv, "relative", STRING_OBJ(cstr_to_string(rel))); + PUT(rv, "relative", CSTR_TO_OBJ(rel)); return rv; } -- cgit From 77118d0da8badc4135be430f4cbb15bc95bc760f Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Thu, 20 Apr 2023 21:17:25 +0100 Subject: fix(api): use text_locked() to check textlock Problem: some API functions that check textlock (usually those that can change curwin or curbuf) can break the cmdwin. Solution: make FUNC_API_CHECK_TEXTLOCK call text_locked() instead, which already checks for textlock, cmdwin and `` status. Add FUNC_API_TEXTLOCK_ALLOW_CMDWIN to allow such functions to be usable in the cmdwin if they can work properly there; the opt-in nature of this attribute should hopefully help mitigate future bugs. Also fix a regression in #22634 that made functions checking textlock usable in `` mappings, and rename FUNC_API_CHECK_TEXTLOCK to FUNC_API_TEXTLOCK. --- src/nvim/api/win_config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/api/win_config.c') diff --git a/src/nvim/api/win_config.c b/src/nvim/api/win_config.c index 8e4fbb6779..6ca36a0daf 100644 --- a/src/nvim/api/win_config.c +++ b/src/nvim/api/win_config.c @@ -158,7 +158,7 @@ /// @return Window handle, or 0 on error Window nvim_open_win(Buffer buffer, Boolean enter, Dict(float_config) *config, Error *err) FUNC_API_SINCE(6) - FUNC_API_CHECK_TEXTLOCK + FUNC_API_TEXTLOCK { FloatConfig fconfig = FLOAT_CONFIG_INIT; if (!parse_float_config(config, &fconfig, false, true, err)) { -- cgit From 6b4970f6e0ac36021b2a8bd0533f5078040d31f7 Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Sun, 23 Jul 2023 19:50:20 +0100 Subject: feat(api): allow open_win/win_set_buf in the cmdwin in some cases Problem: As discussed on Matrix, there was some interest in having `nvim_open_win` again be able to open floats in the cmdwin (e.g: displaying a hover doc related to what's in the cmdwin). After #23228, this was disallowed. Solution: Allow `nvim_open_win` in the cmdwin as long as `!enter` and `buffer != curbuf` (the former can cause all sorts of issues, and the latter can crash Nvim after closing cmdwin). Also allow `nvim_win_set_buf` in a similar fashion. Note that we're not *entirely* sure if this is 100% safe (cmdwin is a global-state-using-main-loop-calling beast), but this seems to work OK..? Also: - Check the buffer argument of `nvim_open_win` earlier, and abort if it's invalid (it used to still open a window in this case). - Untranslate `e_cmdwin` errors in the API (other errors in the API are not translated: although not detailed in the API contract yet, errors are supposed to be stable). --- src/nvim/api/win_config.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src/nvim/api/win_config.c') diff --git a/src/nvim/api/win_config.c b/src/nvim/api/win_config.c index 6ca36a0daf..81a239d913 100644 --- a/src/nvim/api/win_config.c +++ b/src/nvim/api/win_config.c @@ -158,8 +158,17 @@ /// @return Window handle, or 0 on error Window nvim_open_win(Buffer buffer, Boolean enter, Dict(float_config) *config, Error *err) FUNC_API_SINCE(6) - FUNC_API_TEXTLOCK + FUNC_API_TEXTLOCK_ALLOW_CMDWIN { + buf_T *buf = find_buffer_by_handle(buffer, err); + if (!buf) { + return 0; + } + if (cmdwin_type != 0 && (enter || buf == curbuf)) { + api_set_error(err, kErrorTypeException, "%s", e_cmdwin); + return 0; + } + FloatConfig fconfig = FLOAT_CONFIG_INIT; if (!parse_float_config(config, &fconfig, false, true, err)) { return 0; @@ -173,7 +182,7 @@ Window nvim_open_win(Buffer buffer, Boolean enter, Dict(float_config) *config, E } // autocmds in win_enter or win_set_buf below may close the window if (win_valid(wp) && buffer > 0) { - win_set_buf(wp->handle, buffer, fconfig.noautocmd, err); + win_set_buf(wp, buf, fconfig.noautocmd, err); } if (!win_valid(wp)) { api_set_error(err, kErrorTypeException, "Window was closed immediately"); -- cgit From 7bc93e0e2f246dd78026a3472d929a0fe450f70d Mon Sep 17 00:00:00 2001 From: bfredl Date: Tue, 1 Aug 2023 14:01:19 +0200 Subject: refactor(api): use typed keysets Initially this is just for geting rid of boilerplate, but eventually the types could get exposed as metadata --- src/nvim/api/win_config.c | 206 +++++++++++++++++++--------------------------- 1 file changed, 83 insertions(+), 123 deletions(-) (limited to 'src/nvim/api/win_config.c') diff --git a/src/nvim/api/win_config.c b/src/nvim/api/win_config.c index 81a239d913..b666d1efa2 100644 --- a/src/nvim/api/win_config.c +++ b/src/nvim/api/win_config.c @@ -7,6 +7,7 @@ #include "klib/kvec.h" #include "nvim/api/extmark.h" #include "nvim/api/private/defs.h" +#include "nvim/api/private/dispatch.h" #include "nvim/api/private/helpers.h" #include "nvim/api/win_config.h" #include "nvim/ascii.h" @@ -231,7 +232,7 @@ void nvim_win_set_config(Window window, Dict(float_config) *config, Error *err) win_config_float(win, fconfig); win->w_pos_changed = true; } - if (HAS_KEY(config->style)) { + if (HAS_KEY(config, float_config, style)) { if (fconfig.style == kWinStyleMinimal) { win_set_minimal_style(win); didset_window_options(win, true); @@ -380,12 +381,8 @@ static bool parse_float_bufpos(Array bufpos, lpos_T *out) return true; } -static void parse_border_title(Object title, Object title_pos, FloatConfig *fconfig, Error *err) +static void parse_border_title(Object title, FloatConfig *fconfig, Error *err) { - if (!parse_title_pos(title_pos, fconfig, err)) { - return; - } - if (title.type == kObjectTypeString) { if (title.data.string.size == 0) { fconfig->title = false; @@ -415,24 +412,14 @@ static void parse_border_title(Object title, Object title_pos, FloatConfig *fcon fconfig->title = true; } -static bool parse_title_pos(Object title_pos, FloatConfig *fconfig, Error *err) +static bool parse_title_pos(String title_pos, FloatConfig *fconfig, Error *err) { - if (!HAS_KEY(title_pos)) { + if (title_pos.size == 0) { fconfig->title_pos = kAlignLeft; return true; } - if (title_pos.type != kObjectTypeString) { - api_set_error(err, kErrorTypeValidation, "title_pos must be string"); - return false; - } - - if (title_pos.data.string.size == 0) { - fconfig->title_pos = kAlignLeft; - return true; - } - - char *pos = title_pos.data.string.data; + char *pos = title_pos.data; if (strequal(pos, "left")) { fconfig->title_pos = kAlignLeft; @@ -559,110 +546,90 @@ static void parse_border_style(Object style, FloatConfig *fconfig, Error *err) static bool parse_float_config(Dict(float_config) *config, FloatConfig *fconfig, bool reconf, bool new_win, Error *err) { +#define HAS_KEY_X(d, key) HAS_KEY(d, float_config, key) bool has_relative = false, relative_is_win = false; - if (config->relative.type == kObjectTypeString) { - // ignore empty string, to match nvim_win_get_config - if (config->relative.data.string.size > 0) { - if (!parse_float_relative(config->relative.data.string, &fconfig->relative)) { - api_set_error(err, kErrorTypeValidation, "Invalid value of 'relative' key"); - return false; - } + // ignore empty string, to match nvim_win_get_config + if (HAS_KEY_X(config, relative) && config->relative.size > 0) { + if (!parse_float_relative(config->relative, &fconfig->relative)) { + api_set_error(err, kErrorTypeValidation, "Invalid value of 'relative' key"); + return false; + } - if (!(HAS_KEY(config->row) && HAS_KEY(config->col)) && !HAS_KEY(config->bufpos)) { - api_set_error(err, kErrorTypeValidation, - "'relative' requires 'row'/'col' or 'bufpos'"); - return false; - } + if (!(HAS_KEY_X(config, row) && HAS_KEY_X(config, col)) && !HAS_KEY_X(config, bufpos)) { + api_set_error(err, kErrorTypeValidation, + "'relative' requires 'row'/'col' or 'bufpos'"); + return false; + } - has_relative = true; - fconfig->external = false; - if (fconfig->relative == kFloatRelativeWindow) { - relative_is_win = true; - fconfig->bufpos.lnum = -1; - } + has_relative = true; + fconfig->external = false; + if (fconfig->relative == kFloatRelativeWindow) { + relative_is_win = true; + fconfig->bufpos.lnum = -1; } - } else if (HAS_KEY(config->relative)) { - api_set_error(err, kErrorTypeValidation, "'relative' key must be String"); - return false; } - if (config->anchor.type == kObjectTypeString) { - if (!parse_float_anchor(config->anchor.data.string, &fconfig->anchor)) { + if (HAS_KEY_X(config, anchor)) { + if (!parse_float_anchor(config->anchor, &fconfig->anchor)) { api_set_error(err, kErrorTypeValidation, "Invalid value of 'anchor' key"); return false; } - } else if (HAS_KEY(config->anchor)) { - api_set_error(err, kErrorTypeValidation, "'anchor' key must be String"); - return false; } - if (HAS_KEY(config->row)) { + if (HAS_KEY_X(config, row)) { if (!has_relative) { api_set_error(err, kErrorTypeValidation, "non-float cannot have 'row'"); return false; - } else if (config->row.type == kObjectTypeInteger) { - fconfig->row = (double)config->row.data.integer; - } else if (config->row.type == kObjectTypeFloat) { - fconfig->row = config->row.data.floating; - } else { - api_set_error(err, kErrorTypeValidation, - "'row' key must be Integer or Float"); - return false; } + fconfig->row = config->row; } - if (HAS_KEY(config->col)) { + if (HAS_KEY_X(config, col)) { if (!has_relative) { api_set_error(err, kErrorTypeValidation, "non-float cannot have 'col'"); return false; - } else if (config->col.type == kObjectTypeInteger) { - fconfig->col = (double)config->col.data.integer; - } else if (config->col.type == kObjectTypeFloat) { - fconfig->col = config->col.data.floating; - } else { - api_set_error(err, kErrorTypeValidation, - "'col' key must be Integer or Float"); - return false; } + fconfig->col = config->col; } - if (HAS_KEY(config->bufpos)) { + if (HAS_KEY_X(config, bufpos)) { if (!has_relative) { api_set_error(err, kErrorTypeValidation, "non-float cannot have 'bufpos'"); return false; - } else if (config->bufpos.type == kObjectTypeArray) { - if (!parse_float_bufpos(config->bufpos.data.array, &fconfig->bufpos)) { + } else { + if (!parse_float_bufpos(config->bufpos, &fconfig->bufpos)) { api_set_error(err, kErrorTypeValidation, "Invalid value of 'bufpos' key"); return false; } - if (!HAS_KEY(config->row)) { + if (!HAS_KEY_X(config, row)) { fconfig->row = (fconfig->anchor & kFloatAnchorSouth) ? 0 : 1; } - if (!HAS_KEY(config->col)) { + if (!HAS_KEY_X(config, col)) { fconfig->col = 0; } - } else { - api_set_error(err, kErrorTypeValidation, "'bufpos' key must be Array"); - return false; } } - if (config->width.type == kObjectTypeInteger && config->width.data.integer > 0) { - fconfig->width = (int)config->width.data.integer; - } else if (HAS_KEY(config->width)) { - api_set_error(err, kErrorTypeValidation, "'width' key must be a positive Integer"); - return false; + if (HAS_KEY_X(config, width)) { + if (config->width > 0) { + fconfig->width = (int)config->width; + } else { + api_set_error(err, kErrorTypeValidation, "'width' key must be a positive Integer"); + return false; + } } else if (!reconf) { api_set_error(err, kErrorTypeValidation, "Must specify 'width'"); return false; } - if (config->height.type == kObjectTypeInteger && config->height.data.integer > 0) { - fconfig->height = (int)config->height.data.integer; - } else if (HAS_KEY(config->height)) { - api_set_error(err, kErrorTypeValidation, "'height' key must be a positive Integer"); - return false; + if (HAS_KEY_X(config, height)) { + if (config->height > 0) { + fconfig->height = (int)config->height; + } else { + api_set_error(err, kErrorTypeValidation, "'height' key must be a positive Integer"); + return false; + } } else if (!reconf) { api_set_error(err, kErrorTypeValidation, "Must specify 'height'"); return false; @@ -670,26 +637,20 @@ static bool parse_float_config(Dict(float_config) *config, FloatConfig *fconfig, if (relative_is_win) { fconfig->window = curwin->handle; - if (config->win.type == kObjectTypeInteger || config->win.type == kObjectTypeWindow) { - if (config->win.data.integer > 0) { - fconfig->window = (Window)config->win.data.integer; + if (HAS_KEY_X(config, win)) { + if (config->win > 0) { + fconfig->window = config->win; } - } else if (HAS_KEY(config->win)) { - api_set_error(err, kErrorTypeValidation, "'win' key must be Integer or Window"); - return false; } } else { - if (HAS_KEY(config->win)) { + if (HAS_KEY_X(config, win)) { api_set_error(err, kErrorTypeValidation, "'win' key is only valid with relative='win'"); return false; } } - if (HAS_KEY(config->external)) { - fconfig->external = api_object_to_bool(config->external, "'external' key", false, err); - if (ERROR_SET(err)) { - return false; - } + if (HAS_KEY_X(config, external)) { + fconfig->external = config->external; if (has_relative && fconfig->external) { api_set_error(err, kErrorTypeValidation, "Only one of 'relative' and 'external' must be used"); @@ -708,30 +669,22 @@ static bool parse_float_config(Dict(float_config) *config, FloatConfig *fconfig, return false; } - if (HAS_KEY(config->focusable)) { - fconfig->focusable = api_object_to_bool(config->focusable, "'focusable' key", false, err); - if (ERROR_SET(err)) { - return false; - } - } - - if (config->zindex.type == kObjectTypeInteger && config->zindex.data.integer > 0) { - fconfig->zindex = (int)config->zindex.data.integer; - } else if (HAS_KEY(config->zindex)) { - api_set_error(err, kErrorTypeValidation, "'zindex' key must be a positive Integer"); - return false; + if (HAS_KEY_X(config, focusable)) { + fconfig->focusable = config->focusable; } - if (HAS_KEY(config->title_pos)) { - if (!HAS_KEY(config->title)) { - api_set_error(err, kErrorTypeException, "title_pos requires title to be set"); + if (HAS_KEY_X(config, zindex)) { + if (config->zindex > 0) { + fconfig->zindex = (int)config->zindex; + } else { + api_set_error(err, kErrorTypeValidation, "'zindex' key must be a positive Integer"); return false; } } - if (HAS_KEY(config->title)) { + if (HAS_KEY_X(config, title)) { // title only work with border - if (!HAS_KEY(config->border) && !fconfig->border) { + if (!HAS_KEY_X(config, border) && !fconfig->border) { api_set_error(err, kErrorTypeException, "title requires border to be set"); return false; } @@ -739,42 +692,49 @@ static bool parse_float_config(Dict(float_config) *config, FloatConfig *fconfig, if (fconfig->title) { clear_virttext(&fconfig->title_chunks); } - parse_border_title(config->title, config->title_pos, fconfig, err); + + parse_border_title(config->title, fconfig, err); if (ERROR_SET(err)) { return false; } + + // handles unset 'title_pos' same as empty string + if (!parse_title_pos(config->title_pos, fconfig, err)) { + return false; + } + } else { + if (HAS_KEY_X(config, title_pos)) { + api_set_error(err, kErrorTypeException, "title_pos requires title to be set"); + return false; + } } - if (HAS_KEY(config->border)) { + if (HAS_KEY_X(config, border)) { parse_border_style(config->border, fconfig, err); if (ERROR_SET(err)) { return false; } } - if (config->style.type == kObjectTypeString) { - if (config->style.data.string.data[0] == NUL) { + if (HAS_KEY_X(config, style)) { + if (config->style.data[0] == NUL) { fconfig->style = kWinStyleUnused; - } else if (striequal(config->style.data.string.data, "minimal")) { + } else if (striequal(config->style.data, "minimal")) { fconfig->style = kWinStyleMinimal; } else { api_set_error(err, kErrorTypeValidation, "Invalid value of 'style' key"); + return false; } - } else if (HAS_KEY(config->style)) { - api_set_error(err, kErrorTypeValidation, "'style' key must be String"); - return false; } - if (HAS_KEY(config->noautocmd)) { + if (HAS_KEY_X(config, noautocmd)) { if (!new_win) { api_set_error(err, kErrorTypeValidation, "Invalid key: 'noautocmd'"); return false; } - fconfig->noautocmd = api_object_to_bool(config->noautocmd, "'noautocmd' key", false, err); - if (ERROR_SET(err)) { - return false; - } + fconfig->noautocmd = config->noautocmd; } return true; +#undef HAS_KEY_X } -- cgit From 617fd5bdc6ab9a82bfc6136f549fc31dcf442ed7 Mon Sep 17 00:00:00 2001 From: Evgeni Chasnovski Date: Fri, 25 Aug 2023 10:53:29 +0300 Subject: refactor(float): extract "title" and "title_pos" handling --- src/nvim/api/win_config.c | 127 ++++++++++++++++++++++++++++++---------------- 1 file changed, 84 insertions(+), 43 deletions(-) (limited to 'src/nvim/api/win_config.c') diff --git a/src/nvim/api/win_config.c b/src/nvim/api/win_config.c index b666d1efa2..9473803652 100644 --- a/src/nvim/api/win_config.c +++ b/src/nvim/api/win_config.c @@ -240,6 +240,48 @@ void nvim_win_set_config(Window window, Dict(float_config) *config, Error *err) } } +Dictionary config_put_bordertext(Dictionary config, FloatConfig *fconfig, + BorderTextType bordertext_type) +{ + VirtText chunks; + AlignTextPos align; + char *field_name; + char *field_pos_name; + if (bordertext_type == kBorderTextTitle) { + chunks = fconfig->title_chunks; + align = fconfig->title_pos; + field_name = "title"; + field_pos_name = "title_pos"; + } + + Array bordertext = ARRAY_DICT_INIT; + for (size_t i = 0; i < chunks.size; i++) { + Array tuple = ARRAY_DICT_INIT; + ADD(tuple, CSTR_TO_OBJ(chunks.items[i].text)); + if (chunks.items[i].hl_id > 0) { + ADD(tuple, CSTR_TO_OBJ(syn_id2name(chunks.items[i].hl_id))); + } + ADD(bordertext, ARRAY_OBJ(tuple)); + } + PUT(config, field_name, ARRAY_OBJ(bordertext)); + + char *pos; + switch (align) { + case kAlignLeft: + pos = "left"; + break; + case kAlignCenter: + pos = "center"; + break; + case kAlignRight: + pos = "right"; + break; + } + PUT(config, field_pos_name, CSTR_TO_OBJ(pos)); + + return config; +} + /// Gets window configuration. /// /// The returned value may be given to |nvim_open_win()|. @@ -301,26 +343,7 @@ Dictionary nvim_win_get_config(Window window, Error *err) } PUT(rv, "border", ARRAY_OBJ(border)); if (config->title) { - Array titles = ARRAY_DICT_INIT; - VirtText title_datas = config->title_chunks; - for (size_t i = 0; i < title_datas.size; i++) { - Array tuple = ARRAY_DICT_INIT; - ADD(tuple, CSTR_TO_OBJ(title_datas.items[i].text)); - if (title_datas.items[i].hl_id > 0) { - ADD(tuple, CSTR_TO_OBJ(syn_id2name(title_datas.items[i].hl_id))); - } - ADD(titles, ARRAY_OBJ(tuple)); - } - PUT(rv, "title", ARRAY_OBJ(titles)); - char *title_pos; - if (config->title_pos == kAlignLeft) { - title_pos = "left"; - } else if (config->title_pos == kAlignCenter) { - title_pos = "center"; - } else { - title_pos = "right"; - } - PUT(rv, "title_pos", CSTR_TO_OBJ(title_pos)); + rv = config_put_bordertext(rv, config, kBorderTextTitle); } } } @@ -381,54 +404,72 @@ static bool parse_float_bufpos(Array bufpos, lpos_T *out) return true; } -static void parse_border_title(Object title, FloatConfig *fconfig, Error *err) +static void parse_bordertext(Object bordertext, BorderTextType bordertext_type, + FloatConfig *fconfig, Error *err) { - if (title.type == kObjectTypeString) { - if (title.data.string.size == 0) { - fconfig->title = false; + bool *is_present; + VirtText *chunks; + int *width; + if (bordertext_type == kBorderTextTitle) { + is_present = &fconfig->title; + chunks = &fconfig->title_chunks; + width = &fconfig->title_width; + } + + if (bordertext.type == kObjectTypeString) { + if (bordertext.data.string.size == 0) { + *is_present = false; return; } int hl_id = syn_check_group(S_LEN("FloatTitle")); - kv_push(fconfig->title_chunks, ((VirtTextChunk){ .text = xstrdup(title.data.string.data), - .hl_id = hl_id })); - fconfig->title_width = (int)mb_string2cells(title.data.string.data); - fconfig->title = true; + kv_push(*chunks, ((VirtTextChunk){ .text = xstrdup(bordertext.data.string.data), + .hl_id = hl_id })); + *width = (int)mb_string2cells(bordertext.data.string.data); + *is_present = true; return; } - if (title.type != kObjectTypeArray) { + if (bordertext.type != kObjectTypeArray) { api_set_error(err, kErrorTypeValidation, "title must be string or array"); return; } - if (title.data.array.size == 0) { + if (bordertext.data.array.size == 0) { api_set_error(err, kErrorTypeValidation, "title cannot be an empty array"); return; } - fconfig->title_width = 0; - fconfig->title_chunks = parse_virt_text(title.data.array, err, &fconfig->title_width); + *width = 0; + *chunks = parse_virt_text(bordertext.data.array, err, width); - fconfig->title = true; + *is_present = true; } -static bool parse_title_pos(String title_pos, FloatConfig *fconfig, Error *err) +static bool parse_bordertext_pos(String bordertext_pos, BorderTextType bordertext_type, + FloatConfig *fconfig, Error *err) { - if (title_pos.size == 0) { - fconfig->title_pos = kAlignLeft; + AlignTextPos *align; + if (bordertext_type == kBorderTextTitle) { + align = &fconfig->title_pos; + } + + if (bordertext_pos.size == 0) { + *align = kAlignLeft; return true; } - char *pos = title_pos.data; + char *pos = bordertext_pos.data; if (strequal(pos, "left")) { - fconfig->title_pos = kAlignLeft; + *align = kAlignLeft; } else if (strequal(pos, "center")) { - fconfig->title_pos = kAlignCenter; + *align = kAlignCenter; } else if (strequal(pos, "right")) { - fconfig->title_pos = kAlignRight; + *align = kAlignRight; } else { - api_set_error(err, kErrorTypeValidation, "invalid title_pos value"); + if (bordertext_type == kBorderTextTitle) { + api_set_error(err, kErrorTypeValidation, "invalid title_pos value"); + } return false; } return true; @@ -693,13 +734,13 @@ static bool parse_float_config(Dict(float_config) *config, FloatConfig *fconfig, clear_virttext(&fconfig->title_chunks); } - parse_border_title(config->title, fconfig, err); + parse_bordertext(config->title, kBorderTextTitle, fconfig, err); if (ERROR_SET(err)) { return false; } // handles unset 'title_pos' same as empty string - if (!parse_title_pos(config->title_pos, fconfig, err)) { + if (!parse_bordertext_pos(config->title_pos, kBorderTextTitle, fconfig, err)) { return false; } } else { -- cgit From 35570e4a11bef061777d741929f74fa66ba3f45a Mon Sep 17 00:00:00 2001 From: Evgeni Chasnovski Date: Fri, 25 Aug 2023 10:53:35 +0300 Subject: feat(float): implement footer Problem: Now way to show text at the bottom part of floating window border (a.k.a. "footer"). Solution: Allows `footer` and `footer_pos` config fields similar to `title` and `title_pos`. --- src/nvim/api/win_config.c | 83 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 73 insertions(+), 10 deletions(-) (limited to 'src/nvim/api/win_config.c') diff --git a/src/nvim/api/win_config.c b/src/nvim/api/win_config.c index 9473803652..325d0cbfa0 100644 --- a/src/nvim/api/win_config.c +++ b/src/nvim/api/win_config.c @@ -145,11 +145,18 @@ /// By default, `FloatBorder` highlight is used, which links to `WinSeparator` /// when not defined. It could also be specified by character: /// [ ["+", "MyCorner"], ["x", "MyBorder"] ]. -/// - title: Title (optional) in window border, String or list. -/// List is [text, highlight] tuples. if is string the default -/// highlight group is `FloatTitle`. -/// - title_pos: Title position must set with title option. -/// value can be of `left` `center` `right` default is left. +/// - title: Title (optional) in window border, string or list. +/// List should consist of `[text, highlight]` tuples. +/// If string, the default highlight group is `FloatTitle`. +/// - title_pos: Title position. Must be set with `title` option. +/// Value can be one of "left", "center", or "right". +/// Default is `"left"`. +/// - footer: Footer (optional) in window border, string or list. +/// List should consist of `[text, highlight]` tuples. +/// If string, the default highlight group is `FloatTitle`. +/// - footer_pos: Footer position. Must be set with `footer` option. +/// Value can be one of "left", "center", or "right". +/// Default is `"left"`. /// - noautocmd: If true then no buffer-related autocommand events such as /// |BufEnter|, |BufLeave| or |BufWinEnter| may fire from /// calling this function. @@ -247,11 +254,19 @@ Dictionary config_put_bordertext(Dictionary config, FloatConfig *fconfig, AlignTextPos align; char *field_name; char *field_pos_name; - if (bordertext_type == kBorderTextTitle) { + switch (bordertext_type) { + case kBorderTextTitle: chunks = fconfig->title_chunks; align = fconfig->title_pos; field_name = "title"; field_pos_name = "title_pos"; + break; + case kBorderTextFooter: + chunks = fconfig->footer_chunks; + align = fconfig->footer_pos; + field_name = "footer"; + field_pos_name = "footer_pos"; + break; } Array bordertext = ARRAY_DICT_INIT; @@ -345,6 +360,9 @@ Dictionary nvim_win_get_config(Window window, Error *err) if (config->title) { rv = config_put_bordertext(rv, config, kBorderTextTitle); } + if (config->footer) { + rv = config_put_bordertext(rv, config, kBorderTextFooter); + } } } @@ -410,10 +428,17 @@ static void parse_bordertext(Object bordertext, BorderTextType bordertext_type, bool *is_present; VirtText *chunks; int *width; - if (bordertext_type == kBorderTextTitle) { + switch (bordertext_type) { + case kBorderTextTitle: is_present = &fconfig->title; chunks = &fconfig->title_chunks; width = &fconfig->title_width; + break; + case kBorderTextFooter: + is_present = &fconfig->footer; + chunks = &fconfig->footer_chunks; + width = &fconfig->footer_width; + break; } if (bordertext.type == kObjectTypeString) { @@ -449,8 +474,13 @@ static bool parse_bordertext_pos(String bordertext_pos, BorderTextType bordertex FloatConfig *fconfig, Error *err) { AlignTextPos *align; - if (bordertext_type == kBorderTextTitle) { + switch (bordertext_type) { + case kBorderTextTitle: align = &fconfig->title_pos; + break; + case kBorderTextFooter: + align = &fconfig->footer_pos; + break; } if (bordertext_pos.size == 0) { @@ -467,8 +497,13 @@ static bool parse_bordertext_pos(String bordertext_pos, BorderTextType bordertex } else if (strequal(pos, "right")) { *align = kAlignRight; } else { - if (bordertext_type == kBorderTextTitle) { + switch (bordertext_type) { + case kBorderTextTitle: api_set_error(err, kErrorTypeValidation, "invalid title_pos value"); + break; + case kBorderTextFooter: + api_set_error(err, kErrorTypeValidation, "invalid footer_pos value"); + break; } return false; } @@ -559,8 +594,9 @@ static void parse_border_style(Object style, FloatConfig *fconfig, Error *err) String str = style.data.string; if (str.size == 0 || strequal(str.data, "none")) { fconfig->border = false; - // title does not work with border equal none + // border text does not work with border equal none fconfig->title = false; + fconfig->footer = false; return; } for (size_t i = 0; defaults[i].name; i++) { @@ -750,6 +786,33 @@ static bool parse_float_config(Dict(float_config) *config, FloatConfig *fconfig, } } + if (HAS_KEY_X(config, footer)) { + // footer only work with border + if (!HAS_KEY_X(config, border) && !fconfig->border) { + api_set_error(err, kErrorTypeException, "footer requires border to be set"); + return false; + } + + if (fconfig->footer) { + clear_virttext(&fconfig->footer_chunks); + } + + parse_bordertext(config->footer, kBorderTextFooter, fconfig, err); + if (ERROR_SET(err)) { + return false; + } + + // handles unset 'footer_pos' same as empty string + if (!parse_bordertext_pos(config->footer_pos, kBorderTextFooter, fconfig, err)) { + return false; + } + } else { + if (HAS_KEY_X(config, footer_pos)) { + api_set_error(err, kErrorTypeException, "footer_pos requires footer to be set"); + return false; + } + } + if (HAS_KEY_X(config, border)) { parse_border_style(config->border, fconfig, err); if (ERROR_SET(err)) { -- cgit From 986bf7e78d09286e198b696630254eb097ad0875 Mon Sep 17 00:00:00 2001 From: Evgeni Chasnovski Date: Fri, 25 Aug 2023 10:53:39 +0300 Subject: feat(highlight): add `FloatFooter` highlight group Problem: No clear separation of floating title and footer highlighting. Solution: Add new `FloatFooter` highlight group. --- src/nvim/api/win_config.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/nvim/api/win_config.c') diff --git a/src/nvim/api/win_config.c b/src/nvim/api/win_config.c index 325d0cbfa0..ac27554172 100644 --- a/src/nvim/api/win_config.c +++ b/src/nvim/api/win_config.c @@ -153,7 +153,7 @@ /// Default is `"left"`. /// - footer: Footer (optional) in window border, string or list. /// List should consist of `[text, highlight]` tuples. -/// If string, the default highlight group is `FloatTitle`. +/// If string, the default highlight group is `FloatFooter`. /// - footer_pos: Footer position. Must be set with `footer` option. /// Value can be one of "left", "center", or "right". /// Default is `"left"`. @@ -428,16 +428,19 @@ static void parse_bordertext(Object bordertext, BorderTextType bordertext_type, bool *is_present; VirtText *chunks; int *width; + int default_hl_id; switch (bordertext_type) { case kBorderTextTitle: is_present = &fconfig->title; chunks = &fconfig->title_chunks; width = &fconfig->title_width; + default_hl_id = syn_check_group(S_LEN("FloatTitle")); break; case kBorderTextFooter: is_present = &fconfig->footer; chunks = &fconfig->footer_chunks; width = &fconfig->footer_width; + default_hl_id = syn_check_group(S_LEN("FloatFooter")); break; } @@ -446,9 +449,8 @@ static void parse_bordertext(Object bordertext, BorderTextType bordertext_type, *is_present = false; return; } - int hl_id = syn_check_group(S_LEN("FloatTitle")); kv_push(*chunks, ((VirtTextChunk){ .text = xstrdup(bordertext.data.string.data), - .hl_id = hl_id })); + .hl_id = default_hl_id })); *width = (int)mb_string2cells(bordertext.data.string.data); *is_present = true; return; -- cgit From 2e92065686f62851318150a315591c30b8306a4b Mon Sep 17 00:00:00 2001 From: Gregory Anders <8965202+gpanders@users.noreply.github.com> Date: Thu, 14 Sep 2023 08:23:01 -0500 Subject: docs: replace
 with ``` (#25136)

---
 src/nvim/api/win_config.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

(limited to 'src/nvim/api/win_config.c')

diff --git a/src/nvim/api/win_config.c b/src/nvim/api/win_config.c
index ac27554172..6a16d06fb7 100644
--- a/src/nvim/api/win_config.c
+++ b/src/nvim/api/win_config.c
@@ -56,16 +56,19 @@
 /// this should not be used to specify arbitrary WM screen positions.
 ///
 /// Example (Lua): window-relative float
-/// 
lua
-///     vim.api.nvim_open_win(0, false,
-///       {relative='win', row=3, col=3, width=12, height=3})
-/// 
+/// +/// ```lua +/// vim.api.nvim_open_win(0, false, +/// {relative='win', row=3, col=3, width=12, height=3}) +/// ``` /// /// Example (Lua): buffer-relative float (travels as buffer is scrolled) -///
lua
-///     vim.api.nvim_open_win(0, false,
-///       {relative='win', width=12, height=3, bufpos={100,10}})
-/// 
+/// +/// ```lua +/// vim.api.nvim_open_win(0, false, +/// {relative='win', width=12, height=3, bufpos={100,10}}) +/// }) +/// ``` /// /// @param buffer Buffer to display, or 0 for current buffer /// @param enter Enter the window (make it the current window) -- cgit From a916523574135549865d698732a6c9eaae7c7811 Mon Sep 17 00:00:00 2001 From: glepnir Date: Sun, 10 Sep 2023 15:09:20 +0800 Subject: fix(ui): doesn't trigger au event when enter is false --- src/nvim/api/win_config.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/nvim/api/win_config.c') diff --git a/src/nvim/api/win_config.c b/src/nvim/api/win_config.c index ac27554172..3a3e6da2b1 100644 --- a/src/nvim/api/win_config.c +++ b/src/nvim/api/win_config.c @@ -190,7 +190,8 @@ Window nvim_open_win(Buffer buffer, Boolean enter, Dict(float_config) *config, E } // autocmds in win_enter or win_set_buf below may close the window if (win_valid(wp) && buffer > 0) { - win_set_buf(wp, buf, fconfig.noautocmd, err); + Boolean noautocmd = !enter || fconfig.noautocmd; + win_set_buf(wp, buf, noautocmd, err); } if (!win_valid(wp)) { api_set_error(err, kErrorTypeException, "Window was closed immediately"); -- cgit From fd08fd3de3020647c8ae73f1c7d2cf9a4926c828 Mon Sep 17 00:00:00 2001 From: glepnir Date: Thu, 14 Sep 2023 13:30:51 +0800 Subject: fix(float): add fixd option --- src/nvim/api/win_config.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/nvim/api/win_config.c') diff --git a/src/nvim/api/win_config.c b/src/nvim/api/win_config.c index ac27554172..74c5228329 100644 --- a/src/nvim/api/win_config.c +++ b/src/nvim/api/win_config.c @@ -160,6 +160,8 @@ /// - noautocmd: If true then no buffer-related autocommand events such as /// |BufEnter|, |BufLeave| or |BufWinEnter| may fire from /// calling this function. +/// - fixed: If true when anchor is NW or SW, the float window +/// would be kept fixed even if the window would be truncated. /// /// @param[out] err Error details, if any /// @@ -841,6 +843,10 @@ static bool parse_float_config(Dict(float_config) *config, FloatConfig *fconfig, fconfig->noautocmd = config->noautocmd; } + if (HAS_KEY_X(config, fixed)) { + fconfig->fixed = config->fixed; + } + return true; #undef HAS_KEY_X } -- cgit From 8da986ea877b07a5eb117446f410f2a7fc8cd9cb Mon Sep 17 00:00:00 2001 From: bfredl Date: Wed, 13 Sep 2023 13:39:18 +0200 Subject: refactor(grid): change schar_T representation to be more compact Previously, a screen cell would occupy 28+4=32 bytes per cell as we always made space for up to MAX_MCO+1 codepoints in a cell. As an example, even a pretty modest 50*80 screen would consume 50*80*2*32 = 256000, i e a quarter megabyte With the factor of two due to the TUI side buffer, and even more when using msg_grid and/or ext_multigrid. This instead stores a 4-byte union of either: - a valid UTF-8 sequence up to 4 bytes - an escape char which is invalid UTF-8 (0xFF) plus a 24-bit index to a glyph cache This avoids allocating space for huge composed glyphs _upfront_, while still keeping rendering such glyphs reasonably fast (1 hash table lookup + one plain index lookup). If the same large glyphs are using repeatedly on the screen, this is still a net reduction of memory/cache consumption. The only case which really gets worse is if you blast the screen full with crazy emojis and zalgo text and even this case only leads to 4 extra bytes per char. When only <= 4-byte glyphs are used, plus the 4-byte attribute code, i e 8 bytes in total there is a factor of four reduction of memory use. Memory which will be quite hot in cache as the screen buffer is scanned over in win_line() buffer text drawing A slight complication is that the representation depends on host byte order. I've tested this manually by compling and running this in qemu-s390x and it works fine. We might add a qemu based solution to CI at some point. --- src/nvim/api/win_config.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim/api/win_config.c') diff --git a/src/nvim/api/win_config.c b/src/nvim/api/win_config.c index 63cf3bb701..a579b0dde5 100644 --- a/src/nvim/api/win_config.c +++ b/src/nvim/api/win_config.c @@ -16,7 +16,7 @@ #include "nvim/drawscreen.h" #include "nvim/extmark_defs.h" #include "nvim/globals.h" -#include "nvim/grid_defs.h" +#include "nvim/grid.h" #include "nvim/highlight_group.h" #include "nvim/macros.h" #include "nvim/mbyte.h" @@ -348,7 +348,7 @@ Dictionary nvim_win_get_config(Window window, Error *err) for (size_t i = 0; i < 8; i++) { Array tuple = ARRAY_DICT_INIT; - String s = cstrn_to_string(config->border_chars[i], sizeof(schar_T)); + String s = cstrn_to_string(config->border_chars[i], MAX_SCHAR_SIZE); int hi_id = config->border_hl_ids[i]; char *hi_name = syn_id2name(hi_id); @@ -520,7 +520,7 @@ static void parse_border_style(Object style, FloatConfig *fconfig, Error *err) { struct { const char *name; - schar_T chars[8]; + char chars[8][MAX_SCHAR_SIZE]; bool shadow_color; } defaults[] = { { "double", { "╔", "═", "╗", "║", "╝", "═", "╚", "║" }, false }, @@ -531,7 +531,7 @@ static void parse_border_style(Object style, FloatConfig *fconfig, Error *err) { NULL, { { NUL } }, false }, }; - schar_T *chars = fconfig->border_chars; + char (*chars)[MAX_SCHAR_SIZE] = fconfig->border_chars; int *hl_ids = fconfig->border_hl_ids; fconfig->border = true; -- cgit From 437ed3cee2d29a24d555a873d024cd851b953153 Mon Sep 17 00:00:00 2001 From: glepnir Date: Mon, 11 Sep 2023 19:46:15 +0800 Subject: fix(float): trigger winnew event when float window create --- src/nvim/api/win_config.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/nvim/api/win_config.c') diff --git a/src/nvim/api/win_config.c b/src/nvim/api/win_config.c index 63cf3bb701..35b9e73d81 100644 --- a/src/nvim/api/win_config.c +++ b/src/nvim/api/win_config.c @@ -195,6 +195,9 @@ Window nvim_open_win(Buffer buffer, Boolean enter, Dict(float_config) *config, E if (win_valid(wp) && buffer > 0) { Boolean noautocmd = !enter || fconfig.noautocmd; win_set_buf(wp, buf, noautocmd, err); + if (!fconfig.noautocmd) { + apply_autocmds(EVENT_WINNEW, NULL, NULL, false, buf); + } } if (!win_valid(wp)) { api_set_error(err, kErrorTypeException, "Window was closed immediately"); -- cgit From b7763d7f6b7fdcabe06658c664457df8bc147563 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 22 Sep 2023 17:56:05 +0800 Subject: fix(api): get virtual text with multiple hl properly (#25307) --- src/nvim/api/win_config.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) (limited to 'src/nvim/api/win_config.c') diff --git a/src/nvim/api/win_config.c b/src/nvim/api/win_config.c index ebdbd896a5..ea0b7ce512 100644 --- a/src/nvim/api/win_config.c +++ b/src/nvim/api/win_config.c @@ -259,34 +259,28 @@ void nvim_win_set_config(Window window, Dict(float_config) *config, Error *err) Dictionary config_put_bordertext(Dictionary config, FloatConfig *fconfig, BorderTextType bordertext_type) { - VirtText chunks; + VirtText vt; AlignTextPos align; char *field_name; char *field_pos_name; switch (bordertext_type) { case kBorderTextTitle: - chunks = fconfig->title_chunks; + vt = fconfig->title_chunks; align = fconfig->title_pos; field_name = "title"; field_pos_name = "title_pos"; break; case kBorderTextFooter: - chunks = fconfig->footer_chunks; + vt = fconfig->footer_chunks; align = fconfig->footer_pos; field_name = "footer"; field_pos_name = "footer_pos"; break; + default: + abort(); } - Array bordertext = ARRAY_DICT_INIT; - for (size_t i = 0; i < chunks.size; i++) { - Array tuple = ARRAY_DICT_INIT; - ADD(tuple, CSTR_TO_OBJ(chunks.items[i].text)); - if (chunks.items[i].hl_id > 0) { - ADD(tuple, CSTR_TO_OBJ(syn_id2name(chunks.items[i].hl_id))); - } - ADD(bordertext, ARRAY_OBJ(tuple)); - } + Array bordertext = virt_text_to_array(vt, true); PUT(config, field_name, ARRAY_OBJ(bordertext)); char *pos; -- cgit From cf8b2c0e74fd5e723b0c15c2ce84e6900fd322d3 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 30 Sep 2023 12:05:28 +0800 Subject: build(iwyu): add a few more _defs.h mappings (#25435) --- src/nvim/api/win_config.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/nvim/api/win_config.c') diff --git a/src/nvim/api/win_config.c b/src/nvim/api/win_config.c index ea0b7ce512..656f33aab1 100644 --- a/src/nvim/api/win_config.c +++ b/src/nvim/api/win_config.c @@ -2,15 +2,17 @@ // it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com #include +#include #include #include "klib/kvec.h" #include "nvim/api/extmark.h" +#include "nvim/api/keysets.h" #include "nvim/api/private/defs.h" -#include "nvim/api/private/dispatch.h" #include "nvim/api/private/helpers.h" #include "nvim/api/win_config.h" #include "nvim/ascii.h" +#include "nvim/autocmd.h" #include "nvim/buffer_defs.h" #include "nvim/decoration.h" #include "nvim/drawscreen.h" -- cgit From 4200a0f1678c06c6da4e4cfb0184c29c1174ed21 Mon Sep 17 00:00:00 2001 From: glepnir Date: Wed, 27 Sep 2023 17:23:42 +0800 Subject: feat(float): support toggle show float window --- src/nvim/api/win_config.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/nvim/api/win_config.c') diff --git a/src/nvim/api/win_config.c b/src/nvim/api/win_config.c index ea0b7ce512..60d32eb30d 100644 --- a/src/nvim/api/win_config.c +++ b/src/nvim/api/win_config.c @@ -165,6 +165,7 @@ /// calling this function. /// - fixed: If true when anchor is NW or SW, the float window /// would be kept fixed even if the window would be truncated. +/// - hide: If true the floating window will be hidden. /// /// @param[out] err Error details, if any /// @@ -323,6 +324,7 @@ Dictionary nvim_win_get_config(Window window, Error *err) PUT(rv, "focusable", BOOLEAN_OBJ(config->focusable)); PUT(rv, "external", BOOLEAN_OBJ(config->external)); + PUT(rv, "hide", BOOLEAN_OBJ(config->hide)); if (wp->w_floating) { PUT(rv, "width", INTEGER_OBJ(config->width)); @@ -848,6 +850,10 @@ static bool parse_float_config(Dict(float_config) *config, FloatConfig *fconfig, fconfig->fixed = config->fixed; } + if (HAS_KEY_X(config, hide)) { + fconfig->hide = config->hide; + } + return true; #undef HAS_KEY_X } -- cgit From 9ff6f73f838a1f90d09922448c434033ba5e094e Mon Sep 17 00:00:00 2001 From: Famiu Haque Date: Mon, 9 Oct 2023 00:36:48 +0600 Subject: refactor: allow not having a `default` case for enum Problem: The style guide states that all switch statements that are not conditional on an enum must have a `default` case, but does not give any explicit guideline for switch statements that are conditional on enums. As a result, a `default` case is added in many enum switch statements, even when the switch statement is exhaustive. This is not ideal because it removes the ability to have compiler errors to easily detect unchanged switch statements when a new possible value for an enum is added. Solution: Add explicit guidelines for switch statements that are conditional on an enum, clarifying that a `default` case is not necessary if the switch statement is exhaustive. Also refactor pre-existing code with unnecessary `default` cases. --- src/nvim/api/win_config.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/nvim/api/win_config.c') diff --git a/src/nvim/api/win_config.c b/src/nvim/api/win_config.c index ca7086ab7f..2fd30bc5a5 100644 --- a/src/nvim/api/win_config.c +++ b/src/nvim/api/win_config.c @@ -279,8 +279,6 @@ Dictionary config_put_bordertext(Dictionary config, FloatConfig *fconfig, field_name = "footer"; field_pos_name = "footer_pos"; break; - default: - abort(); } Array bordertext = virt_text_to_array(vt, true); -- cgit From 2dc9ceb99c018b15dcf0c443cad46efecccaf94e Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sun, 29 Oct 2023 09:02:32 +0100 Subject: docs: small fixes (#25585) Co-authored-by: tmummert Co-authored-by: parikshit adhikari --- src/nvim/api/win_config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/api/win_config.c') diff --git a/src/nvim/api/win_config.c b/src/nvim/api/win_config.c index 2fd30bc5a5..6f38989c96 100644 --- a/src/nvim/api/win_config.c +++ b/src/nvim/api/win_config.c @@ -135,7 +135,7 @@ /// - "solid": Adds padding by a single whitespace cell. /// - "shadow": A drop shadow effect by blending with the background. /// - If it is an array, it should have a length of eight or any divisor of -/// eight. The array will specifify the eight chars building up the border +/// eight. The array will specify the eight chars building up the border /// in a clockwise fashion starting with the top-left corner. As an /// example, the double box style could be specified as /// [ "╔", "═" ,"╗", "║", "╝", "═", "╚", "║" ]. -- cgit From 353a4be7e84fdc101318215bdcc8a7e780d737fe Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sun, 12 Nov 2023 13:13:58 +0100 Subject: build: remove PVS We already have an extensive suite of static analysis tools we use, which causes a fair bit of redundancy as we get duplicate warnings. PVS is also prone to give false warnings which creates a lot of work to identify and disable. --- src/nvim/api/win_config.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'src/nvim/api/win_config.c') diff --git a/src/nvim/api/win_config.c b/src/nvim/api/win_config.c index 6f38989c96..83c8ba832c 100644 --- a/src/nvim/api/win_config.c +++ b/src/nvim/api/win_config.c @@ -1,6 +1,3 @@ -// This is an open source non-commercial project. Dear PVS-Studio, please check -// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com - #include #include #include -- cgit From 326d46f690b383846f136f2a25523cffe2882f27 Mon Sep 17 00:00:00 2001 From: Raphael Date: Thu, 16 Nov 2023 09:54:47 +0800 Subject: refactor: move some functions to winfloat.c (#26020) --- src/nvim/api/win_config.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/api/win_config.c') diff --git a/src/nvim/api/win_config.c b/src/nvim/api/win_config.c index 83c8ba832c..0e6daf6b95 100644 --- a/src/nvim/api/win_config.c +++ b/src/nvim/api/win_config.c @@ -25,6 +25,7 @@ #include "nvim/syntax.h" #include "nvim/ui.h" #include "nvim/window.h" +#include "nvim/winfloat.h" #ifdef INCLUDE_GENERATED_DECLARATIONS # include "api/win_config.c.generated.h" -- cgit From bb4b4576e384c71890b4df4fa4f1ae76fad3a59d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 16 Nov 2023 10:55:54 +0800 Subject: refactor: iwyu (#26062) --- src/nvim/api/win_config.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/nvim/api/win_config.c') diff --git a/src/nvim/api/win_config.c b/src/nvim/api/win_config.c index 0e6daf6b95..4b16e26103 100644 --- a/src/nvim/api/win_config.c +++ b/src/nvim/api/win_config.c @@ -1,5 +1,4 @@ #include -#include #include #include "klib/kvec.h" -- cgit From a827003e3052c6d9ee7bdb71518182e9bd76317d Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sat, 25 Nov 2023 11:32:32 +0100 Subject: build: rework IWYU mapping files Create mapping to most of the C spec and some POSIX specific functions. This is more robust than relying files shipped with IWYU. --- src/nvim/api/win_config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/api/win_config.c') diff --git a/src/nvim/api/win_config.c b/src/nvim/api/win_config.c index 4b16e26103..a35ad57d8f 100644 --- a/src/nvim/api/win_config.c +++ b/src/nvim/api/win_config.c @@ -11,8 +11,8 @@ #include "nvim/autocmd.h" #include "nvim/buffer_defs.h" #include "nvim/decoration.h" +#include "nvim/decoration_defs.h" #include "nvim/drawscreen.h" -#include "nvim/extmark_defs.h" #include "nvim/globals.h" #include "nvim/grid.h" #include "nvim/highlight_group.h" -- cgit From 6361806aa28edca55ad3316a58bc3e936df9c0eb Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 26 Nov 2023 22:58:52 +0800 Subject: refactor: move garray_T to garray_defs.h (#26227) --- src/nvim/api/win_config.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/nvim/api/win_config.c') diff --git a/src/nvim/api/win_config.c b/src/nvim/api/win_config.c index a35ad57d8f..de26c1255c 100644 --- a/src/nvim/api/win_config.c +++ b/src/nvim/api/win_config.c @@ -11,7 +11,6 @@ #include "nvim/autocmd.h" #include "nvim/buffer_defs.h" #include "nvim/decoration.h" -#include "nvim/decoration_defs.h" #include "nvim/drawscreen.h" #include "nvim/globals.h" #include "nvim/grid.h" -- cgit From 574d25642fc9ca65b396633aeab6e2d32778b642 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 27 Nov 2023 17:21:58 +0800 Subject: refactor: move Arena and ArenaMem to memory_defs.h (#26240) --- src/nvim/api/win_config.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/api/win_config.c') diff --git a/src/nvim/api/win_config.c b/src/nvim/api/win_config.c index de26c1255c..8b9f73ae87 100644 --- a/src/nvim/api/win_config.c +++ b/src/nvim/api/win_config.c @@ -255,8 +255,8 @@ void nvim_win_set_config(Window window, Dict(float_config) *config, Error *err) } } -Dictionary config_put_bordertext(Dictionary config, FloatConfig *fconfig, - BorderTextType bordertext_type) +static Dictionary config_put_bordertext(Dictionary config, FloatConfig *fconfig, + BorderTextType bordertext_type) { VirtText vt; AlignTextPos align; -- cgit From 8b428ca8b79ebb7b36c3e403ff3bcb6924a635a6 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 27 Nov 2023 16:00:21 +0100 Subject: build(IWYU): fix includes for func_attr.h --- src/nvim/api/win_config.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/api/win_config.c') diff --git a/src/nvim/api/win_config.c b/src/nvim/api/win_config.c index 8b9f73ae87..72a1c952b0 100644 --- a/src/nvim/api/win_config.c +++ b/src/nvim/api/win_config.c @@ -12,6 +12,7 @@ #include "nvim/buffer_defs.h" #include "nvim/decoration.h" #include "nvim/drawscreen.h" +#include "nvim/func_attr.h" #include "nvim/globals.h" #include "nvim/grid.h" #include "nvim/highlight_group.h" -- cgit From f4aedbae4cb1f206f5b7c6142697b71dd473059b Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 27 Nov 2023 18:39:38 +0100 Subject: build(IWYU): fix includes for undo_defs.h --- src/nvim/api/win_config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/api/win_config.c') diff --git a/src/nvim/api/win_config.c b/src/nvim/api/win_config.c index 72a1c952b0..bec369b907 100644 --- a/src/nvim/api/win_config.c +++ b/src/nvim/api/win_config.c @@ -20,7 +20,7 @@ #include "nvim/mbyte.h" #include "nvim/memory.h" #include "nvim/option.h" -#include "nvim/pos.h" +#include "nvim/pos_defs.h" #include "nvim/syntax.h" #include "nvim/ui.h" #include "nvim/window.h" -- cgit From e38a05369293293b5b510b1b0014fcc2e7cb87f4 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 27 Nov 2023 18:46:03 +0100 Subject: build(IWYU): export generated headers --- src/nvim/api/win_config.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/api/win_config.c') diff --git a/src/nvim/api/win_config.c b/src/nvim/api/win_config.c index bec369b907..ee9e75f183 100644 --- a/src/nvim/api/win_config.c +++ b/src/nvim/api/win_config.c @@ -5,6 +5,7 @@ #include "nvim/api/extmark.h" #include "nvim/api/keysets.h" #include "nvim/api/private/defs.h" +#include "nvim/api/private/dispatch.h" #include "nvim/api/private/helpers.h" #include "nvim/api/win_config.h" #include "nvim/ascii.h" -- cgit From e3f735ef101d670555f44226614a5c3557053b1f Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 27 Nov 2023 20:13:32 +0100 Subject: refactor: fix includes for api/autocmd.h --- src/nvim/api/win_config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/api/win_config.c') diff --git a/src/nvim/api/win_config.c b/src/nvim/api/win_config.c index ee9e75f183..f980c277d1 100644 --- a/src/nvim/api/win_config.c +++ b/src/nvim/api/win_config.c @@ -3,7 +3,7 @@ #include "klib/kvec.h" #include "nvim/api/extmark.h" -#include "nvim/api/keysets.h" +#include "nvim/api/keysets_defs.h" #include "nvim/api/private/defs.h" #include "nvim/api/private/dispatch.h" #include "nvim/api/private/helpers.h" -- cgit From 79b6ff28ad1204fbb4199b9092f5c578d88cb28e Mon Sep 17 00:00:00 2001 From: dundargoc Date: Tue, 28 Nov 2023 20:31:00 +0100 Subject: refactor: fix headers with IWYU --- src/nvim/api/win_config.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/api/win_config.c') diff --git a/src/nvim/api/win_config.c b/src/nvim/api/win_config.c index f980c277d1..874be200ee 100644 --- a/src/nvim/api/win_config.c +++ b/src/nvim/api/win_config.c @@ -8,7 +8,7 @@ #include "nvim/api/private/dispatch.h" #include "nvim/api/private/helpers.h" #include "nvim/api/win_config.h" -#include "nvim/ascii.h" +#include "nvim/ascii_defs.h" #include "nvim/autocmd.h" #include "nvim/buffer_defs.h" #include "nvim/decoration.h" @@ -17,7 +17,7 @@ #include "nvim/globals.h" #include "nvim/grid.h" #include "nvim/highlight_group.h" -#include "nvim/macros.h" +#include "nvim/macros_defs.h" #include "nvim/mbyte.h" #include "nvim/memory.h" #include "nvim/option.h" -- cgit From 86cc791debba09c8ed1aa0d863be844108866a38 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 29 Nov 2023 23:10:21 +0800 Subject: refactor: move function macros out of vim_defs.h (#26300) --- src/nvim/api/win_config.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/api/win_config.c') diff --git a/src/nvim/api/win_config.c b/src/nvim/api/win_config.c index 874be200ee..4e23717dc6 100644 --- a/src/nvim/api/win_config.c +++ b/src/nvim/api/win_config.c @@ -22,6 +22,7 @@ #include "nvim/memory.h" #include "nvim/option.h" #include "nvim/pos_defs.h" +#include "nvim/strings.h" #include "nvim/syntax.h" #include "nvim/ui.h" #include "nvim/window.h" -- cgit