diff options
Diffstat (limited to 'src')
33 files changed, 259 insertions, 287 deletions
diff --git a/src/nvim/diff.c b/src/nvim/diff.c index 878971a35c..4bfe67c9d3 100644 --- a/src/nvim/diff.c +++ b/src/nvim/diff.c @@ -1962,12 +1962,10 @@ bool diff_find_change(win_T *wp, linenr_T lnum, int *startp, int *endp) } } - if (has_mbyte) { - // Move back to first byte of character in both lines (may - // have "nn^" in line_org and "n^ in line_new). - si_org -= (*mb_head_off)(line_org, line_org + si_org); - si_new -= (*mb_head_off)(line_new, line_new + si_new); - } + // Move back to first byte of character in both lines (may + // have "nn^" in line_org and "n^ in line_new). + si_org -= utf_head_off(line_org, line_org + si_org); + si_new -= utf_head_off(line_new, line_new + si_new); if (*startp > si_org) { *startp = si_org; diff --git a/src/nvim/edit.c b/src/nvim/edit.c index 08b74249ba..a20661bb16 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -1556,14 +1556,11 @@ void display_dollar(colnr_T col) save_col = curwin->w_cursor.col; curwin->w_cursor.col = col; - if (has_mbyte) { - char_u *p; - /* If on the last byte of a multi-byte move to the first byte. */ - p = get_cursor_line_ptr(); - curwin->w_cursor.col -= (*mb_head_off)(p, p + col); - } - curs_columns(FALSE); /* recompute w_wrow and w_wcol */ + // If on the last byte of a multi-byte move to the first byte. + char_u *p = get_cursor_line_ptr(); + curwin->w_cursor.col -= utf_head_off(p, p + col); + curs_columns(false); // Recompute w_wrow and w_wcol if (curwin->w_wcol < curwin->w_width) { edit_putchar('$', FALSE); dollar_vcol = curwin->w_virtcol; @@ -3448,10 +3445,10 @@ static void ins_compl_fixRedoBufForLeader(char_u *ptr_arg) } if (compl_orig_text != NULL) { p = compl_orig_text; - for (len = 0; p[len] != NUL && p[len] == ptr[len]; ++len) - ; - if (len > 0) - len -= (*mb_head_off)(p, p + len); + for (len = 0; p[len] != NUL && p[len] == ptr[len]; len++) {} + if (len > 0) { + len -= utf_head_off(p, p + len); + } for (p += len; *p != NUL; MB_PTR_ADV(p)) { AppendCharToRedobuff(K_BS); } @@ -4587,24 +4584,17 @@ static int ins_complete(int c, bool enable_pum) compl_col += curs_col; compl_length = 0; } else { - /* Search the point of change class of multibyte character - * or not a word single byte character backward. */ - if (has_mbyte) { - int base_class; - int head_off; - - startcol -= (*mb_head_off)(line, line + startcol); - base_class = mb_get_class(line + startcol); - while (--startcol >= 0) { - head_off = (*mb_head_off)(line, line + startcol); - if (base_class != mb_get_class(line + startcol - - head_off)) - break; - startcol -= head_off; + // Search the point of change class of multibyte character + // or not a word single byte character backward. + startcol -= utf_head_off(line, line + startcol); + int base_class = mb_get_class(line + startcol); + while (--startcol >= 0) { + int head_off = utf_head_off(line, line + startcol); + if (base_class != mb_get_class(line + startcol - head_off)) { + break; } - } else - while (--startcol >= 0 && vim_iswordc(line[startcol])) - ; + startcol -= head_off; + } compl_col += ++startcol; compl_length = (int)curs_col - startcol; if (compl_length == 1) { diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 8db8aaa168..d750a47588 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -10609,6 +10609,7 @@ static void f_has(typval_T *argvars, typval_T *rettv, FunPtr fptr) #ifdef HAVE_ACL "acl", #endif + "autochdir", "arabic", "autocmd", "browsefilter", @@ -11234,7 +11235,7 @@ void get_user_input(const typval_T *const argvars, } } - int cmd_silent_save = cmd_silent; + const bool cmd_silent_save = cmd_silent; cmd_silent = false; // Want to see the prompt. // Only the part of the message after the last NL is considered as diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index c9eccfa6b0..ca975ee02a 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -5649,11 +5649,11 @@ void ex_sign(exarg_T *eap) // Count cells and check for non-printable chars cells = 0; - for (s = arg; s < p; s += (*mb_ptr2len)(s)) { + for (s = arg; s < p; s += utfc_ptr2len(s)) { if (!vim_isprintc(utf_ptr2char(s))) { break; } - cells += (*mb_ptr2cells)(s); + cells += utf_ptr2cells(s); } // Currently must be one or two display cells if (s != p || cells < 1 || cells > 2) { diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c index ab24b63110..f5822535ba 100644 --- a/src/nvim/ex_cmds2.c +++ b/src/nvim/ex_cmds2.c @@ -123,7 +123,7 @@ void do_debug(char_u *cmd) int save_msg_scroll = msg_scroll; int save_State = State; int save_did_emsg = did_emsg; - int save_cmd_silent = cmd_silent; + const bool save_cmd_silent = cmd_silent; int save_msg_silent = msg_silent; int save_emsg_silent = emsg_silent; int save_redir_off = redir_off; @@ -1279,15 +1279,14 @@ bool check_changed(buf_T *buf, int flags) /// /// @param buf /// @param checkall may abandon all changed buffers -void dialog_changed(buf_T *buf, int checkall) +void dialog_changed(buf_T *buf, bool checkall) { char_u buff[DIALOG_MSG_SIZE]; int ret; exarg_T ea; - dialog_msg(buff, _("Save changes to \"%s\"?"), - (buf->b_fname != NULL) ? - buf->b_fname : (char_u *)_("Untitled")); + assert(buf->b_fname != NULL); + dialog_msg(buff, _("Save changes to \"%s\"?"), buf->b_fname); if (checkall) { ret = vim_dialog_yesnoallcancel(VIM_QUESTION, NULL, buff, 1); } else { diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index df4adef15f..786e2cd12c 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -722,9 +722,7 @@ static int command_line_execute(VimState *state, int key) s->j = ccline.cmdpos; s->i = (int)(s->xpc.xp_pattern - ccline.cmdbuff); while (--s->j > s->i) { - if (has_mbyte) { - s->j -= (*mb_head_off)(ccline.cmdbuff, ccline.cmdbuff + s->j); - } + s->j -= utf_head_off(ccline.cmdbuff, ccline.cmdbuff + s->j); if (vim_ispathsep(ccline.cmdbuff[s->j])) { found = true; break; @@ -744,9 +742,7 @@ static int command_line_execute(VimState *state, int key) s->j = ccline.cmdpos - 1; s->i = (int)(s->xpc.xp_pattern - ccline.cmdbuff); while (--s->j > s->i) { - if (has_mbyte) { - s->j -= (*mb_head_off)(ccline.cmdbuff, ccline.cmdbuff + s->j); - } + s->j -= utf_head_off(ccline.cmdbuff, ccline.cmdbuff + s->j); if (vim_ispathsep(ccline.cmdbuff[s->j]) #ifdef BACKSLASH_IN_FILENAME && vim_strchr((const char_u *)" *?[{`$%#", ccline.cmdbuff[s->j + 1]) @@ -1432,20 +1428,17 @@ static int command_line_handle_key(CommandLineState *s) return command_line_not_changed(s); } do { - --ccline.cmdpos; - if (has_mbyte) { // move to first byte of char - ccline.cmdpos -= (*mb_head_off)(ccline.cmdbuff, - ccline.cmdbuff + ccline.cmdpos); - } + ccline.cmdpos--; + // Move to first byte of possibly multibyte char. + ccline.cmdpos -= utf_head_off(ccline.cmdbuff, + ccline.cmdbuff + ccline.cmdpos); ccline.cmdspos -= cmdline_charsize(ccline.cmdpos); } while (ccline.cmdpos > 0 && (s->c == K_S_LEFT || s->c == K_C_LEFT || (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL))) && ccline.cmdbuff[ccline.cmdpos - 1] != ' '); - if (has_mbyte) { - set_cmdspos_cursor(); - } + set_cmdspos_cursor(); return command_line_not_changed(s); @@ -2159,10 +2152,11 @@ static void set_cmdspos_cursor(void) */ static void correct_cmdspos(int idx, int cells) { - if ((*mb_ptr2len)(ccline.cmdbuff + idx) > 1 - && (*mb_ptr2cells)(ccline.cmdbuff + idx) > 1 - && ccline.cmdspos % Columns + cells > Columns) + if (utfc_ptr2len(ccline.cmdbuff + idx) > 1 + && utf_ptr2cells(ccline.cmdbuff + idx) > 1 + && ccline.cmdspos % Columns + cells > Columns) { ccline.cmdspos++; + } } /* @@ -2271,14 +2265,10 @@ getexmodeline ( if (c1 == BS || c1 == K_BS || c1 == DEL || c1 == K_DEL || c1 == K_KDEL) { if (!GA_EMPTY(&line_ga)) { - if (has_mbyte) { - p = (char_u *)line_ga.ga_data; - p[line_ga.ga_len] = NUL; - len = (*mb_head_off)(p, p + line_ga.ga_len - 1) + 1; - line_ga.ga_len -= len; - } else { - line_ga.ga_len--; - } + p = (char_u *)line_ga.ga_data; + p[line_ga.ga_len] = NUL; + len = utf_head_off(p, p + line_ga.ga_len - 1) + 1; + line_ga.ga_len -= len; goto redraw; } continue; @@ -3159,18 +3149,15 @@ void put_on_cmdline(char_u *str, int len, int redraw) i = 0; c = utf_ptr2char(ccline.cmdbuff + ccline.cmdpos); while (ccline.cmdpos > 0 && utf_iscomposing(c)) { - i = (*mb_head_off)(ccline.cmdbuff, - ccline.cmdbuff + ccline.cmdpos - 1) + 1; + i = utf_head_off(ccline.cmdbuff, ccline.cmdbuff + ccline.cmdpos - 1) + 1; ccline.cmdpos -= i; len += i; c = utf_ptr2char(ccline.cmdbuff + ccline.cmdpos); } if (i == 0 && ccline.cmdpos > 0 && arabic_maycombine(c)) { - /* Check the previous character for Arabic combining pair. */ - i = (*mb_head_off)(ccline.cmdbuff, - ccline.cmdbuff + ccline.cmdpos - 1) + 1; - if (arabic_combine(utf_ptr2char(ccline.cmdbuff - + ccline.cmdpos - i), c)) { + // Check the previous character for Arabic combining pair. + i = utf_head_off(ccline.cmdbuff, ccline.cmdbuff + ccline.cmdpos - 1) + 1; + if (arabic_combine(utf_ptr2char(ccline.cmdbuff + ccline.cmdpos - i), c)) { ccline.cmdpos -= i; len += i; } else diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index b57e1f6558..df185f1a5b 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -448,7 +448,7 @@ void flush_buffers(int flush_typeahead) } typebuf.tb_maplen = 0; typebuf.tb_silent = 0; - cmd_silent = FALSE; + cmd_silent = false; typebuf.tb_no_abbr_cnt = 0; } @@ -652,15 +652,13 @@ void stuffnumReadbuff(long n) add_num_buff(&readbuf1, n); } -/* - * Read a character from the redo buffer. Translates K_SPECIAL, CSI and - * multibyte characters. - * The redo buffer is left as it is. - * If init is TRUE, prepare for redo, return FAIL if nothing to redo, OK - * otherwise. - * If old is TRUE, use old_redobuff instead of redobuff. - */ -static int read_redo(int init, int old_redo) +// Read a character from the redo buffer. Translates K_SPECIAL, CSI and +// multibyte characters. +// The redo buffer is left as it is. +// If init is true, prepare for redo, return FAIL if nothing to redo, OK +// otherwise. +// If old_redo is true, use old_redobuff instead of redobuff. +static int read_redo(bool init, bool old_redo) { static buffblock_T *bp; static char_u *p; @@ -713,38 +711,35 @@ static int read_redo(int init, int old_redo) return c; } -/* - * Copy the rest of the redo buffer into the stuff buffer (in a slow way). - * If old_redo is TRUE, use old_redobuff instead of redobuff. - * The escaped K_SPECIAL and CSI are copied without translation. - */ -static void copy_redo(int old_redo) +// Copy the rest of the redo buffer into the stuff buffer (in a slow way). +// If old_redo is true, use old_redobuff instead of redobuff. +// The escaped K_SPECIAL and CSI are copied without translation. +static void copy_redo(bool old_redo) { int c; - while ((c = read_redo(FALSE, old_redo)) != NUL) { + while ((c = read_redo(false, old_redo)) != NUL) { add_char_buff(&readbuf2, c); } } -/* - * 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, int 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 +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) + // init the pointers; return if nothing to redo + if (read_redo(true, old_redo) == FAIL) { return FAIL; + } - c = read_redo(FALSE, old_redo); + c = read_redo(false, old_redo); /* copy the buffer name, if present */ if (c == '"') { @@ -755,22 +750,30 @@ int start_redo(long count, int old_redo) if (c >= '1' && c < '9') ++c; add_char_buff(&readbuf2, c); - c = read_redo(FALSE, old_redo); + + // the expression register should be re-evaluated + if (c == '=') { + add_char_buff(&readbuf2, CAR); + cmd_silent = true; + } + + c = read_redo(false, old_redo); } if (c == 'v') { /* redo Visual */ VIsual = curwin->w_cursor; - VIsual_active = TRUE; - VIsual_select = FALSE; - VIsual_reselect = TRUE; - redo_VIsual_busy = TRUE; - c = read_redo(FALSE, old_redo); + VIsual_active = true; + VIsual_select = false; + VIsual_reselect = true; + redo_VIsual_busy = true; + c = read_redo(false, old_redo); } - /* try to enter the count (in place of a previous count) */ + // try to enter the count (in place of a previous count) if (count) { - while (ascii_isdigit(c)) /* skip "old" count */ - c = read_redo(FALSE, old_redo); + while (ascii_isdigit(c)) { // skip "old" count + c = read_redo(false, old_redo); + } add_num_buff(&readbuf2, count); } @@ -789,12 +792,13 @@ int start_redo_ins(void) { int c; - if (read_redo(TRUE, FALSE) == FAIL) + if (read_redo(true, false) == FAIL) { return FAIL; + } start_stuff(); - /* skip the count and the command character */ - while ((c = read_redo(FALSE, FALSE)) != NUL) { + // skip the count and the command character + while ((c = read_redo(false, false)) != NUL) { if (vim_strchr((char_u *)"AaIiRrOo", c) != NULL) { if (c == 'O' || c == 'o') { add_buff(&readbuf2, NL_STR, -1L); @@ -803,9 +807,9 @@ int start_redo_ins(void) } } - /* copy the typed text from the redo buffer into the stuff buffer */ - copy_redo(FALSE); - block_redo = TRUE; + // copy the typed text from the redo buffer into the stuff buffer + copy_redo(false); + block_redo = true; return OK; } @@ -952,7 +956,7 @@ int ins_typebuf(char_u *str, int noremap, int offset, int nottyped, bool silent) typebuf.tb_maplen += addlen; if (silent || typebuf.tb_silent > offset) { typebuf.tb_silent += addlen; - cmd_silent = TRUE; + cmd_silent = true; } if (typebuf.tb_no_abbr_cnt && offset == 0) /* and not used for abbrev.s */ typebuf.tb_no_abbr_cnt += addlen; @@ -1716,7 +1720,7 @@ static int vgetorpeek(int advance) *typebuf.tb_buf = (char_u)c; gotchars(typebuf.tb_buf, 1); } - cmd_silent = FALSE; + cmd_silent = false; break; } else if (typebuf.tb_len > 0) { @@ -2129,13 +2133,14 @@ static int vgetorpeek(int advance) curwin->w_wcol = curwin->w_width - 1; col = curwin->w_cursor.col - 1; } - if (has_mbyte && col > 0 && curwin->w_wcol > 0) { - /* Correct when the cursor is on the right halve - * of a double-wide character. */ + if (col > 0 && curwin->w_wcol > 0) { + // Correct when the cursor is on the right halve + // of a double-wide character. ptr = get_cursor_line_ptr(); - col -= (*mb_head_off)(ptr, ptr + col); - if ((*mb_ptr2cells)(ptr + col) > 1) - --curwin->w_wcol; + col -= utf_head_off(ptr, ptr + col); + if (utf_ptr2cells(ptr + col) > 1) { + curwin->w_wcol--; + } } } setcursor(); diff --git a/src/nvim/globals.h b/src/nvim/globals.h index a31f6950e9..3bb18d2b5f 100644 --- a/src/nvim/globals.h +++ b/src/nvim/globals.h @@ -751,7 +751,7 @@ EXTERN cmdmod_T cmdmod; /* Ex command modifiers */ EXTERN int msg_silent INIT(= 0); // don't print messages EXTERN int emsg_silent INIT(= 0); // don't print error messages EXTERN bool emsg_noredir INIT(= false); // don't redirect error messages -EXTERN int cmd_silent INIT(= false); // don't echo the command line +EXTERN bool cmd_silent INIT(= false); // don't echo the command line /* Values for swap_exists_action: what to do when swap file already exists */ #define SEA_NONE 0 /* don't use dialog */ diff --git a/src/nvim/hardcopy.c b/src/nvim/hardcopy.c index a2f48f46aa..a8731d5bd7 100644 --- a/src/nvim/hardcopy.c +++ b/src/nvim/hardcopy.c @@ -892,10 +892,7 @@ static colnr_T hardcopy_line(prt_settings_T *psettings, int page_line, prt_pos_T need_break = 1; } else { need_break = mch_print_text_out(line + col, (size_t)outputlen); - if (has_mbyte) - print_pos += (*mb_ptr2cells)(line + col); - else - print_pos++; + print_pos += utf_ptr2cells(line + col); } } @@ -2912,7 +2909,7 @@ int mch_print_text_out(char_u *const textp, size_t len) } } if (prt_out_mbyte) { - const bool half_width = ((*mb_ptr2cells)(p) == 1); + const bool half_width = (utf_ptr2cells(p) == 1); if (half_width) { char_width /= 2; } diff --git a/src/nvim/keymap.c b/src/nvim/keymap.c index 628bfef221..3cc74c0044 100644 --- a/src/nvim/keymap.c +++ b/src/nvim/keymap.c @@ -898,7 +898,7 @@ char_u *replace_termcodes(const char_u *from, const size_t from_len, } // skip multibyte char correctly - for (i = (*mb_ptr2len_len)(src, (int) (end - src) + 1); i > 0; i--) { + for (i = utfc_ptr2len_len(src, (int)(end - src) + 1); i > 0; i--) { // If the character is K_SPECIAL, replace it with K_SPECIAL // KS_SPECIAL KE_FILLER. // If compiled with the GUI replace CSI with K_CSI. diff --git a/src/nvim/macros.h b/src/nvim/macros.h index b02af723b4..d447bff765 100644 --- a/src/nvim/macros.h +++ b/src/nvim/macros.h @@ -118,7 +118,8 @@ // Advance multi-byte pointer, do not skip over composing chars. # define MB_CPTR_ADV(p) (p += utf_ptr2len(p)) // Backup multi-byte pointer. Only use with "p" > "s" ! -# define MB_PTR_BACK(s, p) (p -= mb_head_off((char_u *)s, (char_u *)p - 1) + 1) +# define MB_PTR_BACK(s, p) \ + (p -= utf_head_off((char_u *)s, (char_u *)p - 1) + 1) // get length of multi-byte char, not including composing chars # define MB_CPTR2LEN(p) utf_ptr2len(p) diff --git a/src/nvim/mark.c b/src/nvim/mark.c index 3861d9ceb8..5366fa4b7f 100644 --- a/src/nvim/mark.c +++ b/src/nvim/mark.c @@ -1468,7 +1468,7 @@ void mark_mb_adjustpos(buf_T *buf, pos_T *lp) if (*p == NUL || (int)STRLEN(p) < lp->col) { lp->col = 0; } else { - lp->col -= (*mb_head_off)(p, p + lp->col); + lp->col -= utf_head_off(p, p + lp->col); } // Reset "coladd" when the cursor would be on the right half of a // double-wide character. diff --git a/src/nvim/mbyte.c b/src/nvim/mbyte.c index 94bf7fb985..0ee8e2bd85 100644 --- a/src/nvim/mbyte.c +++ b/src/nvim/mbyte.c @@ -550,7 +550,7 @@ size_t mb_string2cells(const char_u *str) size_t clen = 0; for (const char_u *p = str; *p != NUL; p += (*mb_ptr2len)(p)) { - clen += (*mb_ptr2cells)(p); + clen += utf_ptr2cells(p); } return clen; @@ -1710,7 +1710,7 @@ void mb_check_adjust_col(void *win_) win->w_cursor.col = len - 1; } // Move the cursor to the head byte. - win->w_cursor.col -= (*mb_head_off)(p, p + win->w_cursor.col); + win->w_cursor.col -= utf_head_off(p, p + win->w_cursor.col); } // Reset `coladd` when the cursor would be on the right half of a @@ -2124,8 +2124,9 @@ static char_u *iconv_string(const vimconv_T *const vcp, char_u *str, * conversion from 'encoding' to something else. In other * situations we don't know what to skip anyway. */ *to++ = '?'; - if ((*mb_ptr2cells)((char_u *)from) > 1) + if (utf_ptr2cells((char_u *)from) > 1) { *to++ = '?'; + } l = utfc_ptr2len_len((const char_u *)from, (int)fromlen); from += l; fromlen -= l; diff --git a/src/nvim/mbyte.h b/src/nvim/mbyte.h index 5f48e1783e..6656780df5 100644 --- a/src/nvim/mbyte.h +++ b/src/nvim/mbyte.h @@ -47,13 +47,9 @@ enum { MAX_MCO = 6 }; // TODO(bfredl): eventually we should keep only one of the namings #define mb_ptr2len utfc_ptr2len -#define mb_ptr2len_len utfc_ptr2len_len #define mb_char2len utf_char2len #define mb_char2bytes utf_char2bytes -#define mb_ptr2cells utf_ptr2cells -#define mb_ptr2cells_len utf_ptr2cells_len #define mb_char2cells utf_char2cells -#define mb_head_off utf_head_off /// Flags for vimconv_T typedef enum { diff --git a/src/nvim/memline.c b/src/nvim/memline.c index fbd376641f..61d944eb75 100644 --- a/src/nvim/memline.c +++ b/src/nvim/memline.c @@ -4035,24 +4035,18 @@ int incl(pos_T *lp) int dec(pos_T *lp) { - char_u *p; - lp->coladd = 0; if (lp->col > 0) { // still within line lp->col--; - if (has_mbyte) { - p = ml_get(lp->lnum); - lp->col -= (*mb_head_off)(p, p + lp->col); - } + char_u *p = ml_get(lp->lnum); + lp->col -= utf_head_off(p, p + lp->col); return 0; } if (lp->lnum > 1) { // there is a prior line lp->lnum--; - p = ml_get(lp->lnum); + char_u *p = ml_get(lp->lnum); lp->col = (colnr_T)STRLEN(p); - if (has_mbyte) { - lp->col -= (*mb_head_off)(p, p + lp->col); - } + lp->col -= utf_head_off(p, p + lp->col); return 1; } return -1; // at start of file diff --git a/src/nvim/message.c b/src/nvim/message.c index 4b0824c90f..0821ff3489 100644 --- a/src/nvim/message.c +++ b/src/nvim/message.c @@ -541,7 +541,7 @@ int emsg(const char_u *s_) // Reset msg_silent, an error causes messages to be switched back on. msg_silent = 0; - cmd_silent = FALSE; + cmd_silent = false; if (global_busy) { // break :global command global_busy++; @@ -699,8 +699,8 @@ char_u *msg_may_trunc(int force, char_u *s) return s; for (n = 0; size >= room; ) { - size -= (*mb_ptr2cells)(s + n); - n += (*mb_ptr2len)(s + n); + size -= utf_ptr2cells(s + n); + n += utfc_ptr2len(s + n); } --n; } @@ -1222,7 +1222,7 @@ int msg_outtrans_len_attr(char_u *msgstr, int len, int attr) c = utf_ptr2char((char_u *)str); if (vim_isprintc(c)) { // Printable multi-byte char: count the cells. - retval += (*mb_ptr2cells)((char_u *)str); + retval += utf_ptr2cells((char_u *)str); } else { // Unprintable multi-byte char: print the printable chars so // far and the translation of the unprintable char. @@ -1476,13 +1476,13 @@ void msg_prt_line(char_u *s, int list) c = c_extra; else c = *p_extra++; - } else if (has_mbyte && (l = (*mb_ptr2len)(s)) > 1) { - col += (*mb_ptr2cells)(s); + } else if ((l = utfc_ptr2len(s)) > 1) { + col += utf_ptr2cells(s); char buf[MB_MAXBYTES + 1]; if (lcs_nbsp != NUL && list && (utf_ptr2char(s) == 160 || utf_ptr2char(s) == 0x202f)) { - mb_char2bytes(lcs_nbsp, (char_u *)buf); - buf[(*mb_ptr2len)((char_u *)buf)] = NUL; + utf_char2bytes(lcs_nbsp, (char_u *)buf); + buf[utfc_ptr2len((char_u *)buf)] = NUL; } else { memmove(buf, s, (size_t)l); buf[l] = NUL; @@ -1549,7 +1549,7 @@ static char_u *screen_puts_mbyte(char_u *s, int l, int attr) int cw; msg_didout = true; // remember that line is not empty - cw = (*mb_ptr2cells)(s); + cw = utf_ptr2cells(s); if (cw > 1 && (cmdmsg_rl ? msg_col <= 1 : msg_col == Columns - 1)) { // Doesn't fit, print a highlighted '>' to fill it up. @@ -1711,14 +1711,12 @@ static void msg_puts_display(const char_u *str, int maxlen, int attr, && (*s == '\n' || (cmdmsg_rl ? (msg_col <= 1 || (*s == TAB && msg_col <= 7) - || (has_mbyte - && (*mb_ptr2cells)(s) > 1 + || (utf_ptr2cells(s) > 1 && msg_col <= 2)) : (msg_col + t_col >= Columns - 1 || (*s == TAB && msg_col + t_col >= ((Columns - 1) & ~7)) - || (has_mbyte - && (*mb_ptr2cells)(s) > 1 + || (utf_ptr2cells(s) > 1 && msg_col + t_col >= Columns - 2))))) { // The screen is scrolled up when at the last row (some terminals // scroll automatically, some don't. To avoid problems we scroll @@ -1787,7 +1785,7 @@ static void msg_puts_display(const char_u *str, int maxlen, int attr, wrap = *s == '\n' || msg_col + t_col >= Columns - || (has_mbyte && (*mb_ptr2cells)(s) > 1 + || (utf_ptr2cells(s) > 1 && msg_col + t_col >= Columns - 1) ; if (t_col > 0 && (wrap || *s == '\r' || *s == '\b' @@ -1821,7 +1819,7 @@ static void msg_puts_display(const char_u *str, int maxlen, int attr, } else if (*s == BELL) { // beep (from ":sh") vim_beep(BO_SH); } else if (*s >= 0x20) { // printable char - cw = mb_ptr2cells(s); + cw = utf_ptr2cells(s); if (maxlen >= 0) { // avoid including composing chars after the end l = utfc_ptr2len_len(s, (int)((str + maxlen) - s)); diff --git a/src/nvim/misc1.c b/src/nvim/misc1.c index caaa310a8b..50cc9dae02 100644 --- a/src/nvim/misc1.c +++ b/src/nvim/misc1.c @@ -548,7 +548,7 @@ open_line ( /* blank-out any other chars from the old leader. */ while (--p >= leader) { - int l = mb_head_off(leader, p); + int l = utf_head_off(leader, p); if (l > 1) { p -= l; @@ -1652,9 +1652,7 @@ int del_bytes(colnr_T count, bool fixpos_arg, bool use_delcombine) ) { --curwin->w_cursor.col; curwin->w_cursor.coladd = 0; - if (has_mbyte) - curwin->w_cursor.col -= - (*mb_head_off)(oldp, oldp + curwin->w_cursor.col); + curwin->w_cursor.col -= utf_head_off(oldp, oldp + curwin->w_cursor.col); } count = oldlen - col; movelen = 1; diff --git a/src/nvim/msgpack_rpc/channel.c b/src/nvim/msgpack_rpc/channel.c index 3244d83a93..bb4aea0986 100644 --- a/src/nvim/msgpack_rpc/channel.c +++ b/src/nvim/msgpack_rpc/channel.c @@ -505,6 +505,11 @@ end: static void unsubscribe(Channel *channel, char *event) { char *event_string = pmap_get(cstr_t)(event_strings, event); + if (!event_string) { + WLOG("RPC: ch %" PRIu64 ": tried to unsubscribe unknown event '%s'", + channel->id, event); + return; + } pmap_del(cstr_t)(channel->rpc.subscribed_events, event_string); map_foreach_value(channels, channel, { diff --git a/src/nvim/normal.c b/src/nvim/normal.c index afddd548a3..0bf93ee001 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -2858,9 +2858,10 @@ static void find_start_of_word(pos_T *pos) while (pos->col > 0) { col = pos->col - 1; - col -= (*mb_head_off)(line, line + col); - if (get_mouse_class(line + col) != cclass) + col -= utf_head_off(line, line + col); + if (get_mouse_class(line + col) != cclass) { break; + } pos->col = col; } } @@ -2877,8 +2878,8 @@ static void find_end_of_word(pos_T *pos) line = ml_get(pos->lnum); if (*p_sel == 'e' && pos->col > 0) { - --pos->col; - pos->col -= (*mb_head_off)(line, line + pos->col); + pos->col--; + pos->col -= utf_head_off(line, line + pos->col); } cclass = get_mouse_class(line + pos->col); while (line[pos->col] != NUL) { @@ -3094,9 +3095,9 @@ size_t find_ident_at_pos(win_T *wp, linenr_T lnum, colnr_T startcol, // When starting on a ']' count it, so that we include the '['. bn = ptr[col] == ']'; - /* - * 2. Back up to start of identifier/string. - */ + // + // 2. Back up to start of identifier/string. + // // Remember class of character under cursor. if ((find_type & FIND_EVAL) && ptr[col] == ']') { this_class = mb_get_class((char_u *)"a"); @@ -3129,7 +3130,7 @@ size_t find_ident_at_pos(win_T *wp, linenr_T lnum, colnr_T startcol, } if (ptr[col] == NUL || (i == 0 && this_class != 2)) { - // didn't find an identifier or string + // Didn't find an identifier or string. if (find_type & FIND_STRING) { EMSG(_("E348: No string under cursor")); } else { diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 9ffd934d44..23948df769 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -520,12 +520,12 @@ static void block_insert(oparg_T *oap, char_u *s, int b_insert, struct block_def } } - if (has_mbyte && spaces > 0) { + if (spaces > 0) { int off; // Avoid starting halfway through a multi-byte character. if (b_insert) { - off = (*mb_head_off)(oldp, oldp + offset + spaces); + off = utf_head_off(oldp, oldp + offset + spaces); } else { off = (*mb_off_next)(oldp, oldp + offset); offset += off; @@ -2460,11 +2460,10 @@ static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append) if (virtual_op) { getvcol(curwin, &oap->end, &cs, NULL, &ce); if (p[endcol] == NUL || (cs + oap->end.coladd < ce - /* Don't add space for double-wide - * char; endcol will be on last byte - * of multi-byte char. */ - && (*mb_head_off)(p, p + endcol) == 0 - )) { + // Don't add space for double-wide + // char; endcol will be on last byte + // of multi-byte char. + && utf_head_off(p, p + endcol) == 0)) { if (oap->start.lnum == oap->end.lnum && oap->start.col == oap->end.col) { /* Special case: inside a single char */ @@ -3021,7 +3020,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) bd.startspaces = incr - bd.endspaces; --bd.textcol; delcount = 1; - bd.textcol -= (*mb_head_off)(oldp, oldp + bd.textcol); + bd.textcol -= utf_head_off(oldp, oldp + bd.textcol); if (oldp[bd.textcol] != TAB) { /* Only a Tab can be split into spaces. Other * characters will have to be moved to after the diff --git a/src/nvim/options.lua b/src/nvim/options.lua index bd816f2ca4..f8bec30988 100644 --- a/src/nvim/options.lua +++ b/src/nvim/options.lua @@ -1771,7 +1771,6 @@ return { { full_name='printheader', abbreviation='pheader', type='string', scope={'global'}, - gettext=true, vi_def=true, varname='p_header', defaults={if_true={vi="%<%f%h%m%=Page %N"}} diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c index 04f59d7522..f42005f392 100644 --- a/src/nvim/os/shell.c +++ b/src/nvim/os/shell.c @@ -450,8 +450,8 @@ static void out_data_ring(char *output, size_t size) /// @param output Data to append to screen lines. /// @param remaining Size of data. /// @param new_line If true, next data output will be on a new line. -static void out_data_append_to_screen(char *output, size_t *count, - bool eof) +static void out_data_append_to_screen(char *output, size_t *count, bool eof) + FUNC_ATTR_NONNULL_ALL { char *p = output, *end = output + *count; while (p < end) { @@ -466,7 +466,7 @@ static void out_data_append_to_screen(char *output, size_t *count, // incomplete UTF-8 sequence that could be composing with the last // complete sequence. // This will be corrected when we switch to vterm based implementation - int i = *p ? mb_ptr2len_len((char_u *)p, (int)(end-p)) : 1; + int i = *p ? utfc_ptr2len_len((char_u *)p, (int)(end-p)) : 1; if (!eof && i == 1 && utf8len_tab_zero[*(uint8_t *)p] > (end-p)) { *count = (size_t)(p - output); goto end; @@ -491,7 +491,7 @@ static void out_data_cb(Stream *stream, RBuffer *buf, size_t count, void *data, && out_data_decide_throttle(cnt)) { // Skip output above a threshold. // Save the skipped output. If it is the final chunk, we display it later. out_data_ring(ptr, cnt); - } else { + } else if (ptr != NULL) { out_data_append_to_screen(ptr, &cnt, eof); } diff --git a/src/nvim/path.c b/src/nvim/path.c index cc4a5f62a7..eeb374cf44 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -1819,7 +1819,7 @@ void path_fix_case(char_u *name) int after_pathsep(const char *b, const char *p) { return p > b && vim_ispathsep(p[-1]) - && (!has_mbyte || (*mb_head_off)((char_u *)b, (char_u *)p - 1) == 0); + && utf_head_off((char_u *)b, (char_u *)p - 1) == 0; } /* diff --git a/src/nvim/popupmnu.c b/src/nvim/popupmnu.c index 5bd4b4ddff..60c7502fa4 100644 --- a/src/nvim/popupmnu.c +++ b/src/nvim/popupmnu.c @@ -399,7 +399,7 @@ void pum_redraw(void) if (size > pum_width) { do { - size -= has_mbyte ? (*mb_ptr2cells)(rt) : 1; + size -= utf_ptr2cells(rt); MB_PTR_ADV(rt); } while (size > pum_width); diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c index 98d737c9a9..bbc161ee3e 100644 --- a/src/nvim/regexp.c +++ b/src/nvim/regexp.c @@ -3653,8 +3653,7 @@ static long regtry(bt_regprog_T *prog, colnr_T col) static int reg_prev_class(void) { if (reginput > regline) { - return mb_get_class_tab(reginput - 1 - (*mb_head_off)(regline, - reginput - 1), + return mb_get_class_tab(reginput - 1 - utf_head_off(regline, reginput - 1), rex.reg_buf->b_chartab); } return -1; diff --git a/src/nvim/regexp_nfa.c b/src/nvim/regexp_nfa.c index 29191c14a8..3be1f3d2f3 100644 --- a/src/nvim/regexp_nfa.c +++ b/src/nvim/regexp_nfa.c @@ -4639,10 +4639,10 @@ static int recursive_regmatch(nfa_state_T *state, nfa_pim_T *pim, nfa_regprog_T } if ((int)(reginput - regline) >= state->val) { reginput -= state->val; - if (has_mbyte) - reginput -= mb_head_off(regline, reginput); - } else + reginput -= utf_head_off(regline, reginput); + } else { reginput = regline; + } } } diff --git a/src/nvim/screen.c b/src/nvim/screen.c index 6b75902f87..91840026a5 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -1874,8 +1874,8 @@ static void fold_line(win_T *wp, long fold_count, foldinfo_T *foldinfo, linenr_T // Store multibyte characters in ScreenLines[] et al. correctly. for (p = text; *p != NUL; ) { - cells = (*mb_ptr2cells)(p); - c_len = (*mb_ptr2len)(p); + cells = utf_ptr2cells(p); + c_len = utfc_ptr2len(p); if (col + cells > wp->w_width - (wp->w_p_rl ? col : 0)) { break; } @@ -2914,16 +2914,17 @@ win_line ( if (draw_state == WL_LINE && area_highlighting) { /* handle Visual or match highlighting in this line */ if (vcol == fromcol - || (has_mbyte && vcol + 1 == fromcol && n_extra == 0 - && (*mb_ptr2cells)(ptr) > 1) + || (vcol + 1 == fromcol && n_extra == 0 + && utf_ptr2cells(ptr) > 1) || ((int)vcol_prev == fromcol_prev - && vcol_prev < vcol /* not at margin */ - && vcol < tocol)) - area_attr = attr; /* start highlighting */ - else if (area_attr != 0 - && (vcol == tocol - || (noinvcur && (colnr_T)vcol == wp->w_virtcol))) - area_attr = 0; /* stop highlighting */ + && vcol_prev < vcol // not at margin + && vcol < tocol)) { + area_attr = attr; // start highlighting + } else if (area_attr != 0 && (vcol == tocol + || (noinvcur + && (colnr_T)vcol == wp->w_virtcol))) { + area_attr = 0; // stop highlighting + } if (!n_extra) { /* @@ -3435,7 +3436,7 @@ win_line ( // Found last space before word: check for line break. if (wp->w_p_lbr && c0 == c && vim_isbreak(c) && !vim_isbreak((int)(*ptr))) { - int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1) : 0; + int mb_off = utf_head_off(line, ptr - 1); char_u *p = ptr - (mb_off + 1); // TODO: is passing p for start of the line OK? n_extra = win_lbr_chartabsize(wp, line, p, (colnr_T)vcol, NULL) - 1; @@ -4879,8 +4880,8 @@ static void win_redr_status(win_T *wp, int ignore_pum) // Find first character that will fit. // Going from start to end is much faster for DBCS. for (i = 0; p[i] != NUL && clen >= this_ru_col - 1; - i += (*mb_ptr2len)(p + i)) { - clen -= (*mb_ptr2cells)(p + i); + i += utfc_ptr2len(p + i)) { + clen -= utf_ptr2cells(p + i); } len = clen; if (i > 0) { @@ -6128,16 +6129,16 @@ void setcursor(void) { if (redrawing()) { validate_cursor(); + int left_offset = curwin->w_wcol; + if (curwin->w_p_rl) { + // With 'rightleft' set and the cursor on a double-wide character, + // position it on the leftmost column. + left_offset = curwin->w_width - curwin->w_wcol + - ((utf_ptr2cells(get_cursor_pos_ptr()) == 2 + && vim_isprintc(gchar_cursor())) ? 2 : 1); + } ui_cursor_goto(curwin->w_winrow + curwin->w_wrow, - curwin->w_wincol + ( - /* With 'rightleft' set and the cursor on a double-wide - * character, position it on the leftmost column. */ - curwin->w_p_rl ? (curwin->w_width - curwin->w_wcol - ( - (has_mbyte - && (*mb_ptr2cells)(get_cursor_pos_ptr()) == 2 - && vim_isprintc(gchar_cursor())) ? 2 : - 1)) : - curwin->w_wcol)); + curwin->w_wincol + left_offset); } } @@ -6968,18 +6969,15 @@ static void win_redr_ruler(win_T *wp, int always) } get_rel_pos(wp, buffer + i, RULER_BUF_LEN - i); } - /* Truncate at window boundary. */ - if (has_mbyte) { - o = 0; - for (i = 0; buffer[i] != NUL; i += (*mb_ptr2len)(buffer + i)) { - o += (*mb_ptr2cells)(buffer + i); - if (this_ru_col + o > width) { - buffer[i] = NUL; - break; - } + // Truncate at window boundary. + o = 0; + for (i = 0; buffer[i] != NUL; i += utfc_ptr2len(buffer + i)) { + o += utf_ptr2cells(buffer + i); + if (this_ru_col + o > width) { + buffer[i] = NUL; + break; } - } else if (this_ru_col + (int)STRLEN(buffer) > width) - buffer[width - this_ru_col] = NUL; + } screen_puts(buffer, row, this_ru_col + off, attr); i = redraw_cmdline; diff --git a/src/nvim/search.c b/src/nvim/search.c index 40d3f74103..9280bb6fa4 100644 --- a/src/nvim/search.c +++ b/src/nvim/search.c @@ -821,11 +821,10 @@ int searchit( pos->lnum, FALSE)); } } else { - --pos->col; - if (has_mbyte - && pos->lnum <= buf->b_ml.ml_line_count) { - ptr = ml_get_buf(buf, pos->lnum, FALSE); - pos->col -= (*mb_head_off)(ptr, ptr + pos->col); + pos->col--; + if (pos->lnum <= buf->b_ml.ml_line_count) { + ptr = ml_get_buf(buf, pos->lnum, false); + pos->col -= utf_head_off(ptr, ptr + pos->col); } } } else { @@ -1423,7 +1422,7 @@ int searchc(cmdarg_T *cap, int t_cmd) } else { if (col == 0) return FAIL; - col -= (*mb_head_off)(p, p + col - 1) + 1; + col -= utf_head_off(p, p + col - 1) + 1; } if (lastc_bytelen == 1) { if (p[col] == c && stop) { @@ -1446,15 +1445,14 @@ int searchc(cmdarg_T *cap, int t_cmd) } if (t_cmd) { - /* backup to before the character (possibly double-byte) */ + // Backup to before the character (possibly double-byte). col -= dir; - if (has_mbyte) { - if (dir < 0) - /* Landed on the search char which is lastc_bytelen long */ - col += lastc_bytelen - 1; - else - /* To previous char, which may be multi-byte. */ - col -= (*mb_head_off)(p, p + col); + if (dir < 0) { + // Landed on the search char which is lastc_bytelen long. + col += lastc_bytelen - 1; + } else { + // To previous char, which may be multi-byte. + col -= utf_head_off(p, p + col); } } curwin->w_cursor.col = col; @@ -1476,21 +1474,21 @@ pos_T *findmatch(oparg_T *oap, int initc) return findmatchlimit(oap, initc, 0, 0); } -/* - * Return TRUE if the character before "linep[col]" equals "ch". - * Return FALSE if "col" is zero. - * Update "*prevcol" to the column of the previous character, unless "prevcol" - * is NULL. - * Handles multibyte string correctly. - */ -static int check_prevcol(char_u *linep, int col, int ch, int *prevcol) +// Return true if the character before "linep[col]" equals "ch". +// Return false if "col" is zero. +// Update "*prevcol" to the column of the previous character, unless "prevcol" +// is NULL. +// Handles multibyte string correctly. +static bool check_prevcol(char_u *linep, int col, int ch, int *prevcol) { - --col; - if (col > 0 && has_mbyte) - col -= (*mb_head_off)(linep, linep + col); - if (prevcol) + col--; + if (col > 0) { + col -= utf_head_off(linep, linep + col); + } + if (prevcol) { *prevcol = col; - return (col >= 0 && linep[col] == ch) ? TRUE : FALSE; + } + return (col >= 0 && linep[col] == ch) ? true : false; } /* @@ -1797,9 +1795,8 @@ pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int64_t maxtravel) if (lisp && comment_col != MAXCOL) pos.col = comment_col; } else { - --pos.col; - if (has_mbyte) - pos.col -= (*mb_head_off)(linep, linep + pos.col); + pos.col--; + pos.col -= utf_head_off(linep, linep + pos.col); } } else { /* forward search */ if (linep[pos.col] == NUL @@ -2386,8 +2383,7 @@ findpar ( // motion inclusive. if ((curwin->w_cursor.col = (colnr_T)STRLEN(line)) != 0) { curwin->w_cursor.col--; - curwin->w_cursor.col -= - (*mb_head_off)(line, line + curwin->w_cursor.col); + curwin->w_cursor.col -= utf_head_off(line, line + curwin->w_cursor.col); *pincl = true; } } else @@ -3694,8 +3690,8 @@ find_prev_quote( int n; while (col_start > 0) { - --col_start; - col_start -= (*mb_head_off)(line, line + col_start); + col_start--; + col_start -= utf_head_off(line, line + col_start); n = 0; if (escape != NULL) while (col_start - n > 0 && vim_strchr(escape, diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 4acbdcc298..0ac1dd95e2 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -688,8 +688,9 @@ static void find_word(matchinf_T *mip, int mode) arridx = endidx[endidxcnt]; wlen = endlen[endidxcnt]; - if ((*mb_head_off)(ptr, ptr + wlen) > 0) + if (utf_head_off(ptr, ptr + wlen) > 0) { continue; // not at first byte of character + } if (spell_iswordp(ptr + wlen, mip->mi_win)) { if (slang->sl_compprog == NULL && !slang->sl_nobreak) continue; // next char is a word character diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c index b8774bd680..21a86c6946 100644 --- a/src/nvim/spellfile.c +++ b/src/nvim/spellfile.c @@ -1202,7 +1202,6 @@ static int read_sal_section(FILE *fd, slang_T *slang) SPELL_READ_NONNUL_BYTES( // <salfrom> (char *)p, (size_t)(ccnt - i), fd, xfree(smp->sm_lead)); p += (ccnt - i); - i = ccnt; } *p++ = NUL; diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index 3cb998b805..332c50129e 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -1726,16 +1726,12 @@ static int syn_current_attr( */ if (do_keywords) { line = syn_getcurline(); - if (vim_iswordp_buf(line + current_col, syn_buf) - && (current_col == 0 - || !vim_iswordp_buf(line + current_col - 1 - - (has_mbyte - ? (*mb_head_off)(line, line + current_col - 1) - : 0) - , syn_buf))) { - syn_id = check_keyword_id(line, (int)current_col, - &endcol, &flags, &next_list, cur_si, - &cchar); + const char_u *cur_pos = line + current_col; + if (vim_iswordp_buf(cur_pos, syn_buf) + && (current_col == 0 || !vim_iswordp_buf( + cur_pos - 1 - utf_head_off(line, cur_pos - 1), syn_buf))) { + syn_id = check_keyword_id(line, (int)current_col, &endcol, &flags, + &next_list, cur_si, &cchar); if (syn_id != 0) { push_current_state(KEYWORD_IDX); { diff --git a/src/nvim/testdir/test_put.vim b/src/nvim/testdir/test_put.vim index 38c812bc9c..0b8961c52b 100644 --- a/src/nvim/testdir/test_put.vim +++ b/src/nvim/testdir/test_put.vim @@ -34,3 +34,16 @@ func Test_put_char_block2() bw! call setreg('a', a[0], a[1]) endfunc + +func Test_put_expr() + new + call setline(1, repeat(['A'], 6)) + exec "1norm! \"=line('.')\<cr>p" + norm! j0. + norm! j0. + exec "4norm! \"=\<cr>P" + norm! j0. + norm! j0. + call assert_equal(['A1','A2','A3','4A','5A','6A'], getline(1,'$')) + bw! +endfunc diff --git a/src/nvim/window.c b/src/nvim/window.c index 3f66568b58..9976ae9aff 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -2882,8 +2882,8 @@ close_others ( } if (!r) { if (message && (p_confirm || cmdmod.confirm) && p_write) { - dialog_changed(wp->w_buffer, FALSE); - if (!win_valid(wp)) { /* autocommands messed wp up */ + dialog_changed(wp->w_buffer, false); + if (!win_valid(wp)) { // autocommands messed wp up nextwp = firstwin; continue; } @@ -5162,13 +5162,14 @@ file_name_in_line ( * Go one char back to ":" before "//" even when ':' is not in 'isfname'. */ while (ptr > line) { - if (has_mbyte && (len = (size_t)((*mb_head_off)(line, ptr - 1))) > 0) + if ((len = (size_t)(utf_head_off(line, ptr - 1))) > 0) { ptr -= len + 1; - else if (vim_isfilec(ptr[-1]) - || ((options & FNAME_HYP) && path_is_url((char *)ptr - 1))) - --ptr; - else + } else if (vim_isfilec(ptr[-1]) + || ((options & FNAME_HYP) && path_is_url((char *)ptr - 1))) { + ptr--; + } else { break; + } } /* |