Merge pull request #4688 from ZyX-I/clint-checks

Add check for boolean operators placement
This commit is contained in:
Justin M. Keyes 2016-05-01 17:30:38 -04:00
commit d542de4a76
39 changed files with 567 additions and 612 deletions

View File

@ -2305,6 +2305,13 @@ def CheckSpacing(filename, clean_lines, linenum, nesting_state, error):
if match: if match:
error(filename, linenum, 'whitespace/operators', 3, error(filename, linenum, 'whitespace/operators', 3,
'Missing spaces around %s' % match.group(1)) 'Missing spaces around %s' % match.group(1))
# Boolean operators should be placed on the next line.
if Search(r'(?:&&|\|\|)$', line):
error(filename, linenum, 'whitespace/operators', 4,
'Boolean operator should be placed on the same line as the start '
'of its right operand')
# We allow no-spaces around << when used like this: 10<<20, but # We allow no-spaces around << when used like this: 10<<20, but
# not otherwise (particularly, not when used as streams) # not otherwise (particularly, not when used as streams)
# Also ignore using ns::operator<<; # Also ignore using ns::operator<<;

View File

@ -57,8 +57,8 @@ void window_set_cursor(Window window, ArrayOf(Integer, 2) pos, Error *err)
{ {
win_T *win = find_window_by_handle(window, err); win_T *win = find_window_by_handle(window, err);
if (pos.size != 2 || pos.items[0].type != kObjectTypeInteger || if (pos.size != 2 || pos.items[0].type != kObjectTypeInteger
pos.items[1].type != kObjectTypeInteger) { || pos.items[1].type != kObjectTypeInteger) {
api_set_error(err, api_set_error(err,
Validation, Validation,
_("Argument \"pos\" must be a [row, col] array")); _("Argument \"pos\" must be a [row, col] array"));

View File

@ -1367,8 +1367,8 @@ int arabic_shape(int c, int *ccp, int *c1p, int prev_c, int prev_c1,
int prev_laa = A_firstc_laa(prev_c, prev_c1); int prev_laa = A_firstc_laa(prev_c, prev_c1);
if (curr_laa) { if (curr_laa) {
if (A_is_valid(prev_c) && !A_is_f(shape_c) && !A_is_s(shape_c) && if (A_is_valid(prev_c) && !A_is_f(shape_c) && !A_is_s(shape_c)
!prev_laa) { && !prev_laa) {
curr_c = chg_c_laa2f(curr_laa); curr_c = chg_c_laa2f(curr_laa);
} else { } else {
curr_c = chg_c_laa2i(curr_laa); curr_c = chg_c_laa2i(curr_laa);
@ -1454,19 +1454,19 @@ static bool A_is_harakat(int c)
// (alphabet/number/punctuation) // (alphabet/number/punctuation)
static bool A_is_iso(int c) static bool A_is_iso(int c)
{ {
return (c >= a_HAMZA && c <= a_GHAIN) || return ((c >= a_HAMZA && c <= a_GHAIN)
(c >= a_TATWEEL && c <= a_HAMZA_BELOW) || || (c >= a_TATWEEL && c <= a_HAMZA_BELOW)
c == a_MINI_ALEF; || c == a_MINI_ALEF);
} }
// A_is_formb returns true if 'c' is an Arabic 10646-1 FormB character. // A_is_formb returns true if 'c' is an Arabic 10646-1 FormB character.
// (alphabet/number/punctuation) // (alphabet/number/punctuation)
static bool A_is_formb(int c) static bool A_is_formb(int c)
{ {
return (c >= a_s_FATHATAN && c <= a_s_DAMMATAN) || return ((c >= a_s_FATHATAN && c <= a_s_DAMMATAN)
c == a_s_KASRATAN || || c == a_s_KASRATAN
(c >= a_s_FATHA && c <= a_f_LAM_ALEF) || || (c >= a_s_FATHA && c <= a_f_LAM_ALEF)
c == a_BYTE_ORDER_MARK; || c == a_BYTE_ORDER_MARK);
} }
// A_is_ok returns true if 'c' is an Arabic 10646 (8859-6 or Form-B). // A_is_ok returns true if 'c' is an Arabic 10646 (8859-6 or Form-B).

View File

@ -407,10 +407,9 @@ close_buffer (
buf->b_nwindows = nwindows; buf->b_nwindows = nwindows;
buf_freeall(buf, (del_buf ? BFA_DEL : 0) + (wipe_buf ? BFA_WIPE : 0)); buf_freeall(buf, (del_buf ? BFA_DEL : 0) + (wipe_buf ? BFA_WIPE : 0));
if ( if (win_valid(win) && win->w_buffer == buf) {
win_valid(win) && win->w_buffer = NULL; // make sure we don't use the buffer now
win->w_buffer == buf) }
win->w_buffer = NULL; /* make sure we don't use the buffer now */
/* Autocommands may have deleted the buffer. */ /* Autocommands may have deleted the buffer. */
if (!buf_valid(buf)) if (!buf_valid(buf))
@ -1340,8 +1339,8 @@ buflist_new (
/* We can use inode numbers when the file exists. Works better /* We can use inode numbers when the file exists. Works better
* for hard links. */ * for hard links. */
FileID file_id; FileID file_id;
bool file_id_valid = (sfname != NULL && bool file_id_valid = (sfname != NULL
os_fileid((char *)sfname, &file_id)); && os_fileid((char *)sfname, &file_id));
if (ffname != NULL && !(flags & BLN_DUMMY) if (ffname != NULL && !(flags & BLN_DUMMY)
&& (buf = buflist_findname_file_id(ffname, &file_id, && (buf = buflist_findname_file_id(ffname, &file_id,
file_id_valid)) != NULL) { file_id_valid)) != NULL) {

View File

@ -4424,11 +4424,10 @@ static int ins_complete(int c, bool enable_pum)
prefix = (char_u *)""; prefix = (char_u *)"";
STRCPY((char *)compl_pattern, prefix); STRCPY((char *)compl_pattern, prefix);
(void)quote_meta(compl_pattern + STRLEN(prefix), (void)quote_meta(compl_pattern + STRLEN(prefix),
line + compl_col, compl_length); line + compl_col, compl_length);
} else if (--startcol < 0 || } else if (--startcol < 0
!vim_iswordp(mb_prevptr(line, line + startcol + 1)) || !vim_iswordp(mb_prevptr(line, line + startcol + 1))) {
) { // Match any word of at least two chars
/* Match any word of at least two chars */
compl_pattern = vim_strsave((char_u *)"\\<\\k\\k"); compl_pattern = vim_strsave((char_u *)"\\<\\k\\k");
compl_col += curs_col; compl_col += curs_col;
compl_length = 0; compl_length = 0;
@ -6684,8 +6683,8 @@ bool in_cinkeys(int keytyped, int when, bool line_is_empty)
} else if (*look == 'e') { } else if (*look == 'e') {
if (try_match && keytyped == 'e' && curwin->w_cursor.col >= 4) { if (try_match && keytyped == 'e' && curwin->w_cursor.col >= 4) {
p = get_cursor_line_ptr(); p = get_cursor_line_ptr();
if (skipwhite(p) == p + curwin->w_cursor.col - 4 && if (skipwhite(p) == p + curwin->w_cursor.col - 4
STRNCMP(p + curwin->w_cursor.col - 4, "else", 4) == 0) { && STRNCMP(p + curwin->w_cursor.col - 4, "else", 4) == 0) {
return true; return true;
} }
} }
@ -7384,17 +7383,16 @@ static bool ins_bs(int c, int mode, int *inserted_space_p)
* can't backup past starting point unless 'backspace' > 1 * can't backup past starting point unless 'backspace' > 1
* can backup to a previous line if 'backspace' == 0 * can backup to a previous line if 'backspace' == 0
*/ */
if ( bufempty() if (bufempty()
|| ( || (!revins_on
!revins_on && && ((curwin->w_cursor.lnum == 1 && curwin->w_cursor.col == 0)
((curwin->w_cursor.lnum == 1 && curwin->w_cursor.col == 0) || (!can_bs(BS_START)
|| (!can_bs(BS_START) && (arrow_used
&& (arrow_used || (curwin->w_cursor.lnum == Insstart_orig.lnum
|| (curwin->w_cursor.lnum == Insstart_orig.lnum && curwin->w_cursor.col <= Insstart_orig.col)))
&& curwin->w_cursor.col <= Insstart_orig.col))) || (!can_bs(BS_INDENT) && !arrow_used && ai_col > 0
|| (!can_bs(BS_INDENT) && !arrow_used && ai_col > 0 && curwin->w_cursor.col <= ai_col)
&& curwin->w_cursor.col <= ai_col) || (!can_bs(BS_EOL) && curwin->w_cursor.col == 0)))) {
|| (!can_bs(BS_EOL) && curwin->w_cursor.col == 0)))) {
vim_beep(BO_BS); vim_beep(BO_BS);
return false; return false;
} }
@ -7640,14 +7638,14 @@ static bool ins_bs(int c, int mode, int *inserted_space_p)
if (revins_on && gchar_cursor() == NUL) if (revins_on && gchar_cursor() == NUL)
break; break;
} }
/* Just a single backspace?: */ // Just a single backspace?:
if (mode == BACKSPACE_CHAR) if (mode == BACKSPACE_CHAR) {
break; break;
} while ( }
revins_on || } while (revins_on
(curwin->w_cursor.col > mincol || (curwin->w_cursor.col > mincol
&& (curwin->w_cursor.lnum != Insstart_orig.lnum && (curwin->w_cursor.lnum != Insstart_orig.lnum
|| curwin->w_cursor.col != Insstart_orig.col))); || curwin->w_cursor.col != Insstart_orig.col)));
} }
did_backspace = true; did_backspace = true;
} }

View File

@ -2266,8 +2266,8 @@ static void set_var_lval(lval_T *lp, char_u *endp, typval_T *rettv, int copy, ch
if (get_var_tv(lp->ll_name, (int)STRLEN(lp->ll_name), if (get_var_tv(lp->ll_name, (int)STRLEN(lp->ll_name),
&tv, &di, true, false) == OK) { &tv, &di, true, false) == OK) {
if ((di == NULL if ((di == NULL
|| (!var_check_ro(di->di_flags, lp->ll_name, false) && || (!var_check_ro(di->di_flags, lp->ll_name, false)
!tv_check_lock(di->di_tv.v_lock, lp->ll_name, false))) && !tv_check_lock(di->di_tv.v_lock, lp->ll_name, false)))
&& tv_op(&tv, rettv, op) == OK) { && tv_op(&tv, rettv, op) == OK) {
set_var(lp->ll_name, &tv, false); set_var(lp->ll_name, &tv, false);
} }
@ -7655,8 +7655,9 @@ static void assert_bool(typval_T *argvars, bool is_true)
int error = (int)false; int error = (int)false;
garray_T ga; garray_T ga;
if ((argvars[0].v_type != VAR_NUMBER || if ((argvars[0].v_type != VAR_NUMBER
(get_tv_number_chk(&argvars[0], &error) == 0) == is_true || error) || (get_tv_number_chk(&argvars[0], &error) == 0) == is_true
|| error)
&& (argvars[0].v_type != VAR_SPECIAL && (argvars[0].v_type != VAR_SPECIAL
|| (argvars[0].vval.v_special || (argvars[0].vval.v_special
!= (SpecialVarValue) (is_true != (SpecialVarValue) (is_true
@ -15140,12 +15141,12 @@ static void do_sort_uniq(typval_T *argvars, typval_T *rettv, bool sort)
EMSG2(_(e_listarg), sort ? "sort()" : "uniq()"); EMSG2(_(e_listarg), sort ? "sort()" : "uniq()");
} else { } else {
l = argvars[0].vval.v_list; l = argvars[0].vval.v_list;
if (l == NULL || if (l == NULL
tv_check_lock(l->lv_lock, || tv_check_lock(l->lv_lock,
(char_u *)(sort (char_u *)(sort
? N_("sort() argument") ? N_("sort() argument")
: N_("uniq() argument")), : N_("uniq() argument")),
true)) { true)) {
return; return;
} }
rettv->vval.v_list = l; rettv->vval.v_list = l;
@ -19265,9 +19266,10 @@ void ex_function(exarg_T *eap)
if ((p[0] == 'a' && (!ASCII_ISALPHA(p[1]) || p[1] == 'p')) if ((p[0] == 'a' && (!ASCII_ISALPHA(p[1]) || p[1] == 'p'))
|| (p[0] == 'i' || (p[0] == 'i'
&& (!ASCII_ISALPHA(p[1]) || (p[1] == 'n' && (!ASCII_ISALPHA(p[1]) || (p[1] == 'n'
&& (!ASCII_ISALPHA(p[2]) || && (!ASCII_ISALPHA(p[2])
(p[2] == 's')))))) || (p[2] == 's')))))) {
skip_until = vim_strsave((char_u *)"."); skip_until = vim_strsave((char_u *)".");
}
// Check for ":python <<EOF", ":lua <<EOF", etc. // Check for ":python <<EOF", ":lua <<EOF", etc.
arg = skipwhite(skiptowhite(p)); arg = skipwhite(skiptowhite(p));
@ -19534,11 +19536,12 @@ trans_function_name (
*pp = end; *pp = end;
} else { } else {
if (!skip && !(flags & TFN_QUIET) && (fdp == NULL if (!skip && !(flags & TFN_QUIET) && (fdp == NULL
|| lv.ll_dict == NULL || || lv.ll_dict == NULL
fdp->fd_newkey == NULL)) || fdp->fd_newkey == NULL)) {
EMSG(_(e_funcref)); EMSG(_(e_funcref));
else } else {
*pp = end; *pp = end;
}
name = NULL; name = NULL;
} }
goto theend; goto theend;
@ -20438,9 +20441,9 @@ call_user_func (
--RedrawingDisabled; --RedrawingDisabled;
/* when the function was aborted because of an error, return -1 */ // when the function was aborted because of an error, return -1
if ((did_emsg && if ((did_emsg
(fp->uf_flags & FC_ABORT)) || rettv->v_type == VAR_UNKNOWN) { && (fp->uf_flags & FC_ABORT)) || rettv->v_type == VAR_UNKNOWN) {
clear_tv(rettv); clear_tv(rettv);
rettv->v_type = VAR_NUMBER; rettv->v_type = VAR_NUMBER;
rettv->vval.v_number = -1; rettv->vval.v_number = -1;

View File

@ -187,9 +187,9 @@ int process_wait(Process *proc, int ms, Queue *events) FUNC_ATTR_NONNULL_ARG(1)
// being freed) before we have a chance to get the status. // being freed) before we have a chance to get the status.
proc->refcount++; proc->refcount++;
LOOP_PROCESS_EVENTS_UNTIL(proc->loop, events, ms, LOOP_PROCESS_EVENTS_UNTIL(proc->loop, events, ms,
// Until... // Until...
got_int || // interrupted by the user got_int // interrupted by the user
proc->refcount == 1); // job exited || proc->refcount == 1); // job exited
// we'll assume that a user frantically hitting interrupt doesn't like // we'll assume that a user frantically hitting interrupt doesn't like
// the current job. Signal that it has to be killed. // the current job. Signal that it has to be killed.

View File

@ -650,13 +650,13 @@ void ex_retab(exarg_T *eap)
num_tabs += num_spaces / new_ts; num_tabs += num_spaces / new_ts;
num_spaces -= (num_spaces / new_ts) * new_ts; num_spaces -= (num_spaces / new_ts) * new_ts;
} }
if (curbuf->b_p_et || got_tab || if (curbuf->b_p_et || got_tab
(num_spaces + num_tabs < len)) { || (num_spaces + num_tabs < len)) {
if (did_undo == FALSE) { if (did_undo == false) {
did_undo = TRUE; did_undo = true;
if (u_save((linenr_T)(lnum - 1), if (u_save((linenr_T)(lnum - 1),
(linenr_T)(lnum + 1)) == FAIL) { (linenr_T)(lnum + 1)) == FAIL) {
new_line = NULL; /* flag out-of-memory */ new_line = NULL; // flag out-of-memory
break; break;
} }
} }
@ -1623,15 +1623,14 @@ int do_write(exarg_T *eap)
} }
} }
/* // Writing to the current file is not allowed in readonly mode
* Writing to the current file is not allowed in readonly mode // and a file name is required.
* and a file name is required. // "nofile" and "nowrite" buffers cannot be written implicitly either.
* "nofile" and "nowrite" buffers cannot be written implicitly either. if (!other && (bt_dontwrite_msg(curbuf)
*/ || check_fname() == FAIL
if (!other && ( || check_readonly(&eap->forceit, curbuf))) {
bt_dontwrite_msg(curbuf) ||
check_fname() == FAIL || check_readonly(&eap->forceit, curbuf)))
goto theend; goto theend;
}
if (!other) { if (!other) {
ffname = curbuf->b_ffname; ffname = curbuf->b_ffname;
@ -2258,16 +2257,15 @@ do_ecmd (
delbuf_msg(new_name); /* frees new_name */ delbuf_msg(new_name); /* frees new_name */
goto theend; goto theend;
} }
if (buf == curbuf) /* already in new buffer */ if (buf == curbuf) { // already in new buffer
auto_buf = TRUE; auto_buf = true;
else { } else {
/* // <VN> We could instead free the synblock
* <VN> We could instead free the synblock // and re-attach to buffer, perhaps.
* and re-attach to buffer, perhaps. if (curwin->w_buffer != NULL
*/ && curwin->w_s == &(curwin->w_buffer->b_s)) {
if (curwin->w_buffer != NULL &&
curwin->w_s == &(curwin->w_buffer->b_s))
curwin->w_s = &(buf->b_s); curwin->w_s = &(buf->b_s);
}
curwin->w_buffer = buf; curwin->w_buffer = buf;
curbuf = buf; curbuf = buf;
@ -2294,11 +2292,11 @@ do_ecmd (
curwin->w_pcmark.lnum = 1; curwin->w_pcmark.lnum = 1;
curwin->w_pcmark.col = 0; curwin->w_pcmark.col = 0;
} else { /* !other_file */ } else { // !other_file
if ( if ((flags & ECMD_ADDBUF)
(flags & ECMD_ADDBUF) || || check_fname() == FAIL) {
check_fname() == FAIL)
goto theend; goto theend;
}
oldbuf = (flags & ECMD_OLDBUF); oldbuf = (flags & ECMD_OLDBUF);
} }
@ -5818,13 +5816,14 @@ void set_context_in_sign_cmd(expand_T *xp, char_u *arg)
switch (cmd_idx) switch (cmd_idx)
{ {
case SIGNCMD_DEFINE: case SIGNCMD_DEFINE:
if (STRNCMP(last, "texthl", p - last) == 0 || if (STRNCMP(last, "texthl", p - last) == 0
STRNCMP(last, "linehl", p - last) == 0) || STRNCMP(last, "linehl", p - last) == 0) {
xp->xp_context = EXPAND_HIGHLIGHT; xp->xp_context = EXPAND_HIGHLIGHT;
else if (STRNCMP(last, "icon", p - last) == 0) } else if (STRNCMP(last, "icon", p - last) == 0) {
xp->xp_context = EXPAND_FILES; xp->xp_context = EXPAND_FILES;
else } else {
xp->xp_context = EXPAND_NOTHING; xp->xp_context = EXPAND_NOTHING;
}
break; break;
case SIGNCMD_PLACE: case SIGNCMD_PLACE:
if (STRNCMP(last, "name", p - last) == 0) if (STRNCMP(last, "name", p - last) == 0)

View File

@ -432,14 +432,12 @@ dbg_parsearg (
bp = &DEBUGGY(gap, gap->ga_len); bp = &DEBUGGY(gap, gap->ga_len);
/* Find "func" or "file". */ // Find "func" or "file".
if (STRNCMP(p, "func", 4) == 0) if (STRNCMP(p, "func", 4) == 0) {
bp->dbg_type = DBG_FUNC; bp->dbg_type = DBG_FUNC;
else if (STRNCMP(p, "file", 4) == 0) } else if (STRNCMP(p, "file", 4) == 0) {
bp->dbg_type = DBG_FILE; bp->dbg_type = DBG_FILE;
else if ( } else if (gap != &prof_ga && STRNCMP(p, "here", 4) == 0) {
gap != &prof_ga &&
STRNCMP(p, "here", 4) == 0) {
if (curbuf->b_ffname == NULL) { if (curbuf->b_ffname == NULL) {
EMSG(_(e_noname)); EMSG(_(e_noname));
return FAIL; return FAIL;
@ -452,16 +450,15 @@ dbg_parsearg (
} }
p = skipwhite(p + 4); p = skipwhite(p + 4);
/* Find optional line number. */ // Find optional line number.
if (here) if (here) {
bp->dbg_lnum = curwin->w_cursor.lnum; bp->dbg_lnum = curwin->w_cursor.lnum;
else if ( } else if (gap != &prof_ga && ascii_isdigit(*p)) {
gap != &prof_ga &&
ascii_isdigit(*p)) {
bp->dbg_lnum = getdigits_long(&p); bp->dbg_lnum = getdigits_long(&p);
p = skipwhite(p); p = skipwhite(p);
} else } else {
bp->dbg_lnum = 0; bp->dbg_lnum = 0;
}
/* Find the function or file name. Don't accept a function name with (). */ /* Find the function or file name. Don't accept a function name with (). */
if ((!here && *p == NUL) if ((!here && *p == NUL)
@ -700,14 +697,13 @@ debuggy_find (
/* Skip entries that are not useful or are for a line that is beyond /* Skip entries that are not useful or are for a line that is beyond
* an already found breakpoint. */ * an already found breakpoint. */
bp = &DEBUGGY(gap, i); bp = &DEBUGGY(gap, i);
if (((bp->dbg_type == DBG_FILE) == file && ( if (((bp->dbg_type == DBG_FILE) == file
gap == &prof_ga || && (gap == &prof_ga
(bp->dbg_lnum > after && (lnum == 0 || bp->dbg_lnum < lnum))))) { || (bp->dbg_lnum > after
/* && (lnum == 0 || bp->dbg_lnum < lnum))))) {
* Save the value of got_int and reset it. We don't want a // Save the value of got_int and reset it. We don't want a
* previous interruption cancel matching, only hitting CTRL-C // previous interruption cancel matching, only hitting CTRL-C
* while matching should abort it. // while matching should abort it.
*/
prev_got_int = got_int; prev_got_int = got_int;
got_int = FALSE; got_int = FALSE;
if (vim_regexec_prog(&bp->dbg_prog, false, name, (colnr_T)0)) { if (vim_regexec_prog(&bp->dbg_prog, false, name, (colnr_T)0)) {
@ -1937,8 +1933,8 @@ void ex_listdo(exarg_T *eap)
if (buf != NULL) { if (buf != NULL) {
goto_buffer(eap, DOBUF_FIRST, FORWARD, buf->b_fnum); goto_buffer(eap, DOBUF_FIRST, FORWARD, buf->b_fnum);
} }
} else if (eap->cmdidx == CMD_cdo || eap->cmdidx == CMD_ldo || } else if (eap->cmdidx == CMD_cdo || eap->cmdidx == CMD_ldo
eap->cmdidx == CMD_cfdo || eap->cmdidx == CMD_lfdo) { || eap->cmdidx == CMD_cfdo || eap->cmdidx == CMD_lfdo) {
qf_size = qf_get_size(eap); qf_size = qf_get_size(eap);
assert(eap->line1 >= 0); assert(eap->line1 >= 0);
if (qf_size == 0 || (size_t)eap->line1 > qf_size) { if (qf_size == 0 || (size_t)eap->line1 > qf_size) {
@ -2040,8 +2036,8 @@ void ex_listdo(exarg_T *eap)
} }
} }
if (eap->cmdidx == CMD_cdo || eap->cmdidx == CMD_ldo || if (eap->cmdidx == CMD_cdo || eap->cmdidx == CMD_ldo
eap->cmdidx == CMD_cfdo || eap->cmdidx == CMD_lfdo) { || eap->cmdidx == CMD_cfdo || eap->cmdidx == CMD_lfdo) {
assert(i >= 0); assert(i >= 0);
if ((size_t)i >= qf_size || i >= eap->line2) { if ((size_t)i >= qf_size || i >= eap->line2) {
break; break;

View File

@ -1654,16 +1654,15 @@ static char_u * do_one_cmd(char_u **cmdlinep,
* If we got a line, but no command, then go to the line. * If we got a line, but no command, then go to the line.
* If we find a '|' or '\n' we set ea.nextcmd. * If we find a '|' or '\n' we set ea.nextcmd.
*/ */
if (*ea.cmd == NUL || *ea.cmd == '"' || if (*ea.cmd == NUL || *ea.cmd == '"'
(ea.nextcmd = check_nextcmd(ea.cmd)) != NULL) { || (ea.nextcmd = check_nextcmd(ea.cmd)) != NULL) {
/* // strange vi behaviour:
* strange vi behaviour: // ":3" jumps to line 3
* ":3" jumps to line 3 // ":3|..." prints line 3
* ":3|..." prints line 3 // ":|" prints current line
* ":|" prints current line if (ea.skip) { // skip this if inside :if
*/
if (ea.skip) /* skip this if inside :if */
goto doend; goto doend;
}
if (*ea.cmd == '|' || (exmode_active && ea.line1 != ea.line2)) { if (*ea.cmd == '|' || (exmode_active && ea.line1 != ea.line2)) {
ea.cmdidx = CMD_print; ea.cmdidx = CMD_print;
ea.argt = RANGE | COUNT | TRLBAR; ea.argt = RANGE | COUNT | TRLBAR;
@ -2824,10 +2823,11 @@ set_one_cmd_context (
} }
} }
/* no arguments allowed */ // no arguments allowed
if (!(ea.argt & EXTRA) && *arg != NUL && if (!(ea.argt & EXTRA) && *arg != NUL
vim_strchr((char_u *)"|\"", *arg) == NULL) && vim_strchr((char_u *)"|\"", *arg) == NULL) {
return NULL; return NULL;
}
/* Find start of last argument (argument just before cursor): */ /* Find start of last argument (argument just before cursor): */
p = buff; p = buff;
@ -4772,14 +4772,15 @@ static void uc_list(char_u *name, size_t name_len)
IObuff[len++] = ' '; IObuff[len++] = ' ';
} while (len < 11); } while (len < 11);
/* Address Type */ // Address Type
for (j = 0; addr_type_complete[j].expand != -1; ++j) for (j = 0; addr_type_complete[j].expand != -1; j++) {
if (addr_type_complete[j].expand != ADDR_LINES && if (addr_type_complete[j].expand != ADDR_LINES
addr_type_complete[j].expand == cmd->uc_addr_type) { && addr_type_complete[j].expand == cmd->uc_addr_type) {
STRCPY(IObuff + len, addr_type_complete[j].name); STRCPY(IObuff + len, addr_type_complete[j].name);
len += (int)STRLEN(IObuff + len); len += (int)STRLEN(IObuff + len);
break; break;
} }
}
do { do {
IObuff[len++] = ' '; IObuff[len++] = ' ';
@ -5654,12 +5655,13 @@ static void ex_quit(exarg_T *eap)
wp = curwin; wp = curwin;
} }
apply_autocmds(EVENT_QUITPRE, NULL, NULL, FALSE, curbuf); apply_autocmds(EVENT_QUITPRE, NULL, NULL, false, curbuf);
/* Refuse to quit when locked or when the buffer in the last window is // Refuse to quit when locked or when the buffer in the last window is
* being closed (can only happen in autocommands). */ // being closed (can only happen in autocommands).
if (curbuf_locked() || if (curbuf_locked()
(wp->w_buffer->b_nwindows == 1 && wp->w_buffer->b_closing)) || (wp->w_buffer->b_nwindows == 1 && wp->w_buffer->b_closing)) {
return; return;
}
/* /*
@ -9185,16 +9187,15 @@ static char *get_view_file(int c)
*/ */
int put_eol(FILE *fd) int put_eol(FILE *fd)
{ {
if ( #if defined(USE_CRNL) && defined(MKSESSION_NL)
#ifdef USE_CRNL if ((!mksession_nl && putc('\r', fd) < 0) || putc('\n', fd) < 0) {
( #elif defined(USE_CRNL)
# ifdef MKSESSION_NL if (putc('\r', fd) < 0 || putc('\n', fd) < 0) {
!mksession_nl && #else
# endif if (putc('\n', fd) < 0) {
(putc('\r', fd) < 0)) ||
#endif #endif
(putc('\n', fd) < 0))
return FAIL; return FAIL;
}
return OK; return OK;
} }

View File

@ -403,14 +403,15 @@ char_u *get_exception_string(void *value, int type, char_u *cmdname, int *should
&& (p[3] == ':' && (p[3] == ':'
|| (ascii_isdigit(p[3]) || (ascii_isdigit(p[3])
&& p[4] == ':')))))) { && p[4] == ':')))))) {
if (*p == NUL || p == mesg) if (*p == NUL || p == mesg) {
STRCAT(val, mesg); /* 'E123' missing or at beginning */ STRCAT(val, mesg); // 'E123' missing or at beginning
else { } else {
/* '"filename" E123: message text' */ // '"filename" E123: message text'
if (mesg[0] != '"' || p-2 < &mesg[1] || if (mesg[0] != '"' || p-2 < &mesg[1]
p[-2] != '"' || p[-1] != ' ') || p[-2] != '"' || p[-1] != ' ') {
/* "E123:" is part of the file name. */ // "E123:" is part of the file name.
continue; continue;
}
STRCAT(val, p); STRCAT(val, p);
p[-2] = NUL; p[-2] = NUL;
@ -1565,22 +1566,21 @@ void ex_endtry(exarg_T *eap)
void *rettv = NULL; void *rettv = NULL;
struct condstack *cstack = eap->cstack; struct condstack *cstack = eap->cstack;
if (cstack->cs_trylevel <= 0 || cstack->cs_idx < 0) if (cstack->cs_trylevel <= 0 || cstack->cs_idx < 0) {
eap->errmsg = (char_u *)N_("E602: :endtry without :try"); eap->errmsg = (char_u *)N_("E602: :endtry without :try");
else { } else {
/* // Don't do something after an error, interrupt or throw in the try
* Don't do something after an error, interrupt or throw in the try // block, catch clause, or finally clause preceding this ":endtry" or
* block, catch clause, or finally clause preceding this ":endtry" or // when an error or interrupt occurred after a ":continue", ":break",
* when an error or interrupt occurred after a ":continue", ":break", // ":return", or ":finish" in a try block or catch clause preceding this
* ":return", or ":finish" in a try block or catch clause preceding this // ":endtry" or when the try block never got active (because of an
* ":endtry" or when the try block never got active (because of an // inactive surrounding conditional or after an error or interrupt or
* inactive surrounding conditional or after an error or interrupt or // throw) or when there is a surrounding conditional and it has been
* throw) or when there is a surrounding conditional and it has been // made inactive by a ":continue", ":break", ":return", or ":finish" in
* made inactive by a ":continue", ":break", ":return", or ":finish" in // the finally clause. The latter case need not be tested since then
* the finally clause. The latter case need not be tested since then // anything pending has already been discarded.
* anything pending has already been discarded. */ skip = (did_emsg || got_int || did_throw
skip = did_emsg || got_int || did_throw || || !(cstack->cs_flags[cstack->cs_idx] & CSF_TRUE));
!(cstack->cs_flags[cstack->cs_idx] & CSF_TRUE);
if (!(cstack->cs_flags[cstack->cs_idx] & CSF_TRY)) { if (!(cstack->cs_flags[cstack->cs_idx] & CSF_TRY)) {
eap->errmsg = get_end_emsg(cstack); eap->errmsg = get_end_emsg(cstack);

View File

@ -624,8 +624,8 @@ static int command_line_execute(VimState *state, int key)
// CTRL-\ e doesn't work when obtaining an expression, unless it // CTRL-\ e doesn't work when obtaining an expression, unless it
// is in a mapping. // is in a mapping.
if (s->c != Ctrl_N && s->c != Ctrl_G && (s->c != 'e' if (s->c != Ctrl_N && s->c != Ctrl_G && (s->c != 'e'
|| (ccline.cmdfirstc == '=' && || (ccline.cmdfirstc == '='
KeyTyped))) { && KeyTyped))) {
vungetc(s->c); vungetc(s->c);
s->c = Ctrl_BSL; s->c = Ctrl_BSL;
} else if (s->c == 'e') { } else if (s->c == 'e') {

View File

@ -100,8 +100,9 @@ static char_u toF_Xor_X_(int c)
case F_HE : case F_HE :
tempc = _HE; tempc = _HE;
if (p_ri && if (p_ri
(curwin->w_cursor.col + 1 < (colnr_T)STRLEN(get_cursor_line_ptr()))) { && (curwin->w_cursor.col + 1
< (colnr_T)STRLEN(get_cursor_line_ptr()))) {
inc_cursor(); inc_cursor();
if (F_is_TyB_TyC_TyD(SRC_EDT, AT_CURSOR)) { if (F_is_TyB_TyC_TyD(SRC_EDT, AT_CURSOR)) {
tempc = _HE_; tempc = _HE_;
@ -526,8 +527,8 @@ static void chg_l_toXor_X(void)
{ {
char_u tempc; char_u tempc;
if ((curwin->w_cursor.col != 0) && if ((curwin->w_cursor.col != 0)
(curwin->w_cursor.col + 1 == (colnr_T)STRLEN(get_cursor_line_ptr()))) { && (curwin->w_cursor.col + 1 == (colnr_T)STRLEN(get_cursor_line_ptr()))) {
return; return;
} }
@ -680,17 +681,17 @@ int fkmap(int c)
} }
} }
if ((c < 0x100) && if ((c < 0x100)
(isalpha(c) || && (isalpha(c)
(c == '&') || || (c == '&')
(c == '^') || || (c == '^')
(c == ';') || || (c == ';')
(c == '\'') || || (c == '\'')
(c == ',') || || (c == ',')
(c == '[') || || (c == '[')
(c == ']') || || (c == ']')
(c == '{') || || (c == '{')
(c == '}'))) { || (c == '}'))) {
chg_r_to_Xor_X_(); chg_r_to_Xor_X_();
} }

View File

@ -605,13 +605,14 @@ readfile (
* Don't do this for a "nofile" or "nowrite" buffer type. */ * Don't do this for a "nofile" or "nowrite" buffer type. */
if (!bt_dontwrite(curbuf)) { if (!bt_dontwrite(curbuf)) {
check_need_swap(newfile); check_need_swap(newfile);
if (!read_stdin && (curbuf != old_curbuf if (!read_stdin
|| (using_b_ffname && (old_b_ffname != curbuf->b_ffname)) && (curbuf != old_curbuf
|| (using_b_fname && || (using_b_ffname && (old_b_ffname != curbuf->b_ffname))
(old_b_fname != curbuf->b_fname)))) { || (using_b_fname && (old_b_fname != curbuf->b_fname)))) {
EMSG(_(e_auchangedbuf)); EMSG(_(e_auchangedbuf));
if (!read_buffer) if (!read_buffer) {
close(fd); close(fd);
}
return FAIL; return FAIL;
} }
#ifdef UNIX #ifdef UNIX
@ -4369,8 +4370,8 @@ char *modname(const char *fname, const char *ext, bool prepend_dot)
// (we need the full path in case :cd is used). // (we need the full path in case :cd is used).
if (fname == NULL || *fname == NUL) { if (fname == NULL || *fname == NUL) {
retval = xmalloc(MAXPATHL + extlen + 3); // +3 for PATHSEP, "_" (Win), NUL retval = xmalloc(MAXPATHL + extlen + 3); // +3 for PATHSEP, "_" (Win), NUL
if (os_dirname((char_u *)retval, MAXPATHL) == FAIL || if (os_dirname((char_u *)retval, MAXPATHL) == FAIL
(fnamelen = strlen(retval)) == 0) { || (fnamelen = strlen(retval)) == 0) {
xfree(retval); xfree(retval);
return NULL; return NULL;
} }

View File

@ -2669,13 +2669,14 @@ do_map (
p = keys; p = keys;
do_backslash = (vim_strchr(p_cpo, CPO_BSLASH) == NULL); do_backslash = (vim_strchr(p_cpo, CPO_BSLASH) == NULL);
while (*p && (maptype == 1 || !ascii_iswhite(*p))) { while (*p && (maptype == 1 || !ascii_iswhite(*p))) {
if ((p[0] == Ctrl_V || (do_backslash && p[0] == '\\')) && if ((p[0] == Ctrl_V || (do_backslash && p[0] == '\\')) && p[1] != NUL) {
p[1] != NUL) p++; // skip CTRL-V or backslash
++p; /* skip CTRL-V or backslash */ }
++p; p++;
} }
if (*p != NUL) if (*p != NUL) {
*p++ = NUL; *p++ = NUL;
}
p = skipwhite(p); p = skipwhite(p);
rhs = p; rhs = p;

View File

@ -2190,18 +2190,19 @@ int mch_print_init(prt_settings_T *psettings, char_u *jobname, int forceit)
mbfont_opts[OPT_MBFONT_BOLDOBLIQUE].strlen); mbfont_opts[OPT_MBFONT_BOLDOBLIQUE].strlen);
} }
/* Check if need to use Courier for ASCII code range, and if so pick up // Check if need to use Courier for ASCII code range, and if so pick up
* the encoding to use */ // the encoding to use
prt_use_courier = mbfont_opts[OPT_MBFONT_USECOURIER].present && prt_use_courier = (
(TOLOWER_ASC(mbfont_opts[OPT_MBFONT_USECOURIER].string[0]) mbfont_opts[OPT_MBFONT_USECOURIER].present
== 'y'); && (TOLOWER_ASC(mbfont_opts[OPT_MBFONT_USECOURIER].string[0]) == 'y'));
if (prt_use_courier) { if (prt_use_courier) {
/* Use national ASCII variant unless ASCII wanted */ // Use national ASCII variant unless ASCII wanted
if (mbfont_opts[OPT_MBFONT_ASCII].present && if (mbfont_opts[OPT_MBFONT_ASCII].present
(TOLOWER_ASC(mbfont_opts[OPT_MBFONT_ASCII].string[0]) == 'y')) && (TOLOWER_ASC(mbfont_opts[OPT_MBFONT_ASCII].string[0]) == 'y')) {
prt_ascii_encoding = "ascii"; prt_ascii_encoding = "ascii";
else } else {
prt_ascii_encoding = prt_ps_mbfonts[cmap].ascii_enc; prt_ascii_encoding = prt_ps_mbfonts[cmap].ascii_enc;
}
} }
prt_ps_font = &prt_ps_mb_font; prt_ps_font = &prt_ps_mb_font;
@ -3029,10 +3030,10 @@ int mch_print_text_out(char_u *p, size_t len)
prt_text_run += char_width; prt_text_run += char_width;
prt_pos_x += char_width; prt_pos_x += char_width;
/* The downside of fp - use relative error on right margin check */ // The downside of fp - use relative error on right margin check
next_pos = prt_pos_x + prt_char_width; next_pos = prt_pos_x + prt_char_width;
need_break = (next_pos > prt_right_margin) && need_break = ((next_pos > prt_right_margin)
((next_pos - prt_right_margin) > (prt_right_margin*1e-5)); && ((next_pos - prt_right_margin) > (prt_right_margin * 1e-5)));
if (need_break) if (need_break)
prt_flush_buffer(); prt_flush_buffer();

View File

@ -2282,15 +2282,14 @@ int get_c_indent(void)
* location for b_ind_open_extra. * location for b_ind_open_extra.
*/ */
if (start_brace == BRACE_IN_COL0) { /* '{' is in column 0 */ if (start_brace == BRACE_IN_COL0) { // '{' is in column 0
amount = curbuf->b_ind_open_left_imag; amount = curbuf->b_ind_open_left_imag;
lookfor_cpp_namespace = TRUE; lookfor_cpp_namespace = true;
} else if (start_brace == BRACE_AT_START && } else if (start_brace == BRACE_AT_START
lookfor_cpp_namespace) { /* '{' is at start */ && lookfor_cpp_namespace) { // '{' is at start
lookfor_cpp_namespace = true;
lookfor_cpp_namespace = TRUE;
} else { } else {
if (start_brace == BRACE_AT_END) { /* '{' is at end of line */ if (start_brace == BRACE_AT_END) { // '{' is at end of line
amount += curbuf->b_ind_open_imag; amount += curbuf->b_ind_open_imag;
l = skipwhite(get_cursor_line_ptr()); l = skipwhite(get_cursor_line_ptr());

View File

@ -786,9 +786,8 @@ void ml_recover(void)
if (fname == NULL) /* When there is no file name */ if (fname == NULL) /* When there is no file name */
fname = (char_u *)""; fname = (char_u *)"";
len = (int)STRLEN(fname); len = (int)STRLEN(fname);
if (len >= 4 && if (len >= 4
STRNICMP(fname + len - 4, ".s", 2) && STRNICMP(fname + len - 4, ".s", 2) == 0
== 0
&& vim_strchr((char_u *)"UVWuvw", fname[len - 2]) != NULL && vim_strchr((char_u *)"UVWuvw", fname[len - 2]) != NULL
&& ASCII_ISALPHA(fname[len - 1])) { && ASCII_ISALPHA(fname[len - 1])) {
directly = TRUE; directly = TRUE;

View File

@ -1570,39 +1570,31 @@ static void msg_puts_display(char_u *str, int maxlen, int attr, int recurse)
int wrap; int wrap;
int did_last_char; int did_last_char;
did_wait_return = FALSE; did_wait_return = false;
while ((maxlen < 0 || (int)(s - str) < maxlen) && *s != NUL) { while ((maxlen < 0 || (int)(s - str) < maxlen) && *s != NUL) {
/* // We are at the end of the screen line when:
* We are at the end of the screen line when: // - When outputting a newline.
* - When outputting a newline. // - When outputting a character in the last column.
* - When outputting a character in the last column. if (!recurse && msg_row >= Rows - 1
*/ && (*s == '\n' || (cmdmsg_rl
if (!recurse && msg_row >= Rows - 1 && (*s == '\n' || ( ? (msg_col <= 1
cmdmsg_rl || (*s == TAB && msg_col <= 7)
? ( || (has_mbyte
msg_col <= 1 && (*mb_ptr2cells)(s) > 1
|| (*s == TAB && msg_col <= 7) && msg_col <= 2))
|| (has_mbyte && : (msg_col + t_col >= Columns - 1
(*mb_ptr2cells)(s) > 1 && || (*s == TAB
msg_col <= 2) && msg_col + t_col >= ((Columns - 1) & ~7))
) || (has_mbyte
: && (*mb_ptr2cells)(s) > 1
(msg_col + t_col >= Columns - 1 && msg_col + t_col >= Columns - 2))))) {
|| (*s == TAB && msg_col + // The screen is scrolled up when at the last row (some terminals
t_col >= ((Columns - 1) & ~7)) // scroll automatically, some don't. To avoid problems we scroll
|| (has_mbyte && // ourselves).
(*mb_ptr2cells)(s) > 1 if (t_col > 0) {
&& msg_col + t_col >= // output postponed text
Columns - 2)
)))) {
/*
* The screen is scrolled up when at the last row (some terminals
* scroll automatically, some don't. To avoid problems we scroll
* ourselves).
*/
if (t_col > 0)
/* output postponed text */
t_puts(&t_col, t_s, s, attr); t_puts(&t_col, t_s, s, attr);
}
/* When no more prompt and no more room, truncate here */ /* When no more prompt and no more room, truncate here */
if (msg_no_more && lines_left == 0) if (msg_no_more && lines_left == 0)
@ -1709,18 +1701,15 @@ static void msg_puts_display(char_u *str, int maxlen, int attr, int recurse)
cw = 1; cw = 1;
l = 1; l = 1;
} }
/* When drawing from right to left or when a double-wide character // When drawing from right to left or when a double-wide character
* doesn't fit, draw a single character here. Otherwise collect // doesn't fit, draw a single character here. Otherwise collect
* characters and draw them all at once later. */ // characters and draw them all at once later.
if ( if (cmdmsg_rl || (cw > 1 && msg_col + t_col >= Columns - 1)) {
cmdmsg_rl if (l > 1) {
||
(cw > 1 && msg_col + t_col >= Columns - 1)
) {
if (l > 1)
s = screen_puts_mbyte(s, l, attr) - 1; s = screen_puts_mbyte(s, l, attr) - 1;
else } else {
msg_screen_putchar(*s, attr); msg_screen_putchar(*s, attr);
}
} else { } else {
/* postpone this character until later */ /* postpone this character until later */
if (t_col == 0) if (t_col == 0)
@ -3382,8 +3371,8 @@ int vim_vsnprintf(char *str, size_t str_m, const char *fmt, va_list ap,
// leave negative numbers for sprintf to handle, to // leave negative numbers for sprintf to handle, to
// avoid handling tricky cases like (short int)-32768 // avoid handling tricky cases like (short int)-32768
} else if (alternate_form) { } else if (alternate_form) {
if (arg_sign != 0 && (fmt_spec == 'x' || fmt_spec == 'X' || if (arg_sign != 0 && (fmt_spec == 'x' || fmt_spec == 'X'
fmt_spec == 'b' || fmt_spec == 'B')) { || fmt_spec == 'b' || fmt_spec == 'B')) {
tmp[str_arg_l++] = '0'; tmp[str_arg_l++] = '0';
tmp[str_arg_l++] = fmt_spec; tmp[str_arg_l++] = fmt_spec;
} }

View File

@ -204,15 +204,12 @@ open_line (
else else
lead_len = 0; lead_len = 0;
if (dir == FORWARD) { if (dir == FORWARD) {
/* // Skip preprocessor directives, unless they are
* Skip preprocessor directives, unless they are // recognised as comments.
* recognised as comments. if (lead_len == 0 && ptr[0] == '#') {
*/ while (ptr[0] == '#' && curwin->w_cursor.lnum > 1) {
if (
lead_len == 0 &&
ptr[0] == '#') {
while (ptr[0] == '#' && curwin->w_cursor.lnum > 1)
ptr = ml_get(--curwin->w_cursor.lnum); ptr = ml_get(--curwin->w_cursor.lnum);
}
newindent = get_indent(); newindent = get_indent();
} }
if (flags & OPENLINE_DO_COM) if (flags & OPENLINE_DO_COM)
@ -296,28 +293,26 @@ open_line (
&& cin_is_cinword(ptr)) && cin_is_cinword(ptr))
did_si = TRUE; did_si = TRUE;
} }
} else { /* dir == BACKWARD */ } else { // dir == BACKWARD
/* // Skip preprocessor directives, unless they are
* Skip preprocessor directives, unless they are // recognised as comments.
* recognised as comments. if (lead_len == 0 && ptr[0] == '#') {
*/ bool was_backslashed = false;
if (
lead_len == 0 &&
ptr[0] == '#') {
int was_backslashed = FALSE;
while ((ptr[0] == '#' || was_backslashed) && while ((ptr[0] == '#' || was_backslashed)
curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) { && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) {
if (*ptr && ptr[STRLEN(ptr) - 1] == '\\') if (*ptr && ptr[STRLEN(ptr) - 1] == '\\') {
was_backslashed = TRUE; was_backslashed = true;
else } else {
was_backslashed = FALSE; was_backslashed = false;
}
ptr = ml_get(++curwin->w_cursor.lnum); ptr = ml_get(++curwin->w_cursor.lnum);
} }
if (was_backslashed) if (was_backslashed) {
newindent = 0; /* Got to end of file */ newindent = 0; // Got to end of file
else } else {
newindent = get_indent(); newindent = get_indent();
}
} }
p = skipwhite(ptr); p = skipwhite(ptr);
if (*p == '}') /* if line starts with '}': do indent */ if (*p == '}') /* if line starts with '}': do indent */
@ -667,16 +662,12 @@ open_line (
did_si = can_si = FALSE; did_si = can_si = FALSE;
} else if (comment_end != NULL) { } else if (comment_end != NULL) {
/* // We have finished a comment, so we don't use the leader.
* We have finished a comment, so we don't use the leader. // If this was a C-comment and 'ai' or 'si' is set do a normal
* If this was a C-comment and 'ai' or 'si' is set do a normal // indent to align with the line containing the start of the
* indent to align with the line containing the start of the // comment.
* comment. if (comment_end[0] == '*' && comment_end[1] == '/'
*/ && (curbuf->b_p_ai || do_si)) {
if (comment_end[0] == '*' && comment_end[1] == '/' &&
(curbuf->b_p_ai
|| do_si
)) {
old_cursor = curwin->w_cursor; old_cursor = curwin->w_cursor;
curwin->w_cursor.col = (colnr_T)(comment_end - saved_line); curwin->w_cursor.col = (colnr_T)(comment_end - saved_line);
if ((pos = findmatch(NULL, NUL)) != NULL) { if ((pos = findmatch(NULL, NUL)) != NULL) {

View File

@ -535,9 +535,9 @@ static linenr_T find_longest_lnum(void)
// Calculate maximum for horizontal scrollbar. Check for reasonable // Calculate maximum for horizontal scrollbar. Check for reasonable
// line numbers, topline and botline can be invalid when displaying is // line numbers, topline and botline can be invalid when displaying is
// postponed. // postponed.
if (curwin->w_topline <= curwin->w_cursor.lnum && if (curwin->w_topline <= curwin->w_cursor.lnum
curwin->w_botline > curwin->w_cursor.lnum && && curwin->w_botline > curwin->w_cursor.lnum
curwin->w_botline <= curbuf->b_ml.ml_line_count + 1) { && curwin->w_botline <= curbuf->b_ml.ml_line_count + 1) {
long max = 0; long max = 0;
// Use maximum of all visible lines. Remember the lnum of the // Use maximum of all visible lines. Remember the lnum of the

View File

@ -1010,12 +1010,9 @@ scrollup (
int byfold /* true: count a closed fold as one line */ int byfold /* true: count a closed fold as one line */
) )
{ {
if ( if ((byfold && hasAnyFolding(curwin))
(byfold && hasAnyFolding(curwin)) || curwin->w_p_diff) {
|| // count each sequence of folded lines as one logical line
curwin->w_p_diff
) {
/* count each sequence of folded lines as one logical line */
linenr_T lnum = curwin->w_topline; linenr_T lnum = curwin->w_topline;
while (line_count--) { while (line_count--) {
if (curwin->w_topfill > 0) if (curwin->w_topfill > 0)

View File

@ -419,8 +419,8 @@ void msgpack_rpc_validate(uint64_t *response_id,
return; return;
} }
if ((type == kMessageTypeRequest && req->via.array.size != 4) || if ((type == kMessageTypeRequest && req->via.array.size != 4)
(type == kMessageTypeNotification && req->via.array.size != 3)) { || (type == kMessageTypeNotification && req->via.array.size != 3)) {
api_set_error(err, Validation, _("Request array size should be 4 (request) " api_set_error(err, Validation, _("Request array size should be 4 (request) "
"or 3 (notification)")); "or 3 (notification)"));
return; return;

View File

@ -569,36 +569,33 @@ static bool normal_need_aditional_char(NormalState *s)
static bool normal_need_redraw_mode_message(NormalState *s) static bool normal_need_redraw_mode_message(NormalState *s)
{ {
return ( return (
(
// 'showmode' is set and messages can be printed // 'showmode' is set and messages can be printed
p_smd && msg_silent == 0 ((p_smd && msg_silent == 0
// must restart insert mode(ctrl+o or ctrl+l) or we just entered visual // must restart insert mode(ctrl+o or ctrl+l) or we just entered visual
// mode // mode
&& (restart_edit != 0 || (VIsual_active && (restart_edit != 0 || (VIsual_active
&& s->old_pos.lnum == curwin->w_cursor.lnum && s->old_pos.lnum == curwin->w_cursor.lnum
&& s->old_pos.col == curwin->w_cursor.col)) && s->old_pos.col == curwin->w_cursor.col))
// command-line must be cleared or redrawn // command-line must be cleared or redrawn
&& (clear_cmdline || redraw_cmdline) && (clear_cmdline || redraw_cmdline)
// some message was printed or scrolled // some message was printed or scrolled
&& (msg_didout || (msg_didany && msg_scroll)) && (msg_didout || (msg_didany && msg_scroll))
// it is fine to remove the current message // it is fine to remove the current message
&& !msg_nowait && !msg_nowait
// the command was the result of direct user input and not a mapping // the command was the result of direct user input and not a mapping
&& KeyTyped && KeyTyped)
) // must restart insert mode, not in visual mode and error message is
|| // being shown
// must restart insert mode, not in visual mode and error message is || (restart_edit != 0 && !VIsual_active && msg_scroll
// being shown && emsg_on_display))
(restart_edit != 0 && !VIsual_active && (msg_scroll && emsg_on_display)) // no register was used
) && s->oa.regname == 0
// no register was used && !(s->ca.retval & CA_COMMAND_BUSY)
&& s->oa.regname == 0 && stuff_empty()
&& !(s->ca.retval & CA_COMMAND_BUSY) && typebuf_typed()
&& stuff_empty() && emsg_silent == 0
&& typebuf_typed() && !did_wait_return
&& emsg_silent == 0 && s->oa.op_type == OP_NOP);
&& !did_wait_return
&& s->oa.op_type == OP_NOP;
} }
static void normal_redraw_mode_message(NormalState *s) static void normal_redraw_mode_message(NormalState *s)
@ -4060,16 +4057,15 @@ static void nv_zet(cmdarg_T *cap)
} }
dozet: dozet:
if ( // "zf" and "zF" are always an operator, "zd", "zo", "zO", "zc"
/* "zf" and "zF" are always an operator, "zd", "zo", "zO", "zc" // and "zC" only in Visual mode. "zj" and "zk" are motion
* and "zC" only in Visual mode. "zj" and "zk" are motion // commands. */
* commands. */ if (cap->nchar != 'f' && cap->nchar != 'F'
cap->nchar != 'f' && cap->nchar != 'F' && !(VIsual_active && vim_strchr((char_u *)"dcCoO", cap->nchar))
&& !(VIsual_active && vim_strchr((char_u *)"dcCoO", cap->nchar)) && cap->nchar != 'j' && cap->nchar != 'k'
&& cap->nchar != 'j' && cap->nchar != 'k' && checkclearop(cap->oap)) {
&&
checkclearop(cap->oap))
return; return;
}
/* /*
* For "z+", "z<CR>", "zt", "z.", "zz", "z^", "z-", "zb": * For "z+", "z<CR>", "zt", "z.", "zz", "z^", "z-", "zb":
@ -5817,14 +5813,11 @@ static void nv_replace(cmdarg_T *cap)
return; return;
} }
/* // Replacing with a TAB is done by edit() when it is complicated because
* Replacing with a TAB is done by edit() when it is complicated because // 'expandtab' or 'smarttab' is set. CTRL-V TAB inserts a literal TAB.
* 'expandtab' or 'smarttab' is set. CTRL-V TAB inserts a literal TAB. // Other characters are done below to avoid problems with things like
* Other characters are done below to avoid problems with things like // CTRL-V 048 (for edit() this would be R CTRL-V 0 ESC).
* CTRL-V 048 (for edit() this would be R CTRL-V 0 ESC). if (had_ctrl_v != Ctrl_V && cap->nchar == '\t' && (curbuf->b_p_et || p_sta)) {
*/
if (had_ctrl_v != Ctrl_V && cap->nchar == '\t' &&
(curbuf->b_p_et || p_sta)) {
stuffnumReadbuff(cap->count1); stuffnumReadbuff(cap->count1);
stuffcharReadbuff('R'); stuffcharReadbuff('R');
stuffcharReadbuff('\t'); stuffcharReadbuff('\t');

View File

@ -2046,8 +2046,8 @@ void op_insert(oparg_T *oap, long count1)
// When a tab was inserted, and the characters in front of the tab // When a tab was inserted, and the characters in front of the tab
// have been converted to a tab as well, the column of the cursor // have been converted to a tab as well, the column of the cursor
// might have actually been reduced, so need to adjust here. */ // might have actually been reduced, so need to adjust here. */
if (t1.lnum == curbuf->b_op_start_orig.lnum && if (t1.lnum == curbuf->b_op_start_orig.lnum
lt(curbuf->b_op_start_orig, t1)) { && lt(curbuf->b_op_start_orig, t1)) {
oap->start = curbuf->b_op_start_orig; oap->start = curbuf->b_op_start_orig;
} }
@ -3189,11 +3189,9 @@ void adjust_cursor_eol(void)
*/ */
int preprocs_left(void) int preprocs_left(void)
{ {
return return ((curbuf->b_p_si && !curbuf->b_p_cin)
(curbuf->b_p_si && !curbuf->b_p_cin) || || (curbuf->b_p_cin && in_cinkeys('#', ' ', true)
(curbuf->b_p_cin && in_cinkeys('#', ' ', TRUE) && curbuf->b_ind_hash_comment == 0));
&& curbuf->b_ind_hash_comment == 0)
;
} }
/* Return the character name of the register with the given number */ /* Return the character name of the register with the given number */
@ -4399,8 +4397,7 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1)
if (dobin if (dobin
&& dohex && dohex
&& !((col > 0 && !((col > 0
&& (ptr[col] == 'X' || && (ptr[col] == 'X' || ptr[col] == 'x')
ptr[col] == 'x')
&& ptr[col - 1] == '0' && ptr[col - 1] == '0'
&& ascii_isxdigit(ptr[col + 1])))) { && ascii_isxdigit(ptr[col + 1])))) {
// In case of binary/hexadecimal pattern overlap match, rescan // In case of binary/hexadecimal pattern overlap match, rescan
@ -4414,17 +4411,15 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1)
if ((dohex if ((dohex
&& col > 0 && col > 0
&& (ptr[col] == 'X' && (ptr[col] == 'X' || ptr[col] == 'x')
|| ptr[col] == 'x')
&& ptr[col - 1] == '0' && ptr[col - 1] == '0'
&& ascii_isxdigit(ptr[col + 1])) || && ascii_isxdigit(ptr[col + 1]))
(dobin || (dobin
&& col > 0 && col > 0
&& (ptr[col] == 'B' && (ptr[col] == 'B' || ptr[col] == 'b')
|| ptr[col] == 'b') && ptr[col - 1] == '0'
&& ptr[col - 1] == '0' && ascii_isbdigit(ptr[col + 1]))) {
&& ascii_isbdigit(ptr[col + 1]))) { // Found hexadecimal or binary number, move to its start.
// Found hexadecimal or binary number, move to its start.
col--; col--;
} else { } else {
// Search forward and then backward to find the start of number. // Search forward and then backward to find the start of number.
@ -4445,8 +4440,8 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1)
} }
if (visual) { if (visual) {
while (ptr[col] != NUL && length > 0 && !ascii_isdigit(ptr[col]) && while (ptr[col] != NUL && length > 0 && !ascii_isdigit(ptr[col])
!(doalp && ASCII_ISALPHA(ptr[col]))) { && !(doalp && ASCII_ISALPHA(ptr[col]))) {
col++; col++;
length--; length--;
} }
@ -4608,8 +4603,7 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1)
*ptr++ = '0'; *ptr++ = '0';
length--; length--;
} }
if (pre == 'b' || pre == 'B' || if (pre == 'b' || pre == 'B' || pre == 'x' || pre == 'X') {
pre == 'x' || pre == 'X') {
*ptr++ = pre; *ptr++ = pre;
length--; length--;
} }
@ -5035,8 +5029,8 @@ static void str_to_reg(yankreg_T *y_ptr, MotionType yank_type,
} }
if (yank_type == kMTUnknown) { if (yank_type == kMTUnknown) {
yank_type = ((str_list || yank_type = ((str_list
(len > 0 && (str[len - 1] == NL || str[len - 1] == CAR))) || (len > 0 && (str[len - 1] == NL || str[len - 1] == CAR)))
? kMTLineWise : kMTCharWise); ? kMTLineWise : kMTCharWise);
} }

View File

@ -4782,9 +4782,10 @@ showoptions (
option_value2string(p, opt_flags); option_value2string(p, opt_flags);
len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1; len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
} }
if ((len <= INC - GAP && run == 1) || if ((len <= INC - GAP && run == 1)
(len > INC - GAP && run == 2)) || (len > INC - GAP && run == 2)) {
items[item_count++] = p; items[item_count++] = p;
}
} }
} }
@ -4973,18 +4974,15 @@ int makeset(FILE *fd, int opt_flags, int local_only)
} else { /* P_STRING */ } else { /* P_STRING */
int do_endif = FALSE; int do_endif = FALSE;
/* Don't set 'syntax' and 'filetype' again if the value is // Don't set 'syntax' and 'filetype' again if the value is
* already right, avoids reloading the syntax file. */ // already right, avoids reloading the syntax file.
if ( if (p->indir == PV_SYN || p->indir == PV_FT) {
p->indir == PV_SYN
||
p->indir == PV_FT
) {
if (fprintf(fd, "if &%s != '%s'", p->fullname, if (fprintf(fd, "if &%s != '%s'", p->fullname,
*(char_u **)(varp)) < 0 *(char_u **)(varp)) < 0
|| put_eol(fd) < 0) || put_eol(fd) < 0) {
return FAIL; return FAIL;
do_endif = TRUE; }
do_endif = true;
} }
if (put_setstring(fd, cmd, p->fullname, (char_u **)varp, if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
(p->flags & P_EXPAND) != 0) == FAIL) (p->flags & P_EXPAND) != 0) == FAIL)
@ -6225,10 +6223,10 @@ int has_format_option(int x)
/// 'shortmess' contains 'a' and "x" is present in SHM_ALL_ABBREVIATIONS. /// 'shortmess' contains 'a' and "x" is present in SHM_ALL_ABBREVIATIONS.
bool shortmess(int x) bool shortmess(int x)
{ {
return p_shm != NULL && return (p_shm != NULL
(vim_strchr(p_shm, x) != NULL && (vim_strchr(p_shm, x) != NULL
|| (vim_strchr(p_shm, 'a') != NULL || (vim_strchr(p_shm, 'a') != NULL
&& vim_strchr((char_u *)SHM_ALL_ABBREVIATIONS, x) != NULL)); && vim_strchr((char_u *)SHM_ALL_ABBREVIATIONS, x) != NULL)));
} }
/* /*

View File

@ -175,9 +175,10 @@ bool os_can_exe(const char_u *name, char_u **abspath)
FUNC_ATTR_NONNULL_ARG(1) FUNC_ATTR_NONNULL_ARG(1)
{ {
// If it's an absolute or relative path don't need to use $PATH. // If it's an absolute or relative path don't need to use $PATH.
if (path_is_absolute_path(name) || if (path_is_absolute_path(name)
(name[0] == '.' && (name[1] == '/' || || (name[0] == '.'
(name[1] == '.' && name[2] == '/')))) { && (name[1] == '/'
|| (name[1] == '.' && name[2] == '/')))) {
if (is_executable(name)) { if (is_executable(name)) {
if (abspath != NULL) { if (abspath != NULL) {
*abspath = save_absolute_path(name); *abspath = save_absolute_path(name);

View File

@ -403,9 +403,9 @@ static int push_event_key(uint8_t *buf, int maxlen)
// Check if there's pending input // Check if there's pending input
static bool input_ready(void) static bool input_ready(void)
{ {
return typebuf_was_filled || // API call filled typeahead return (typebuf_was_filled // API call filled typeahead
rbuffer_size(input_buffer) || // Input buffer filled || rbuffer_size(input_buffer) // Input buffer filled
pending_events(); // Events must be processed || pending_events()); // Events must be processed
} }
// Exit because of an input read error. // Exit because of an input read error.

View File

@ -1301,9 +1301,10 @@ void addfile(
FileInfo file_info; FileInfo file_info;
// if the file/dir/link doesn't exist, may not add it // if the file/dir/link doesn't exist, may not add it
if (!(flags & EW_NOTFOUND) && if (!(flags & EW_NOTFOUND)
((flags & EW_ALLLINKS) ? && ((flags & EW_ALLLINKS)
!os_fileinfo_link((char *)f, &file_info) : !os_file_exists(f))) { ? !os_fileinfo_link((char *)f, &file_info)
: !os_file_exists(f))) {
return; return;
} }
@ -1383,9 +1384,9 @@ void simplify_filename(char_u *filename)
--p; /* strip preceding path separator */ --p; /* strip preceding path separator */
STRMOVE(p, tail); STRMOVE(p, tail);
} }
} else if (p[0] == '.' && p[1] == '.' && } else if (p[0] == '.' && p[1] == '.'
(vim_ispathsep(p[2]) || p[2] == NUL)) { && (vim_ispathsep(p[2]) || p[2] == NUL)) {
/* Skip to after ".." or "../" or "..///". */ // Skip to after ".." or "../" or "..///".
tail = p + 2; tail = p + 2;
while (vim_ispathsep(*tail)) while (vim_ispathsep(*tail))
mb_ptr_adv(tail); mb_ptr_adv(tail);
@ -2016,8 +2017,8 @@ int match_suffix(char_u *fname)
break; break;
} }
} else { } else {
if (fnamelen >= setsuflen && if (fnamelen >= setsuflen
fnamencmp(suf_buf, fname + fnamelen - setsuflen, setsuflen) == 0) { && fnamencmp(suf_buf, fname + fnamelen - setsuflen, setsuflen) == 0) {
break; break;
} }
setsuflen = 0; setsuflen = 0;

View File

@ -2757,8 +2757,8 @@ void ex_cc(exarg_T *eap)
// For cdo and ldo commands, jump to the nth valid error. // For cdo and ldo commands, jump to the nth valid error.
// For cfdo and lfdo commands, jump to the nth valid file entry. // For cfdo and lfdo commands, jump to the nth valid file entry.
if (eap->cmdidx == CMD_cdo || eap->cmdidx == CMD_ldo || if (eap->cmdidx == CMD_cdo || eap->cmdidx == CMD_ldo
eap->cmdidx == CMD_cfdo || eap->cmdidx == CMD_lfdo) { || eap->cmdidx == CMD_cfdo || eap->cmdidx == CMD_lfdo) {
size_t n; size_t n;
if (eap->addr_count > 0) { if (eap->addr_count > 0) {
assert(eap->line1 >= 0); assert(eap->line1 >= 0);
@ -2801,9 +2801,9 @@ void ex_cnext(exarg_T *eap)
} }
int errornr; int errornr;
if (eap->addr_count > 0 && if (eap->addr_count > 0
(eap->cmdidx != CMD_cdo && eap->cmdidx != CMD_ldo && && (eap->cmdidx != CMD_cdo && eap->cmdidx != CMD_ldo
eap->cmdidx != CMD_cfdo && eap->cmdidx != CMD_lfdo)) { && eap->cmdidx != CMD_cfdo && eap->cmdidx != CMD_lfdo)) {
errornr = (int)eap->line2; errornr = (int)eap->line2;
} else { } else {
errornr = 1; errornr = 1;
@ -2972,16 +2972,18 @@ void ex_vimgrep(exarg_T *eap)
goto theend; goto theend;
} }
if ((eap->cmdidx != CMD_grepadd && eap->cmdidx != CMD_lgrepadd && if ((eap->cmdidx != CMD_grepadd && eap->cmdidx != CMD_lgrepadd
eap->cmdidx != CMD_vimgrepadd && eap->cmdidx != CMD_lvimgrepadd) && eap->cmdidx != CMD_vimgrepadd && eap->cmdidx != CMD_lvimgrepadd)
|| qi->qf_curlist == qi->qf_listcount) || qi->qf_curlist == qi->qf_listcount) {
/* make place for a new list */ // make place for a new list
qf_new_list(qi, *eap->cmdlinep); qf_new_list(qi, *eap->cmdlinep);
else if (qi->qf_lists[qi->qf_curlist].qf_count > 0) } else if (qi->qf_lists[qi->qf_curlist].qf_count > 0) {
/* Adding to existing list, find last entry. */ // Adding to existing list, find last entry.
for (prevp = qi->qf_lists[qi->qf_curlist].qf_start; for (prevp = qi->qf_lists[qi->qf_curlist].qf_start;
prevp->qf_next != prevp; prevp = prevp->qf_next) prevp->qf_next != prevp;
; prevp = prevp->qf_next) {
}
}
/* parse the list of arguments */ /* parse the list of arguments */
if (get_arglist_exp(p, &fcount, &fnames, true) == FAIL) if (get_arglist_exp(p, &fcount, &fnames, true) == FAIL)

View File

@ -3445,13 +3445,14 @@ static long bt_regexec_both(char_u *line,
c = regline[col]; c = regline[col];
if (prog->regstart == NUL if (prog->regstart == NUL
|| prog->regstart == c || prog->regstart == c
|| (ireg_ic && (( || (ireg_ic
(enc_utf8 && utf_fold(prog->regstart) == utf_fold(c))) && (((enc_utf8 && utf_fold(prog->regstart) == utf_fold(c)))
|| (c < 255 && prog->regstart < 255 && || (c < 255 && prog->regstart < 255
vim_tolower(prog->regstart) == vim_tolower(c))))) && vim_tolower(prog->regstart) == vim_tolower(c))))) {
retval = regtry(prog, col); retval = regtry(prog, col);
else } else {
retval = 0; retval = 0;
}
} else { } else {
int tm_count = 0; int tm_count = 0;
/* Messy cases: unanchored match. */ /* Messy cases: unanchored match. */
@ -4121,15 +4122,15 @@ regmatch (
char_u *opnd; char_u *opnd;
opnd = OPERAND(scan); opnd = OPERAND(scan);
/* Inline the first byte, for speed. */ // Inline the first byte, for speed.
if (*opnd != *reginput if (*opnd != *reginput
&& (!ireg_ic || ( && (!ireg_ic
!enc_utf8 && || (!enc_utf8
vim_tolower(*opnd) != vim_tolower(*reginput)))) && vim_tolower(*opnd) != vim_tolower(*reginput)))) {
status = RA_NOMATCH; status = RA_NOMATCH;
else if (*opnd == NUL) { } else if (*opnd == NUL) {
/* match empty string always works; happens when "~" is // match empty string always works; happens when "~" is
* empty. */ // empty.
} else { } else {
if (opnd[1] == NUL && !(enc_utf8 && ireg_ic)) { if (opnd[1] == NUL && !(enc_utf8 && ireg_ic)) {
len = 1; /* matched a single byte above */ len = 1; /* matched a single byte above */

View File

@ -4777,8 +4777,8 @@ static long find_match_text(colnr_T startcol, int regstart, char_u *match_text)
int c2_len = PTR2LEN(s2); int c2_len = PTR2LEN(s2);
int c2 = PTR2CHAR(s2); int c2 = PTR2CHAR(s2);
if ((c1 != c2 && (!ireg_ic || vim_tolower(c1) != vim_tolower(c2))) || if ((c1 != c2 && (!ireg_ic || vim_tolower(c1) != vim_tolower(c2)))
c1_len != c2_len) { || c1_len != c2_len) {
match = false; match = false;
break; break;
} }

View File

@ -387,14 +387,15 @@ void update_screen(int type)
if (wp->w_buffer->b_mod_set) { if (wp->w_buffer->b_mod_set) {
win_T *wwp; win_T *wwp;
/* Check if we already did this buffer. */ // Check if we already did this buffer.
for (wwp = firstwin; wwp != wp; wwp = wwp->w_next) for (wwp = firstwin; wwp != wp; wwp = wwp->w_next) {
if (wwp->w_buffer == wp->w_buffer) if (wwp->w_buffer == wp->w_buffer) {
break; break;
if ( }
wwp == wp && }
syntax_present(wp)) if (wwp == wp && syntax_present(wp)) {
syn_stack_apply_changes(wp->w_buffer); syn_stack_apply_changes(wp->w_buffer);
}
} }
} }
@ -1231,16 +1232,16 @@ static void win_update(win_T *wp)
|| did_update == DID_FOLD || did_update == DID_FOLD
|| (did_update == DID_LINE || (did_update == DID_LINE
&& syntax_present(wp) && syntax_present(wp)
&& ( && ((foldmethodIsSyntax(wp)
(foldmethodIsSyntax(wp) && hasAnyFolding(wp))
&& hasAnyFolding(wp)) || || syntax_check_changed(lnum)))
syntax_check_changed(lnum)))
// match in fixed position might need redraw // match in fixed position might need redraw
// if lines were inserted or deleted // if lines were inserted or deleted
|| (wp->w_match_head != NULL && buf->b_mod_xlines != 0) || (wp->w_match_head != NULL
))))) { && buf->b_mod_xlines != 0)))))) {
if (lnum == mod_top) if (lnum == mod_top) {
top_to_mod = FALSE; top_to_mod = false;
}
/* /*
* When at start of changed lines: May scroll following lines * When at start of changed lines: May scroll following lines
@ -2472,21 +2473,16 @@ win_line (
mb_ptr_adv(ptr); mb_ptr_adv(ptr);
} }
/* When: // When:
* - 'cuc' is set, or // - 'cuc' is set, or
* - 'colorcolumn' is set, or // - 'colorcolumn' is set, or
* - 'virtualedit' is set, or // - 'virtualedit' is set, or
* - the visual mode is active, // - the visual mode is active,
* the end of the line may be before the start of the displayed part. // the end of the line may be before the start of the displayed part.
*/ if (vcol < v && (wp->w_p_cuc
if (vcol < v && ( || draw_color_col
wp->w_p_cuc || virtual_active()
|| draw_color_col || (VIsual_active && wp->w_buffer == curwin->w_buffer))) {
||
virtual_active()
||
(VIsual_active && wp->w_buffer == curwin->w_buffer)
)) {
vcol = v; vcol = v;
} }
@ -3273,12 +3269,12 @@ win_line (
* contains the @Spell cluster. */ * contains the @Spell cluster. */
if (has_spell && v >= word_end && v > cur_checked_col) { if (has_spell && v >= word_end && v > cur_checked_col) {
spell_attr = 0; spell_attr = 0;
if (!attr_pri) if (!attr_pri) {
char_attr = syntax_attr; char_attr = syntax_attr;
if (c != 0 && ( }
!has_syntax || if (c != 0 && (!has_syntax || can_spell)) {
can_spell)) { char_u *prev_ptr;
char_u *prev_ptr, *p; char_u *p;
int len; int len;
hlf_T spell_hlf = HLF_COUNT; hlf_T spell_hlf = HLF_COUNT;
if (has_mbyte) { if (has_mbyte) {
@ -3607,25 +3603,22 @@ win_line (
wp->w_p_rl ? (col >= 0) : wp->w_p_rl ? (col >= 0) :
(col < wp->w_width))) { (col < wp->w_width))) {
c = ' '; c = ' ';
--ptr; /* put it back at the NUL */ ptr--; // put it back at the NUL
} else if (( } else if ((diff_hlf != (hlf_T)0 || line_attr != 0)
diff_hlf != (hlf_T)0 || && (wp->w_p_rl
line_attr != 0 ? (col >= 0)
) && ( : (col - boguscols < wp->w_width))) {
wp->w_p_rl ? (col >= 0) : // Highlight until the right side of the window
(col
- boguscols
< wp->w_width))) {
/* Highlight until the right side of the window */
c = ' '; c = ' ';
--ptr; /* put it back at the NUL */ ptr--; // put it back at the NUL
/* Remember we do the char for line highlighting. */ // Remember we do the char for line highlighting.
++did_line_attr; did_line_attr++;
/* don't do search HL for the rest of the line */ // don't do search HL for the rest of the line
if (line_attr != 0 && char_attr == search_attr && col > 0) if (line_attr != 0 && char_attr == search_attr && col > 0) {
char_attr = line_attr; char_attr = line_attr;
}
if (diff_hlf == HLF_TXD) { if (diff_hlf == HLF_TXD) {
diff_hlf = HLF_CHD; diff_hlf = HLF_CHD;
if (attr == 0 || char_attr != attr) { if (attr == 0 || char_attr != attr) {
@ -3639,8 +3632,8 @@ win_line (
} }
if (wp->w_p_cole > 0 if (wp->w_p_cole > 0
&& (wp != curwin || lnum != wp->w_cursor.lnum || && (wp != curwin || lnum != wp->w_cursor.lnum
conceal_cursor_line(wp)) || conceal_cursor_line(wp))
&& ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc) && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc)
&& !(lnum_in_visual_area && !(lnum_in_visual_area
&& vim_strchr(wp->w_p_cocu, 'v') == NULL)) { && vim_strchr(wp->w_p_cocu, 'v') == NULL)) {

View File

@ -638,9 +638,9 @@ int searchit(
break; break;
} }
if (ptr[matchcol] == NUL || if (ptr[matchcol] == NUL
(nmatched = vim_regexec_multi(&regmatch, win, buf, lnum, || (nmatched = vim_regexec_multi(&regmatch, win, buf, lnum,
matchcol, tm)) == 0) { matchcol, tm)) == 0) {
match_ok = false; match_ok = false;
break; break;
} }
@ -1027,19 +1027,18 @@ int do_search(
spats[0].off.line = FALSE; spats[0].off.line = FALSE;
spats[0].off.end = FALSE; spats[0].off.end = FALSE;
spats[0].off.off = 0; spats[0].off.off = 0;
/* // Check for a line offset or a character offset.
* Check for a line offset or a character offset. // For get_address (echo off) we don't check for a character
* For get_address (echo off) we don't check for a character // offset, because it is meaningless and the 's' could be a
* offset, because it is meaningless and the 's' could be a // substitute command.
* substitute command. if (*p == '+' || *p == '-' || ascii_isdigit(*p)) {
*/ spats[0].off.line = true;
if (*p == '+' || *p == '-' || ascii_isdigit(*p)) } else if ((options & SEARCH_OPT)
spats[0].off.line = TRUE; && (*p == 'e' || *p == 's' || *p == 'b')) {
else if ((options & SEARCH_OPT) && if (*p == 'e') { // end
(*p == 'e' || *p == 's' || *p == 'b')) {
if (*p == 'e') /* end */
spats[0].off.end = true; spats[0].off.end = true;
++p; }
p++;
} }
if (ascii_isdigit(*p) || *p == '+' || *p == '-') { /* got an offset */ if (ascii_isdigit(*p) || *p == '+' || *p == '-') { /* got an offset */
/* 'nr' or '+nr' or '-nr' */ /* 'nr' or '+nr' or '-nr' */
@ -1784,14 +1783,13 @@ pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int64_t maxtravel)
} }
} }
/* // If FM_BLOCKSTOP given, stop at a '{' or '}' in column 0.
* If FM_BLOCKSTOP given, stop at a '{' or '}' in column 0. if (pos.col == 0 && (flags & FM_BLOCKSTOP)
*/ && (linep[0] == '{' || linep[0] == '}')) {
if (pos.col == 0 && (flags & FM_BLOCKSTOP) && if (linep[0] == findc && count == 0) { // match!
(linep[0] == '{' || linep[0] == '}')) {
if (linep[0] == findc && count == 0) /* match! */
return &pos; return &pos;
break; /* out of scope */ }
break; // out of scope
} }
if (comment_dir) { if (comment_dir) {
@ -1960,15 +1958,15 @@ pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int64_t maxtravel)
if (linep[pos.col - 2] == '\'') { if (linep[pos.col - 2] == '\'') {
pos.col -= 2; pos.col -= 2;
break; break;
} else if (linep[pos.col - 2] == '\\' && } else if (linep[pos.col - 2] == '\\'
pos.col > 2 && linep[pos.col - 3] == '\'') { && pos.col > 2 && linep[pos.col - 3] == '\'') {
pos.col -= 3; pos.col -= 3;
break; break;
} }
} }
} else if (linep[pos.col + 1]) { /* forward search */ } else if (linep[pos.col + 1]) { // forward search
if (linep[pos.col + 1] == '\\' && if (linep[pos.col + 1] == '\\'
linep[pos.col + 2] && linep[pos.col + 3] == '\'') { && linep[pos.col + 2] && linep[pos.col + 3] == '\'') {
pos.col += 3; pos.col += 3;
break; break;
} else if (linep[pos.col + 2] == '\'') { } else if (linep[pos.col + 2] == '\'') {
@ -2185,30 +2183,32 @@ int findsent(int dir, long count)
* if on an empty line, skip up to a non-empty line * if on an empty line, skip up to a non-empty line
*/ */
if (gchar_pos(&pos) == NUL) { if (gchar_pos(&pos) == NUL) {
do do {
if ((*func)(&pos) == -1) if ((*func)(&pos) == -1) {
break; break;
while (gchar_pos(&pos) == NUL); }
if (dir == FORWARD) } while (gchar_pos(&pos) == NUL);
if (dir == FORWARD) {
goto found; goto found;
} }
/* // if on the start of a paragraph or a section and searching forward,
* if on the start of a paragraph or a section and searching forward, // go to the next line
* go to the next line } else if (dir == FORWARD && pos.col == 0
*/ && startPS(pos.lnum, NUL, false)) {
else if (dir == FORWARD && pos.col == 0 && if (pos.lnum == curbuf->b_ml.ml_line_count) {
startPS(pos.lnum, NUL, FALSE)) {
if (pos.lnum == curbuf->b_ml.ml_line_count)
return FAIL; return FAIL;
++pos.lnum; }
pos.lnum++;
goto found; goto found;
} else if (dir == BACKWARD) } else if (dir == BACKWARD) {
decl(&pos); decl(&pos);
}
/* go back to the previous non-blank char */ // go back to the previous non-blank char
found_dot = FALSE; found_dot = false;
while ((c = gchar_pos(&pos)) == ' ' || c == '\t' || while ((c = gchar_pos(&pos)) == ' ' || c == '\t'
(dir == BACKWARD && vim_strchr((char_u *)".!?)]\"'", c) != NULL)) { || (dir == BACKWARD
&& vim_strchr((char_u *)".!?)]\"'", c) != NULL)) {
if (vim_strchr((char_u *)".!?", c) != NULL) { if (vim_strchr((char_u *)".!?", c) != NULL) {
/* Only skip over a '.', '!' and '?' once. */ /* Only skip over a '.', '!' and '?' once. */
if (found_dot) if (found_dot)
@ -2372,12 +2372,14 @@ int startPS(linenr_T lnum, int para, int both)
char_u *s; char_u *s;
s = ml_get(lnum); s = ml_get(lnum);
if (*s == para || *s == '\f' || (both && *s == '}')) if (*s == para || *s == '\f' || (both && *s == '}')) {
return TRUE; return true;
if (*s == '.' && (inmacro(p_sections, s + 1) || }
(!para && inmacro(p_para, s + 1)))) if (*s == '.' && (inmacro(p_sections, s + 1)
return TRUE; || (!para && inmacro(p_para, s + 1)))) {
return FALSE; return true;
}
return false;
} }
/* /*
@ -4151,19 +4153,20 @@ find_pattern_in_path (
FNAME_EXP|FNAME_INCL|FNAME_REL, 1L, p_fname, NULL); FNAME_EXP|FNAME_INCL|FNAME_REL, 1L, p_fname, NULL);
already_searched = FALSE; already_searched = FALSE;
if (new_fname != NULL) { if (new_fname != NULL) {
/* Check whether we have already searched in this file */ // Check whether we have already searched in this file
for (i = 0;; i++) { for (i = 0;; i++) {
if (i == depth + 1) if (i == depth + 1) {
i = old_files; i = old_files;
if (i == max_path_depth) }
if (i == max_path_depth) {
break; break;
if (path_full_compare(new_fname, files[i].name, TRUE) & kEqualFiles) { }
if (type != CHECK_PATH && if (path_full_compare(new_fname, files[i].name, true) & kEqualFiles) {
action == ACTION_SHOW_ALL && files[i].matched) { if (type != CHECK_PATH
msg_putchar('\n'); /* cursor below last one */ && action == ACTION_SHOW_ALL && files[i].matched) {
if (!got_int) { /* don't display if 'q' msg_putchar('\n'); // cursor below last one */
typed at "--more--" if (!got_int) { // don't display if 'q' typed at "--more--"
message */ // message
msg_home_replace_hl(new_fname); msg_home_replace_hl(new_fname);
MSG_PUTS(_(" (includes previously listed match)")); MSG_PUTS(_(" (includes previously listed match)"));
prev_fname = NULL; prev_fname = NULL;
@ -4178,15 +4181,15 @@ find_pattern_in_path (
} }
if (type == CHECK_PATH && (action == ACTION_SHOW_ALL if (type == CHECK_PATH && (action == ACTION_SHOW_ALL
|| (new_fname == NULL && || (new_fname == NULL && !already_searched))) {
!already_searched))) { if (did_show) {
if (did_show) msg_putchar('\n'); // cursor below last one
msg_putchar('\n'); /* cursor below last one */ } else {
else { gotocmdline(true); // cursor at status line
gotocmdline(TRUE); /* cursor at status line */
MSG_PUTS_TITLE(_("--- Included files ")); MSG_PUTS_TITLE(_("--- Included files "));
if (action != ACTION_SHOW_ALL) if (action != ACTION_SHOW_ALL) {
MSG_PUTS_TITLE(_("not found ")); MSG_PUTS_TITLE(_("not found "));
}
MSG_PUTS_TITLE(_("in path ---\n")); MSG_PUTS_TITLE(_("in path ---\n"));
} }
did_show = TRUE; did_show = TRUE;
@ -4345,16 +4348,15 @@ search_line:
&& vim_regexec(&regmatch, line, (colnr_T)(p - line))) { && vim_regexec(&regmatch, line, (colnr_T)(p - line))) {
matched = TRUE; matched = TRUE;
startp = regmatch.startp[0]; startp = regmatch.startp[0];
/* // Check if the line is not a comment line (unless we are
* Check if the line is not a comment line (unless we are // looking for a define). A line starting with "# define"
* looking for a define). A line starting with "# define" // is not considered to be a comment line.
* is not considered to be a comment line.
*/
if (skip_comments) { if (skip_comments) {
if ((*line != '#' || if ((*line != '#'
STRNCMP(skipwhite(line + 1), "define", 6) != 0) || STRNCMP(skipwhite(line + 1), "define", 6) != 0)
&& get_leader_len(line, NULL, FALSE, TRUE)) && get_leader_len(line, NULL, false, true)) {
matched = FALSE; matched = false;
}
/* /*
* Also check for a "/ *" or "/ /" before the match. * Also check for a "/ *" or "/ /" before the match.

View File

@ -4478,12 +4478,10 @@ syn_cmd_region (
if (illegal || not_enough) if (illegal || not_enough)
rest = NULL; rest = NULL;
/* // Must have a "start" and "end" pattern.
* Must have a "start" and "end" pattern. if (rest != NULL && (pat_ptrs[ITEM_START] == NULL
*/ || pat_ptrs[ITEM_END] == NULL)) {
if (rest != NULL && (pat_ptrs[ITEM_START] == NULL || not_enough = true;
pat_ptrs[ITEM_END] == NULL)) {
not_enough = TRUE;
rest = NULL; rest = NULL;
} }

View File

@ -526,19 +526,17 @@ do_tag (
taglen_advance(taglen); taglen_advance(taglen);
MSG_PUTS_ATTR(_("file\n"), hl_attr(HLF_T)); MSG_PUTS_ATTR(_("file\n"), hl_attr(HLF_T));
for (i = 0; i < num_matches && !got_int; ++i) { for (i = 0; i < num_matches && !got_int; i++) {
parse_match(matches[i], &tagp); parse_match(matches[i], &tagp);
if (!new_tag && ( if (!new_tag && ((g_do_tagpreview != 0 && i == ptag_entry.cur_match)
(g_do_tagpreview != 0 || (use_tagstack
&& i == ptag_entry.cur_match) || && i == tagstack[tagstackidx].cur_match))) {
(use_tagstack
&& i == tagstack[tagstackidx].cur_match)))
*IObuff = '>'; *IObuff = '>';
else } else {
*IObuff = ' '; *IObuff = ' ';
vim_snprintf((char *)IObuff + 1, IOSIZE - 1, }
"%2d %s ", i + 1, vim_snprintf((char *)IObuff + 1, IOSIZE - 1, "%2d %s ", i + 1,
mt_names[matches[i][0] & MT_MASK]); mt_names[matches[i][0] & MT_MASK]);
msg_puts(IObuff); msg_puts(IObuff);
if (tagp.tagkind != NULL) if (tagp.tagkind != NULL)
msg_outtrans_len(tagp.tagkind, msg_outtrans_len(tagp.tagkind,
@ -1226,20 +1224,15 @@ find_tags (
for (round = 1; round <= 2; ++round) { for (round = 1; round <= 2; ++round) {
linear = (orgpat.headlen == 0 || !p_tbs || round == 2); linear = (orgpat.headlen == 0 || !p_tbs || round == 2);
/* // Try tag file names from tags option one by one.
* Try tag file names from tags option one by one. for (first_file = true;
*/ use_cscope || get_tagfname(&tn, first_file, tag_fname) == OK;
for (first_file = TRUE; first_file = false) {
use_cscope || // A file that doesn't exist is silently ignored. Only when not a
get_tagfname(&tn, first_file, tag_fname) == OK; // single file is found, an error message is given (further on).
first_file = FALSE) { if (use_cscope) {
/* fp = NULL; // avoid GCC warning
* A file that doesn't exist is silently ignored. Only when not a } else {
* single file is found, an error message is given (further on).
*/
if (use_cscope)
fp = NULL; /* avoid GCC warning */
else {
if (curbuf->b_help) { if (curbuf->b_help) {
/* Prefer help tags according to 'helplang'. Put the /* Prefer help tags according to 'helplang'. Put the
* two-letter language name in help_lang[]. */ * two-letter language name in help_lang[]. */

View File

@ -224,9 +224,9 @@ static void tk_getkeys(TermInput *input, bool force)
while ((result = tk_getkey(input->tk, &key, force)) == TERMKEY_RES_KEY) { while ((result = tk_getkey(input->tk, &key, force)) == TERMKEY_RES_KEY) {
if (key.type == TERMKEY_TYPE_UNICODE && !key.modifiers) { if (key.type == TERMKEY_TYPE_UNICODE && !key.modifiers) {
forward_simple_utf8(input, &key); forward_simple_utf8(input, &key);
} else if (key.type == TERMKEY_TYPE_UNICODE || } else if (key.type == TERMKEY_TYPE_UNICODE
key.type == TERMKEY_TYPE_FUNCTION || || key.type == TERMKEY_TYPE_FUNCTION
key.type == TERMKEY_TYPE_KEYSYM) { || key.type == TERMKEY_TYPE_KEYSYM) {
forward_modified_utf8(input, &key); forward_modified_utf8(input, &key);
} else if (key.type == TERMKEY_TYPE_MOUSE) { } else if (key.type == TERMKEY_TYPE_MOUSE) {
forward_mouse_event(input, &key); forward_mouse_event(input, &key);
@ -282,9 +282,9 @@ static bool handle_focus_event(TermInput *input)
static bool handle_bracketed_paste(TermInput *input) static bool handle_bracketed_paste(TermInput *input)
{ {
if (rbuffer_size(input->read_stream.buffer) > 5 && if (rbuffer_size(input->read_stream.buffer) > 5
(!rbuffer_cmp(input->read_stream.buffer, "\x1b[200~", 6) || && (!rbuffer_cmp(input->read_stream.buffer, "\x1b[200~", 6)
!rbuffer_cmp(input->read_stream.buffer, "\x1b[201~", 6))) { || !rbuffer_cmp(input->read_stream.buffer, "\x1b[201~", 6))) {
bool enable = *rbuffer_get(input->read_stream.buffer, 4) == '0'; bool enable = *rbuffer_get(input->read_stream.buffer, 4) == '0';
// Advance past the sequence // Advance past the sequence
rbuffer_consumed(input->read_stream.buffer, 6); rbuffer_consumed(input->read_stream.buffer, 6);

View File

@ -628,8 +628,8 @@ static void tui_suspend(UI *ui)
static void tui_set_title(UI *ui, char *title) static void tui_set_title(UI *ui, char *title)
{ {
TUIData *data = ui->data; TUIData *data = ui->data;
if (!(title && unibi_get_str(data->ut, unibi_to_status_line) && if (!(title && unibi_get_str(data->ut, unibi_to_status_line)
unibi_get_str(data->ut, unibi_from_status_line))) { && unibi_get_str(data->ut, unibi_from_status_line))) {
return; return;
} }
unibi_out(ui, unibi_to_status_line); unibi_out(ui, unibi_to_status_line);
@ -694,8 +694,8 @@ static void update_size(UI *ui)
} }
// 2 - try from a system call(ioctl/TIOCGWINSZ on unix) // 2 - try from a system call(ioctl/TIOCGWINSZ on unix)
if (data->out_isatty && if (data->out_isatty
!uv_tty_get_winsize(&data->output_handle.tty, &width, &height)) { && !uv_tty_get_winsize(&data->output_handle.tty, &width, &height)) {
goto end; goto end;
} }

View File

@ -2876,9 +2876,7 @@ static char_u *u_save_line(linenr_T lnum)
/// @return true if the buffer has changed /// @return true if the buffer has changed
bool bufIsChanged(buf_T *buf) bool bufIsChanged(buf_T *buf)
{ {
return return !bt_dontwrite(buf) && (buf->b_changed || file_ff_differs(buf, true));
!bt_dontwrite(buf) &&
(buf->b_changed || file_ff_differs(buf, true));
} }
/// Check if the 'modified' flag is set, or 'ff' has changed (only need to /// Check if the 'modified' flag is set, or 'ff' has changed (only need to
@ -2888,9 +2886,8 @@ bool bufIsChanged(buf_T *buf)
/// @return true if the current buffer has changed /// @return true if the current buffer has changed
bool curbufIsChanged(void) bool curbufIsChanged(void)
{ {
return return (!bt_dontwrite(curbuf)
!bt_dontwrite(curbuf) && && (curbuf->b_changed || file_ff_differs(curbuf, true)));
(curbuf->b_changed || file_ff_differs(curbuf, true));
} }
/* /*