From c94d8e7f13bbe6aa0d195eeac115695e0d95e7f3 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 26 Jan 2023 07:31:32 +0800 Subject: vim-patch:9.0.1244: cursor displayed in wrong position when leaving Insert mode (#21996) Problem: Cursor briefly displayed in a wrong position when pressing Esc in Insert mode after autoindent was used. Solution: Do not adjust the cursor position for assumed deleted white space if text is following. (closes vim/vim#11877) https://github.com/vim/vim/commit/0f843ef091eceb470caece1d90fdfe08926fe076 Co-authored-by: Bram Moolenaar --- src/nvim/getchar.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/nvim/getchar.c') diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 9c5364e1b1..51554fea22 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -2526,10 +2526,12 @@ static int vgetorpeek(bool advance) // move cursor left, if possible if (curwin->w_cursor.col != 0) { if (curwin->w_wcol > 0) { - if (did_ai) { - // We are expecting to truncate the trailing - // white-space, so find the last non-white - // character -- webb + // After auto-indenting and no text is following, + // we are expecting to truncate the trailing + // white-space, so find the last non-white + // character -- webb + if (did_ai + && *skipwhite(get_cursor_line_ptr() + curwin->w_cursor.col) == NUL) { curwin->w_wcol = 0; ptr = (char_u *)get_cursor_line_ptr(); chartabsize_T cts; -- cgit From 01d3a64e284749ac1ae40b0caf7165155063fc4f Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 1 Feb 2023 18:07:09 +0800 Subject: vim-patch:8.1.1827: allocating more memory than needed for extended structs (#22081) Problem: Allocating more memory than needed for extended structs. Solution: Use offsetof() instead of sizeof(). (Dominique Pelle, closes vim/vim#4786) https://github.com/vim/vim/commit/47ed553fd5bebfc36eb8aa81686eeaa5a84eccac --- src/nvim/getchar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/getchar.c') diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 51554fea22..8ed9381bca 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -252,7 +252,7 @@ static void add_buff(buffheader_T *const buf, const char *const s, ptrdiff_t sle } else { len = (size_t)slen; } - buffblock_T *p = xmalloc(sizeof(buffblock_T) + len); + buffblock_T *p = xmalloc(offsetof(buffblock_T, b_str) + len + 1); buf->bh_space = len - (size_t)slen; xstrlcpy(p->b_str, s, (size_t)slen + 1); -- cgit From 30b29a36e80bfeed50bb6ea618401fe35100490f Mon Sep 17 00:00:00 2001 From: bfredl Date: Thu, 9 Feb 2023 20:56:30 +0100 Subject: refactor(ui): remove some superfluous ui_flush() calls - mapping has no business saving and restoring the low-level UI cursor. The cursor will be put in a reasonable position after input is processed, chill out. - TUI handles output needed for suspend - vgetc() family of function does flushing --- src/nvim/getchar.c | 45 +++++++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 24 deletions(-) (limited to 'src/nvim/getchar.c') diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 8ed9381bca..f5728d29c1 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -2218,9 +2218,6 @@ static int handle_mapping(int *keylenp, const bool *timedout, int *mapdepth) if (mp->m_expr) { const int save_vgetc_busy = vgetc_busy; const bool save_may_garbage_collect = may_garbage_collect; - const int save_cursor_row = ui_current_row(); - const int save_cursor_col = ui_current_col(); - const handle_T save_cursor_grid = ui_cursor_grid(); const int prev_did_emsg = did_emsg; vgetc_busy = 0; @@ -2232,28 +2229,28 @@ static int handle_mapping(int *keylenp, const bool *timedout, int *mapdepth) } map_str = eval_map_expr(mp, NUL); - // The mapping may do anything, but we expect it to take care of - // redrawing. Do put the cursor back where it was. - ui_grid_cursor_goto(save_cursor_grid, save_cursor_row, save_cursor_col); - ui_flush(); - - // If an error was displayed and the expression returns an empty - // string, generate a to allow for a redraw. - if (prev_did_emsg != did_emsg && (map_str == NULL || *map_str == NUL)) { - char buf[4]; - xfree(map_str); - buf[0] = (char)K_SPECIAL; - buf[1] = (char)KS_EXTRA; - buf[2] = KE_IGNORE; - buf[3] = NUL; - map_str = xstrdup(buf); - if (State & MODE_CMDLINE) { - // redraw the command below the error - msg_didout = true; - if (msg_row < cmdline_row) { - msg_row = cmdline_row; + if ((map_str == NULL || *map_str == NUL)) { + // If an error was displayed and the expression returns an empty + // string, generate a to allow for a redraw. + if (prev_did_emsg != did_emsg) { + char buf[4]; + xfree(map_str); + buf[0] = (char)K_SPECIAL; + buf[1] = (char)KS_EXTRA; + buf[2] = KE_IGNORE; + buf[3] = NUL; + map_str = xstrdup(buf); + if (State & MODE_CMDLINE) { + // redraw the command below the error + msg_didout = true; + if (msg_row < cmdline_row) { + msg_row = cmdline_row; + } + redrawcmd(); } - redrawcmd(); + } else if (State & (MODE_NORMAL | MODE_INSERT)) { + // otherwise, just put back the cursor + setcursor(); } } -- cgit From c8c930ea785aa393ebc819139913a9e05f0ccd45 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sat, 11 Feb 2023 10:24:46 +0100 Subject: refactor: reduce scope of locals as per the style guide (#22206) --- src/nvim/getchar.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) (limited to 'src/nvim/getchar.c') diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index f5728d29c1..ca00c5b449 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -155,7 +155,6 @@ static char *get_buffcont(buffheader_T *buffer, int dozero) { size_t count = 0; char *p = NULL; - char *p2; // compute the total length of the string for (const buffblock_T *bp = buffer->bh_first.b_next; @@ -165,7 +164,7 @@ static char *get_buffcont(buffheader_T *buffer, int dozero) if (count || dozero) { p = xmalloc(count + 1); - p2 = p; + char *p2 = p; for (const buffblock_T *bp = buffer->bh_first.b_next; bp != NULL; bp = bp->b_next) { for (const char *str = bp->b_str; *str;) { @@ -1020,8 +1019,6 @@ int typebuf_maplen(void) // remove "len" characters from typebuf.tb_buf[typebuf.tb_off + offset] void del_typebuf(int len, int offset) { - int i; - if (len == 0) { return; // nothing to do } @@ -1034,7 +1031,7 @@ void del_typebuf(int len, int offset) typebuf.tb_off += len; } else { // Have to move the characters in typebuf.tb_buf[] and typebuf.tb_noremap[] - i = typebuf.tb_off + offset; + int i = typebuf.tb_off + offset; // Leave some extra room at the end to avoid reallocation. if (typebuf.tb_off > MAXMAPLEN) { memmove(typebuf.tb_buf + MAXMAPLEN, @@ -1408,10 +1405,8 @@ int merge_modifiers(int c_arg, int *modifiers) /// Returns the modifiers in the global "mod_mask". int vgetc(void) { - int c, c2; - int n; + int c; char_u buf[MB_MAXBYTES + 1]; - int i; // Do garbage collection when garbagecollect() was called previously and // we are now at the toplevel. @@ -1429,6 +1424,9 @@ int vgetc(void) mouse_row = old_mouse_row; mouse_col = old_mouse_col; } else { + int c2; + int n; + int i; // number of characters recorded from the last vgetc() call static size_t last_vgetc_recorded_len = 0; @@ -1754,9 +1752,9 @@ static void getchar_common(typval_T *argvars, typval_T *rettv) int grid = mouse_grid; linenr_T lnum; win_T *wp; - int winnr = 1; if (row >= 0 && col >= 0) { + int winnr = 1; // Find the window at the mouse coordinates and compute the // text position. win_T *const win = mouse_find_win(&grid, &row, &col); @@ -1921,9 +1919,7 @@ static int handle_mapping(int *keylenp, const bool *timedout, int *mapdepth) int max_mlen = 0; int tb_c1; int mlen; - int nolmaplen; int keylen = *keylenp; - int i; int local_State = get_real_state(); bool is_plug_map = false; @@ -1956,6 +1952,7 @@ static int handle_mapping(int *keylenp, const bool *timedout, int *mapdepth) && State != MODE_ASKMORE && State != MODE_CONFIRM && !at_ins_compl_key()) { + int nolmaplen; if (tb_c1 == K_SPECIAL) { nolmaplen = 2; } else { @@ -2168,6 +2165,7 @@ static int handle_mapping(int *keylenp, const bool *timedout, int *mapdepth) // complete match if (keylen >= 0 && keylen <= typebuf.tb_len) { + int i; char *map_str = NULL; // Write chars to script file(s). @@ -2509,9 +2507,6 @@ static int vgetorpeek(bool advance) && (State & MODE_INSERT) && (p_timeout || (keylen == KEYLEN_PART_KEY && p_ttimeout)) && (c = inchar(typebuf.tb_buf + typebuf.tb_off + typebuf.tb_len, 3, 25L)) == 0) { - colnr_T col = 0; - char_u *ptr; - if (mode_displayed) { unshowmode(true); mode_deleted = true; @@ -2522,6 +2517,8 @@ static int vgetorpeek(bool advance) // move cursor left, if possible if (curwin->w_cursor.col != 0) { + colnr_T col = 0; + char_u *ptr; if (curwin->w_wcol > 0) { // After auto-indenting and no text is following, // we are expecting to truncate the trailing -- cgit From 7224c889e0d5d70b99ae377036baa6377c33a568 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sat, 11 Feb 2023 10:25:24 +0100 Subject: build: enable MSVC level 3 warnings (#21934) MSVC has 4 different warning levels: 1 (severe), 2 (significant), 3 (production quality) and 4 (informational). Enabling level 3 warnings mostly revealed conversion problems, similar to GCC/clang -Wconversion flag. --- src/nvim/getchar.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/getchar.c') diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index ca00c5b449..387139fd29 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -582,7 +582,7 @@ void stuffRedoReadbuff(const char *s) add_buff(&readbuf2, s, -1L); } -void stuffReadbuffLen(const char *s, long len) +void stuffReadbuffLen(const char *s, ptrdiff_t len) { add_buff(&readbuf1, s, len); } @@ -634,7 +634,7 @@ void stuffescaped(const char *arg, bool literally) arg++; } if (arg > start) { - stuffReadbuffLen(start, (arg - start)); + stuffReadbuffLen(start, arg - start); } // stuff a single special character -- cgit From 4be6c6cf0ddf5e31d4103cb5df06651ba6f4897b Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sat, 11 Feb 2023 11:05:57 +0100 Subject: refactor: replace char_u with char (#21901) refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/getchar.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/nvim/getchar.c') diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 387139fd29..b54ecdb6ab 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -179,7 +179,7 @@ static char *get_buffcont(buffheader_T *buffer, int dozero) /// Return the contents of the record buffer as a single string /// and clear the record buffer. /// K_SPECIAL in the returned string is escaped. -char_u *get_recorded(void) +char *get_recorded(void) { char *p; size_t len; @@ -201,7 +201,7 @@ char_u *get_recorded(void) p[len - 1] = NUL; } - return (char_u *)p; + return p; } /// Return the contents of the redo buffer as a single string. @@ -978,7 +978,7 @@ int ins_typebuf(char *str, int noremap, int offset, bool nottyped, bool silent) int ins_char_typebuf(int c, int modifiers) { char_u buf[MB_MAXBYTES * 3 + 4]; - unsigned int len = special_to_buf(c, modifiers, true, buf); + unsigned int len = special_to_buf(c, modifiers, true, (char *)buf); assert(len < sizeof(buf)); buf[len] = NUL; (void)ins_typebuf((char *)buf, KeyNoremap, 0, !KeyTyped, cmd_silent); @@ -2197,7 +2197,7 @@ static int handle_mapping(int *keylenp, const bool *timedout, int *mapdepth) // mode temporarily. Append K_SELECT to switch back to Select mode. if (VIsual_active && VIsual_select && (mp->m_mode & MODE_VISUAL)) { VIsual_select = false; - (void)ins_typebuf((char *)K_SELECT_STRING, REMAP_NONE, 0, true, false); + (void)ins_typebuf(K_SELECT_STRING, REMAP_NONE, 0, true, false); } // Copy the values from *mp that are used, because evaluating the @@ -2887,13 +2887,13 @@ int inchar(char_u *buf, int maxlen, long wait_time) typebuf.tb_change_cnt = 1; } - return fix_input_buffer(buf, len); + return fix_input_buffer((char *)buf, len); } // Fix typed characters for use by vgetc() and check_termcode(). // "buf[]" must have room to triple the number of bytes! // Returns the new length. -int fix_input_buffer(char_u *buf, int len) +int fix_input_buffer(char *buf, int len) FUNC_ATTR_NONNULL_ALL { if (!using_script()) { @@ -2905,7 +2905,7 @@ int fix_input_buffer(char_u *buf, int len) // Reading from script, need to process special bytes int i; - char_u *p = buf; + char_u *p = (char_u *)buf; // Two characters are special: NUL and K_SPECIAL. // Replace NUL by K_SPECIAL KS_ZERO KE_FILLER -- cgit From 5f72ab77bff1f1224be5cbbf9423bdddbc25635c Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sun, 12 Feb 2023 18:48:49 +0100 Subject: refactor: reduce scope of locals as per the style guide 3 (#22221) refactor: reduce scope of locals as per the style guide --- src/nvim/getchar.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'src/nvim/getchar.c') diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index b54ecdb6ab..37840f8875 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -661,7 +661,6 @@ static int read_redo(bool init, bool old_redo) int c; int n; char_u buf[MB_MAXBYTES + 1]; - int i; if (init) { bp = old_redo ? old_redobuff.bh_first.b_next : redobuff.bh_first.b_next; @@ -682,7 +681,7 @@ static int read_redo(bool init, bool old_redo) } else { n = 1; } - for (i = 0;; i++) { + for (int i = 0;; i++) { if (c == K_SPECIAL) { // special key or escaped K_SPECIAL c = TO_SPECIAL(p[1], p[2]); p += 2; @@ -857,7 +856,6 @@ int ins_typebuf(char *str, int noremap, int offset, bool nottyped, bool silent) { char_u *s1, *s2; int addlen; - int i; int val; int nrm; @@ -947,7 +945,7 @@ int ins_typebuf(char *str, int noremap, int offset, bool nottyped, bool silent) } else { nrm = noremap; } - for (i = 0; i < addlen; i++) { + for (int i = 0; i < addlen; i++) { typebuf.tb_noremap[typebuf.tb_off + i + offset] = (uint8_t)((--nrm >= 0) ? val : RM_YES); } @@ -1426,7 +1424,6 @@ int vgetc(void) } else { int c2; int n; - int i; // number of characters recorded from the last vgetc() call static size_t last_vgetc_recorded_len = 0; @@ -1552,7 +1549,7 @@ int vgetc(void) if ((n = MB_BYTE2LEN_CHECK(c)) > 1) { no_mapping++; buf[0] = (char_u)c; - for (i = 1; i < n; i++) { + for (int i = 1; i < n; i++) { buf[i] = (char_u)vgetorpeek(true); if (buf[i] == K_SPECIAL) { // Must be a K_SPECIAL - KS_SPECIAL - KE_FILLER sequence, @@ -2904,13 +2901,12 @@ int fix_input_buffer(char *buf, int len) } // Reading from script, need to process special bytes - int i; char_u *p = (char_u *)buf; // Two characters are special: NUL and K_SPECIAL. // Replace NUL by K_SPECIAL KS_ZERO KE_FILLER // Replace K_SPECIAL by K_SPECIAL KS_SPECIAL KE_FILLER - for (i = len; --i >= 0; p++) { + for (int i = len; --i >= 0; p++) { if (p[0] == NUL || (p[0] == K_SPECIAL && (i < 2 || p[1] != KS_EXTRA))) { -- cgit From f113cba3ec127201f54094f9174b50ee3001fbee Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 28 Feb 2023 08:49:02 +0800 Subject: refactor(getchar.c): change most char_u to uint8_t (#22444) --- src/nvim/getchar.c | 97 ++++++++++++++++++++++++++---------------------------- 1 file changed, 47 insertions(+), 50 deletions(-) (limited to 'src/nvim/getchar.c') diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 37840f8875..183fd5e19f 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -125,8 +125,8 @@ static int KeyNoremap = 0; // remapping flags // middle for typeahead and room for new characters (which needs to be 3 * // MAXMAPLEN for the Amiga). #define TYPELEN_INIT (5 * (MAXMAPLEN + 3)) -static char_u typebuf_init[TYPELEN_INIT]; // initial typebuf.tb_buf -static char_u noremapbuf_init[TYPELEN_INIT]; // initial typebuf.tb_noremap +static uint8_t typebuf_init[TYPELEN_INIT]; // initial typebuf.tb_buf +static uint8_t noremapbuf_init[TYPELEN_INIT]; // initial typebuf.tb_noremap static size_t last_recorded_len = 0; // number of last recorded chars @@ -337,14 +337,12 @@ static int read_readbuffers(int advance) static int read_readbuf(buffheader_T *buf, int advance) { - char_u c; - if (buf->bh_first.b_next == NULL) { // buffer is empty return NUL; } buffblock_T *const curr = buf->bh_first.b_next; - c = (char_u)curr->b_str[buf->bh_index]; + uint8_t c = (uint8_t)curr->b_str[buf->bh_index]; if (advance) { if (curr->b_str[++buf->bh_index] == NUL) { @@ -657,17 +655,17 @@ void stuffescaped(const char *arg, bool literally) static int read_redo(bool init, bool old_redo) { static buffblock_T *bp; - static char_u *p; + static uint8_t *p; int c; int n; - char_u buf[MB_MAXBYTES + 1]; + uint8_t buf[MB_MAXBYTES + 1]; if (init) { bp = old_redo ? old_redobuff.bh_first.b_next : redobuff.bh_first.b_next; if (bp == NULL) { return FAIL; } - p = (char_u *)bp->b_str; + p = (uint8_t *)bp->b_str; return OK; } if ((c = *p) == NUL) { @@ -688,9 +686,9 @@ static int read_redo(bool init, bool old_redo) } if (*++p == NUL && bp->b_next != NULL) { bp = bp->b_next; - p = (char_u *)bp->b_str; + p = (uint8_t *)bp->b_str; } - buf[i] = (char_u)c; + buf[i] = (uint8_t)c; if (i == n - 1) { // last byte of a character if (n != 1) { c = utf_ptr2char((char *)buf); @@ -854,7 +852,7 @@ bool noremap_keys(void) // return FAIL for failure, OK otherwise int ins_typebuf(char *str, int noremap, int offset, bool nottyped, bool silent) { - char_u *s1, *s2; + uint8_t *s1, *s2; int addlen; int val; int nrm; @@ -975,11 +973,11 @@ int ins_typebuf(char *str, int noremap, int offset, bool nottyped, bool silent) /// @return the length of what was inserted int ins_char_typebuf(int c, int modifiers) { - char_u buf[MB_MAXBYTES * 3 + 4]; - unsigned int len = special_to_buf(c, modifiers, true, (char *)buf); + char buf[MB_MAXBYTES * 3 + 4]; + unsigned int len = special_to_buf(c, modifiers, true, buf); assert(len < sizeof(buf)); buf[len] = NUL; - (void)ins_typebuf((char *)buf, KeyNoremap, 0, !KeyTyped, cmd_silent); + (void)ins_typebuf(buf, KeyNoremap, 0, !KeyTyped, cmd_silent); return (int)len; } @@ -1081,11 +1079,11 @@ void del_typebuf(int len, int offset) // Write typed characters to script file. // If recording is on put the character in the recordbuffer. -static void gotchars(const char_u *chars, size_t len) +static void gotchars(const uint8_t *chars, size_t len) FUNC_ATTR_NONNULL_ALL { - const char_u *s = chars; - static char_u buf[4] = { 0 }; + const uint8_t *s = chars; + static uint8_t buf[4] = { 0 }; static size_t buflen = 0; size_t todo = len; @@ -1404,7 +1402,7 @@ int merge_modifiers(int c_arg, int *modifiers) int vgetc(void) { int c; - char_u buf[MB_MAXBYTES + 1]; + uint8_t buf[MB_MAXBYTES + 1]; // Do garbage collection when garbagecollect() was called previously and // we are now at the toplevel. @@ -1548,9 +1546,9 @@ int vgetc(void) // Note: This will loop until enough bytes are received! if ((n = MB_BYTE2LEN_CHECK(c)) > 1) { no_mapping++; - buf[0] = (char_u)c; + buf[0] = (uint8_t)c; for (int i = 1; i < n; i++) { - buf[i] = (char_u)vgetorpeek(true); + buf[i] = (uint8_t)vgetorpeek(true); if (buf[i] == K_SPECIAL) { // Must be a K_SPECIAL - KS_SPECIAL - KE_FILLER sequence, // which represents a K_SPECIAL (0x80). @@ -1815,7 +1813,7 @@ typedef enum { /// Put "string[new_slen]" in typebuf. /// Remove "slen" bytes. /// @return FAIL for error, OK otherwise. -static int put_string_in_typebuf(int offset, int slen, char_u *string, int new_slen) +static int put_string_in_typebuf(int offset, int slen, uint8_t *string, int new_slen) { int extra = new_slen - slen; string[new_slen] = NUL; @@ -1838,7 +1836,7 @@ static int put_string_in_typebuf(int offset, int slen, char_u *string, int new_s /// in Insert mode completion. This includes the form with a CTRL modifier. static bool at_ins_compl_key(void) { - char_u *p = typebuf.tb_buf + typebuf.tb_off; + uint8_t *p = typebuf.tb_buf + typebuf.tb_off; int c = *p; if (typebuf.tb_len > 3 && c == K_SPECIAL && p[1] == KS_MODIFIER && (p[2] & MOD_MASK_CTRL)) { @@ -1858,7 +1856,7 @@ static int check_simplify_modifier(int max_offset) if (offset + 3 >= typebuf.tb_len) { break; } - char_u *tp = typebuf.tb_buf + typebuf.tb_off + offset; + uint8_t *tp = typebuf.tb_buf + typebuf.tb_off + offset; if (tp[0] == K_SPECIAL && tp[1] == KS_MODIFIER) { // A modifier was not used for a mapping, apply it to ASCII // keys. Shift would already have been applied. @@ -1874,12 +1872,12 @@ static int check_simplify_modifier(int max_offset) vgetc_char = c; vgetc_mod_mask = tp[2]; } - char_u new_string[MB_MAXBYTES]; + uint8_t new_string[MB_MAXBYTES]; int len; if (IS_SPECIAL(new_c)) { new_string[0] = K_SPECIAL; - new_string[1] = (char_u)K_SECOND(new_c); - new_string[2] = (char_u)K_THIRD(new_c); + new_string[1] = (uint8_t)K_SECOND(new_c); + new_string[2] = (uint8_t)K_THIRD(new_c); len = 3; } else { len = utf_char2bytes(new_c, (char *)new_string); @@ -1889,7 +1887,7 @@ static int check_simplify_modifier(int max_offset) return -1; } } else { - tp[2] = (char_u)modifier; + tp[2] = (uint8_t)modifier; if (put_string_in_typebuf(offset + 3, 1, new_string, len) == FAIL) { return -1; } @@ -2010,10 +2008,10 @@ static int handle_mapping(int *keylenp, const bool *timedout, int *mapdepth) // Don't allow mapping the first byte(s) of a multi-byte char. // Happens when mapping and then changing 'encoding'. // Beware that 0x80 is escaped. - char_u *p1 = (char_u *)mp->m_keys; - char_u *p2 = (char_u *)mb_unescape((const char **)&p1); + char *p1 = mp->m_keys; + char *p2 = (char *)mb_unescape((const char **)&p1); - if (p2 != NULL && MB_BYTE2LEN(tb_c1) > utfc_ptr2len((char *)p2)) { + if (p2 != NULL && MB_BYTE2LEN(tb_c1) > utfc_ptr2len(p2)) { mlen = 0; } @@ -2077,7 +2075,7 @@ static int handle_mapping(int *keylenp, const bool *timedout, int *mapdepth) // Check for match with 'pastetoggle' if (*p_pt != NUL && mp == NULL && (State & (MODE_INSERT | MODE_NORMAL))) { - bool match = typebuf_match_len((char_u *)p_pt, &mlen); + bool match = typebuf_match_len((uint8_t *)p_pt, &mlen); if (match) { // write chars to script file(s) if (mlen > typebuf.tb_maplen) { @@ -2267,7 +2265,7 @@ static int handle_mapping(int *keylenp, const bool *timedout, int *mapdepth) // If this is a LANGMAP mapping, then we didn't record the keys // at the start of the function and have to record them now. if (keylen > typebuf.tb_maplen && (mp->m_mode & MODE_LANGMAP) != 0) { - gotchars((char_u *)map_str, strlen(map_str)); + gotchars((uint8_t *)map_str, strlen(map_str)); } if (save_m_noremap != REMAP_YES) { @@ -2442,7 +2440,7 @@ static int vgetorpeek(bool advance) if (advance) { // Also record this character, it might be needed to // get out of Insert mode. - *typebuf.tb_buf = (char_u)c; + *typebuf.tb_buf = (uint8_t)c; gotchars(typebuf.tb_buf, 1); } cmd_silent = false; @@ -2515,7 +2513,7 @@ static int vgetorpeek(bool advance) // move cursor left, if possible if (curwin->w_cursor.col != 0) { colnr_T col = 0; - char_u *ptr; + char *ptr; if (curwin->w_wcol > 0) { // After auto-indenting and no text is following, // we are expecting to truncate the trailing @@ -2524,11 +2522,10 @@ static int vgetorpeek(bool advance) if (did_ai && *skipwhite(get_cursor_line_ptr() + curwin->w_cursor.col) == NUL) { curwin->w_wcol = 0; - ptr = (char_u *)get_cursor_line_ptr(); + ptr = get_cursor_line_ptr(); chartabsize_T cts; - init_chartabsize_arg(&cts, curwin, - curwin->w_cursor.lnum, 0, (char *)ptr, (char *)ptr); - while ((char_u *)cts.cts_ptr < ptr + curwin->w_cursor.col) { + init_chartabsize_arg(&cts, curwin, curwin->w_cursor.lnum, 0, ptr, ptr); + while (cts.cts_ptr < ptr + curwin->w_cursor.col) { if (!ascii_iswhite(*cts.cts_ptr)) { curwin->w_wcol = cts.cts_vcol; } @@ -2554,9 +2551,9 @@ static int vgetorpeek(bool advance) if (col > 0 && curwin->w_wcol > 0) { // Correct when the cursor is on the right halve // of a double-wide character. - ptr = (char_u *)get_cursor_line_ptr(); - col -= utf_head_off((char *)ptr, (char *)ptr + col); - if (utf_ptr2cells((char *)ptr + col) > 1) { + ptr = get_cursor_line_ptr(); + col -= utf_head_off(ptr, ptr + col); + if (utf_ptr2cells(ptr + col) > 1) { curwin->w_wcol--; } } @@ -2760,7 +2757,7 @@ static int vgetorpeek(bool advance) } if (timedout && c == ESC) { - char_u nop_buf[3]; + uint8_t nop_buf[3]; // When recording there will be no timeout. Add a after the ESC // to avoid that it forms a key code with following characters. @@ -2798,7 +2795,7 @@ static int vgetorpeek(bool advance) /// Return -1 when end of input script reached. /// /// @param wait_time milliseconds -int inchar(char_u *buf, int maxlen, long wait_time) +int inchar(uint8_t *buf, int maxlen, long wait_time) { int len = 0; // Init for GCC. int retesc = false; // Return ESC with gotint. @@ -2837,7 +2834,7 @@ int inchar(char_u *buf, int maxlen, long wait_time) return -1; } } else { - buf[0] = (char_u)script_char; + buf[0] = (uint8_t)script_char; len = 1; } } @@ -2851,7 +2848,7 @@ int inchar(char_u *buf, int maxlen, long wait_time) // and buf may be pointing inside typebuf.tb_buf[]. if (got_int) { #define DUM_LEN (MAXMAPLEN * 3 + 3) - char_u dum[DUM_LEN + 1]; + uint8_t dum[DUM_LEN + 1]; for (;;) { len = os_inchar(dum, DUM_LEN, 0L, 0, NULL); @@ -2884,13 +2881,13 @@ int inchar(char_u *buf, int maxlen, long wait_time) typebuf.tb_change_cnt = 1; } - return fix_input_buffer((char *)buf, len); + return fix_input_buffer(buf, len); } // Fix typed characters for use by vgetc() and check_termcode(). // "buf[]" must have room to triple the number of bytes! // Returns the new length. -int fix_input_buffer(char *buf, int len) +int fix_input_buffer(uint8_t *buf, int len) FUNC_ATTR_NONNULL_ALL { if (!using_script()) { @@ -2901,7 +2898,7 @@ int fix_input_buffer(char *buf, int len) } // Reading from script, need to process special bytes - char_u *p = (char_u *)buf; + uint8_t *p = buf; // Two characters are special: NUL and K_SPECIAL. // Replace NUL by K_SPECIAL KS_ZERO KE_FILLER @@ -2911,8 +2908,8 @@ int fix_input_buffer(char *buf, int len) || (p[0] == K_SPECIAL && (i < 2 || p[1] != KS_EXTRA))) { memmove(p + 3, p + 1, (size_t)i); - p[2] = (char_u)K_THIRD(p[0]); - p[1] = (char_u)K_SECOND(p[0]); + p[2] = (uint8_t)K_THIRD(p[0]); + p[1] = (uint8_t)K_SECOND(p[0]); p[0] = K_SPECIAL; p += 2; len += 2; -- cgit From eaccd0decd707ff7cec318e06914f963daa9574c Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 9 Mar 2023 08:15:06 +0800 Subject: vim-patch:9.0.1392: using NULL pointer with nested :open command (#22583) Problem: Using NULL pointer with nested :open command. Solution: Check that ccline.cmdbuff is not NULL. https://github.com/vim/vim/commit/7ac5023a5f1a37baafbe1043645f97ba3443d9f6 Co-authored-by: Bram Moolenaar --- src/nvim/getchar.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'src/nvim/getchar.c') diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 183fd5e19f..ea541dbca4 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -2345,7 +2345,7 @@ void check_end_reg_executing(bool advance) /// K_SPECIAL may be escaped, need to get two more bytes then. static int vgetorpeek(bool advance) { - int c, c1; + int c; bool timedout = false; // waited for more than 'timeoutlen' // for mapping to complete or // 'ttimeoutlen' for complete key code @@ -2639,7 +2639,7 @@ static int vgetorpeek(bool advance) // input from the user), show the partially matched characters // to the user with showcmd. int showcmd_idx = 0; - c1 = 0; + bool showing_partial = false; if (typebuf.tb_len > 0 && advance && !exmode_active) { if (((State & (MODE_NORMAL | MODE_INSERT)) || State == MODE_LANGMAP) && State != MODE_HITRETURN) { @@ -2648,7 +2648,7 @@ static int vgetorpeek(bool advance) && ptr2cells((char *)typebuf.tb_buf + typebuf.tb_off + typebuf.tb_len - 1) == 1) { edit_putchar(typebuf.tb_buf[typebuf.tb_off + typebuf.tb_len - 1], false); setcursor(); // put cursor back where it belongs - c1 = 1; + showing_partial = true; } // need to use the col and row from above here old_wcol = curwin->w_wcol; @@ -2666,12 +2666,15 @@ static int vgetorpeek(bool advance) curwin->w_wrow = old_wrow; } - // this looks nice when typing a dead character map - if ((State & MODE_CMDLINE) && cmdline_star == 0) { + // This looks nice when typing a dead character map. + // There is no actual command line for get_number(). + if ((State & MODE_CMDLINE) + && get_cmdline_info()->cmdbuff != NULL + && cmdline_star == 0) { char *p = (char *)typebuf.tb_buf + typebuf.tb_off + typebuf.tb_len - 1; if (ptr2cells(p) == 1 && (uint8_t)(*p) < 128) { putcmdline(*p, false); - c1 = 1; + showing_partial = true; } } } @@ -2704,11 +2707,12 @@ static int vgetorpeek(bool advance) if (showcmd_idx != 0) { pop_showcmd(); } - if (c1 == 1) { + if (showing_partial == 1) { if (State & MODE_INSERT) { edit_unputchar(); } - if (State & MODE_CMDLINE) { + if ((State & MODE_CMDLINE) + && get_cmdline_info()->cmdbuff != NULL) { unputcmdline(); } else { setcursor(); // put cursor back where it belongs -- cgit From 2daf0b37dbfe54a4510c1033531dbaefd168c387 Mon Sep 17 00:00:00 2001 From: ii14 <59243201+ii14@users.noreply.github.com> Date: Mon, 13 Mar 2023 03:29:11 +0100 Subject: feat(options)!: deprecate paste, remove pastetoggle (#22647) we cannot remove 'paste'. It is very common in plugins and configs. 'pastetoggle' can and should be removed though, it's a total waste of everyone's time because it generates bug reports and doesn't work well, and is useless because bracketed-paste works better. --- src/nvim/getchar.c | 52 ---------------------------------------------------- 1 file changed, 52 deletions(-) (limited to 'src/nvim/getchar.c') diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index ea541dbca4..605705e0e3 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -2073,39 +2073,6 @@ static int handle_mapping(int *keylenp, const bool *timedout, int *mapdepth) } } - // Check for match with 'pastetoggle' - if (*p_pt != NUL && mp == NULL && (State & (MODE_INSERT | MODE_NORMAL))) { - bool match = typebuf_match_len((uint8_t *)p_pt, &mlen); - if (match) { - // write chars to script file(s) - if (mlen > typebuf.tb_maplen) { - gotchars(typebuf.tb_buf + typebuf.tb_off + typebuf.tb_maplen, - (size_t)(mlen - typebuf.tb_maplen)); - } - - del_typebuf(mlen, 0); // remove the chars - set_option_value_give_err("paste", !p_paste, NULL, 0); - if (!(State & MODE_INSERT)) { - msg_col = 0; - msg_row = Rows - 1; - msg_clr_eos(); // clear ruler - } - status_redraw_all(); - redraw_statuslines(); - showmode(); - setcursor(); - *keylenp = keylen; - return map_result_retry; - } - // Need more chars for partly match. - if (mlen == typebuf.tb_len) { - keylen = KEYLEN_PART_KEY; - } else if (max_mlen < mlen) { - // no match, may have to check for termcode at next character - max_mlen = mlen + 1; - } - } - if ((mp == NULL || max_mlen > mp_match_len) && keylen != KEYLEN_PART_MAP) { // When no matching mapping found or found a non-matching mapping that // matches at least what the matching mapping matched: @@ -2116,13 +2083,6 @@ static int handle_mapping(int *keylenp, const bool *timedout, int *mapdepth) || (typebuf.tb_buf[typebuf.tb_off + 1] == KS_MODIFIER && typebuf.tb_len < 4))) { // Incomplete modifier sequence: cannot decide whether to simplify yet. keylen = KEYLEN_PART_KEY; - } else if (keylen == KEYLEN_PART_KEY && !*timedout) { - // If 'pastetoggle' matched partially, don't simplify. - // When the last characters were not typed, don't wait for a typed character to - // complete 'pastetoggle'. - if (typebuf.tb_len == typebuf.tb_maplen) { - keylen = 0; - } } else { // Try to include the modifier into the key. keylen = check_simplify_modifier(max_mlen + 1); @@ -2923,18 +2883,6 @@ int fix_input_buffer(uint8_t *buf, int len) return len; } -static bool typebuf_match_len(const uint8_t *str, int *mlen) -{ - int i; - for (i = 0; i < typebuf.tb_len && str[i]; i++) { - if (str[i] != typebuf.tb_buf[typebuf.tb_off + i]) { - break; - } - } - *mlen = i; - return str[i] == NUL; // matched the whole string -} - /// Get command argument for key char *getcmdkeycmd(int promptc, void *cookie, int indent, bool do_concat) { -- 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/getchar.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/nvim/getchar.c') diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 605705e0e3..745e9d27e2 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -54,7 +54,6 @@ #include "nvim/os/os.h" #include "nvim/plines.h" #include "nvim/pos.h" -#include "nvim/screen.h" #include "nvim/state.h" #include "nvim/strings.h" #include "nvim/types.h" -- cgit From 04933b1ea968f958d2541dd65fd33ebb503caac3 Mon Sep 17 00:00:00 2001 From: ii14 <59243201+ii14@users.noreply.github.com> Date: Fri, 7 Apr 2023 21:08:16 +0200 Subject: refactor: remove redundant casts --- src/nvim/getchar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/getchar.c') diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 745e9d27e2..9aed2630dd 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -1788,7 +1788,7 @@ void f_getcharstr(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) int i = 0; if (n != 0) { - i += utf_char2bytes((int)n, (char *)temp); + i += utf_char2bytes((int)n, temp); } assert(i < 7); temp[i++] = NUL; -- cgit From 2d78e656b715119ca11d131a1a932f22f1b4ad36 Mon Sep 17 00:00:00 2001 From: ii14 <59243201+ii14@users.noreply.github.com> Date: Fri, 7 Apr 2023 21:43:00 +0200 Subject: refactor: remove redundant casts --- src/nvim/getchar.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/getchar.c') diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 9aed2630dd..69a371ccf9 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -2007,8 +2007,8 @@ static int handle_mapping(int *keylenp, const bool *timedout, int *mapdepth) // Don't allow mapping the first byte(s) of a multi-byte char. // Happens when mapping and then changing 'encoding'. // Beware that 0x80 is escaped. - char *p1 = mp->m_keys; - char *p2 = (char *)mb_unescape((const char **)&p1); + const char *p1 = mp->m_keys; + const char *p2 = mb_unescape(&p1); if (p2 != NULL && MB_BYTE2LEN(tb_c1) > utfc_ptr2len(p2)) { mlen = 0; -- cgit From 431b152726013ec6a5cece0285e7c103673bc511 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 23 Apr 2023 08:12:44 +0800 Subject: vim-patch:9.0.1479: small source file problems; outdated list of distrib. files (#23272) Problem: Small source file problems; outdated list of distributed files. Solution: Small updates to source files and list of distributed files. https://github.com/vim/vim/commit/f39d9e9dca443e42920066be3a98fd9780e4ed33 Co-authored-by: Bram Moolenaar --- src/nvim/getchar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/getchar.c') diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 69a371ccf9..15f2e6d06f 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -161,7 +161,7 @@ static char *get_buffcont(buffheader_T *buffer, int dozero) count += strlen(bp->b_str); } - if (count || dozero) { + if (count > 0 || dozero) { p = xmalloc(count + 1); char *p2 = p; for (const buffblock_T *bp = buffer->bh_first.b_next; -- 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/getchar.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/nvim/getchar.c') diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 15f2e6d06f..057043b225 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -973,7 +973,7 @@ int ins_typebuf(char *str, int noremap, int offset, bool nottyped, bool silent) int ins_char_typebuf(int c, int modifiers) { char buf[MB_MAXBYTES * 3 + 4]; - unsigned int len = special_to_buf(c, modifiers, true, buf); + unsigned len = special_to_buf(c, modifiers, true, buf); assert(len < sizeof(buf)); buf[len] = NUL; (void)ins_typebuf(buf, KeyNoremap, 0, !KeyTyped, cmd_silent); @@ -1432,7 +1432,7 @@ int vgetc(void) // if peeking records more last_recorded_len -= last_vgetc_recorded_len; - for (;;) { // this is done twice if there are modifiers + while (true) { // this is done twice if there are modifiers bool did_inc = false; if (mod_mask) { // no mapping after modifier has been read no_mapping++; @@ -1670,7 +1670,7 @@ static void getchar_common(typval_T *argvars, typval_T *rettv) no_mapping++; allow_keys++; - for (;;) { + while (true) { if (msg_col > 0) { // Position the cursor. Needed after a message that ends in a space. ui_cursor_goto(msg_row, msg_col); @@ -2363,7 +2363,7 @@ static int vgetorpeek(bool advance) // are sure that it is not a mapped key. // If a mapped key sequence is found we go back to the start to // try re-mapping. - for (;;) { + while (true) { check_end_reg_executing(advance); // os_breakcheck() is slow, don't use it too often when // inside a mapping. But call it each time for typed @@ -2694,7 +2694,7 @@ static int vgetorpeek(bool advance) typebuf.tb_noremap[typebuf.tb_off + typebuf.tb_len++] = RM_YES; } } - } // for (;;) + } // while (true) } // if (!character from stuffbuf) // if advance is false don't loop on NULs @@ -2813,7 +2813,7 @@ int inchar(uint8_t *buf, int maxlen, long wait_time) #define DUM_LEN (MAXMAPLEN * 3 + 3) uint8_t dum[DUM_LEN + 1]; - for (;;) { + while (true) { len = os_inchar(dum, DUM_LEN, 0L, 0, NULL); if (len == 0 || (len == 1 && dum[0] == Ctrl_C)) { break; -- cgit From 88cfb49bee3c9102082c7010acb92244e4ad1348 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 5 May 2023 07:14:39 +0800 Subject: vim-patch:8.2.4890: inconsistent capitalization in error messages Problem: Inconsistent capitalization in error messages. Solution: Make capitalization consistent. (Doug Kearns) https://github.com/vim/vim/commit/cf030578b26460643dca4a40e7f2e3bc19c749aa Co-authored-by: Bram Moolenaar --- src/nvim/getchar.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/nvim/getchar.c') diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 057043b225..69a77e1e89 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -133,6 +133,8 @@ static size_t last_recorded_len = 0; // number of last recorded chars # include "getchar.c.generated.h" #endif +static const char e_recursive_mapping[] = N_("E223: Recursive mapping"); + // Free and clear a buffer. void free_buff(buffheader_T *buf) { @@ -2135,7 +2137,7 @@ static int handle_mapping(int *keylenp, const bool *timedout, int *mapdepth) // Put the replacement string in front of mapstr. // The depth check catches ":map x y" and ":map y x". if (++*mapdepth >= p_mmd) { - emsg(_("E223: recursive mapping")); + emsg(_(e_recursive_mapping)); if (State & MODE_CMDLINE) { redrawcmdline(); } else { -- cgit From e8661133c533345e8d83a38b077e45922988fa90 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 6 May 2023 09:34:29 +0800 Subject: vim-patch:9.0.0904: various comment and indent flaws (#23498) Problem: Various comment and indent flaws. Solution: Improve comments and indenting. https://github.com/vim/vim/commit/88456cd3c49a3dd1fda17cf350daa9b8216b1aa6 Omit test_function_lists.vim change as that file is likely not applicable to Nvim due to the existence of Nvim-only functions. Co-authored-by: Bram Moolenaar --- src/nvim/getchar.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'src/nvim/getchar.c') diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 69a77e1e89..a0e8350287 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -834,23 +834,23 @@ bool noremap_keys(void) return KeyNoremap & (RM_NONE|RM_SCRIPT); } -// Insert a string in position 'offset' in the typeahead buffer (for "@r" -// and ":normal" command, vgetorpeek() and check_termcode()) -// -// If noremap is REMAP_YES, new string can be mapped again. -// If noremap is REMAP_NONE, new string cannot be mapped again. -// If noremap is REMAP_SKIP, first char of new string cannot be mapped again, -// but abbreviations are allowed. -// If noremap is REMAP_SCRIPT, new string cannot be mapped again, except for -// script-local mappings. -// If noremap is > 0, that many characters of the new string cannot be mapped. -// -// If nottyped is true, the string does not return KeyTyped (don't use when -// offset is non-zero!). -// -// If silent is true, cmd_silent is set when the characters are obtained. -// -// return FAIL for failure, OK otherwise +/// Insert a string in position "offset" in the typeahead buffer (for "@r" +/// and ":normal" command, vgetorpeek() and check_termcode()) +/// +/// If "noremap" is REMAP_YES, new string can be mapped again. +/// If "noremap" is REMAP_NONE, new string cannot be mapped again. +/// If "noremap" is REMAP_SKIP, first char of new string cannot be mapped again, +/// but abbreviations are allowed. +/// If "noremap" is REMAP_SCRIPT, new string cannot be mapped again, except for +/// script-local mappings. +/// If "noremap" is > 0, that many characters of the new string cannot be mapped. +/// +/// If "nottyped" is true, the string does not return KeyTyped (don't use when +/// "offset" is non-zero!). +/// +/// If "silent" is true, cmd_silent is set when the characters are obtained. +/// +/// @return FAIL for failure, OK otherwise int ins_typebuf(char *str, int noremap, int offset, bool nottyped, bool silent) { uint8_t *s1, *s2; @@ -1351,8 +1351,8 @@ void before_blocking(void) } } -/// updatescript() is called when a character can be written to the script file -/// or when we have waited some time for a character (c == 0). +/// updatescript() is called when a character can be written to the script +/// file or when we have waited some time for a character (c == 0). /// /// All the changed memfiles are synced if c == 0 or when the number of typed /// characters reaches 'updatecount' and 'updatecount' is non-zero. -- cgit From a2b9117ca8f8abe8d4c9e2d1bacb73b1902a4e1f Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 7 May 2023 08:12:42 +0800 Subject: vim-patch:8.2.1978: making a mapping work in all modes is complicated Problem: Making a mapping work in all modes is complicated. Solution: Add the special key. (Yegappan Lakshmanan, closes vim/vim#7282, closes 4784, based on patch by Bjorn Linse) https://github.com/vim/vim/commit/957cf67d50516ba98716f59c9e1cb6412ec1535d Change docs to match Vim if it's wording is better. Change error numbers to match Vim. Co-authored-by: Bram Moolenaar --- src/nvim/getchar.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'src/nvim/getchar.c') diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index a0e8350287..31817676e1 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -134,6 +134,10 @@ static size_t last_recorded_len = 0; // number of last recorded chars #endif static const char e_recursive_mapping[] = N_("E223: Recursive mapping"); +static const char e_cmd_mapping_must_end_with_cr[] + = N_("E1135: mapping must end with "); +static const char e_cmd_mapping_must_end_with_cr_before_second_cmd[] + = N_("E1136: mapping must end with before second "); // Free and clear a buffer. void free_buff(buffheader_T *buf) @@ -2884,7 +2888,8 @@ int fix_input_buffer(uint8_t *buf, int len) return len; } -/// Get command argument for key +/// Function passed to do_cmdline() to get the command after a key from +/// typeahead. char *getcmdkeycmd(int promptc, void *cookie, int indent, bool do_concat) { garray_T line_ga; @@ -2894,6 +2899,7 @@ char *getcmdkeycmd(int promptc, void *cookie, int indent, bool do_concat) ga_init(&line_ga, 1, 32); + // no mapping for these characters no_mapping++; got_int = false; @@ -2903,16 +2909,17 @@ char *getcmdkeycmd(int promptc, void *cookie, int indent, bool do_concat) if (vgetorpeek(false) == NUL) { // incomplete is an error, because there is not much the user // could do in this state. - emsg(e_cmdmap_err); + emsg(_(e_cmd_mapping_must_end_with_cr)); aborted = true; break; } // Get one character at a time. c1 = vgetorpeek(true); + // Get two extra bytes for special keys if (c1 == K_SPECIAL) { - c1 = vgetorpeek(true); // no mapping for these chars + c1 = vgetorpeek(true); c2 = vgetorpeek(true); if (c1 == KS_MODIFIER) { cmod = c2; @@ -2928,8 +2935,8 @@ char *getcmdkeycmd(int promptc, void *cookie, int indent, bool do_concat) } else if (c1 == ESC) { aborted = true; } else if (c1 == K_COMMAND) { - // special case to give nicer error message - emsg(e_cmdmap_repeated); + // give a nicer error message for this special case + emsg(_(e_cmd_mapping_must_end_with_cr_before_second_cmd)); aborted = true; } else if (c1 == K_SNR) { ga_concat(&line_ga, ""); -- cgit From f7c1e460f8ae9e316a679a29945ce6a585336322 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 7 May 2023 08:31:06 +0800 Subject: vim-patch:8.2.2062: does not handle CTRL-V Problem: does not handle CTRL-V. Solution: Call get_literal() after encountering CTRL-V. (closes vim/vim#7387) https://github.com/vim/vim/commit/4a44120e3dc1d40dd7109658afd5e078360b1d8f Co-authored-by: Bram Moolenaar --- src/nvim/getchar.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/nvim/getchar.c') diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 31817676e1..32fa517324 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -2927,6 +2927,11 @@ char *getcmdkeycmd(int promptc, void *cookie, int indent, bool do_concat) } c1 = TO_SPECIAL(c1, c2); } + if (c1 == Ctrl_V) { + // CTRL-V is followed by octal, hex or other characters, reverses + // what AppendToRedobuffLit() does. + c1 = get_literal(true); + } if (got_int) { aborted = true; -- cgit From 29c228dc1087676af5b72f4145ab146cff75156e Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 7 May 2023 08:33:06 +0800 Subject: vim-patch:8.2.3887: E1135 is used for two different errors Problem: E1135 is used for two different errors. Solution: Renumber one error. https://github.com/vim/vim/commit/806da5176e9e9ab011d927c4ca33a8dde1769539 Co-authored-by: Bram Moolenaar --- src/nvim/getchar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/getchar.c') diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 32fa517324..07d7887fc6 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -135,7 +135,7 @@ static size_t last_recorded_len = 0; // number of last recorded chars static const char e_recursive_mapping[] = N_("E223: Recursive mapping"); static const char e_cmd_mapping_must_end_with_cr[] - = N_("E1135: mapping must end with "); + = N_("E1255: mapping must end with "); static const char e_cmd_mapping_must_end_with_cr_before_second_cmd[] = N_("E1136: mapping must end with before second "); -- cgit From 32331378134599ece34298f866889b4b311d7b79 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 7 May 2023 08:34:37 +0800 Subject: vim-patch:9.0.1516: cannot use special keys in mapping Problem: Cannot use special keys in mapping. Solution: Do allow for special keys in and mappings. (closes vim/vim#12326) https://github.com/vim/vim/commit/3ab3a864814f903da8a158c01820e4fbe1013c08 --- src/nvim/getchar.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'src/nvim/getchar.c') diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 07d7887fc6..c070e53089 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -554,6 +554,21 @@ void AppendToRedobuffLit(const char *str, int len) } } +/// Append "s" to the redo buffer, leaving 3-byte special key codes unmodified +/// and escaping other K_SPECIAL bytes. +void AppendToRedobuffSpec(const char *s) +{ + while (*s != NUL) { + if ((uint8_t)(*s) == K_SPECIAL && s[1] != NUL && s[2] != NUL) { + // Insert special key literally. + add_buff(&redobuff, s, 3L); + s += 3; + } else { + add_char_buff(&redobuff, mb_cptr2char_adv(&s)); + } + } +} + /// Append a character to the redo buffer. /// Translates special keys, NUL, K_SPECIAL and multibyte characters. void AppendCharToRedobuff(int c) @@ -2927,11 +2942,6 @@ char *getcmdkeycmd(int promptc, void *cookie, int indent, bool do_concat) } c1 = TO_SPECIAL(c1, c2); } - if (c1 == Ctrl_V) { - // CTRL-V is followed by octal, hex or other characters, reverses - // what AppendToRedobuffLit() does. - c1 = get_literal(true); - } if (got_int) { aborted = true; -- cgit From 5844af0d524956b55100e4350934237e4a12a147 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 8 May 2023 00:41:18 +0800 Subject: vim-patch:9.0.1521: failing redo of command with control characters Problem: Failing redo of command with control characters. Solution: Use AppendToRedobuffLit() for colon commands. (closes vim/vim#12354) https://github.com/vim/vim/commit/30b6d6104c3d541c41c868989c020b743e01af08 --- src/nvim/getchar.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/nvim/getchar.c') diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index c070e53089..ca555937ab 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -92,8 +92,8 @@ static buffheader_T readbuf2 = { { NULL, { NUL } }, NULL, 0, 0 }; static int typeahead_char = 0; // typeahead char that's not flushed -// when block_redo is true redo buffer will not be changed -// used by edit() to repeat insertions and 'V' command for redoing +/// When block_redo is true the redo buffer will not be changed. +/// Used by edit() to repeat insertions. static int block_redo = false; static int KeyNoremap = 0; // remapping flags @@ -558,6 +558,10 @@ void AppendToRedobuffLit(const char *str, int len) /// and escaping other K_SPECIAL bytes. void AppendToRedobuffSpec(const char *s) { + if (block_redo) { + return; + } + while (*s != NUL) { if ((uint8_t)(*s) == K_SPECIAL && s[1] != NUL && s[2] != NUL) { // Insert special key literally. -- cgit From 5ac2e47acc999472042df4f10f8f7b5ffa72ba3e Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 10 May 2023 17:42:14 +0800 Subject: fix(redo): make redo of Lua mappings in op-pending mode work (#23566) --- src/nvim/getchar.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/nvim/getchar.c') diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index ca555937ab..5c1366c5b2 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -2986,7 +2986,12 @@ char *getcmdkeycmd(int promptc, void *cookie, int indent, bool do_concat) return line_ga.ga_data; } -bool map_execute_lua(void) +/// Handle a Lua mapping: get its LuaRef from typeahead and execute it. +/// +/// @param may_repeat save the LuaRef for redoing with "." later +/// +/// @return false if getting the LuaRef was aborted, true otherwise +bool map_execute_lua(bool may_repeat) { garray_T line_ga; int c1 = -1; @@ -3018,6 +3023,10 @@ bool map_execute_lua(void) } LuaRef ref = (LuaRef)atoi(line_ga.ga_data); + if (may_repeat) { + repeat_luaref = ref; + } + Error err = ERROR_INIT; Array args = ARRAY_DICT_INIT; nlua_call_ref(ref, NULL, args, false, &err); -- cgit From 72cf94fc0e69b7a049ae2990572876d641cf5cb9 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 12 Aug 2023 06:50:52 +0800 Subject: vim-patch:9.0.1694: wrong mapping applied when replaying a char search (#24670) Problem: wrong mapping applied when replaying a char search Solution: Store a NOP after the ESC closes: vim/vim#12708 closes: vim/vim#6350 https://github.com/vim/vim/commit/bacc83009bc38c9ba0247aaa22b76d1993d57993 --- src/nvim/getchar.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'src/nvim/getchar.c') diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 5c1366c5b2..2e584e7cff 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -1147,6 +1147,13 @@ static void gotchars(const uint8_t *chars, size_t len) maptick++; } +/// Record a key. +void gotchars_nop(void) +{ + uint8_t nop_buf[3] = { K_SPECIAL, KS_EXTRA, KE_NOP }; + gotchars(nop_buf, 3); +} + /// Undo the last gotchars() for "len" bytes. To be used when putting a typed /// character back into the typeahead buffer, thus gotchars() will be called /// again. @@ -2745,14 +2752,9 @@ static int vgetorpeek(bool advance) } if (timedout && c == ESC) { - uint8_t nop_buf[3]; - // When recording there will be no timeout. Add a after the ESC // to avoid that it forms a key code with following characters. - nop_buf[0] = K_SPECIAL; - nop_buf[1] = KS_EXTRA; - nop_buf[2] = KE_NOP; - gotchars(nop_buf, 3); + gotchars_nop(); } vgetc_busy--; -- cgit From 4956f267449ca7526145c63ef095bfd731174635 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 21 Aug 2023 11:11:02 +0800 Subject: vim-patch:8.1.2046: SafeState may be triggered at the wrong moment Problem: SafeState may be triggered at the wrong moment. Solution: Move it up higher to after where messages are processed. Add a SafeStateAgain event to tigger there. https://github.com/vim/vim/commit/69198cb8c08f124729c41a4681f2d142228a9139 SafeStateAgain is N/A. Move SafeState functions to state.c. Co-authored-by: Bram Moolenaar --- src/nvim/getchar.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/nvim/getchar.c') diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 2e584e7cff..957f13b1da 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -885,6 +885,7 @@ int ins_typebuf(char *str, int noremap, int offset, bool nottyped, bool silent) if (++typebuf.tb_change_cnt == 0) { typebuf.tb_change_cnt = 1; } + state_no_longer_safe(); addlen = (int)strlen(str); @@ -1625,6 +1626,12 @@ int vgetc(void) // Execute Lua on_key callbacks. nlua_execute_on_key(c); + // Need to process the character before we know it's safe to do something + // else. + if (c != K_IGNORE) { + state_no_longer_safe(); + } + return c; } -- cgit From 7ce2acd59be89e5e6d2ac778ad074a9ae42951cd Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 21 Aug 2023 12:16:33 +0800 Subject: vim-patch:8.1.2053: SafeStateAgain not triggered if callback uses feedkeys() Problem: SafeStateAgain not triggered if callback uses feedkeys(). Solution: Check for safe state in the input loop. Make log messages easier to find. Add 'S' flag to state(). https://github.com/vim/vim/commit/d103ee78432f9036d243b18dd5aac1263d3b7dc9 Include misc1.c change from patch 8.1.2062. Co-authored-by: Bram Moolenaar --- src/nvim/getchar.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/getchar.c') diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 957f13b1da..d10e021f14 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -885,7 +885,7 @@ int ins_typebuf(char *str, int noremap, int offset, bool nottyped, bool silent) if (++typebuf.tb_change_cnt == 0) { typebuf.tb_change_cnt = 1; } - state_no_longer_safe(); + state_no_longer_safe("ins_typebuf()"); addlen = (int)strlen(str); @@ -1629,7 +1629,7 @@ int vgetc(void) // Need to process the character before we know it's safe to do something // else. if (c != K_IGNORE) { - state_no_longer_safe(); + state_no_longer_safe("key typed"); } return c; -- cgit From 1635c9e75e21e07c4331cf983e14a11c7e09b119 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 26 Aug 2023 11:13:20 +0800 Subject: refactor: move some structs out of buffer_defs.h (#24878) --- src/nvim/getchar.c | 200 +++++++++++++++++++++++++++-------------------------- 1 file changed, 102 insertions(+), 98 deletions(-) (limited to 'src/nvim/getchar.c') diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index d10e021f14..779ba0f90d 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -84,50 +84,56 @@ static buffheader_T redobuff = { { NULL, { NUL } }, NULL, 0, 0 }; static buffheader_T old_redobuff = { { NULL, { NUL } }, NULL, 0, 0 }; static buffheader_T recordbuff = { { NULL, { NUL } }, NULL, 0, 0 }; -// First read ahead buffer. Used for translated commands. +/// First read ahead buffer. Used for translated commands. static buffheader_T readbuf1 = { { NULL, { NUL } }, NULL, 0, 0 }; -// Second read ahead buffer. Used for redo. +/// Second read ahead buffer. Used for redo. static buffheader_T readbuf2 = { { NULL, { NUL } }, NULL, 0, 0 }; -static int typeahead_char = 0; // typeahead char that's not flushed +static int typeahead_char = 0; ///< typeahead char that's not flushed /// When block_redo is true the redo buffer will not be changed. /// Used by edit() to repeat insertions. static int block_redo = false; -static int KeyNoremap = 0; // remapping flags +static int KeyNoremap = 0; ///< remapping flags -// Variables used by vgetorpeek() and flush_buffers() -// -// typebuf.tb_buf[] contains all characters that are not consumed yet. -// typebuf.tb_buf[typebuf.tb_off] is the first valid character. -// typebuf.tb_buf[typebuf.tb_off + typebuf.tb_len - 1] is the last valid char. -// typebuf.tb_buf[typebuf.tb_off + typebuf.tb_len] must be NUL. -// The head of the buffer may contain the result of mappings, abbreviations -// and @a commands. The length of this part is typebuf.tb_maplen. -// typebuf.tb_silent is the part where applies. -// After the head are characters that come from the terminal. -// typebuf.tb_no_abbr_cnt is the number of characters in typebuf.tb_buf that -// should not be considered for abbreviations. -// Some parts of typebuf.tb_buf may not be mapped. These parts are remembered -// in typebuf.tb_noremap[], which is the same length as typebuf.tb_buf and -// contains RM_NONE for the characters that are not to be remapped. -// typebuf.tb_noremap[typebuf.tb_off] is the first valid flag. -// (typebuf has been put in globals.h, because check_termcode() needs it). -#define RM_YES 0 // tb_noremap: remap -#define RM_NONE 1 // tb_noremap: don't remap -#define RM_SCRIPT 2 // tb_noremap: remap local script mappings -#define RM_ABBR 4 // tb_noremap: don't remap, do abbrev. +/// Variables used by vgetorpeek() and flush_buffers() +/// +/// typebuf.tb_buf[] contains all characters that are not consumed yet. +/// typebuf.tb_buf[typebuf.tb_off] is the first valid character. +/// typebuf.tb_buf[typebuf.tb_off + typebuf.tb_len - 1] is the last valid char. +/// typebuf.tb_buf[typebuf.tb_off + typebuf.tb_len] must be NUL. +/// The head of the buffer may contain the result of mappings, abbreviations +/// and @a commands. The length of this part is typebuf.tb_maplen. +/// typebuf.tb_silent is the part where applies. +/// After the head are characters that come from the terminal. +/// typebuf.tb_no_abbr_cnt is the number of characters in typebuf.tb_buf that +/// should not be considered for abbreviations. +/// Some parts of typebuf.tb_buf may not be mapped. These parts are remembered +/// in typebuf.tb_noremap[], which is the same length as typebuf.tb_buf and +/// contains RM_NONE for the characters that are not to be remapped. +/// typebuf.tb_noremap[typebuf.tb_off] is the first valid flag. +enum { + RM_YES = 0, ///< tb_noremap: remap + RM_NONE = 1, ///< tb_noremap: don't remap + RM_SCRIPT = 2, ///< tb_noremap: remap local script mappings + RM_ABBR = 4, ///< tb_noremap: don't remap, do abbrev. +}; // typebuf.tb_buf has three parts: room in front (for result of mappings), the // middle for typeahead and room for new characters (which needs to be 3 * // MAXMAPLEN for the Amiga). #define TYPELEN_INIT (5 * (MAXMAPLEN + 3)) -static uint8_t typebuf_init[TYPELEN_INIT]; // initial typebuf.tb_buf -static uint8_t noremapbuf_init[TYPELEN_INIT]; // initial typebuf.tb_noremap +static uint8_t typebuf_init[TYPELEN_INIT]; ///< initial typebuf.tb_buf +static uint8_t noremapbuf_init[TYPELEN_INIT]; ///< initial typebuf.tb_noremap + +static size_t last_recorded_len = 0; ///< number of last recorded chars -static size_t last_recorded_len = 0; // number of last recorded chars +enum { + KEYLEN_PART_KEY = -1, ///< keylen value for incomplete key-code + KEYLEN_PART_MAP = -2, ///< keylen value for incomplete mapping +}; #ifdef INCLUDE_GENERATED_DECLARATIONS # include "getchar.c.generated.h" @@ -139,8 +145,8 @@ static const char e_cmd_mapping_must_end_with_cr[] static const char e_cmd_mapping_must_end_with_cr_before_second_cmd[] = N_("E1136: mapping must end with before second "); -// Free and clear a buffer. -void free_buff(buffheader_T *buf) +/// Free and clear a buffer. +static void free_buff(buffheader_T *buf) { buffblock_T *p, *np; @@ -359,7 +365,7 @@ static int read_readbuf(buffheader_T *buf, int advance) return c; } -// Prepare the read buffers for reading (if they contain something). +/// Prepare the read buffers for reading (if they contain something). static void start_stuff(void) { if (readbuf1.bh_first.b_next != NULL) { @@ -387,15 +393,15 @@ int readbuf1_empty(void) return (readbuf1.bh_first.b_next == NULL); } -// Set a typeahead character that won't be flushed. +/// Set a typeahead character that won't be flushed. void typeahead_noflush(int c) { typeahead_char = c; } -// Remove the contents of the stuff buffer and the mapped characters in the -// typeahead buffer (used in case of an error). If "flush_typeahead" is true, -// flush all typeahead characters (used when interrupted by a CTRL-C). +/// Remove the contents of the stuff buffer and the mapped characters in the +/// typeahead buffer (used in case of an error). If "flush_typeahead" is true, +/// flush all typeahead characters (used when interrupted by a CTRL-C). void flush_buffers(flush_buffers_T flush_typeahead) { init_typebuf(); @@ -439,8 +445,8 @@ void beep_flush(void) } } -// The previous contents of the redo buffer is kept in old_redobuffer. -// This is used for the CTRL-O <.> command in insert mode. +/// The previous contents of the redo buffer is kept in old_redobuffer. +/// This is used for the CTRL-O <.> command in insert mode. void ResetRedobuff(void) { if (block_redo) { @@ -452,8 +458,8 @@ void ResetRedobuff(void) redobuff.bh_first.b_next = NULL; } -// Discard the contents of the redo buffer and restore the previous redo -// buffer. +/// Discard the contents of the redo buffer and restore the previous redo +/// buffer. void CancelRedo(void) { if (block_redo) { @@ -740,23 +746,21 @@ static void copy_redo(bool old_redo) } } -// Stuff the redo buffer into readbuf2. -// Insert the redo count into the command. -// If "old_redo" is true, the last but one command is repeated -// instead of the last command (inserting text). This is used for -// CTRL-O <.> in insert mode -// -// return FAIL for failure, OK otherwise +/// Stuff the redo buffer into readbuf2. +/// Insert the redo count into the command. +/// If "old_redo" is true, the last but one command is repeated +/// instead of the last command (inserting text). This is used for +/// CTRL-O <.> in insert mode +/// +/// @return FAIL for failure, OK otherwise int start_redo(long count, bool old_redo) { - int c; - // init the pointers; return if nothing to redo if (read_redo(true, old_redo) == FAIL) { return FAIL; } - c = read_redo(false, old_redo); + int c = read_redo(false, old_redo); // copy the buffer name, if present if (c == '"') { @@ -801,9 +805,10 @@ int start_redo(long count, bool old_redo) return OK; } -// Repeat the last insert (R, o, O, a, A, i or I command) by stuffing -// the redo buffer into readbuf2. -// return FAIL for failure, OK otherwise +/// Repeat the last insert (R, o, O, a, A, i or I command) by stuffing +/// the redo buffer into readbuf2. +/// +/// @return FAIL for failure, OK otherwise int start_redo_ins(void) { int c; @@ -834,9 +839,9 @@ void stop_redo_ins(void) block_redo = false; } -// Initialize typebuf.tb_buf to point to typebuf_init. -// alloc() cannot be used here: In out-of-memory situations it would -// be impossible to type anything. +/// Initialize typebuf.tb_buf to point to typebuf_init. +/// alloc() cannot be used here: In out-of-memory situations it would +/// be impossible to type anything. static void init_typebuf(void) { if (typebuf.tb_buf != NULL) { @@ -857,8 +862,7 @@ bool noremap_keys(void) return KeyNoremap & (RM_NONE|RM_SCRIPT); } -/// Insert a string in position "offset" in the typeahead buffer (for "@r" -/// and ":normal" command, vgetorpeek() and check_termcode()) +/// Insert a string in position "offset" in the typeahead buffer. /// /// If "noremap" is REMAP_YES, new string can be mapped again. /// If "noremap" is REMAP_NONE, new string cannot be mapped again. @@ -1030,14 +1034,14 @@ int typebuf_typed(void) return typebuf.tb_maplen == 0; } -// Return the number of characters that are mapped (or not typed). +/// Get the number of characters that are mapped (or not typed). int typebuf_maplen(void) FUNC_ATTR_PURE { return typebuf.tb_maplen; } -// remove "len" characters from typebuf.tb_buf[typebuf.tb_off + offset] +/// Remove "len" characters from typebuf.tb_buf[typebuf.tb_off + offset] void del_typebuf(int len, int offset) { if (len == 0) { @@ -1102,8 +1106,8 @@ void del_typebuf(int len, int offset) } } -// Write typed characters to script file. -// If recording is on put the character in the recordbuffer. +/// Write typed characters to script file. +/// If recording is on put the character in the recordbuffer. static void gotchars(const uint8_t *chars, size_t len) FUNC_ATTR_NONNULL_ALL { @@ -1169,12 +1173,12 @@ void ungetchars(int len) last_recorded_len -= (size_t)len; } -// Sync undo. Called when typed characters are obtained from the typeahead -// buffer, or when a menu is used. -// Do not sync: -// - In Insert mode, unless cursor key has been used. -// - While reading a script file. -// - When no_u_sync is non-zero. +/// Sync undo. Called when typed characters are obtained from the typeahead +/// buffer, or when a menu is used. +/// Do not sync: +/// - In Insert mode, unless cursor key has been used. +/// - While reading a script file. +/// - When no_u_sync is non-zero. void may_sync_undo(void) { if ((!(State & (MODE_INSERT | MODE_CMDLINE)) || arrow_used) @@ -1183,7 +1187,7 @@ void may_sync_undo(void) } } -// Make "typebuf" empty and allocate new buffers. +/// Make "typebuf" empty and allocate new buffers. void alloc_typebuf(void) { typebuf.tb_buf = xmalloc(TYPELEN_INIT); @@ -1199,7 +1203,7 @@ void alloc_typebuf(void) } } -// Free the buffers of "typebuf". +/// Free the buffers of "typebuf". void free_typebuf(void) { if (typebuf.tb_buf == typebuf_init) { @@ -1214,8 +1218,8 @@ void free_typebuf(void) } } -// When doing ":so! file", the current typeahead needs to be saved, and -// restored when "file" has been read completely. +/// When doing ":so! file", the current typeahead needs to be saved, and +/// restored when "file" has been read completely. static typebuf_T saved_typebuf[NSCRIPT]; void save_typebuf(void) @@ -1225,12 +1229,12 @@ void save_typebuf(void) alloc_typebuf(); } -static int old_char = -1; // character put back by vungetc() -static int old_mod_mask; // mod_mask for ungotten character -static int old_mouse_grid; // mouse_grid related to old_char -static int old_mouse_row; // mouse_row related to old_char -static int old_mouse_col; // mouse_col related to old_char -static int old_KeyStuffed; // whether old_char was stuffed +static int old_char = -1; ///< character put back by vungetc() +static int old_mod_mask; ///< mod_mask for ungotten character +static int old_mouse_grid; ///< mouse_grid related to old_char +static int old_mouse_row; ///< mouse_row related to old_char +static int old_mouse_col; ///< mouse_col related to old_char +static int old_KeyStuffed; ///< whether old_char was stuffed static bool can_get_old_char(void) { @@ -1239,7 +1243,7 @@ static bool can_get_old_char(void) return old_char != -1 && (old_KeyStuffed || stuff_empty()); } -// Save all three kinds of typeahead, so that the user must type at a prompt. +/// Save all three kinds of typeahead, so that the user must type at a prompt. void save_typeahead(tasave_T *tp) { tp->save_typebuf = typebuf; @@ -1255,8 +1259,8 @@ void save_typeahead(tasave_T *tp) readbuf2.bh_first.b_next = NULL; } -// Restore the typeahead to what it was before calling save_typeahead(). -// The allocated memory is freed, can only be called once! +/// Restore the typeahead to what it was before calling save_typeahead(). +/// The allocated memory is freed, can only be called once! void restore_typeahead(tasave_T *tp) { if (tp->typebuf_valid) { @@ -1342,7 +1346,7 @@ void openscript(char *name, bool directly) } } -// Close the currently active input script. +/// Close the currently active input script. static void closescript(void) { free_typebuf(); @@ -1635,8 +1639,8 @@ int vgetc(void) return c; } -// Like vgetc(), but never return a NUL when called recursively, get a key -// directly from the user (ignoring typeahead). +/// Like vgetc(), but never return a NUL when called recursively, get a key +/// directly from the user (ignoring typeahead). int safe_vgetc(void) { int c; @@ -1648,8 +1652,8 @@ int safe_vgetc(void) return c; } -// Like safe_vgetc(), but loop to handle K_IGNORE. -// Also ignore scrollbar events. +/// Like safe_vgetc(), but loop to handle K_IGNORE. +/// Also ignore scrollbar events. int plain_vgetc(void) { int c; @@ -1662,10 +1666,10 @@ int plain_vgetc(void) return c; } -// Check if a character is available, such that vgetc() will not block. -// If the next character is a special character or multi-byte, the returned -// character is not valid!. -// Returns NUL if no character is available. +/// Check if a character is available, such that vgetc() will not block. +/// If the next character is a special character or multi-byte, the returned +/// character is not valid!. +/// Returns NUL if no character is available. int vpeekc(void) { if (can_get_old_char()) { @@ -1674,9 +1678,9 @@ int vpeekc(void) return vgetorpeek(false); } -// Check if any character is available, also half an escape sequence. -// Trick: when no typeahead found, but there is something in the typeahead -// buffer, it must be an ESC that is recognized as the start of a key code. +/// Check if any character is available, also half an escape sequence. +/// Trick: when no typeahead found, but there is something in the typeahead +/// buffer, it must be an ESC that is recognized as the start of a key code. int vpeekc_any(void) { int c; @@ -1688,9 +1692,9 @@ int vpeekc_any(void) return c; } -// Call vpeekc() without causing anything to be mapped. -// Return true if a character is available, false otherwise. -int char_avail(void) +/// Call vpeekc() without causing anything to be mapped. +/// @return true if a character is available, false otherwise. +bool char_avail(void) { int retval; @@ -2881,9 +2885,9 @@ int inchar(uint8_t *buf, int maxlen, long wait_time) return fix_input_buffer(buf, len); } -// Fix typed characters for use by vgetc() and check_termcode(). -// "buf[]" must have room to triple the number of bytes! -// Returns the new length. +/// Fix typed characters for use by vgetc(). +/// "buf[]" must have room to triple the number of bytes! +/// Returns the new length. int fix_input_buffer(uint8_t *buf, int len) FUNC_ATTR_NONNULL_ALL { -- cgit From af7d317f3ff31d5ac5d8724b5057a422e1451b54 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Tue, 26 Sep 2023 22:36:08 +0200 Subject: refactor: remove long long is 32-bits even on 64-bit windows which makes the type suboptimal for a codebase meant to be cross-platform. --- src/nvim/getchar.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/getchar.c') diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 779ba0f90d..76aa012d2d 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -2695,9 +2695,9 @@ static int vgetorpeek(bool advance) // blocking wait wait_time = -1L; } else if (keylen == KEYLEN_PART_KEY && p_ttm >= 0) { - wait_time = p_ttm; + wait_time = (long)p_ttm; } else { - wait_time = p_tm; + wait_time = (long)p_tm; } } -- 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/getchar.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/getchar.c') diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 76aa012d2d..dc943922db 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -5,9 +5,10 @@ // file, manipulations with redo buffer and stuff buffer. #include -#include +#include #include #include +#include #include #include #include @@ -24,7 +25,6 @@ #include "nvim/eval.h" #include "nvim/eval/typval.h" #include "nvim/eval/typval_defs.h" -#include "nvim/event/loop.h" #include "nvim/event/multiqueue.h" #include "nvim/ex_cmds.h" #include "nvim/ex_docmd.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/getchar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/getchar.c') diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index dc943922db..b696f8ab37 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -48,7 +48,7 @@ #include "nvim/move.h" #include "nvim/normal.h" #include "nvim/ops.h" -#include "nvim/option.h" +#include "nvim/option_vars.h" #include "nvim/os/fileio.h" #include "nvim/os/input.h" #include "nvim/os/os.h" -- cgit From e72b546354cd90bf0cd8ee6dd045538d713009ad Mon Sep 17 00:00:00 2001 From: dundargoc Date: Fri, 29 Sep 2023 14:58:48 +0200 Subject: refactor: the long goodbye long is 32 bits on windows, while it is 64 bits on other architectures. This makes the type suboptimal for a codebase meant to be cross-platform. Replace it with more appropriate integer types. --- src/nvim/getchar.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/nvim/getchar.c') diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index b696f8ab37..7c5d39bd70 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -291,10 +291,10 @@ static void delete_buff_tail(buffheader_T *buf, int slen) } /// Add number "n" to buffer "buf". -static void add_num_buff(buffheader_T *buf, long n) +static void add_num_buff(buffheader_T *buf, int n) { char number[32]; - snprintf(number, sizeof(number), "%ld", n); + snprintf(number, sizeof(number), "%d", n); add_buff(buf, number, -1L); } @@ -589,7 +589,7 @@ void AppendCharToRedobuff(int c) } // Append a number to the redo buffer. -void AppendNumberToRedobuff(long n) +void AppendNumberToRedobuff(int n) { if (!block_redo) { add_num_buff(&redobuff, n); @@ -643,7 +643,7 @@ void stuffcharReadbuff(int c) } // Append a number to the stuff buffer. -void stuffnumReadbuff(long n) +void stuffnumReadbuff(int n) { add_num_buff(&readbuf1, n); } @@ -753,7 +753,7 @@ static void copy_redo(bool old_redo) /// CTRL-O <.> in insert mode /// /// @return FAIL for failure, OK otherwise -int start_redo(long count, bool old_redo) +int start_redo(int count, bool old_redo) { // init the pointers; return if nothing to redo if (read_redo(true, old_redo) == FAIL) { -- cgit From bf70a33f5e7de0218704126c149db24542e39766 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 14 Oct 2023 09:58:30 +0800 Subject: vim-patch:8.1.0822: peeking and flushing output slows down execution (#25629) Problem: Peeking and flushing output slows down execution. Solution: Do not update the mode message when global_busy is set. Do not flush when only peeking for a character. (Ken Takata) https://github.com/vim/vim/commit/cb574f415486adff645ce384979bfecf27f5be8c --- src/nvim/getchar.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/nvim/getchar.c') diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 7c5d39bd70..5f3b143998 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -2861,8 +2861,10 @@ int inchar(uint8_t *buf, int maxlen, long wait_time) } // Always flush the output characters when getting input characters - // from the user. - ui_flush(); + // from the user and not just peeking. + if (wait_time == -1L || wait_time > 10L) { + ui_flush(); + } // Fill up to a third of the buffer, because each character may be // tripled below. -- cgit From acc646ad8fc3ef11fcc63b69f3d8484e4a91accd Mon Sep 17 00:00:00 2001 From: dundargoc Date: Fri, 29 Sep 2023 14:58:48 +0200 Subject: refactor: the long goodbye long is 32 bits on windows, while it is 64 bits on other architectures. This makes the type suboptimal for a codebase meant to be cross-platform. Replace it with more appropriate integer types. --- src/nvim/getchar.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'src/nvim/getchar.c') diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 5f3b143998..8b1e2f9105 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -295,7 +295,7 @@ static void add_num_buff(buffheader_T *buf, int n) { char number[32]; snprintf(number, sizeof(number), "%d", n); - add_buff(buf, number, -1L); + add_buff(buf, number, -1); } /// Add character 'c' to buffer "buf". @@ -327,7 +327,7 @@ static void add_char_buff(buffheader_T *buf, int c) temp[0] = (char)c; temp[1] = NUL; } - add_buff(buf, temp, -1L); + add_buff(buf, temp, -1); } } @@ -419,7 +419,7 @@ void flush_buffers(flush_buffers_T flush_typeahead) // We have to get all characters, because we may delete the first // part of an escape sequence. In an xterm we get one char at a // time and we have to get them all. - while (inchar(typebuf.tb_buf, typebuf.tb_buflen - 1, 10L) != 0) {} + while (inchar(typebuf.tb_buf, typebuf.tb_buflen - 1, 10) != 0) {} } typebuf.tb_off = MAXMAPLEN; typebuf.tb_len = 0; @@ -488,7 +488,7 @@ void saveRedobuff(save_redo_T *save_redo) return; } - add_buff(&redobuff, s, -1L); + add_buff(&redobuff, s, -1); xfree(s); } @@ -507,7 +507,7 @@ void restoreRedobuff(save_redo_T *save_redo) void AppendToRedobuff(const char *s) { if (!block_redo) { - add_buff(&redobuff, s, -1L); + add_buff(&redobuff, s, -1); } } @@ -553,7 +553,7 @@ void AppendToRedobuffLit(const char *str, int len) // CTRL-V '0' must be inserted as CTRL-V 048. if (*s == NUL && c == '0') { - add_buff(&redobuff, "048", 3L); + add_buff(&redobuff, "048", 3); } else { add_char_buff(&redobuff, c); } @@ -571,7 +571,7 @@ void AppendToRedobuffSpec(const char *s) while (*s != NUL) { if ((uint8_t)(*s) == K_SPECIAL && s[1] != NUL && s[2] != NUL) { // Insert special key literally. - add_buff(&redobuff, s, 3L); + add_buff(&redobuff, s, 3); s += 3; } else { add_char_buff(&redobuff, mb_cptr2char_adv(&s)); @@ -600,14 +600,14 @@ void AppendNumberToRedobuff(int n) /// K_SPECIAL must already have been escaped. void stuffReadbuff(const char *s) { - add_buff(&readbuf1, s, -1L); + add_buff(&readbuf1, s, -1); } /// Append string "s" to the redo stuff buffer. /// @remark K_SPECIAL must already have been escaped. void stuffRedoReadbuff(const char *s) { - add_buff(&readbuf2, s, -1L); + add_buff(&readbuf2, s, -1); } void stuffReadbuffLen(const char *s, ptrdiff_t len) @@ -764,7 +764,7 @@ int start_redo(int count, bool old_redo) // copy the buffer name, if present if (c == '"') { - add_buff(&readbuf2, "\"", 1L); + add_buff(&readbuf2, "\"", 1); c = read_redo(false, old_redo); // if a numbered buffer is used, increment the number @@ -822,7 +822,7 @@ int start_redo_ins(void) while ((c = read_redo(false, false)) != NUL) { if (vim_strchr("AaIiRrOo", c) != NULL) { if (c == 'O' || c == 'o') { - add_buff(&readbuf2, NL_STR, -1L); + add_buff(&readbuf2, NL_STR, -1); } break; } @@ -2424,7 +2424,7 @@ static int vgetorpeek(bool advance) int keylen = 0; if (got_int) { // flush all input - c = inchar(typebuf.tb_buf, typebuf.tb_buflen - 1, 0L); + c = inchar(typebuf.tb_buf, typebuf.tb_buflen - 1, 0); // If inchar() returns true (script file was active) or we // are inside a mapping, get out of Insert mode. @@ -2503,7 +2503,7 @@ static int vgetorpeek(bool advance) && typebuf.tb_maplen == 0 && (State & MODE_INSERT) && (p_timeout || (keylen == KEYLEN_PART_KEY && p_ttimeout)) - && (c = inchar(typebuf.tb_buf + typebuf.tb_off + typebuf.tb_len, 3, 25L)) == 0) { + && (c = inchar(typebuf.tb_buf + typebuf.tb_off + typebuf.tb_len, 3, 25)) == 0) { if (mode_displayed) { unshowmode(true); mode_deleted = true; @@ -2688,16 +2688,16 @@ static int vgetorpeek(bool advance) timedout = false; } - long wait_time = 0; + int wait_time = 0; if (advance) { if (typebuf.tb_len == 0 || !(p_timeout || (p_ttimeout && keylen == KEYLEN_PART_KEY))) { // blocking wait - wait_time = -1L; + wait_time = -1; } else if (keylen == KEYLEN_PART_KEY && p_ttm >= 0) { - wait_time = (long)p_ttm; + wait_time = (int)p_ttm; } else { - wait_time = (long)p_tm; + wait_time = (int)p_tm; } } @@ -2802,7 +2802,7 @@ int inchar(uint8_t *buf, int maxlen, long wait_time) int retesc = false; // Return ESC with gotint. const int tb_change_cnt = typebuf.tb_change_cnt; - if (wait_time == -1L || wait_time > 100L) { + if (wait_time == -1 || wait_time > 100) { // flush output before waiting ui_flush(); } @@ -2852,7 +2852,7 @@ int inchar(uint8_t *buf, int maxlen, long wait_time) uint8_t dum[DUM_LEN + 1]; while (true) { - len = os_inchar(dum, DUM_LEN, 0L, 0, NULL); + len = os_inchar(dum, DUM_LEN, 0, 0, NULL); if (len == 0 || (len == 1 && dum[0] == Ctrl_C)) { break; } @@ -2862,7 +2862,7 @@ int inchar(uint8_t *buf, int maxlen, long wait_time) // Always flush the output characters when getting input characters // from the user and not just peeking. - if (wait_time == -1L || wait_time > 10L) { + if (wait_time == -1 || wait_time > 10) { ui_flush(); } -- cgit From d5a85d737aa2a5c3a64ef0aa5b01672b7ed49c09 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 10 Nov 2023 15:24:36 +0800 Subject: fix(f_wait): flush UI before blocking (#25962) --- src/nvim/getchar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/getchar.c') diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 8b1e2f9105..2370df916c 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -1723,7 +1723,7 @@ static void getchar_common(typval_T *argvars, typval_T *rettv) // getchar(): blocking wait. // TODO(bfredl): deduplicate shared logic with state_enter ? if (!char_avail()) { - // flush output before waiting + // Flush screen updates before blocking. ui_flush(); (void)os_inchar(NULL, 0, -1, typebuf.tb_change_cnt, main_loop.events); if (!multiqueue_empty(main_loop.events)) { -- 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/getchar.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'src/nvim/getchar.c') diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 2370df916c..47577714bb 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.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 - // getchar.c: Code related to getting a character from the user or a script // file, manipulations with redo buffer and stuff buffer. -- 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/getchar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/getchar.c') diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 47577714bb..df94822936 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -1952,7 +1952,6 @@ static int handle_mapping(int *keylenp, const bool *timedout, int *mapdepth) int mp_match_len = 0; int max_mlen = 0; int tb_c1; - int mlen; int keylen = *keylenp; int local_State = get_real_state(); bool is_plug_map = false; @@ -1986,6 +1985,7 @@ static int handle_mapping(int *keylenp, const bool *timedout, int *mapdepth) && State != MODE_ASKMORE && State != MODE_CONFIRM && !at_ins_compl_key()) { + int mlen; int nolmaplen; if (tb_c1 == K_SPECIAL) { nolmaplen = 2; -- cgit From ac1113ded5f8f09dd99a9894d7a7e795626fb728 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 13 Nov 2023 23:40:37 +0100 Subject: refactor: follow style guide - reduce variable scope - prefer initialization over declaration and assignment --- src/nvim/getchar.c | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) (limited to 'src/nvim/getchar.c') diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index df94822936..8fc480009a 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -145,9 +145,9 @@ static const char e_cmd_mapping_must_end_with_cr_before_second_cmd[] /// Free and clear a buffer. static void free_buff(buffheader_T *buf) { - buffblock_T *p, *np; + buffblock_T *np; - for (p = buf->bh_first.b_next; p != NULL; p = np) { + for (buffblock_T *p = buf->bh_first.b_next; p != NULL; p = np) { np = p->b_next; xfree(p); } @@ -877,8 +877,6 @@ bool noremap_keys(void) /// @return FAIL for failure, OK otherwise int ins_typebuf(char *str, int noremap, int offset, bool nottyped, bool silent) { - uint8_t *s1, *s2; - int addlen; int val; int nrm; @@ -888,7 +886,7 @@ int ins_typebuf(char *str, int noremap, int offset, bool nottyped, bool silent) } state_no_longer_safe("ins_typebuf()"); - addlen = (int)strlen(str); + int addlen = (int)strlen(str); if (offset == 0 && addlen <= typebuf.tb_off) { // Easy case: there is room in front of typebuf.tb_buf[typebuf.tb_off] @@ -914,8 +912,8 @@ int ins_typebuf(char *str, int noremap, int offset, bool nottyped, bool silent) return FAIL; } int newlen = typebuf.tb_len + extra; - s1 = xmalloc((size_t)newlen); - s2 = xmalloc((size_t)newlen); + uint8_t *s1 = xmalloc((size_t)newlen); + uint8_t *s2 = xmalloc((size_t)newlen); typebuf.tb_buflen = newlen; // copy the old chars, before the insertion point @@ -2350,10 +2348,6 @@ static int vgetorpeek(bool advance) // 'ttimeoutlen' for complete key code int mapdepth = 0; // check for recursive mapping bool mode_deleted = false; // set when mode has been deleted - int new_wcol, new_wrow; - int n; - int old_wcol, old_wrow; - int wait_tb_len; // This function doesn't work very well when called recursively. This may // happen though, because of: @@ -2490,8 +2484,8 @@ static int vgetorpeek(bool advance) // have to redisplay the mode. That the cursor is in the wrong // place does not matter. c = 0; - new_wcol = curwin->w_wcol; - new_wrow = curwin->w_wrow; + int new_wcol = curwin->w_wcol; + int new_wrow = curwin->w_wrow; if (advance && typebuf.tb_len == 1 && typebuf.tb_buf[typebuf.tb_off] == ESC @@ -2506,8 +2500,8 @@ static int vgetorpeek(bool advance) mode_deleted = true; } validate_cursor(); - old_wcol = curwin->w_wcol; - old_wrow = curwin->w_wrow; + int old_wcol = curwin->w_wcol; + int old_wrow = curwin->w_wrow; // move cursor left, if possible if (curwin->w_cursor.col != 0) { @@ -2570,7 +2564,7 @@ static int vgetorpeek(bool advance) // Allow mapping for just typed characters. When we get here c // is the number of extra bytes and typebuf.tb_len is 1. - for (n = 1; n <= c; n++) { + for (int n = 1; n <= c; n++) { typebuf.tb_noremap[typebuf.tb_off + n] = RM_YES; } typebuf.tb_len += c; @@ -2650,8 +2644,8 @@ static int vgetorpeek(bool advance) showing_partial = true; } // need to use the col and row from above here - old_wcol = curwin->w_wcol; - old_wrow = curwin->w_wrow; + int old_wcol = curwin->w_wcol; + int old_wrow = curwin->w_wrow; curwin->w_wcol = new_wcol; curwin->w_wrow = new_wrow; push_showcmd(); @@ -2698,7 +2692,7 @@ static int vgetorpeek(bool advance) } } - wait_tb_len = typebuf.tb_len; + int wait_tb_len = typebuf.tb_len; c = inchar(typebuf.tb_buf + typebuf.tb_off + typebuf.tb_len, typebuf.tb_buflen - typebuf.tb_off - typebuf.tb_len - 1, wait_time); @@ -2924,7 +2918,8 @@ int fix_input_buffer(uint8_t *buf, int len) char *getcmdkeycmd(int promptc, void *cookie, int indent, bool do_concat) { garray_T line_ga; - int c1 = -1, c2; + int c1 = -1; + int c2; int cmod = 0; bool aborted = false; -- 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/getchar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/getchar.c') diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 8fc480009a..6c08987cdd 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -2,6 +2,7 @@ // file, manipulations with redo buffer and stuff buffer. #include +#include #include #include #include @@ -10,7 +11,6 @@ #include #include -#include "lauxlib.h" #include "nvim/api/private/defs.h" #include "nvim/api/private/helpers.h" #include "nvim/ascii.h" -- 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/getchar.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/getchar.c') diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 6c08987cdd..4a9f861d77 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -26,6 +26,7 @@ #include "nvim/ex_cmds.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 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/getchar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/getchar.c') diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 4a9f861d77..d0007a7a38 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -51,7 +51,7 @@ #include "nvim/os/input.h" #include "nvim/os/os.h" #include "nvim/plines.h" -#include "nvim/pos.h" +#include "nvim/pos_defs.h" #include "nvim/state.h" #include "nvim/strings.h" #include "nvim/types.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/getchar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/getchar.c') diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index d0007a7a38..21e27541e8 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -54,7 +54,7 @@ #include "nvim/pos_defs.h" #include "nvim/state.h" #include "nvim/strings.h" -#include "nvim/types.h" +#include "nvim/types_defs.h" #include "nvim/ui.h" #include "nvim/undo.h" #include "nvim/vim.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/getchar.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/getchar.c') diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 21e27541e8..73af78d3e2 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -13,7 +13,7 @@ #include "nvim/api/private/defs.h" #include "nvim/api/private/helpers.h" -#include "nvim/ascii.h" +#include "nvim/ascii_defs.h" #include "nvim/buffer_defs.h" #include "nvim/charset.h" #include "nvim/cursor.h" @@ -35,7 +35,7 @@ #include "nvim/insexpand.h" #include "nvim/keycodes.h" #include "nvim/lua/executor.h" -#include "nvim/macros.h" +#include "nvim/macros_defs.h" #include "nvim/main.h" #include "nvim/mapping.h" #include "nvim/mbyte.h" @@ -57,7 +57,7 @@ #include "nvim/types_defs.h" #include "nvim/ui.h" #include "nvim/undo.h" -#include "nvim/vim.h" +#include "nvim/vim_defs.h" /// Index in scriptin static int curscript = 0; -- cgit