From 6cab36e5b7b0d741abe6c5a7c0e20bad30361034 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sat, 4 Mar 2023 13:10:00 +0100 Subject: refactor: replace char_u with char or uint8_t (#22400) Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/digraph.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/nvim/digraph.c') diff --git a/src/nvim/digraph.c b/src/nvim/digraph.c index a057978a5e..ae13164191 100644 --- a/src/nvim/digraph.c +++ b/src/nvim/digraph.c @@ -41,8 +41,8 @@ typedef int result_T; typedef struct digraph { - char_u char1; - char_u char2; + uint8_t char1; + uint8_t char2; result_T result; } digr_T; @@ -1493,7 +1493,7 @@ char *get_digraph_for_char(int val_arg) { const int val = val_arg; const digr_T *dp; - static char_u r[3]; + static char r[3]; for (int use_defaults = 0; use_defaults <= 1; use_defaults++) { if (use_defaults == 0) { @@ -1503,10 +1503,10 @@ char *get_digraph_for_char(int val_arg) } for (int i = 0; use_defaults ? dp->char1 != NUL : i < user_digraphs.ga_len; i++) { if (dp->result == val) { - r[0] = dp->char1; - r[1] = dp->char2; + r[0] = (char)dp->char1; + r[1] = (char)dp->char2; r[2] = NUL; - return (char *)r; + return r; } dp++; } @@ -1645,8 +1645,8 @@ static void registerdigraph(int char1, int char2, int n) // Add a new digraph to the table. dp = GA_APPEND_VIA_PTR(digr_T, &user_digraphs); - dp->char1 = (char_u)char1; - dp->char2 = (char_u)char2; + dp->char1 = (uint8_t)char1; + dp->char2 = (uint8_t)char2; dp->result = n; } -- cgit From d6ecead36406233cc56353dd05f3380f0497630f Mon Sep 17 00:00:00 2001 From: bfredl Date: Tue, 14 Mar 2023 11:49:46 +0100 Subject: refactor(screen): screen.c delenda est drawscreen.c vs screen.c makes absolutely no sense. The screen exists only to draw upon it, therefore helper functions are distributed randomly between screen.c and the file that does the redrawing. In addition screen.c does a lot of drawing on the screen. It made more sense for vim/vim as our grid.c is their screen.c Not sure if we want to dump all the code for option chars into optionstr.c, so keep these in a optionchar.c for now. --- src/nvim/digraph.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'src/nvim/digraph.c') diff --git a/src/nvim/digraph.c b/src/nvim/digraph.c index ae13164191..2066151564 100644 --- a/src/nvim/digraph.c +++ b/src/nvim/digraph.c @@ -15,6 +15,7 @@ #include "nvim/charset.h" #include "nvim/digraph.h" #include "nvim/drawscreen.h" +#include "nvim/eval.h" #include "nvim/eval/typval.h" #include "nvim/eval/typval_defs.h" #include "nvim/ex_cmds_defs.h" @@ -2180,3 +2181,42 @@ static void keymap_unload(void) curbuf->b_kmap_state &= ~KEYMAP_LOADED; status_redraw_curbuf(); } + +/// Get the value to show for the language mappings, active 'keymap'. +/// +/// @param fmt format string containing one %s item +/// @param buf buffer for the result +/// @param len length of buffer +bool get_keymap_str(win_T *wp, char *fmt, char *buf, int len) +{ + char *p; + + if (wp->w_buffer->b_p_iminsert != B_IMODE_LMAP) { + return false; + } + + buf_T *old_curbuf = curbuf; + win_T *old_curwin = curwin; + char *s; + + curbuf = wp->w_buffer; + curwin = wp; + STRCPY(buf, "b:keymap_name"); // must be writable + emsg_skip++; + s = p = eval_to_string(buf, NULL, false); + emsg_skip--; + curbuf = old_curbuf; + curwin = old_curwin; + if (p == NULL || *p == NUL) { + if (wp->w_buffer->b_kmap_state & KEYMAP_LOADED) { + p = wp->w_buffer->b_p_keymap; + } else { + p = "lang"; + } + } + if (vim_snprintf(buf, (size_t)len, fmt, p) > len - 1) { + buf[0] = NUL; + } + xfree(s); + return buf[0] != NUL; +} -- cgit From 371823d407d7d7519735131bcad4670c62a731a7 Mon Sep 17 00:00:00 2001 From: ii14 <59243201+ii14@users.noreply.github.com> Date: Wed, 5 Apr 2023 21:13:53 +0200 Subject: refactor: make error message definitions const message.c functions now take const char * as a format. Error message definitions can be made const. --- src/nvim/digraph.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/digraph.c') diff --git a/src/nvim/digraph.c b/src/nvim/digraph.c index 2066151564..7d6349e552 100644 --- a/src/nvim/digraph.c +++ b/src/nvim/digraph.c @@ -47,11 +47,11 @@ typedef struct digraph { result_T result; } digr_T; -static char e_digraph_must_be_just_two_characters_str[] +static const char e_digraph_must_be_just_two_characters_str[] = N_("E1214: Digraph must be just two characters: %s"); -static char e_digraph_argument_must_be_one_character_str[] +static const char e_digraph_argument_must_be_one_character_str[] = N_("E1215: Digraph must be one character: %s"); -static char e_digraph_setlist_argument_must_be_list_of_lists_with_two_items[] +static const char e_digraph_setlist_argument_must_be_list_of_lists_with_two_items[] = N_("E1216: digraph_setlist() argument must be a list of lists with two items"); #ifdef INCLUDE_GENERATED_DECLARATIONS -- cgit From 8e2903d2fe810cfa3be41fc1e7a4d8394c84cf11 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 14 Apr 2023 09:11:37 +0800 Subject: vim-patch:8.2.1049: Vim9: leaking memory when using continuation line Problem: Vim9: leaking memory when using continuation line. Solution: Keep a pointer to the continuation line in evalarg_T. Centralize checking for a next command. https://github.com/vim/vim/commit/b171fb179053fa631fec74911b5fb9374cb6a8a1 Omit eval_next_line(): Vim9 script only. vim-patch:8.2.1050: missing change in struct Problem: Missing change in struct. Solution: Add missing change. https://github.com/vim/vim/commit/65a8ed37f7bc61fbe5c612a7b0eb0dfc16ad3e11 Co-authored-by: Bram Moolenaar --- src/nvim/digraph.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/digraph.c') diff --git a/src/nvim/digraph.c b/src/nvim/digraph.c index 7d6349e552..de3808e4f5 100644 --- a/src/nvim/digraph.c +++ b/src/nvim/digraph.c @@ -2203,7 +2203,7 @@ bool get_keymap_str(win_T *wp, char *fmt, char *buf, int len) curwin = wp; STRCPY(buf, "b:keymap_name"); // must be writable emsg_skip++; - s = p = eval_to_string(buf, NULL, false); + s = p = eval_to_string(buf, false); emsg_skip--; curbuf = old_curbuf; curwin = old_curwin; -- cgit From 3b0df1780e2c8526bda5dead18ee7cc45925caba Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Wed, 26 Apr 2023 23:23:44 +0200 Subject: refactor: uncrustify Notable changes: replace all infinite loops to `while(true)` and remove `int` from `unsigned int`. --- src/nvim/digraph.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/digraph.c') diff --git a/src/nvim/digraph.c b/src/nvim/digraph.c index de3808e4f5..7a690d889f 100644 --- a/src/nvim/digraph.c +++ b/src/nvim/digraph.c @@ -2098,7 +2098,7 @@ void ex_loadkeymap(exarg_T *eap) p_cpo = "C"; // Get each line of the sourced file, break at the end. - for (;;) { + while (true) { char *line = eap->getline(0, eap->cookie, 0, true); if (line == NULL) { -- cgit From f91cd31d7d9d70006e0000592637d5d997eab52c Mon Sep 17 00:00:00 2001 From: bfredl Date: Wed, 27 Sep 2023 21:46:39 +0200 Subject: refactor(messages): fold msg_outtrans_attr into msg_outtrans problem: there are too many different functions in message.c solution: fold some of the functions into themselves --- src/nvim/digraph.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim/digraph.c') diff --git a/src/nvim/digraph.c b/src/nvim/digraph.c index 7a690d889f..69a4676148 100644 --- a/src/nvim/digraph.c +++ b/src/nvim/digraph.c @@ -1706,7 +1706,7 @@ static void digraph_header(const char *msg) if (msg_col > 0) { msg_putchar('\n'); } - msg_outtrans_attr(msg, HL_ATTR(HLF_CM)); + msg_outtrans(msg, HL_ATTR(HLF_CM)); msg_putchar('\n'); } @@ -1860,7 +1860,7 @@ static void printdigraph(const digr_T *dp, result_T *previous) *p++ = (char)dp->char2; *p++ = ' '; *p = NUL; - msg_outtrans(buf); + msg_outtrans(buf, 0); p = buf; // add a space to draw a composing char on @@ -1870,14 +1870,14 @@ static void printdigraph(const digr_T *dp, result_T *previous) p += utf_char2bytes(dp->result, p); *p = NUL; - msg_outtrans_attr(buf, HL_ATTR(HLF_8)); + msg_outtrans(buf, HL_ATTR(HLF_8)); p = buf; if (char2cells(dp->result) == 1) { *p++ = ' '; } assert(p >= buf); vim_snprintf(p, sizeof(buf) - (size_t)(p - buf), " %3d", dp->result); - msg_outtrans(buf); + msg_outtrans(buf, 0); } /// Get the two digraph characters from a typval. -- 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/digraph.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/nvim/digraph.c') diff --git a/src/nvim/digraph.c b/src/nvim/digraph.c index 69a4676148..49fc916f23 100644 --- a/src/nvim/digraph.c +++ b/src/nvim/digraph.c @@ -17,7 +17,6 @@ #include "nvim/drawscreen.h" #include "nvim/eval.h" #include "nvim/eval/typval.h" -#include "nvim/eval/typval_defs.h" #include "nvim/ex_cmds_defs.h" #include "nvim/ex_docmd.h" #include "nvim/ex_getln.h" -- cgit From dc6d0d2daf69e2fdadda81feb97906dbc962a239 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 30 Sep 2023 14:41:34 +0800 Subject: refactor: reorganize option header files (#25437) - Move vimoption_T to option.h - option_defs.h is for option-related types - option_vars.h corresponds to Vim's option.h - option_defs.h and option_vars.h don't include each other --- src/nvim/digraph.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/digraph.c') diff --git a/src/nvim/digraph.c b/src/nvim/digraph.c index 49fc916f23..1bcb21508b 100644 --- a/src/nvim/digraph.c +++ b/src/nvim/digraph.c @@ -31,7 +31,7 @@ #include "nvim/memory.h" #include "nvim/message.h" #include "nvim/normal.h" -#include "nvim/option_defs.h" +#include "nvim/option_vars.h" #include "nvim/os/input.h" #include "nvim/runtime.h" #include "nvim/strings.h" -- cgit From f4b896198fdd44f1994397a4e5d6475a2dcec05c Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Fri, 20 Oct 2023 12:18:17 +0200 Subject: vim-patch:9.0.2056: no digraph for quadruple prime Problem: no digraph for quadruple prime Solution: add quadruple prime digraph using 4' closes: vim/vim#13380 https://github.com/vim/vim/commit/47416d1a7441f8c815438903e78ba0a2d877699e Co-authored-by: Jonathan Wright --- src/nvim/digraph.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/digraph.c') diff --git a/src/nvim/digraph.c b/src/nvim/digraph.c index 1bcb21508b..5f0dfb381d 100644 --- a/src/nvim/digraph.c +++ b/src/nvim/digraph.c @@ -879,6 +879,7 @@ static digr_T digraphdefault[] = { '1', '\'', 0x2032 }, { '2', '\'', 0x2033 }, { '3', '\'', 0x2034 }, + { '4', '\'', 0x2057 }, { '1', '"', 0x2035 }, { '2', '"', 0x2036 }, { '3', '"', 0x2037 }, -- cgit From cd63a9addd6e1114c3524fa041ece560550cfe7b Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 10 Nov 2023 08:39:21 +0800 Subject: refactor: change some xstrndup() and xstrnsave() to xmemdupz() (#25959) When the given length is exactly the number of bytes to copy, xmemdupz() makes the intention clearer. --- src/nvim/digraph.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/digraph.c') diff --git a/src/nvim/digraph.c b/src/nvim/digraph.c index 5f0dfb381d..de76d55977 100644 --- a/src/nvim/digraph.c +++ b/src/nvim/digraph.c @@ -2110,10 +2110,10 @@ void ex_loadkeymap(exarg_T *eap) if ((*p != '"') && (*p != NUL)) { kmap_T *kp = GA_APPEND_VIA_PTR(kmap_T, &curbuf->b_kmap_ga); s = skiptowhite(p); - kp->from = xstrnsave(p, (size_t)(s - p)); + kp->from = xmemdupz(p, (size_t)(s - p)); p = skipwhite(s); s = skiptowhite(p); - kp->to = xstrnsave(p, (size_t)(s - p)); + kp->to = xmemdupz(p, (size_t)(s - p)); if ((strlen(kp->from) + strlen(kp->to) >= KMAP_LLEN) || (*kp->from == NUL) -- 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/digraph.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'src/nvim/digraph.c') diff --git a/src/nvim/digraph.c b/src/nvim/digraph.c index de76d55977..b29b5aed72 100644 --- a/src/nvim/digraph.c +++ b/src/nvim/digraph.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 - /// @file digraph.c /// /// code for digraphs @@ -1624,7 +1621,7 @@ int digraph_get(int char1, int char2, bool meta_char) if (((retval = getexactdigraph(char1, char2, meta_char)) == char2) && (char1 != char2) - && ((retval = getexactdigraph(char2, char1, meta_char)) // -V764 + && ((retval = getexactdigraph(char2, char1, meta_char)) == char1)) { return char2; } -- cgit From 28f4f3c48498086307ed825d1761edb5789ca0e8 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sun, 12 Nov 2023 15:54:54 +0100 Subject: refactor: follow style guide - reduce variable scope - prefer initialization over declaration and assignment - use bool to represent boolean values --- src/nvim/digraph.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/nvim/digraph.c') diff --git a/src/nvim/digraph.c b/src/nvim/digraph.c index b29b5aed72..bc0ce99c5e 100644 --- a/src/nvim/digraph.c +++ b/src/nvim/digraph.c @@ -2074,8 +2074,6 @@ char *keymap_init(void) /// @param eap void ex_loadkeymap(exarg_T *eap) { - char *s; - #define KMAP_LLEN 200 // max length of "to" and "from" together char buf[KMAP_LLEN + 11]; char *save_cpo = p_cpo; @@ -2106,7 +2104,7 @@ void ex_loadkeymap(exarg_T *eap) if ((*p != '"') && (*p != NUL)) { kmap_T *kp = GA_APPEND_VIA_PTR(kmap_T, &curbuf->b_kmap_ga); - s = skiptowhite(p); + char *s = skiptowhite(p); kp->from = xmemdupz(p, (size_t)(s - p)); p = skipwhite(s); s = skiptowhite(p); -- cgit From b522cb1ac3fbdf6e68eed5d0b6e1cbeaf3ac2254 Mon Sep 17 00:00:00 2001 From: bfredl Date: Mon, 6 Nov 2023 14:52:27 +0100 Subject: refactor(grid): make screen rendering more multibyte than ever before Problem: buffer text with composing chars are converted from UTF-8 to an array of up to seven UTF-32 values and then converted back to UTF-8 strings. Solution: Convert buffer text directly to UTF-8 based schar_T values. The limit of the text size is now in schar_T bytes, which is currently 31+1 but easily could be raised as it no longer multiplies the size of the entire screen grid when not used, the full size is only required for temporary scratch buffers. Also does some general cleanup to win_line text handling, which was unnecessarily complicated due to multibyte rendering being an "opt-in" feature long ago. Nowadays, a char is just a char, regardless if it consists of one ASCII byte or multiple bytes. --- src/nvim/digraph.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/digraph.c') diff --git a/src/nvim/digraph.c b/src/nvim/digraph.c index bc0ce99c5e..1bff78f90a 100644 --- a/src/nvim/digraph.c +++ b/src/nvim/digraph.c @@ -1654,7 +1654,7 @@ static void registerdigraph(int char1, int char2, int n) bool check_digraph_chars_valid(int char1, int char2) { if (char2 == 0) { - char msg[MB_MAXBYTES + 1]; + char msg[MB_MAXCHAR + 1]; msg[utf_char2bytes(char1, msg)] = NUL; semsg(_(e_digraph_must_be_just_two_characters_str), msg); return false; -- 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/digraph.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/digraph.c') diff --git a/src/nvim/digraph.c b/src/nvim/digraph.c index 1bff78f90a..65e410cca0 100644 --- a/src/nvim/digraph.c +++ b/src/nvim/digraph.c @@ -17,6 +17,7 @@ #include "nvim/ex_cmds_defs.h" #include "nvim/ex_docmd.h" #include "nvim/ex_getln.h" +#include "nvim/func_attr.h" #include "nvim/garray.h" #include "nvim/getchar.h" #include "nvim/gettext.h" -- cgit From 6c14ae6bfaf51415b555e9a6b85d1d280976358d Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 27 Nov 2023 20:27:32 +0100 Subject: refactor: rename types.h to types_defs.h --- src/nvim/digraph.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/digraph.c') diff --git a/src/nvim/digraph.c b/src/nvim/digraph.c index 65e410cca0..a45417ca1e 100644 --- a/src/nvim/digraph.c +++ b/src/nvim/digraph.c @@ -33,7 +33,7 @@ #include "nvim/os/input.h" #include "nvim/runtime.h" #include "nvim/strings.h" -#include "nvim/types.h" +#include "nvim/types_defs.h" #include "nvim/vim.h" typedef int result_T; -- 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/digraph.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/digraph.c') diff --git a/src/nvim/digraph.c b/src/nvim/digraph.c index a45417ca1e..647ab26441 100644 --- a/src/nvim/digraph.c +++ b/src/nvim/digraph.c @@ -7,7 +7,7 @@ #include #include -#include "nvim/ascii.h" +#include "nvim/ascii_defs.h" #include "nvim/buffer_defs.h" #include "nvim/charset.h" #include "nvim/digraph.h" @@ -34,7 +34,7 @@ #include "nvim/runtime.h" #include "nvim/strings.h" #include "nvim/types_defs.h" -#include "nvim/vim.h" +#include "nvim/vim_defs.h" typedef int result_T; -- cgit From a6cba103cebce535279db197f9efeb34e9d1171f Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 29 Nov 2023 20:32:40 +0800 Subject: refactor: move some constants out of vim_defs.h (#26298) --- src/nvim/digraph.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/nvim/digraph.c') diff --git a/src/nvim/digraph.c b/src/nvim/digraph.c index 647ab26441..99d5cf1035 100644 --- a/src/nvim/digraph.c +++ b/src/nvim/digraph.c @@ -22,7 +22,7 @@ #include "nvim/getchar.h" #include "nvim/gettext.h" #include "nvim/globals.h" -#include "nvim/highlight_defs.h" +#include "nvim/highlight.h" #include "nvim/keycodes.h" #include "nvim/mapping.h" #include "nvim/mbyte.h" @@ -32,6 +32,7 @@ #include "nvim/option_vars.h" #include "nvim/os/input.h" #include "nvim/runtime.h" +#include "nvim/state_defs.h" #include "nvim/strings.h" #include "nvim/types_defs.h" #include "nvim/vim_defs.h" -- cgit