diff options
Diffstat (limited to 'src/nvim')
35 files changed, 431 insertions, 347 deletions
diff --git a/src/nvim/charset.c b/src/nvim/charset.c index 4f70bcc41a..99ced6c8c2 100644 --- a/src/nvim/charset.c +++ b/src/nvim/charset.c @@ -804,7 +804,7 @@ unsigned int win_linetabsize(win_T *wp, char_u *line, colnr_T len) for (char_u *s = line; *s != NUL && (len == MAXCOL || s < line + len); - mb_ptr_adv(s)) { + MB_PTR_ADV(s)) { col += win_lbr_chartabsize(wp, line, s, col, NULL); } @@ -971,7 +971,7 @@ int lbr_chartabsize_adv(char_u *line, char_u **s, colnr_T col) int retval; retval = lbr_chartabsize(line, *s, col); - mb_ptr_adv(*s); + MB_PTR_ADV(*s); return retval; } @@ -1038,7 +1038,7 @@ int win_lbr_chartabsize(win_T *wp, char_u *line, char_u *s, colnr_T col, int *he for (;;) { ps = s; - mb_ptr_adv(s); + MB_PTR_ADV(s); c = *s; if (!(c != NUL @@ -1283,7 +1283,7 @@ void getvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor, } vcol += incr; - mb_ptr_adv(ptr); + MB_PTR_ADV(ptr); } } else { for (;;) { @@ -1304,7 +1304,7 @@ void getvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor, } vcol += incr; - mb_ptr_adv(ptr); + MB_PTR_ADV(ptr); } } diff --git a/src/nvim/charset.h b/src/nvim/charset.h index eb64b6128a..e657ce19b6 100644 --- a/src/nvim/charset.h +++ b/src/nvim/charset.h @@ -5,6 +5,7 @@ #include "nvim/pos.h" #include "nvim/buffer_defs.h" #include "nvim/eval/typval.h" +#include "nvim/option_defs.h" /// Return the folded-case equivalent of the given character /// @@ -34,4 +35,15 @@ typedef enum { #ifdef INCLUDE_GENERATED_DECLARATIONS # include "charset.h.generated.h" #endif + +static inline bool vim_isbreak(int c) + REAL_FATTR_CONST + REAL_FATTR_ALWAYS_INLINE; + +/// Check if `c` is one of the characters in 'breakat'. +/// Used very often if 'linebreak' is set +static inline bool vim_isbreak(int c) +{ + return breakat_flags[(char_u)c]; +} #endif // NVIM_CHARSET_H diff --git a/src/nvim/cursor.c b/src/nvim/cursor.c index 0e97e2203f..177f167d74 100644 --- a/src/nvim/cursor.c +++ b/src/nvim/cursor.c @@ -144,7 +144,7 @@ static int coladvance2( while (col <= wcol && *ptr != NUL) { /* Count a tab for what it's worth (if list mode not on) */ csize = win_lbr_chartabsize(curwin, line, ptr, col, &head); - mb_ptr_adv(ptr); + MB_PTR_ADV(ptr); col += csize; } idx = (int)(ptr - line); diff --git a/src/nvim/edit.c b/src/nvim/edit.c index f3e2663d76..cf6167c6ea 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -658,7 +658,7 @@ static int insert_execute(VimState *state, int key) char_u *p; if (str != NULL) { - for (p = str; *p != NUL; mb_ptr_adv(p)) { + for (p = str; *p != NUL; MB_PTR_ADV(p)) { ins_compl_addleader(PTR2CHAR(p)); } xfree(str); @@ -1196,7 +1196,7 @@ normalchar: if (str != NULL) { if (*str != NUL && stop_arrow() != FAIL) { // Insert the new value of v:char literally. - for (p = str; *p != NUL; mb_ptr_adv(p)) { + for (p = str; *p != NUL; MB_PTR_ADV(p)) { s->c = PTR2CHAR(p); if (s->c == CAR || s->c == K_KENTER || s->c == NL) { ins_eol(s->c); @@ -2008,8 +2008,8 @@ int ins_compl_add_infercase(char_u *str, int len, int icase, char_u *fname, int const char_u *p = str; actual_len = 0; while (*p != NUL) { - mb_ptr_adv(p); - ++actual_len; + MB_PTR_ADV(p); + actual_len++; } } else actual_len = len; @@ -2019,8 +2019,8 @@ int ins_compl_add_infercase(char_u *str, int len, int icase, char_u *fname, int const char_u *p = compl_orig_text; actual_compl_length = 0; while (*p != NUL) { - mb_ptr_adv(p); - ++actual_compl_length; + MB_PTR_ADV(p); + actual_compl_length++; } } else actual_compl_length = compl_length; @@ -2322,8 +2322,8 @@ static void ins_compl_longest_match(compl_T *match) break; } if (has_mbyte) { - mb_ptr_adv(p); - mb_ptr_adv(s); + MB_PTR_ADV(p); + MB_PTR_ADV(s); } else { ++p; ++s; @@ -2974,7 +2974,7 @@ static int ins_compl_bs(void) line = get_cursor_line_ptr(); p = line + curwin->w_cursor.col; - mb_ptr_back(line, p); + MB_PTR_BACK(line, p); // Stop completion when the whole word was deleted. For Omni completion // allow the word to be deleted, we won't match everything. @@ -3440,8 +3440,9 @@ static void ins_compl_fixRedoBufForLeader(char_u *ptr_arg) ; if (len > 0) len -= (*mb_head_off)(p, p + len); - for (p += len; *p != NUL; mb_ptr_adv(p)) + for (p += len; *p != NUL; MB_PTR_ADV(p)) { AppendCharToRedobuff(K_BS); + } } else { len = 0; } @@ -4597,13 +4598,15 @@ static int ins_complete(int c, bool enable_pum) if (startcol > 0) { char_u *p = line + startcol; - mb_ptr_back(line, p); - while (p > line && vim_isfilec(PTR2CHAR(p))) - mb_ptr_back(line, p); - if (p == line && vim_isfilec(PTR2CHAR(p))) + MB_PTR_BACK(line, p); + while (p > line && vim_isfilec(PTR2CHAR(p))) { + MB_PTR_BACK(line, p); + } + if (p == line && vim_isfilec(PTR2CHAR(p))) { startcol = 0; - else + } else { startcol = (int)(p - line) + 1; + } } compl_col += startcol; diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 9ce354a0c5..eb437931d4 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -110,8 +110,8 @@ #define DICT_MAXNEST 100 /* maximum nesting of lists and dicts */ -#define AUTOLOAD_CHAR '#' /* Character used as separator in autoload - function/variable names. */ +// Character used as separator in autoload function/variable names. +#define AUTOLOAD_CHAR '#' /* * Structure returned by get_lval() and used by set_var_lval(). @@ -728,8 +728,8 @@ static char_u *redir_varname = NULL; * Start recording command output to a variable * Returns OK if successfully completed the setup. FAIL otherwise. */ -int -var_redir_start ( +int +var_redir_start( char_u *name, int append /* append to an existing variable */ ) @@ -926,8 +926,8 @@ void eval_patch(const char *const origfile, const char *const difffile, * Sets "error" to TRUE if there was an error. * Return TRUE or FALSE. */ -int -eval_to_bool ( +int +eval_to_bool( char_u *arg, bool *error, char_u **nextcmd, @@ -1503,8 +1503,8 @@ void ex_let(exarg_T *eap) * or concatenate. * Returns OK or FAIL; */ -static int -ex_let_vars ( +static int +ex_let_vars( char_u *arg_start, typval_T *tv, int copy, /* copy values from "tv", don't move */ @@ -2581,9 +2581,10 @@ void set_context_for_expression(expand_T *xp, char_u *arg, cmdidx_T cmdidx) /* ":let var1 var2 ...": find last space. */ for (p = arg + STRLEN(arg); p >= arg; ) { xp->xp_pattern = p; - mb_ptr_back(arg, p); - if (ascii_iswhite(*p)) + MB_PTR_BACK(arg, p); + if (ascii_iswhite(*p)) { break; + } } return; } @@ -4307,8 +4308,8 @@ static int eval7( * "*arg" points to the '[' or '.'. * Returns FAIL or OK. "*arg" is advanced to after the ']'. */ -static int -eval_index ( +static int +eval_index( char_u **arg, typval_T *rettv, int evaluate, @@ -4653,7 +4654,7 @@ static int get_string_tv(char_u **arg, typval_T *rettv, int evaluate) /* * Find the end of the string, skipping backslashed characters. */ - for (p = *arg + 1; *p != NUL && *p != '"'; mb_ptr_adv(p)) { + for (p = *arg + 1; *p != NUL && *p != '"'; MB_PTR_ADV(p)) { if (*p == '\\' && p[1] != NUL) { ++p; /* A "\<x>" form occupies at least 4 characters, and produces up @@ -4777,7 +4778,7 @@ static int get_lit_string_tv(char_u **arg, typval_T *rettv, int evaluate) /* * Find the end of the string, skipping ''. */ - for (p = *arg + 1; *p != NUL; mb_ptr_adv(p)) { + for (p = *arg + 1; *p != NUL; MB_PTR_ADV(p)) { if (*p == '\'') { if (p[1] != '\'') break; @@ -6061,15 +6062,15 @@ static char_u *deref_func_name(const char *name, int *lenp, * Allocate a variable for the result of a function. * Return OK or FAIL. */ -static int -get_func_tv ( - char_u *name, /* name of the function */ - int len, /* length of "name" */ +static int +get_func_tv( + char_u *name, // name of the function + int len, // length of "name" typval_T *rettv, - char_u **arg, /* argument, pointing to the '(' */ - linenr_T firstline, /* first line of range */ - linenr_T lastline, /* last line of range */ - int *doesrange, /* return: function handled range */ + char_u **arg, // argument, pointing to the '(' + linenr_T firstline, // first line of range + linenr_T lastline, // last line of range + int *doesrange, // return: function handled range int evaluate, partial_T *partial, // for extra arguments dict_T *selfdict // Dictionary for "self" @@ -9961,8 +9962,8 @@ static void f_getmatches(typval_T *argvars, typval_T *rettv, FunPtr fptr) while (cur != NULL) { dict_T *dict = tv_dict_alloc(); if (cur->match.regprog == NULL) { - // match added with matchaddpos() - for (i = 0; i < MAXPOSMATCH; ++i) { + // match added with matchaddpos() + for (i = 0; i < MAXPOSMATCH; i++) { llpos_T *llpos; char buf[6]; @@ -10380,8 +10381,8 @@ static void f_getwinvar(typval_T *argvars, typval_T *rettv, FunPtr fptr) /* * getwinvar() and gettabwinvar() */ -static void -getwinvar ( +static void +getwinvar( typval_T *argvars, typval_T *rettv, int off /* 1 for gettabwinvar() */ @@ -14160,17 +14161,17 @@ static void f_searchpairpos(typval_T *argvars, typval_T *rettv, FunPtr fptr) * Used by searchpair(), see its documentation for the details. * Returns 0 or -1 for no match, */ -long -do_searchpair ( - char_u *spat, /* start pattern */ - char_u *mpat, /* middle pattern */ - char_u *epat, /* end pattern */ - int dir, /* BACKWARD or FORWARD */ - char_u *skip, /* skip expression */ - int flags, /* SP_SETPCMARK and other SP_ values */ +long +do_searchpair( + char_u *spat, // start pattern + char_u *mpat, // middle pattern + char_u *epat, // end pattern + int dir, // BACKWARD or FORWARD + char_u *skip, // skip expression + int flags, // SP_SETPCMARK and other SP_ values pos_T *match_pos, - linenr_T lnum_stop, /* stop at this line if not zero */ - long time_limit /* stop after this many msec */ + linenr_T lnum_stop, // stop at this line if not zero + long time_limit // stop after this many msec ) { char_u *save_cpo; @@ -16398,7 +16399,7 @@ static list_T *string_to_list(const char *str, size_t len, const bool keepempty) return list; } -static void get_system_output_as_rettv(typval_T *argvars, typval_T *rettv, +static void get_system_output_as_rettv(typval_T *argvars, typval_T *rettv, bool retlist) { rettv->v_type = VAR_STRING; @@ -18061,16 +18062,17 @@ static const char_u *find_name_end(const char_u *arg, const char_u **expr_start, || *p == '{' || ((flags & FNE_INCL_BR) && (*p == '[' || *p == '.')) || mb_nest != 0 - || br_nest != 0); mb_ptr_adv(p)) { + || br_nest != 0); MB_PTR_ADV(p)) { if (*p == '\'') { - /* skip over 'string' to avoid counting [ and ] inside it. */ - for (p = p + 1; *p != NUL && *p != '\''; mb_ptr_adv(p)) - ; - if (*p == NUL) + // skip over 'string' to avoid counting [ and ] inside it. + for (p = p + 1; *p != NUL && *p != '\''; MB_PTR_ADV(p)) { + } + if (*p == NUL) { break; + } } else if (*p == '"') { // skip over "str\"ing" to avoid counting [ and ] inside it. - for (p = p + 1; *p != NUL && *p != '"'; mb_ptr_adv(p)) { + for (p = p + 1; *p != NUL && *p != '"'; MB_PTR_ADV(p)) { if (*p == '\\' && p[1] != NUL) { ++p; } @@ -20693,8 +20695,8 @@ void func_dump_profile(FILE *fd) xfree(sorttab); } -static void -prof_sort_list ( +static void +prof_sort_list( FILE *fd, ufunc_T **sorttab, int st_len, @@ -21551,8 +21553,8 @@ static int can_free_funccal(funccall_T *fc, int copyID) /* * Free "fc" and what it contains. */ -static void -free_funccal ( +static void +free_funccal( funccall_T *fc, int free_val /* a: vars were allocated */ ) @@ -22106,13 +22108,13 @@ void reset_v_option_vars(void) * Returns VALID_ flags or -1 for failure. * When there is an error, *fnamep is set to NULL. */ -int -modify_fname ( - char_u *src, /* string with modifiers */ - size_t *usedlen, /* characters after src that are used */ - char_u **fnamep, /* file name so far */ - char_u **bufp, /* buffer for allocated file name or NULL */ - size_t *fnamelen /* length of fnamep */ +int +modify_fname( + char_u *src, // string with modifiers + size_t *usedlen, // characters after src that are used + char_u **fnamep, // file name so far + char_u **bufp, // buffer for allocated file name or NULL + size_t *fnamelen // length of fnamep ) { int valid = 0; @@ -22148,15 +22150,16 @@ repeat: return -1; } - /* When "/." or "/.." is used: force expansion to get rid of it. */ - for (p = *fnamep; *p != NUL; mb_ptr_adv(p)) { + // When "/." or "/.." is used: force expansion to get rid of it. + for (p = *fnamep; *p != NUL; MB_PTR_ADV(p)) { if (vim_ispathsep(*p) && p[1] == '.' && (p[2] == NUL || vim_ispathsep(p[2]) || (p[2] == '.' - && (p[3] == NUL || vim_ispathsep(p[3]))))) + && (p[3] == NUL || vim_ispathsep(p[3]))))) { break; + } } /* FullName_save() is slow, don't use it when not needed. */ @@ -22236,8 +22239,9 @@ repeat: valid |= VALID_HEAD; *usedlen += 2; s = get_past_head(*fnamep); - while (tail > s && after_pathsep((char *)s, (char *)tail)) - mb_ptr_back(*fnamep, tail); + while (tail > s && after_pathsep((char *)s, (char *)tail)) { + MB_PTR_BACK(*fnamep, tail); + } *fnamelen = (size_t)(tail - *fnamep); if (*fnamelen == 0) { /* Result is empty. Turn it into "." to make ":cd %:h" work. */ @@ -22245,8 +22249,9 @@ repeat: *bufp = *fnamep = tail = vim_strsave((char_u *)"."); *fnamelen = 1; } else { - while (tail > s && !after_pathsep((char *)s, (char *)tail)) - mb_ptr_back(*fnamep, tail); + while (tail > s && !after_pathsep((char *)s, (char *)tail)) { + MB_PTR_BACK(*fnamep, tail); + } } } diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 4e0bdb777c..98eda8dcb8 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -3269,9 +3269,10 @@ static buf_T *do_sub(exarg_T *eap, proftime_T timeout, *cmd++ = NUL; /* replace it with a NUL */ break; } - if (cmd[0] == '\\' && cmd[1] != 0) /* skip escaped characters */ - ++cmd; - mb_ptr_adv(cmd); + if (cmd[0] == '\\' && cmd[1] != 0) { // skip escaped characters + cmd++; + } + MB_PTR_ADV(cmd); } if (!eap->skip && !preview) { diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c index e95890adbf..46a7c869e1 100644 --- a/src/nvim/ex_cmds2.c +++ b/src/nvim/ex_cmds2.c @@ -2532,7 +2532,7 @@ static void add_pack_plugin(char_u *fname, void *cookie) if (cookie != &APP_LOAD && strstr((char *)p_rtp, ffname) == NULL) { // directory is not yet in 'runtimepath', add it p4 = p3 = p2 = p1 = get_past_head((char_u *)ffname); - for (p = p1; *p; mb_ptr_adv(p)) { + for (p = p1; *p; MB_PTR_ADV(p)) { if (vim_ispathsep_nocolon(*p)) { p4 = p3; p3 = p2; p2 = p1; p1 = p; } diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 709dc60b13..9590a3715e 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -2872,7 +2872,7 @@ const char * set_one_cmd_context( return NULL; /* It's a comment */ } } - mb_ptr_adv(p); + MB_PTR_ADV(p); } } @@ -2890,9 +2890,10 @@ const char * set_one_cmd_context( // Argument starts after a space. xp->xp_pattern = (char_u *)++p; } else { - if (*p == '\\' && *(p + 1) != NUL) - ++p; /* skip over escaped character */ - mb_ptr_adv(p); + if (*p == '\\' && *(p + 1) != NUL) { + p++; // skip over escaped character + } + MB_PTR_ADV(p); } } @@ -2943,7 +2944,7 @@ const char * set_one_cmd_context( } else { len = 1; } - mb_ptr_adv(p); + MB_PTR_ADV(p); } if (in_quote) { bow = p; @@ -2952,7 +2953,7 @@ const char * set_one_cmd_context( } p -= len; } - mb_ptr_adv(p); + MB_PTR_ADV(p); } /* @@ -3336,12 +3337,13 @@ const char * set_one_cmd_context( // Find start of last argument. p = arg; while (*p) { - if (*p == ' ') - /* argument starts after a space */ + if (*p == ' ') { + // argument starts after a space arg = p + 1; - else if (*p == '\\' && *(p + 1) != NUL) - ++p; /* skip over escaped character */ - mb_ptr_adv(p); + } else if (*p == '\\' && *(p + 1) != NUL) { + p++; // skip over escaped character + } + MB_PTR_ADV(p); } xp->xp_pattern = (char_u *)arg; } @@ -4238,7 +4240,7 @@ void separate_nextcmd(exarg_T *eap) p = skip_grep_pat(eap); - for (; *p; mb_ptr_adv(p)) { + for (; *p; MB_PTR_ADV(p)) { if (*p == Ctrl_V) { if (eap->argt & (USECTRLV | XFILE)) ++p; /* skip CTRL-V and next char */ @@ -4322,7 +4324,7 @@ skip_cmd_arg ( else ++p; } - mb_ptr_adv(p); + MB_PTR_ADV(p); } return p; } @@ -9486,10 +9488,12 @@ static int ses_put_fname(FILE *fd, char_u *name, unsigned *flagp) char_u *sname = home_replace_save(NULL, name); if (*flagp & SSOP_SLASH) { - /* change all backslashes to forward slashes */ - for (p = sname; *p != NUL; mb_ptr_adv(p)) - if (*p == '\\') + // change all backslashes to forward slashes + for (p = sname; *p != NUL; MB_PTR_ADV(p)) { + if (*p == '\\') { *p = '/'; + } + } } // Escape special characters. diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index d2db309c4f..9b1dcfcafb 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -2934,7 +2934,7 @@ static void ui_ext_cmdline_show(CmdlineInfo *line) Array content = ARRAY_DICT_INIT; if (cmdline_star) { size_t len = 0; - for (char_u *p = ccline.cmdbuff; *p; mb_ptr_adv(p)) { + for (char_u *p = ccline.cmdbuff; *p; MB_PTR_ADV(p)) { len++; } char *buf = xmallocz(len); @@ -4254,7 +4254,7 @@ char_u *sm_gettail(char_u *s) t = p; had_sep = FALSE; } - mb_ptr_adv(p); + MB_PTR_ADV(p); } return t; } @@ -5179,7 +5179,7 @@ static int ExpandRTDir(char_u *pat, int flags, int *num_file, char_u ***file, char_u *e = s + STRLEN(s); if (e - s > 4 && STRNICMP(e - 4, ".vim", 4) == 0) { e -= 4; - for (s = e; s > match; mb_ptr_back(match, s)) { + for (s = e; s > match; MB_PTR_BACK(match, s)) { if (vim_ispathsep(*s)) { break; } diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 49de2ab81e..3b6a3a7995 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -4404,7 +4404,7 @@ char *modname(const char *fname, const char *ext, bool prepend_dot) // Search backwards until we hit a '/', '\' or ':'. // Then truncate what is after the '/', '\' or ':' to BASENAMELEN characters. char *ptr = NULL; - for (ptr = retval + fnamelen; ptr > retval; mb_ptr_back(retval, ptr)) { + for (ptr = retval + fnamelen; ptr > retval; MB_PTR_BACK(retval, ptr)) { if (vim_ispathsep(*ptr)) { ptr++; break; diff --git a/src/nvim/fold.c b/src/nvim/fold.c index 282b72b67a..aea7cdd302 100644 --- a/src/nvim/fold.c +++ b/src/nvim/fold.c @@ -1883,7 +1883,7 @@ void foldtext_cleanup(char_u *str) ++len; STRMOVE(s, s + len); } else { - mb_ptr_adv(s); + MB_PTR_ADV(s); } } } @@ -3054,10 +3054,12 @@ static void foldlevelMarker(fline_T *flp) if (flp->lvl_next > start_lvl) flp->lvl_next = start_lvl; } - } else - --flp->lvl_next; - } else - mb_ptr_adv(s); + } else { + flp->lvl_next--; + } + } else { + MB_PTR_ADV(s); + } } /* The level can't go negative, must be missing a start marker. */ diff --git a/src/nvim/globals.h b/src/nvim/globals.h index f5ebaa9753..d9103f516c 100644 --- a/src/nvim/globals.h +++ b/src/nvim/globals.h @@ -872,8 +872,6 @@ enum { }; -EXTERN char breakat_flags[256]; /* which characters are in 'breakat' */ - /* * Some file names are stored in pathdef.c, which is generated from the * Makefile to make their value depend on the Makefile. diff --git a/src/nvim/macros.h b/src/nvim/macros.h index 348df2d9b6..7eb58bea2a 100644 --- a/src/nvim/macros.h +++ b/src/nvim/macros.h @@ -82,12 +82,6 @@ } \ } while (0) -/* - * vim_isbreak() is used very often if 'linebreak' is set, use a macro to make - * it work fast. - */ -#define vim_isbreak(c) (breakat_flags[(char_u)(c)]) - #define WRITEBIN "wb" /* no CR-LF translation */ #define READBIN "rb" #define APPENDBIN "ab" @@ -110,9 +104,9 @@ /* Whether to draw the vertical bar on the right side of the cell. */ # define CURSOR_BAR_RIGHT (curwin->w_p_rl && (!(State & CMDLINE) || cmdmsg_rl)) -// mb_ptr_adv(): advance a pointer to the next character, taking care of +// MB_PTR_ADV(): advance a pointer to the next character, taking care of // multi-byte characters if needed. -// mb_ptr_back(): backup a pointer to the previous character, taking care of +// MB_PTR_BACK(): backup a pointer to the previous character, taking care of // multi-byte characters if needed. // MB_COPY_CHAR(f, t): copy one char from "f" to "t" and advance the pointers. // PTR2CHAR(): get character from pointer. @@ -120,11 +114,11 @@ // Get the length of the character p points to # define MB_PTR2LEN(p) mb_ptr2len(p) // Advance multi-byte pointer, skip over composing chars. -# define mb_ptr_adv(p) (p += mb_ptr2len((char_u *)p)) +# define MB_PTR_ADV(p) (p += mb_ptr2len((char_u *)p)) // Advance multi-byte pointer, do not skip over composing chars. -# define mb_cptr_adv(p) (p += utf_ptr2len(p)) +# 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 -= mb_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 7cfe3f4a18..49e60b5166 100644 --- a/src/nvim/mark.c +++ b/src/nvim/mark.c @@ -603,7 +603,7 @@ static char_u *mark_line(pos_T *mp, int lead_len) /* Truncate the line to fit it in the window */ len = 0; - for (p = s; *p != NUL; mb_ptr_adv(p)) { + for (p = s; *p != NUL; MB_PTR_ADV(p)) { len += ptr2cells(p); if (len >= Columns - lead_len) break; diff --git a/src/nvim/mbyte.c b/src/nvim/mbyte.c index 472c1ee9f6..a8781ffbb8 100644 --- a/src/nvim/mbyte.c +++ b/src/nvim/mbyte.c @@ -1722,8 +1722,9 @@ char_u * mb_prevptr( char_u *p ) { - if (p > line) - mb_ptr_back(line, p); + if (p > line) { + MB_PTR_BACK(line, p); + } return p; } diff --git a/src/nvim/memline.c b/src/nvim/memline.c index 0449af1e2b..b156f2c513 100644 --- a/src/nvim/memline.c +++ b/src/nvim/memline.c @@ -1432,7 +1432,7 @@ static char *make_percent_swname(const char *dir, char *name) char *f = fix_fname(name != NULL ? name : ""); if (f != NULL) { char *s = xstrdup(f); - for (d = s; *d != NUL; mb_ptr_adv(d)) { + for (d = s; *d != NUL; MB_PTR_ADV(d)) { if (vim_ispathsep(*d)) { *d = '%'; } diff --git a/src/nvim/menu.c b/src/nvim/menu.c index 1bbd07686b..968962c894 100644 --- a/src/nvim/menu.c +++ b/src/nvim/menu.c @@ -97,7 +97,7 @@ ex_menu(exarg_T *eap) while (*arg != NUL && *arg != ' ') { if (*arg == '\\') STRMOVE(arg, arg + 1); - mb_ptr_adv(arg); + MB_PTR_ADV(arg); } if (*arg != NUL) { *arg++ = NUL; @@ -1099,7 +1099,7 @@ char_u *menu_name_skip(char_u *const name) { char_u *p; - for (p = name; *p && *p != '.'; mb_ptr_adv(p)) { + for (p = name; *p && *p != '.'; MB_PTR_ADV(p)) { if (*p == '\\' || *p == Ctrl_V) { STRMOVE(p, p + 1); if (*p == NUL) @@ -1549,9 + |