From 543e0256c19f397921a332e06b423215fd9aecb5 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 30 Nov 2023 15:51:05 +0800 Subject: build: don't define FUNC_ATTR_* as empty in headers (#26317) FUNC_ATTR_* should only be used in .c files with generated headers. Defining FUNC_ATTR_* as empty in headers causes misuses of them to be silently ignored. Instead don't define them by default, and only define them as empty after a .c file has included its generated header. --- src/nvim/keycodes.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/nvim/keycodes.c') diff --git a/src/nvim/keycodes.c b/src/nvim/keycodes.c index 745500fe39..49ec245359 100644 --- a/src/nvim/keycodes.c +++ b/src/nvim/keycodes.c @@ -10,7 +10,6 @@ #include "nvim/charset.h" #include "nvim/eval/typval_defs.h" #include "nvim/eval/vars.h" -#include "nvim/func_attr.h" #include "nvim/gettext.h" #include "nvim/globals.h" #include "nvim/keycodes.h" -- cgit From 6cb78e2d1c4c6c63c628c965076a07ce5f7adbb6 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sat, 16 Dec 2023 22:14:28 +0100 Subject: docs: add style rule regarding initialization Specifically, specify that each initialization should be done on a separate line. --- src/nvim/keycodes.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/nvim/keycodes.c') diff --git a/src/nvim/keycodes.c b/src/nvim/keycodes.c index 49ec245359..f8475b3e22 100644 --- a/src/nvim/keycodes.c +++ b/src/nvim/keycodes.c @@ -1058,7 +1058,8 @@ char *vim_strsave_escape_ks(char *p) /// vim_strsave_escape_ks(). Works in-place. void vim_unescape_ks(char *p) { - uint8_t *s = (uint8_t *)p, *d = (uint8_t *)p; + uint8_t *s = (uint8_t *)p; + uint8_t *d = (uint8_t *)p; while (*s != NUL) { if (s[0] == K_SPECIAL && s[1] == KS_SPECIAL && s[2] == KE_FILLER) { -- cgit From af93a74a0f4afa9a3a4f55ffdf28141eaf776d22 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 18 Dec 2023 10:55:23 +0100 Subject: refactor: run IWYU on entire repo Reference: https://github.com/neovim/neovim/issues/6371. --- src/nvim/keycodes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/keycodes.c') diff --git a/src/nvim/keycodes.c b/src/nvim/keycodes.c index f8475b3e22..301c3846e7 100644 --- a/src/nvim/keycodes.c +++ b/src/nvim/keycodes.c @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include "nvim/ascii_defs.h" #include "nvim/charset.h" -- cgit From c16d5729b52d2f878cd035341b951b1f185b45c9 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 23 Dec 2023 15:53:28 +0800 Subject: refactor: remove CPO_TO_CPO_FLAGS() (#26718) Just pass p_cpo to replace_termcodes() directly. This allows removing option_vars.h from keycodes.h, and also avoids the mistake of passing 0 as cpo_flags. --- src/nvim/keycodes.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src/nvim/keycodes.c') diff --git a/src/nvim/keycodes.c b/src/nvim/keycodes.c index 301c3846e7..d913beeb0c 100644 --- a/src/nvim/keycodes.c +++ b/src/nvim/keycodes.c @@ -852,8 +852,8 @@ int get_mouse_button(int code, bool *is_click, bool *is_drag) /// K_SPECIAL by itself is replaced by K_SPECIAL KS_SPECIAL KE_FILLER. /// /// When "flags" has REPTERM_FROM_PART, trailing is included, otherwise it is removed (to make -/// ":map xx ^V" map xx to nothing). When cpo_flags contains FLAG_CPO_BSLASH, a backslash can be -/// used in place of . All other characters are removed. +/// ":map xx ^V" map xx to nothing). When cpo_val contains CPO_BSLASH, a backslash can be used in +/// place of . All other characters are removed. /// /// @param[in] from What characters to replace. /// @param[in] from_len Length of the "from" argument. @@ -867,20 +867,21 @@ int get_mouse_button(int code, bool *is_click, bool *is_drag) /// REPTERM_NO_SPECIAL do not accept notation /// REPTERM_NO_SIMPLIFY do not simplify into 0x08, etc. /// @param[out] did_simplify set when some code was simplified, unless it is NULL. -/// @param[in] cpo_flags Relevant flags derived from p_cpo, see CPO_TO_CPO_FLAGS. +/// @param[in] cpo_val The value of 'cpoptions' to use. Only CPO_BSLASH matters. /// /// @return The same as what `*bufp` is set to. char *replace_termcodes(const char *const from, const size_t from_len, char **const bufp, const scid_T sid_arg, const int flags, bool *const did_simplify, - const int cpo_flags) - FUNC_ATTR_NONNULL_ARG(1, 3) + const char *const cpo_val) + FUNC_ATTR_NONNULL_ARG(1, 3, 7) { char key; size_t dlen = 0; const char *src; const char *const end = from + from_len - 1; - const bool do_backslash = !(cpo_flags & FLAG_CPO_BSLASH); // backslash is a special character + // backslash is a special character + const bool do_backslash = (vim_strchr(cpo_val, CPO_BSLASH) == NULL); const bool do_special = !(flags & REPTERM_NO_SPECIAL); bool allocated = (*bufp == NULL); -- cgit From ab2aad509d6e4fc57a6afe056275405ec6451671 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Wed, 20 Dec 2023 17:22:19 +0100 Subject: refactor: follow style guide --- src/nvim/keycodes.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src/nvim/keycodes.c') diff --git a/src/nvim/keycodes.c b/src/nvim/keycodes.c index d913beeb0c..dd7a917380 100644 --- a/src/nvim/keycodes.c +++ b/src/nvim/keycodes.c @@ -875,9 +875,7 @@ char *replace_termcodes(const char *const from, const size_t from_len, char **co const char *const cpo_val) FUNC_ATTR_NONNULL_ARG(1, 3, 7) { - char key; size_t dlen = 0; - const char *src; const char *const end = from + from_len - 1; // backslash is a special character @@ -891,7 +889,7 @@ char *replace_termcodes(const char *const from, const size_t from_len, char **co const size_t buf_len = allocated ? from_len * 6 + 1 : 128; char *result = allocated ? xmalloc(buf_len) : *bufp; // buffer for resulting string - src = from; + const char *src = from; // Copy each byte from *from to result[dlen] while (src <= end) { @@ -966,7 +964,7 @@ char *replace_termcodes(const char *const from, const size_t from_len, char **co // For "from" side the CTRL-V at the end is included, for the "to" // part it is removed. // If 'cpoptions' does not contain 'B', also accept a backslash. - key = *src; + char key = *src; if (key == Ctrl_V || (do_backslash && key == '\\')) { src++; // skip CTRL-V or backslash if (src > end) { -- cgit From 1813661a6197c76ea6621284570aca1d56597099 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Thu, 4 Jan 2024 15:38:16 +0100 Subject: refactor(IWYU): fix headers Remove `export` pramgas from defs headers as it causes IWYU to believe that the definitions from the defs headers comes from main header, which is not what we really want. --- src/nvim/keycodes.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/nvim/keycodes.c') diff --git a/src/nvim/keycodes.c b/src/nvim/keycodes.c index dd7a917380..c45ad83204 100644 --- a/src/nvim/keycodes.c +++ b/src/nvim/keycodes.c @@ -10,14 +10,16 @@ #include "nvim/charset.h" #include "nvim/eval/typval_defs.h" #include "nvim/eval/vars.h" -#include "nvim/gettext.h" +#include "nvim/gettext_defs.h" #include "nvim/globals.h" #include "nvim/keycodes.h" #include "nvim/macros_defs.h" #include "nvim/mbyte.h" +#include "nvim/mbyte_defs.h" #include "nvim/memory.h" #include "nvim/message.h" #include "nvim/mouse.h" +#include "nvim/option_vars.h" #include "nvim/strings.h" #ifdef INCLUDE_GENERATED_DECLARATIONS -- cgit From 6709f7f8f130377f44c36b2150a167a2afcbdff9 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 3 Feb 2024 11:05:38 +0800 Subject: fix(keycodes): simplify S- properly when D- is present (#27316) --- src/nvim/keycodes.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/nvim/keycodes.c') diff --git a/src/nvim/keycodes.c b/src/nvim/keycodes.c index c45ad83204..c910d0955a 100644 --- a/src/nvim/keycodes.c +++ b/src/nvim/keycodes.c @@ -758,17 +758,20 @@ static int extract_modifiers(int key, int *modp, const bool simplify, bool *cons { int modifiers = *modp; - // Command-key and ctrl are special - if (!(modifiers & MOD_MASK_CMD) && !(modifiers & MOD_MASK_CTRL)) { - if ((modifiers & MOD_MASK_SHIFT) && ASCII_ISALPHA(key)) { - key = TOUPPER_ASC(key); + if ((modifiers & MOD_MASK_SHIFT) && ASCII_ISALPHA(key)) { + key = TOUPPER_ASC(key); + // With we keep the shift modifier. + // With , and we don't keep the shift modifier. + if (!(modifiers & MOD_MASK_CTRL)) { modifiers &= ~MOD_MASK_SHIFT; } } + // and mean the same thing, always use "H" if ((modifiers & MOD_MASK_CTRL) && ASCII_ISALPHA(key)) { key = TOUPPER_ASC(key); } + if (simplify && (modifiers & MOD_MASK_CTRL) && ((key >= '?' && key <= '_') || ASCII_ISALPHA(key))) { key = CTRL_CHR(key); -- cgit From 60701f4fff8a45956f74df429b4361447ffe7f3d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 4 Feb 2024 06:42:47 +0800 Subject: vim-patch:9.1.0073: Looping over modifier_keys_table unnecessarily Problem: Looping over modifier_keys_table[] unnecessarily with only MOD_MASK_ALT or MOD_MASK_CMD, as modifier_keys_table[] only contains MOD_MASK_SHIFT and MOD_MASK_CTRL, and the loop won't do anything. Solution: Remove MOD_MASK_ALT and MOD_MASK_CMD from the condition. (zeertzjq) closes: vim/vim#13963 https://github.com/vim/vim/commit/0c989e4a3ae50085aa8c6bed5d6701760191bc1d --- src/nvim/keycodes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/keycodes.c') diff --git a/src/nvim/keycodes.c b/src/nvim/keycodes.c index c910d0955a..44ddfbba00 100644 --- a/src/nvim/keycodes.c +++ b/src/nvim/keycodes.c @@ -400,7 +400,7 @@ int name_to_mod_mask(int c) int simplify_key(const int key, int *modifiers) FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL { - if (!(*modifiers & (MOD_MASK_SHIFT | MOD_MASK_CTRL | MOD_MASK_ALT))) { + if (!(*modifiers & (MOD_MASK_SHIFT | MOD_MASK_CTRL))) { return key; } -- cgit