Remove has_mbyte from lines near changes in parent commit

This commit is contained in:
ZviRackover 2018-08-15 22:46:48 +03:00
parent 2bddc4ca54
commit 30392b6356
14 changed files with 66 additions and 122 deletions

View File

@ -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
// Move back to first byte of character in both lines (may // have "nn^" in line_org and "n^ in line_new).
// have "nn^" in line_org and "n^ in line_new). si_org -= utf_head_off(line_org, line_org + si_org);
si_org -= utf_head_off(line_org, line_org + si_org); si_new -= utf_head_off(line_new, line_new + si_new);
si_new -= utf_head_off(line_new, line_new + si_new);
}
if (*startp > si_org) { if (*startp > si_org) {
*startp = si_org; *startp = si_org;

View File

@ -1556,13 +1556,10 @@ void display_dollar(colnr_T col)
save_col = curwin->w_cursor.col; save_col = curwin->w_cursor.col;
curwin->w_cursor.col = 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. */ /* If on the last byte of a multi-byte move to the first byte. */
p = get_cursor_line_ptr(); char_u *p = get_cursor_line_ptr();
curwin->w_cursor.col -= utf_head_off(p, p + col); curwin->w_cursor.col -= utf_head_off(p, p + col);
}
curs_columns(FALSE); /* recompute w_wrow and w_wcol */ curs_columns(FALSE); /* recompute w_wrow and w_wcol */
if (curwin->w_wcol < curwin->w_width) { if (curwin->w_wcol < curwin->w_width) {
edit_putchar('$', FALSE); edit_putchar('$', FALSE);
@ -4589,22 +4586,15 @@ static int ins_complete(int c, bool enable_pum)
} else { } else {
/* Search the point of change class of multibyte character /* Search the point of change class of multibyte character
* or not a word single byte character backward. */ * or not a word single byte character backward. */
if (has_mbyte) { startcol -= utf_head_off(line, line + startcol);
int base_class; int base_class = mb_get_class(line + startcol);
int head_off; while (--startcol >= 0) {
int head_off = utf_head_off(line, line + startcol);
startcol -= utf_head_off(line, line + startcol); if (base_class != mb_get_class(line + startcol
base_class = mb_get_class(line + startcol); - head_off))
while (--startcol >= 0) { break;
head_off = utf_head_off(line, line + startcol); startcol -= head_off;
if (base_class != mb_get_class(line + startcol }
- head_off))
break;
startcol -= head_off;
}
} else
while (--startcol >= 0 && vim_iswordc(line[startcol]))
;
compl_col += ++startcol; compl_col += ++startcol;
compl_length = (int)curs_col - startcol; compl_length = (int)curs_col - startcol;
if (compl_length == 1) { if (compl_length == 1) {

View File

@ -725,9 +725,7 @@ static int command_line_execute(VimState *state, int key)
s->j = ccline.cmdpos; s->j = ccline.cmdpos;
s->i = (int)(s->xpc.xp_pattern - ccline.cmdbuff); s->i = (int)(s->xpc.xp_pattern - ccline.cmdbuff);
while (--s->j > s->i) { while (--s->j > s->i) {
if (has_mbyte) { s->j -= utf_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])) { if (vim_ispathsep(ccline.cmdbuff[s->j])) {
found = true; found = true;
break; break;
@ -747,9 +745,7 @@ static int command_line_execute(VimState *state, int key)
s->j = ccline.cmdpos - 1; s->j = ccline.cmdpos - 1;
s->i = (int)(s->xpc.xp_pattern - ccline.cmdbuff); s->i = (int)(s->xpc.xp_pattern - ccline.cmdbuff);
while (--s->j > s->i) { while (--s->j > s->i) {
if (has_mbyte) { s->j -= utf_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]) if (vim_ispathsep(ccline.cmdbuff[s->j])
#ifdef BACKSLASH_IN_FILENAME #ifdef BACKSLASH_IN_FILENAME
&& vim_strchr((const char_u *)" *?[{`$%#", ccline.cmdbuff[s->j + 1]) && vim_strchr((const char_u *)" *?[{`$%#", ccline.cmdbuff[s->j + 1])
@ -1436,19 +1432,16 @@ static int command_line_handle_key(CommandLineState *s)
} }
do { do {
--ccline.cmdpos; --ccline.cmdpos;
if (has_mbyte) { // move to first byte of char // Move to first byte of possibly multibyte char.
ccline.cmdpos -= utf_head_off(ccline.cmdbuff, ccline.cmdpos -= utf_head_off(ccline.cmdbuff,
ccline.cmdbuff + ccline.cmdpos); ccline.cmdbuff + ccline.cmdpos);
}
ccline.cmdspos -= cmdline_charsize(ccline.cmdpos); ccline.cmdspos -= cmdline_charsize(ccline.cmdpos);
} while (ccline.cmdpos > 0 } while (ccline.cmdpos > 0
&& (s->c == K_S_LEFT || s->c == K_C_LEFT && (s->c == K_S_LEFT || s->c == K_C_LEFT
|| (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL))) || (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL)))
&& ccline.cmdbuff[ccline.cmdpos - 1] != ' '); && ccline.cmdbuff[ccline.cmdpos - 1] != ' ');
if (has_mbyte) { set_cmdspos_cursor();
set_cmdspos_cursor();
}
return command_line_not_changed(s); return command_line_not_changed(s);
@ -2268,14 +2261,10 @@ getexmodeline (
if (c1 == BS || c1 == K_BS || c1 == DEL || c1 == K_DEL || c1 == K_KDEL) { if (c1 == BS || c1 == K_BS || c1 == DEL || c1 == K_DEL || c1 == K_KDEL) {
if (!GA_EMPTY(&line_ga)) { if (!GA_EMPTY(&line_ga)) {
if (has_mbyte) { p = (char_u *)line_ga.ga_data;
p = (char_u *)line_ga.ga_data; p[line_ga.ga_len] = NUL;
p[line_ga.ga_len] = NUL; len = utf_head_off(p, p + line_ga.ga_len - 1) + 1;
len = utf_head_off(p, p + line_ga.ga_len - 1) + 1; line_ga.ga_len -= len;
line_ga.ga_len -= len;
} else {
line_ga.ga_len--;
}
goto redraw; goto redraw;
} }
continue; continue;

View File

@ -2129,7 +2129,7 @@ static int vgetorpeek(int advance)
curwin->w_wcol = curwin->w_width - 1; curwin->w_wcol = curwin->w_width - 1;
col = curwin->w_cursor.col - 1; col = curwin->w_cursor.col - 1;
} }
if (has_mbyte && col > 0 && curwin->w_wcol > 0) { if (col > 0 && curwin->w_wcol > 0) {
/* Correct when the cursor is on the right halve /* Correct when the cursor is on the right halve
* of a double-wide character. */ * of a double-wide character. */
ptr = get_cursor_line_ptr(); ptr = get_cursor_line_ptr();

View File

@ -4035,24 +4035,18 @@ int incl(pos_T *lp)
int dec(pos_T *lp) int dec(pos_T *lp)
{ {
char_u *p;
lp->coladd = 0; lp->coladd = 0;
if (lp->col > 0) { // still within line if (lp->col > 0) { // still within line
lp->col--; lp->col--;
if (has_mbyte) { char_u *p = ml_get(lp->lnum);
p = ml_get(lp->lnum); lp->col -= utf_head_off(p, p + lp->col);
lp->col -= utf_head_off(p, p + lp->col);
}
return 0; return 0;
} }
if (lp->lnum > 1) { // there is a prior line if (lp->lnum > 1) { // there is a prior line
lp->lnum--; lp->lnum--;
p = ml_get(lp->lnum); char_u *p = ml_get(lp->lnum);
lp->col = (colnr_T)STRLEN(p); lp->col = (colnr_T)STRLEN(p);
if (has_mbyte) { lp->col -= utf_head_off(p, p + lp->col);
lp->col -= utf_head_off(p, p + lp->col);
}
return 1; return 1;
} }
return -1; // at start of file return -1; // at start of file

View File

@ -1646,9 +1646,7 @@ int del_bytes(colnr_T count, bool fixpos_arg, bool use_delcombine)
) { ) {
--curwin->w_cursor.col; --curwin->w_cursor.col;
curwin->w_cursor.coladd = 0; curwin->w_cursor.coladd = 0;
if (has_mbyte) curwin->w_cursor.col -= utf_head_off(oldp, oldp + curwin->w_cursor.col);
curwin->w_cursor.col -=
utf_head_off(oldp, oldp + curwin->w_cursor.col);
} }
count = oldlen - col; count = oldlen - col;
movelen = 1; movelen = 1;

View File

@ -3058,47 +3058,29 @@ size_t find_ident_at_pos(win_T *wp, linenr_T lnum, colnr_T startcol,
/* /*
* 2. Back up to start of identifier/string. * 2. Back up to start of identifier/string.
*/ */
if (has_mbyte) { /* Remember class of character under cursor. */
/* Remember class of character under cursor. */ this_class = mb_get_class(ptr + col);
this_class = mb_get_class(ptr + col); while (col > 0 && this_class != 0) {
while (col > 0 && this_class != 0) { prevcol = col - 1 - utf_head_off(ptr, ptr + col - 1);
prevcol = col - 1 - utf_head_off(ptr, ptr + col - 1); prev_class = mb_get_class(ptr + prevcol);
prev_class = mb_get_class(ptr + prevcol); if (this_class != prev_class
if (this_class != prev_class && (i == 0
&& (i == 0 || prev_class == 0
|| prev_class == 0 || (find_type & FIND_IDENT))
|| (find_type & FIND_IDENT)) )
)
break;
col = prevcol;
}
/* If we don't want just any old string, or we've found an
* identifier, stop searching. */
if (this_class > 2)
this_class = 2;
if (!(find_type & FIND_STRING) || this_class == 2)
break;
} else {
while (col > 0
&& ((i == 0
? vim_iswordc(ptr[col - 1])
: (!ascii_iswhite(ptr[col - 1])
&& (!(find_type & FIND_IDENT)
|| !vim_iswordc(ptr[col - 1]))))
))
--col;
/* If we don't want just any old string, or we've found an
* identifier, stop searching. */
if (!(find_type & FIND_STRING) || vim_iswordc(ptr[col]))
break; break;
col = prevcol;
} }
/* If we don't want just any old string, or we've found an
* identifier, stop searching. */
if (this_class > 2)
this_class = 2;
if (!(find_type & FIND_STRING) || this_class == 2)
break;
} }
if (ptr[col] == NUL || (i == 0 && ( if (ptr[col] == NUL || (i == 0 && this_class != 2)) {
has_mbyte ? this_class != 2 :
!vim_iswordc(ptr[col])))) {
/* /*
* didn't find an identifier or string * didn't find an identifier or string
*/ */

View File

@ -520,7 +520,7 @@ 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; int off;
// Avoid starting halfway through a multi-byte character. // Avoid starting halfway through a multi-byte character.

View File

@ -1819,7 +1819,7 @@ void path_fix_case(char_u *name)
int after_pathsep(const char *b, const char *p) int after_pathsep(const char *b, const char *p)
{ {
return p > b && vim_ispathsep(p[-1]) return p > b && vim_ispathsep(p[-1])
&& (!has_mbyte || utf_head_off((char_u *)b, (char_u *)p - 1) == 0); && utf_head_off((char_u *)b, (char_u *)p - 1) == 0;
} }
/* /*

View File

@ -4639,8 +4639,7 @@ static int recursive_regmatch(nfa_state_T *state, nfa_pim_T *pim, nfa_regprog_T
} }
if ((int)(reginput - regline) >= state->val) { if ((int)(reginput - regline) >= state->val) {
reginput -= state->val; reginput -= state->val;
if (has_mbyte) reginput -= utf_head_off(regline, reginput);
reginput -= utf_head_off(regline, reginput);
} else } else
reginput = regline; reginput = regline;
} }

View File

@ -3430,7 +3430,7 @@ win_line (
// Found last space before word: check for line break. // Found last space before word: check for line break.
if (wp->w_p_lbr && c0 == c && vim_isbreak(c) if (wp->w_p_lbr && c0 == c && vim_isbreak(c)
&& !vim_isbreak((int)(*ptr))) { && !vim_isbreak((int)(*ptr))) {
int mb_off = has_mbyte ? utf_head_off(line, ptr - 1) : 0; int mb_off = utf_head_off(line, ptr - 1);
char_u *p = ptr - (mb_off + 1); char_u *p = ptr - (mb_off + 1);
// TODO: is passing p for start of the line OK? // TODO: is passing p for start of the line OK?
n_extra = win_lbr_chartabsize(wp, line, p, (colnr_T)vcol, NULL) - 1; n_extra = win_lbr_chartabsize(wp, line, p, (colnr_T)vcol, NULL) - 1;

View File

@ -818,8 +818,7 @@ int searchit(
} }
} else { } else {
--pos->col; --pos->col;
if (has_mbyte if (pos->lnum <= buf->b_ml.ml_line_count) {
&& pos->lnum <= buf->b_ml.ml_line_count) {
ptr = ml_get_buf(buf, pos->lnum, FALSE); ptr = ml_get_buf(buf, pos->lnum, FALSE);
pos->col -= utf_head_off(ptr, ptr + pos->col); pos->col -= utf_head_off(ptr, ptr + pos->col);
} }
@ -1444,14 +1443,12 @@ int searchc(cmdarg_T *cap, int t_cmd)
if (t_cmd) { if (t_cmd) {
/* backup to before the character (possibly double-byte) */ /* backup to before the character (possibly double-byte) */
col -= dir; col -= dir;
if (has_mbyte) { if (dir < 0)
if (dir < 0) /* Landed on the search char which is lastc_bytelen long */
/* Landed on the search char which is lastc_bytelen long */ col += lastc_bytelen - 1;
col += lastc_bytelen - 1; else
else /* To previous char, which may be multi-byte. */
/* To previous char, which may be multi-byte. */ col -= utf_head_off(p, p + col);
col -= utf_head_off(p, p + col);
}
} }
curwin->w_cursor.col = col; curwin->w_cursor.col = col;
@ -1482,7 +1479,7 @@ pos_T *findmatch(oparg_T *oap, int initc)
static int check_prevcol(char_u *linep, int col, int ch, int *prevcol) static int check_prevcol(char_u *linep, int col, int ch, int *prevcol)
{ {
--col; --col;
if (col > 0 && has_mbyte) if (col > 0)
col -= utf_head_off(linep, linep + col); col -= utf_head_off(linep, linep + col);
if (prevcol) if (prevcol)
*prevcol = col; *prevcol = col;
@ -1794,8 +1791,7 @@ pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int64_t maxtravel)
pos.col = comment_col; pos.col = comment_col;
} else { } else {
--pos.col; --pos.col;
if (has_mbyte) pos.col -= utf_head_off(linep, linep + pos.col);
pos.col -= utf_head_off(linep, linep + pos.col);
} }
} else { /* forward search */ } else { /* forward search */
if (linep[pos.col] == NUL if (linep[pos.col] == NUL

View File

@ -1729,9 +1729,7 @@ static int syn_current_attr(
if (vim_iswordp_buf(line + current_col, syn_buf) if (vim_iswordp_buf(line + current_col, syn_buf)
&& (current_col == 0 && (current_col == 0
|| !vim_iswordp_buf(line + current_col - 1 || !vim_iswordp_buf(line + current_col - 1
- (has_mbyte - utf_head_off(line, line + current_col - 1)
? utf_head_off(line, line + current_col - 1)
: 0)
, syn_buf))) { , syn_buf))) {
syn_id = check_keyword_id(line, (int)current_col, syn_id = check_keyword_id(line, (int)current_col,
&endcol, &flags, &next_list, cur_si, &endcol, &flags, &next_list, cur_si,

View File

@ -5130,7 +5130,7 @@ file_name_in_line (
* Go one char back to ":" before "//" even when ':' is not in 'isfname'. * Go one char back to ":" before "//" even when ':' is not in 'isfname'.
*/ */
while (ptr > line) { while (ptr > line) {
if (has_mbyte && (len = (size_t)(utf_head_off(line, ptr - 1))) > 0) if ((len = (size_t)(utf_head_off(line, ptr - 1))) > 0)
ptr -= len + 1; ptr -= len + 1;
else if (vim_isfilec(ptr[-1]) else if (vim_isfilec(ptr[-1])
|| ((options & FNAME_HYP) && path_is_url((char *)ptr - 1))) || ((options & FNAME_HYP) && path_is_url((char *)ptr - 1)))