mirror of
https://github.com/neovim/neovim.git
synced 2025-09-07 03:48:18 +00:00
style: fixing minor issues noted in code review.
This commit is contained in:
@@ -2899,11 +2899,7 @@ const char * set_one_cmd_context(
|
|||||||
xp->xp_pattern = skipwhite((const char_u *)arg);
|
xp->xp_pattern = skipwhite((const char_u *)arg);
|
||||||
p = (const char *)xp->xp_pattern;
|
p = (const char *)xp->xp_pattern;
|
||||||
while (*p != NUL) {
|
while (*p != NUL) {
|
||||||
if (has_mbyte) {
|
c = utf_ptr2char((const char_u *)p);
|
||||||
c = utf_ptr2char((const char_u *)p);
|
|
||||||
} else {
|
|
||||||
c = (uint8_t)(*p);
|
|
||||||
}
|
|
||||||
if (c == '\\' && p[1] != NUL) {
|
if (c == '\\' && p[1] != NUL) {
|
||||||
p++;
|
p++;
|
||||||
} else if (c == '`') {
|
} else if (c == '`') {
|
||||||
@@ -2921,19 +2917,11 @@ const char * set_one_cmd_context(
|
|||||||
|| ascii_iswhite(c)) {
|
|| ascii_iswhite(c)) {
|
||||||
len = 0; /* avoid getting stuck when space is in 'isfname' */
|
len = 0; /* avoid getting stuck when space is in 'isfname' */
|
||||||
while (*p != NUL) {
|
while (*p != NUL) {
|
||||||
if (has_mbyte) {
|
c = utf_ptr2char((const char_u *)p);
|
||||||
c = utf_ptr2char((const char_u *)p);
|
|
||||||
} else {
|
|
||||||
c = *p;
|
|
||||||
}
|
|
||||||
if (c == '`' || vim_isfilec_or_wc(c)) {
|
if (c == '`' || vim_isfilec_or_wc(c)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (has_mbyte) {
|
len = (size_t)utfc_ptr2len((const char_u *)p);
|
||||||
len = (size_t)(*mb_ptr2len)((const char_u *)p);
|
|
||||||
} else {
|
|
||||||
len = 1;
|
|
||||||
}
|
|
||||||
MB_PTR_ADV(p);
|
MB_PTR_ADV(p);
|
||||||
}
|
}
|
||||||
if (in_quote) {
|
if (in_quote) {
|
||||||
|
@@ -3327,17 +3327,11 @@ static bool cmdline_paste(int regname, bool literally, bool remcr)
|
|||||||
|
|
||||||
/* Locate start of last word in the cmd buffer. */
|
/* Locate start of last word in the cmd buffer. */
|
||||||
for (w = ccline.cmdbuff + ccline.cmdpos; w > ccline.cmdbuff; ) {
|
for (w = ccline.cmdbuff + ccline.cmdpos; w > ccline.cmdbuff; ) {
|
||||||
if (has_mbyte) {
|
len = utf_head_off(ccline.cmdbuff, w - 1) + 1;
|
||||||
len = (*mb_head_off)(ccline.cmdbuff, w - 1) + 1;
|
if (!vim_iswordc(utf_ptr2char(w - len))) {
|
||||||
if (!vim_iswordc(utf_ptr2char(w - len))) {
|
break;
|
||||||
break;
|
|
||||||
}
|
|
||||||
w -= len;
|
|
||||||
} else {
|
|
||||||
if (!vim_iswordc(w[-1]))
|
|
||||||
break;
|
|
||||||
--w;
|
|
||||||
}
|
}
|
||||||
|
w -= len;
|
||||||
}
|
}
|
||||||
len = (int)((ccline.cmdbuff + ccline.cmdpos) - w);
|
len = (int)((ccline.cmdbuff + ccline.cmdpos) - w);
|
||||||
if (p_ic ? STRNICMP(w, arg, len) == 0 : STRNCMP(w, arg, len) == 0)
|
if (p_ic ? STRNICMP(w, arg, len) == 0 : STRNCMP(w, arg, len) == 0)
|
||||||
@@ -3838,24 +3832,13 @@ ExpandOne (
|
|||||||
|
|
||||||
// Find longest common part
|
// Find longest common part
|
||||||
if (mode == WILD_LONGEST && xp->xp_numfiles > 0) {
|
if (mode == WILD_LONGEST && xp->xp_numfiles > 0) {
|
||||||
size_t len;
|
size_t len = 0;
|
||||||
size_t mb_len = 1;
|
|
||||||
int c0;
|
|
||||||
int ci;
|
|
||||||
|
|
||||||
for (len = 0; xp->xp_files[0][len]; len += mb_len) {
|
for (size_t mb_len; xp->xp_files[0][len]; len += mb_len) {
|
||||||
if (has_mbyte) {
|
mb_len = utfc_ptr2len(&xp->xp_files[0][len]);
|
||||||
mb_len = (* mb_ptr2len)(&xp->xp_files[0][len]);
|
int c0 = utf_ptr2char(&xp->xp_files[0][len]);
|
||||||
c0 = utf_ptr2char(&xp->xp_files[0][len]);
|
for (i = 1; i < xp->xp_numfiles; i++) {
|
||||||
} else {
|
int ci = utf_ptr2char(&xp->xp_files[i][len]);
|
||||||
c0 = xp->xp_files[0][len];
|
|
||||||
}
|
|
||||||
for (i = 1; i < xp->xp_numfiles; ++i) {
|
|
||||||
if (has_mbyte) {
|
|
||||||
ci = utf_ptr2char(&xp->xp_files[i][len]);
|
|
||||||
} else {
|
|
||||||
ci = xp->xp_files[i][len];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (p_fic && (xp->xp_context == EXPAND_DIRECTORIES
|
if (p_fic && (xp->xp_context == EXPAND_DIRECTORIES
|
||||||
|| xp->xp_context == EXPAND_FILES
|
|| xp->xp_context == EXPAND_FILES
|
||||||
|
@@ -1763,10 +1763,10 @@ char_u *get_foldtext(win_T *wp, linenr_T lnum, linenr_T lnume,
|
|||||||
if (text != NULL) {
|
if (text != NULL) {
|
||||||
/* Replace unprintable characters, if there are any. But
|
/* Replace unprintable characters, if there are any. But
|
||||||
* replace a TAB with a space. */
|
* replace a TAB with a space. */
|
||||||
for (p = text; *p != NUL; ++p) {
|
for (p = text; *p != NUL; p++) {
|
||||||
int len;
|
int len = utfc_ptr2len(p);
|
||||||
|
|
||||||
if (has_mbyte && (len = (*mb_ptr2len)(p)) > 1) {
|
if (len > 1) {
|
||||||
if (!vim_isprintc(utf_ptr2char(p))) {
|
if (!vim_isprintc(utf_ptr2char(p))) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@@ -2866,15 +2866,12 @@ do_dialog (
|
|||||||
// Make the character lowercase, as chars in "hotkeys" are.
|
// Make the character lowercase, as chars in "hotkeys" are.
|
||||||
c = mb_tolower(c);
|
c = mb_tolower(c);
|
||||||
retval = 1;
|
retval = 1;
|
||||||
for (i = 0; hotkeys[i]; ++i) {
|
for (i = 0; hotkeys[i]; i++) {
|
||||||
if (has_mbyte) {
|
if (utf_ptr2char(hotkeys + i) == c) {
|
||||||
if (utf_ptr2char(hotkeys + i) == c) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
i += (*mb_ptr2len)(hotkeys + i) - 1;
|
|
||||||
} else if (hotkeys[i] == c)
|
|
||||||
break;
|
break;
|
||||||
++retval;
|
}
|
||||||
|
i += utfc_ptr2len(hotkeys + i) - 1;
|
||||||
|
retval++;
|
||||||
}
|
}
|
||||||
if (hotkeys[i])
|
if (hotkeys[i])
|
||||||
break;
|
break;
|
||||||
@@ -2906,25 +2903,13 @@ copy_char (
|
|||||||
int lowercase /* make character lower case */
|
int lowercase /* make character lower case */
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
int len;
|
if (lowercase) {
|
||||||
int c;
|
int c = mb_tolower(utf_ptr2char(from));
|
||||||
|
return utf_char2bytes(c, to);
|
||||||
if (has_mbyte) {
|
|
||||||
if (lowercase) {
|
|
||||||
c = mb_tolower(utf_ptr2char(from));
|
|
||||||
return (*mb_char2bytes)(c, to);
|
|
||||||
} else {
|
|
||||||
len = (*mb_ptr2len)(from);
|
|
||||||
memmove(to, from, (size_t)len);
|
|
||||||
return len;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (lowercase)
|
|
||||||
*to = (char_u)TOLOWER_LOC(*from);
|
|
||||||
else
|
|
||||||
*to = *from;
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
int len = utfc_ptr2len(from);
|
||||||
|
memmove(to, from, (size_t)len);
|
||||||
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define HAS_HOTKEY_LEN 30
|
#define HAS_HOTKEY_LEN 30
|
||||||
|
@@ -3639,18 +3639,12 @@ int do_join(size_t count,
|
|||||||
sumsize += currsize + spaces[t];
|
sumsize += currsize + spaces[t];
|
||||||
endcurr1 = endcurr2 = NUL;
|
endcurr1 = endcurr2 = NUL;
|
||||||
if (insert_space && currsize > 0) {
|
if (insert_space && currsize > 0) {
|
||||||
if (has_mbyte) {
|
cend = curr + currsize;
|
||||||
cend = curr + currsize;
|
MB_PTR_BACK(curr, cend);
|
||||||
|
endcurr1 = utf_ptr2char(cend);
|
||||||
|
if (cend > curr) {
|
||||||
MB_PTR_BACK(curr, cend);
|
MB_PTR_BACK(curr, cend);
|
||||||
endcurr1 = utf_ptr2char(cend);
|
endcurr2 = utf_ptr2char(cend);
|
||||||
if (cend > curr) {
|
|
||||||
MB_PTR_BACK(curr, cend);
|
|
||||||
endcurr2 = utf_ptr2char(cend);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
endcurr1 = *(curr + currsize - 1);
|
|
||||||
if (currsize > 1)
|
|
||||||
endcurr2 = *(curr + currsize - 2);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
line_breakcheck();
|
line_breakcheck();
|
||||||
|
@@ -6849,66 +6849,37 @@ int get_sts_value(void)
|
|||||||
*/
|
*/
|
||||||
void find_mps_values(int *initc, int *findc, int *backwards, int switchit)
|
void find_mps_values(int *initc, int *findc, int *backwards, int switchit)
|
||||||
{
|
{
|
||||||
char_u *ptr;
|
char_u *ptr = curbuf->b_p_mps;
|
||||||
|
|
||||||
ptr = curbuf->b_p_mps;
|
|
||||||
while (*ptr != NUL) {
|
while (*ptr != NUL) {
|
||||||
if (has_mbyte) {
|
if (utf_ptr2char(ptr) == *initc) {
|
||||||
char_u *prev;
|
if (switchit) {
|
||||||
|
*findc = *initc;
|
||||||
if (utf_ptr2char(ptr) == *initc) {
|
*initc = utf_ptr2char(ptr + utfc_ptr2len(ptr) + 1);
|
||||||
if (switchit) {
|
*backwards = true;
|
||||||
*findc = *initc;
|
} else {
|
||||||
*initc = utf_ptr2char(ptr + mb_ptr2len(ptr) + 1);
|
*findc = utf_ptr2char(ptr + utfc_ptr2len(ptr) + 1);
|
||||||
*backwards = true;
|
*backwards = false;
|
||||||
} else {
|
|
||||||
*findc = utf_ptr2char(ptr + mb_ptr2len(ptr) + 1);
|
|
||||||
*backwards = false;
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
prev = ptr;
|
return;
|
||||||
ptr += mb_ptr2len(ptr) + 1;
|
}
|
||||||
if (utf_ptr2char(ptr) == *initc) {
|
char_u *prev = ptr;
|
||||||
if (switchit) {
|
ptr += utfc_ptr2len(ptr) + 1;
|
||||||
*findc = *initc;
|
if (utf_ptr2char(ptr) == *initc) {
|
||||||
*initc = utf_ptr2char(prev);
|
if (switchit) {
|
||||||
*backwards = false;
|
*findc = *initc;
|
||||||
} else {
|
*initc = utf_ptr2char(prev);
|
||||||
*findc = utf_ptr2char(prev);
|
*backwards = false;
|
||||||
*backwards = true;
|
} else {
|
||||||
}
|
*findc = utf_ptr2char(prev);
|
||||||
return;
|
*backwards = true;
|
||||||
}
|
}
|
||||||
ptr += mb_ptr2len(ptr);
|
return;
|
||||||
} else {
|
}
|
||||||
if (*ptr == *initc) {
|
ptr += utfc_ptr2len(ptr);
|
||||||
if (switchit) {
|
if (*ptr == ',') {
|
||||||
*backwards = TRUE;
|
ptr++;
|
||||||
*findc = *initc;
|
|
||||||
*initc = ptr[2];
|
|
||||||
} else {
|
|
||||||
*backwards = FALSE;
|
|
||||||
*findc = ptr[2];
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ptr += 2;
|
|
||||||
if (*ptr == *initc) {
|
|
||||||
if (switchit) {
|
|
||||||
*backwards = FALSE;
|
|
||||||
*findc = *initc;
|
|
||||||
*initc = ptr[-2];
|
|
||||||
} else {
|
|
||||||
*backwards = TRUE;
|
|
||||||
*findc = ptr[-2];
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
++ptr;
|
|
||||||
}
|
}
|
||||||
if (*ptr == ',')
|
|
||||||
++ptr;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1103,7 +1103,7 @@ static int get_coll_element(char_u **pp)
|
|||||||
char_u *p = *pp;
|
char_u *p = *pp;
|
||||||
|
|
||||||
if (p[0] != NUL && p[1] == '.') {
|
if (p[0] != NUL && p[1] == '.') {
|
||||||
l = (*mb_ptr2len)(p + 2);
|
l = utfc_ptr2len(p + 2);
|
||||||
if (p[l + 2] == '.' && p[l + 3] == ']') {
|
if (p[l + 2] == '.' && p[l + 3] == ']') {
|
||||||
c = utf_ptr2char(p + 2);
|
c = utf_ptr2char(p + 2);
|
||||||
*pp += l + 4;
|
*pp += l + 4;
|
||||||
@@ -3444,9 +3444,7 @@ static long bt_regexec_both(char_u *line,
|
|||||||
|
|
||||||
/* If there is a "must appear" string, look for it. */
|
/* If there is a "must appear" string, look for it. */
|
||||||
if (prog->regmust != NULL) {
|
if (prog->regmust != NULL) {
|
||||||
int c;
|
int c = utf_ptr2char(prog->regmust);
|
||||||
|
|
||||||
c = utf_ptr2char(prog->regmust);
|
|
||||||
s = line + col;
|
s = line + col;
|
||||||
|
|
||||||
// This is used very often, esp. for ":global". Use two versions of
|
// This is used very often, esp. for ":global". Use two versions of
|
||||||
@@ -5441,7 +5439,7 @@ do_class:
|
|||||||
}
|
}
|
||||||
} else if (rex.reg_line_lbr && *scan == '\n' && WITH_NL(OP(p))) {
|
} else if (rex.reg_line_lbr && *scan == '\n' && WITH_NL(OP(p))) {
|
||||||
scan++;
|
scan++;
|
||||||
} else if (has_mbyte && (len = (*mb_ptr2len)(scan)) > 1) {
|
} else if ((len = utfc_ptr2len(scan)) > 1) {
|
||||||
if ((cstrchr(opnd, utf_ptr2char(scan)) == NULL) == testval) {
|
if ((cstrchr(opnd, utf_ptr2char(scan)) == NULL) == testval) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -6756,14 +6754,13 @@ static int vim_regsub_both(char_u *source, typval_T *expr, char_u *dest,
|
|||||||
// Write to buffer, if copy is set.
|
// Write to buffer, if copy is set.
|
||||||
if (func_one != NULL) {
|
if (func_one != NULL) {
|
||||||
func_one = (fptr_T)(func_one(&cc, c));
|
func_one = (fptr_T)(func_one(&cc, c));
|
||||||
|
} else if (func_all != NULL) {
|
||||||
|
func_all = (fptr_T)(func_all(&cc, c));
|
||||||
} else {
|
} else {
|
||||||
if (func_all != NULL) {
|
// just copy
|
||||||
func_all = (fptr_T)(func_all(&cc, c));
|
cc = c;
|
||||||
} else {
|
|
||||||
// just copy
|
|
||||||
cc = c;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (has_mbyte) {
|
if (has_mbyte) {
|
||||||
int totlen = mb_ptr2len(src - 1);
|
int totlen = mb_ptr2len(src - 1);
|
||||||
|
|
||||||
|
@@ -5030,11 +5030,8 @@ static int nfa_regmatch(nfa_regprog_T *prog, nfa_state_T *start,
|
|||||||
* Run for each character.
|
* Run for each character.
|
||||||
*/
|
*/
|
||||||
for (;; ) {
|
for (;; ) {
|
||||||
int curc;
|
int curc = utf_ptr2char(reginput);
|
||||||
int clen;
|
int clen = utfc_ptr2len(reginput);
|
||||||
|
|
||||||
curc = utf_ptr2char(reginput);
|
|
||||||
clen = utfc_ptr2len(reginput);
|
|
||||||
if (curc == NUL) {
|
if (curc == NUL) {
|
||||||
clen = 0;
|
clen = 0;
|
||||||
go_to_nextline = false;
|
go_to_nextline = false;
|
||||||
|
@@ -4297,12 +4297,13 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
|
|||||||
&& utf_iscomposing(utf_ptr2char(fword
|
&& utf_iscomposing(utf_ptr2char(fword
|
||||||
+ sp->ts_fcharstart))) {
|
+ sp->ts_fcharstart))) {
|
||||||
sp->ts_score -= SCORE_SUBST - SCORE_SUBCOMP;
|
sp->ts_score -= SCORE_SUBST - SCORE_SUBCOMP;
|
||||||
} else if (!soundfold && slang->sl_has_map
|
} else if (
|
||||||
&& similar_chars(slang,
|
!soundfold
|
||||||
utf_ptr2char(tword + sp->ts_twordlen
|
&& slang->sl_has_map
|
||||||
- sp->ts_tcharlen),
|
&& similar_chars(
|
||||||
utf_ptr2char(fword +
|
slang,
|
||||||
sp->ts_fcharstart))) {
|
utf_ptr2char(tword + sp->ts_twordlen - sp->ts_tcharlen),
|
||||||
|
utf_ptr2char(fword + sp->ts_fcharstart))) {
|
||||||
// For a similar character adjust score from
|
// For a similar character adjust score from
|
||||||
// SCORE_SUBST to SCORE_SIMILAR.
|
// SCORE_SUBST to SCORE_SIMILAR.
|
||||||
sp->ts_score -= SCORE_SUBST - SCORE_SIMILAR;
|
sp->ts_score -= SCORE_SUBST - SCORE_SIMILAR;
|
||||||
@@ -4520,21 +4521,22 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
|
|||||||
PROF_STORE(sp->ts_state)
|
PROF_STORE(sp->ts_state)
|
||||||
sp->ts_state = STATE_REP_INI;
|
sp->ts_state = STATE_REP_INI;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// When characters are identical, swap won't do anything.
|
// When characters are identical, swap won't do anything.
|
||||||
// Also get here if the second char is not a word character.
|
// Also get here if the second char is not a word character.
|
||||||
if (c == c2) {
|
if (c == c2) {
|
||||||
PROF_STORE(sp->ts_state)
|
PROF_STORE(sp->ts_state)
|
||||||
sp->ts_state = STATE_SWAP3;
|
sp->ts_state = STATE_SWAP3;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (c2 != NUL && TRY_DEEPER(su, stack, depth, SCORE_SWAP)) {
|
if (c2 != NUL && TRY_DEEPER(su, stack, depth, SCORE_SWAP)) {
|
||||||
go_deeper(stack, depth, SCORE_SWAP);
|
go_deeper(stack, depth, SCORE_SWAP);
|
||||||
#ifdef DEBUG_TRIEWALK
|
#ifdef DEBUG_TRIEWALK
|
||||||
sprintf(changename[depth], "%.*s-%s: swap %c and %c",
|
snprintf(changename[depth], sizeof(changename[0]),
|
||||||
sp->ts_twordlen, tword, fword + sp->ts_fidx,
|
"%.*s-%s: swap %c and %c",
|
||||||
c, c2);
|
sp->ts_twordlen, tword, fword + sp->ts_fidx,
|
||||||
|
c, c2);
|
||||||
#endif
|
#endif
|
||||||
PROF_STORE(sp->ts_state)
|
PROF_STORE(sp->ts_state)
|
||||||
sp->ts_state = STATE_UNSWAP;
|
sp->ts_state = STATE_UNSWAP;
|
||||||
@@ -4652,21 +4654,13 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
|
|||||||
sp->ts_state = STATE_UNROT3L;
|
sp->ts_state = STATE_UNROT3L;
|
||||||
++depth;
|
++depth;
|
||||||
p = fword + sp->ts_fidx;
|
p = fword + sp->ts_fidx;
|
||||||
if (has_mbyte) {
|
n = MB_CPTR2LEN(p);
|
||||||
n = MB_CPTR2LEN(p);
|
c = utf_ptr2char(p);
|
||||||
c = utf_ptr2char(p);
|
fl = MB_CPTR2LEN(p + n);
|
||||||
fl = MB_CPTR2LEN(p + n);
|
fl += MB_CPTR2LEN(p + n + fl);
|
||||||
fl += MB_CPTR2LEN(p + n + fl);
|
memmove(p, p + n, fl);
|
||||||
memmove(p, p + n, fl);
|
utf_char2bytes(c, p + fl);
|
||||||
mb_char2bytes(c, p + fl);
|
stack[depth].ts_fidxtry = sp->ts_fidx + n + fl;
|
||||||
stack[depth].ts_fidxtry = sp->ts_fidx + n + fl;
|
|
||||||
} else {
|
|
||||||
c = *p;
|
|
||||||
*p = p[1];
|
|
||||||
p[1] = p[2];
|
|
||||||
p[2] = c;
|
|
||||||
stack[depth].ts_fidxtry = sp->ts_fidx + 3;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
PROF_STORE(sp->ts_state)
|
PROF_STORE(sp->ts_state)
|
||||||
sp->ts_state = STATE_REP_INI;
|
sp->ts_state = STATE_REP_INI;
|
||||||
|
Reference in New Issue
Block a user