diff options
Diffstat (limited to 'src')
48 files changed, 998 insertions, 983 deletions
diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c index a52f53a3e6..f644453358 100644 --- a/src/nvim/api/window.c +++ b/src/nvim/api/window.c @@ -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); - if (pos.size != 2 || pos.items[0].type != kObjectTypeInteger || - pos.items[1].type != kObjectTypeInteger) { + if (pos.size != 2 || pos.items[0].type != kObjectTypeInteger + || pos.items[1].type != kObjectTypeInteger) { api_set_error(err, Validation, _("Argument \"pos\" must be a [row, col] array")); diff --git a/src/nvim/arabic.c b/src/nvim/arabic.c index b432e12c02..db97bd9dc4 100644 --- a/src/nvim/arabic.c +++ b/src/nvim/arabic.c @@ -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); if (curr_laa) { - if (A_is_valid(prev_c) && !A_is_f(shape_c) && !A_is_s(shape_c) && - !prev_laa) { + if (A_is_valid(prev_c) && !A_is_f(shape_c) && !A_is_s(shape_c) + && !prev_laa) { curr_c = chg_c_laa2f(curr_laa); } else { curr_c = chg_c_laa2i(curr_laa); @@ -1454,19 +1454,19 @@ static bool A_is_harakat(int c) // (alphabet/number/punctuation) static bool A_is_iso(int c) { - return (c >= a_HAMZA && c <= a_GHAIN) || - (c >= a_TATWEEL && c <= a_HAMZA_BELOW) || - c == a_MINI_ALEF; + return ((c >= a_HAMZA && c <= a_GHAIN) + || (c >= a_TATWEEL && c <= a_HAMZA_BELOW) + || c == a_MINI_ALEF); } // A_is_formb returns true if 'c' is an Arabic 10646-1 FormB character. // (alphabet/number/punctuation) static bool A_is_formb(int c) { - return (c >= a_s_FATHATAN && c <= a_s_DAMMATAN) || - c == a_s_KASRATAN || - (c >= a_s_FATHA && c <= a_f_LAM_ALEF) || - c == a_BYTE_ORDER_MARK; + return ((c >= a_s_FATHATAN && c <= a_s_DAMMATAN) + || c == a_s_KASRATAN + || (c >= a_s_FATHA && c <= a_f_LAM_ALEF) + || c == a_BYTE_ORDER_MARK); } // A_is_ok returns true if 'c' is an Arabic 10646 (8859-6 or Form-B). diff --git a/src/nvim/assert.h b/src/nvim/assert.h index 0ce48e4766..2c43777858 100644 --- a/src/nvim/assert.h +++ b/src/nvim/assert.h @@ -46,10 +46,10 @@ #define STATIC_ASSERT_PRAGMA_START #define STATIC_ASSERT_PRAGMA_END -#define STATIC_ASSERT(...) \ +#define STATIC_ASSERT(cond, msg) \ do { \ STATIC_ASSERT_PRAGMA_START \ - STATIC_ASSERT_STATEMENT(__VA_ARGS__); \ + STATIC_ASSERT_STATEMENT(cond, msg); \ STATIC_ASSERT_PRAGMA_END \ } while (0) diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 6ed5b3136f..b00f5e8e5b 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -407,10 +407,9 @@ close_buffer ( buf->b_nwindows = nwindows; buf_freeall(buf, (del_buf ? BFA_DEL : 0) + (wipe_buf ? BFA_WIPE : 0)); - if ( - win_valid(win) && - win->w_buffer == buf) - win->w_buffer = NULL; /* make sure we don't use the buffer now */ + if (win_valid(win) && win->w_buffer == buf) { + win->w_buffer = NULL; // make sure we don't use the buffer now + } /* Autocommands may have deleted the buffer. */ if (!buf_valid(buf)) @@ -1340,8 +1339,8 @@ buflist_new ( /* We can use inode numbers when the file exists. Works better * for hard links. */ FileID file_id; - bool file_id_valid = (sfname != NULL && - os_fileid((char *)sfname, &file_id)); + bool file_id_valid = (sfname != NULL + && os_fileid((char *)sfname, &file_id)); if (ffname != NULL && !(flags & BLN_DUMMY) && (buf = buflist_findname_file_id(ffname, &file_id, file_id_valid)) != NULL) { diff --git a/src/nvim/edit.c b/src/nvim/edit.c index 26966b35c1..e131da8fe0 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -3306,6 +3306,12 @@ static bool ins_compl_prep(int c) showmode(); } + // Avoid the popup menu remains displayed when leaving the + // command line window. + if (c == Ctrl_C && cmdwin_type != 0) { + update_screen(0); + } + /* * Indent now if a key was typed that is in 'cinkeys'. */ @@ -4424,11 +4430,10 @@ static int ins_complete(int c, bool enable_pum) prefix = (char_u *)""; STRCPY((char *)compl_pattern, prefix); (void)quote_meta(compl_pattern + STRLEN(prefix), - line + compl_col, compl_length); - } else if (--startcol < 0 || - !vim_iswordp(mb_prevptr(line, line + startcol + 1)) - ) { - /* Match any word of at least two chars */ + line + compl_col, compl_length); + } else if (--startcol < 0 + || !vim_iswordp(mb_prevptr(line, line + startcol + 1))) { + // Match any word of at least two chars compl_pattern = vim_strsave((char_u *)"\\<\\k\\k"); compl_col += curs_col; compl_length = 0; @@ -6684,8 +6689,8 @@ bool in_cinkeys(int keytyped, int when, bool line_is_empty) } else if (*look == 'e') { if (try_match && keytyped == 'e' && curwin->w_cursor.col >= 4) { p = get_cursor_line_ptr(); - if (skipwhite(p) == p + curwin->w_cursor.col - 4 && - STRNCMP(p + curwin->w_cursor.col - 4, "else", 4) == 0) { + if (skipwhite(p) == p + curwin->w_cursor.col - 4 + && STRNCMP(p + curwin->w_cursor.col - 4, "else", 4) == 0) { return true; } } @@ -7384,17 +7389,16 @@ static bool ins_bs(int c, int mode, int *inserted_space_p) * can't backup past starting point unless 'backspace' > 1 * can backup to a previous line if 'backspace' == 0 */ - if ( bufempty() - || ( - !revins_on && - ((curwin->w_cursor.lnum == 1 && curwin->w_cursor.col == 0) - || (!can_bs(BS_START) - && (arrow_used - || (curwin->w_cursor.lnum == Insstart_orig.lnum - && curwin->w_cursor.col <= Insstart_orig.col))) - || (!can_bs(BS_INDENT) && !arrow_used && ai_col > 0 - && curwin->w_cursor.col <= ai_col) - || (!can_bs(BS_EOL) && curwin->w_cursor.col == 0)))) { + if (bufempty() + || (!revins_on + && ((curwin->w_cursor.lnum == 1 && curwin->w_cursor.col == 0) + || (!can_bs(BS_START) + && (arrow_used + || (curwin->w_cursor.lnum == Insstart_orig.lnum + && curwin->w_cursor.col <= Insstart_orig.col))) + || (!can_bs(BS_INDENT) && !arrow_used && ai_col > 0 + && curwin->w_cursor.col <= ai_col) + || (!can_bs(BS_EOL) && curwin->w_cursor.col == 0)))) { vim_beep(BO_BS); return false; } @@ -7640,14 +7644,14 @@ static bool ins_bs(int c, int mode, int *inserted_space_p) if (revins_on && gchar_cursor() == NUL) break; } - /* Just a single backspace?: */ - if (mode == BACKSPACE_CHAR) + // Just a single backspace?: + if (mode == BACKSPACE_CHAR) { break; - } while ( - revins_on || - (curwin->w_cursor.col > mincol - && (curwin->w_cursor.lnum != Insstart_orig.lnum - || curwin->w_cursor.col != Insstart_orig.col))); + } + } while (revins_on + || (curwin->w_cursor.col > mincol + && (curwin->w_cursor.lnum != Insstart_orig.lnum + || curwin->w_cursor.col != Insstart_orig.col))); } did_backspace = true; } diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 5323e17158..d84bdfebfe 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -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), &tv, &di, true, false) == OK) { if ((di == NULL - || (!var_check_ro(di->di_flags, lp->ll_name, false) && - !tv_check_lock(di->di_tv.v_lock, 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_op(&tv, rettv, op) == OK) { 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; garray_T ga; - if ((argvars[0].v_type != VAR_NUMBER || - (get_tv_number_chk(&argvars[0], &error) == 0) == is_true || error) + if ((argvars[0].v_type != VAR_NUMBER + || (get_tv_number_chk(&argvars[0], &error) == 0) == is_true + || error) && (argvars[0].v_type != VAR_SPECIAL || (argvars[0].vval.v_special != (SpecialVarValue) (is_true @@ -8691,7 +8692,11 @@ static void f_eventhandler(typval_T *argvars, typval_T *rettv) */ static void f_executable(typval_T *argvars, typval_T *rettv) { - rettv->vval.v_number = os_can_exe(get_tv_string(&argvars[0]), NULL); + char_u *name = get_tv_string(&argvars[0]); + + // Check in $PATH and also check directly if there is a directory name + rettv->vval.v_number = os_can_exe(name, NULL, true) + || (gettail_dir(name) != name && os_can_exe(name, NULL, false)); } /// "exepath()" function @@ -8700,7 +8705,7 @@ static void f_exepath(typval_T *argvars, typval_T *rettv) char_u *arg = get_tv_string(&argvars[0]); char_u *path = NULL; - (void)os_can_exe(arg, &path); + (void)os_can_exe(arg, &path, true); rettv->v_type = VAR_STRING; rettv->vval.v_string = path; @@ -10290,7 +10295,7 @@ static void f_getregtype(typval_T *argvars, typval_T *rettv) colnr_T reglen = 0; char buf[NUMBUFLEN + 2]; - char_u reg_type = get_reg_type(regname, ®len); + MotionType reg_type = get_reg_type(regname, ®len); format_reg_type(reg_type, reglen, buf, ARRAY_SIZE(buf)); rettv->v_type = VAR_STRING; @@ -11605,7 +11610,7 @@ static char **tv_to_argv(typval_T *cmd_tv, char **cmd) assert(argl->lv_first); const char_u *exe = get_tv_string_chk(&argl->lv_first->li_tv); - if (!exe || !os_can_exe(exe, NULL)) { + if (!exe || !os_can_exe(exe, NULL, true)) { // String is not executable if (exe) { EMSG2(e_jobexe, exe); @@ -14717,11 +14722,11 @@ static void f_setreg(typval_T *argvars, typval_T *rettv) char_u *strregname; char_u *stropt; bool append = false; - char_u yank_type; + MotionType yank_type; long block_len; block_len = -1; - yank_type = MAUTO; + yank_type = kMTUnknown; strregname = get_tv_string_chk(argvars); rettv->vval.v_number = 1; /* FAIL is default */ @@ -14738,17 +14743,17 @@ static void f_setreg(typval_T *argvars, typval_T *rettv) return; /* type error */ for (; *stropt != NUL; ++stropt) switch (*stropt) { - case 'a': case 'A': /* append */ + case 'a': case 'A': // append append = true; break; - case 'v': case 'c': /* character-wise selection */ - yank_type = MCHAR; + case 'v': case 'c': // character-wise selection + yank_type = kMTCharWise; break; - case 'V': case 'l': /* line-wise selection */ - yank_type = MLINE; + case 'V': case 'l': // line-wise selection + yank_type = kMTLineWise; break; - case 'b': case Ctrl_V: /* block-wise selection */ - yank_type = MBLOCK; + case 'b': case Ctrl_V: // block-wise selection + yank_type = kMTBlockWise; if (ascii_isdigit(stropt[1])) { ++stropt; block_len = getdigits_long(&stropt) - 1; @@ -15140,12 +15145,12 @@ static void do_sort_uniq(typval_T *argvars, typval_T *rettv, bool sort) EMSG2(_(e_listarg), sort ? "sort()" : "uniq()"); } else { l = argvars[0].vval.v_list; - if (l == NULL || - tv_check_lock(l->lv_lock, - (char_u *)(sort - ? N_("sort() argument") - : N_("uniq() argument")), - true)) { + if (l == NULL + || tv_check_lock(l->lv_lock, + (char_u *)(sort + ? N_("sort() argument") + : N_("uniq() argument")), + true)) { return; } rettv->vval.v_list = l; @@ -19265,9 +19270,10 @@ void ex_function(exarg_T *eap) if ((p[0] == 'a' && (!ASCII_ISALPHA(p[1]) || p[1] == 'p')) || (p[0] == 'i' && (!ASCII_ISALPHA(p[1]) || (p[1] == 'n' - && (!ASCII_ISALPHA(p[2]) || - (p[2] == 's')))))) + && (!ASCII_ISALPHA(p[2]) + || (p[2] == 's')))))) { skip_until = vim_strsave((char_u *)"."); + } // Check for ":python <<EOF", ":lua <<EOF", etc. arg = skipwhite(skiptowhite(p)); @@ -19534,11 +19540,12 @@ trans_function_name ( *pp = end; } else { if (!skip && !(flags & TFN_QUIET) && (fdp == NULL - || lv.ll_dict == NULL || - fdp->fd_newkey == NULL)) + || lv.ll_dict == NULL + || fdp->fd_newkey == NULL)) { EMSG(_(e_funcref)); - else + } else { *pp = end; + } name = NULL; } goto theend; @@ -20438,9 +20445,9 @@ call_user_func ( --RedrawingDisabled; - /* when the function was aborted because of an error, return -1 */ - if ((did_emsg && - (fp->uf_flags & FC_ABORT)) || rettv->v_type == VAR_UNKNOWN) { + // when the function was aborted because of an error, return -1 + if ((did_emsg + && (fp->uf_flags & FC_ABORT)) || rettv->v_type == VAR_UNKNOWN) { clear_tv(rettv); rettv->v_type = VAR_NUMBER; rettv->vval.v_number = -1; diff --git a/src/nvim/event/process.c b/src/nvim/event/process.c index e6012595fd..9bb62891c7 100644 --- a/src/nvim/event/process.c +++ b/src/nvim/event/process.c @@ -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. proc->refcount++; LOOP_PROCESS_EVENTS_UNTIL(proc->loop, events, ms, - // Until... - got_int || // interrupted by the user - proc->refcount == 1); // job exited + // Until... + got_int // interrupted by the user + || proc->refcount == 1); // job exited // we'll assume that a user frantically hitting interrupt doesn't like // the current job. Signal that it has to be killed. diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index d020bc8f20..e8314e02e0 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -650,13 +650,13 @@ void ex_retab(exarg_T *eap) num_tabs += num_spaces / new_ts; num_spaces -= (num_spaces / new_ts) * new_ts; } - if (curbuf->b_p_et || got_tab || - (num_spaces + num_tabs < len)) { - if (did_undo == FALSE) { - did_undo = TRUE; + if (curbuf->b_p_et || got_tab + || (num_spaces + num_tabs < len)) { + if (did_undo == false) { + did_undo = true; if (u_save((linenr_T)(lnum - 1), - (linenr_T)(lnum + 1)) == FAIL) { - new_line = NULL; /* flag out-of-memory */ + (linenr_T)(lnum + 1)) == FAIL) { + new_line = NULL; // flag out-of-memory break; } } @@ -1623,15 +1623,14 @@ int do_write(exarg_T *eap) } } - /* - * Writing to the current file is not allowed in readonly mode - * and a file name is required. - * "nofile" and "nowrite" buffers cannot be written implicitly either. - */ - if (!other && ( - bt_dontwrite_msg(curbuf) || - check_fname() == FAIL || check_readonly(&eap->forceit, curbuf))) + // Writing to the current file is not allowed in readonly mode + // and a file name is required. + // "nofile" and "nowrite" buffers cannot be written implicitly either. + if (!other && (bt_dontwrite_msg(curbuf) + || check_fname() == FAIL + || check_readonly(&eap->forceit, curbuf))) { goto theend; + } if (!other) { ffname = curbuf->b_ffname; @@ -2258,16 +2257,15 @@ do_ecmd ( delbuf_msg(new_name); /* frees new_name */ goto theend; } - if (buf == curbuf) /* already in new buffer */ - auto_buf = TRUE; - else { - /* - * <VN> We could instead free the synblock - * and re-attach to buffer, perhaps. - */ - if (curwin->w_buffer != NULL && - curwin->w_s == &(curwin->w_buffer->b_s)) + if (buf == curbuf) { // already in new buffer + auto_buf = true; + } else { + // <VN> We could instead free the synblock + // and re-attach to buffer, perhaps. + if (curwin->w_buffer != NULL + && curwin->w_s == &(curwin->w_buffer->b_s)) { curwin->w_s = &(buf->b_s); + } curwin->w_buffer = buf; curbuf = buf; @@ -2294,11 +2292,11 @@ do_ecmd ( curwin->w_pcmark.lnum = 1; curwin->w_pcmark.col = 0; - } else { /* !other_file */ - if ( - (flags & ECMD_ADDBUF) || - check_fname() == FAIL) + } else { // !other_file + if ((flags & ECMD_ADDBUF) + || check_fname() == FAIL) { goto theend; + } oldbuf = (flags & ECMD_OLDBUF); } @@ -5818,13 +5816,14 @@ void set_context_in_sign_cmd(expand_T *xp, char_u *arg) switch (cmd_idx) { case SIGNCMD_DEFINE: - if (STRNCMP(last, "texthl", p - last) == 0 || - STRNCMP(last, "linehl", p - last) == 0) + if (STRNCMP(last, "texthl", p - last) == 0 + || STRNCMP(last, "linehl", p - last) == 0) { 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; - else + } else { xp->xp_context = EXPAND_NOTHING; + } break; case SIGNCMD_PLACE: if (STRNCMP(last, "name", p - last) == 0) diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c index a0a0b9d3a5..12efddc205 100644 --- a/src/nvim/ex_cmds2.c +++ b/src/nvim/ex_cmds2.c @@ -432,14 +432,12 @@ dbg_parsearg ( bp = &DEBUGGY(gap, gap->ga_len); - /* Find "func" or "file". */ - if (STRNCMP(p, "func", 4) == 0) + // Find "func" or "file". + if (STRNCMP(p, "func", 4) == 0) { bp->dbg_type = DBG_FUNC; - else if (STRNCMP(p, "file", 4) == 0) + } else if (STRNCMP(p, "file", 4) == 0) { bp->dbg_type = DBG_FILE; - else if ( - gap != &prof_ga && - STRNCMP(p, "here", 4) == 0) { + } else if (gap != &prof_ga && STRNCMP(p, "here", 4) == 0) { if (curbuf->b_ffname == NULL) { EMSG(_(e_noname)); return FAIL; @@ -452,16 +450,15 @@ dbg_parsearg ( } p = skipwhite(p + 4); - /* Find optional line number. */ - if (here) + // Find optional line number. + if (here) { bp->dbg_lnum = curwin->w_cursor.lnum; - else if ( - gap != &prof_ga && - ascii_isdigit(*p)) { + } else if (gap != &prof_ga && ascii_isdigit(*p)) { bp->dbg_lnum = getdigits_long(&p); p = skipwhite(p); - } else + } else { bp->dbg_lnum = 0; + } /* Find the function or file name. Don't accept a function name with (). */ if ((!here && *p == NUL) @@ -700,14 +697,13 @@ debuggy_find ( /* Skip entries that are not useful or are for a line that is beyond * an already found breakpoint. */ bp = &DEBUGGY(gap, i); - if (((bp->dbg_type == DBG_FILE) == file && ( - gap == &prof_ga || - (bp->dbg_lnum > after && (lnum == 0 || bp->dbg_lnum < lnum))))) { - /* - * Save the value of got_int and reset it. We don't want a - * previous interruption cancel matching, only hitting CTRL-C - * while matching should abort it. - */ + if (((bp->dbg_type == DBG_FILE) == file + && (gap == &prof_ga + || (bp->dbg_lnum > after + && (lnum == 0 || bp->dbg_lnum < lnum))))) { + // Save the value of got_int and reset it. We don't want a + // previous interruption cancel matching, only hitting CTRL-C + // while matching should abort it. prev_got_int = got_int; got_int = FALSE; 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) { goto_buffer(eap, DOBUF_FIRST, FORWARD, buf->b_fnum); } - } else if (eap->cmdidx == CMD_cdo || eap->cmdidx == CMD_ldo || - eap->cmdidx == CMD_cfdo || eap->cmdidx == CMD_lfdo) { + } else if (eap->cmdidx == CMD_cdo || eap->cmdidx == CMD_ldo + || eap->cmdidx == CMD_cfdo || eap->cmdidx == CMD_lfdo) { qf_size = qf_get_size(eap); assert(eap->line1 >= 0); 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 || - eap->cmdidx == CMD_cfdo || eap->cmdidx == CMD_lfdo) { + if (eap->cmdidx == CMD_cdo || eap->cmdidx == CMD_ldo + || eap->cmdidx == CMD_cfdo || eap->cmdidx == CMD_lfdo) { assert(i >= 0); if ((size_t)i >= qf_size || i >= eap->line2) { break; @@ -3183,8 +3179,11 @@ void set_lang_var(void) * back to LC_CTYPE if it's empty. */ # ifdef HAVE_WORKING_LIBINTL loc = (char *) get_mess_env(); -# else +# elif defined(LC_MESSAGES) loc = get_locale_val(LC_MESSAGES); +# else + // In Windows LC_MESSAGES is not defined fallback to LC_CTYPE + loc = get_locale_val(LC_CTYPE); # endif set_vim_var_string(VV_LANG, loc, -1); diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index e334e9126d..89c35a3c45 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -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 find a '|' or '\n' we set ea.nextcmd. */ - if (*ea.cmd == NUL || *ea.cmd == '"' || - (ea.nextcmd = check_nextcmd(ea.cmd)) != NULL) { - /* - * strange vi behaviour: - * ":3" jumps to line 3 - * ":3|..." prints line 3 - * ":|" prints current line - */ - if (ea.skip) /* skip this if inside :if */ + if (*ea.cmd == NUL || *ea.cmd == '"' + || (ea.nextcmd = check_nextcmd(ea.cmd)) != NULL) { + // strange vi behaviour: + // ":3" jumps to line 3 + // ":3|..." prints line 3 + // ":|" prints current line + if (ea.skip) { // skip this if inside :if goto doend; + } if (*ea.cmd == '|' || (exmode_active && ea.line1 != ea.line2)) { ea.cmdidx = CMD_print; ea.argt = RANGE | COUNT | TRLBAR; @@ -2824,10 +2823,11 @@ set_one_cmd_context ( } } - /* no arguments allowed */ - if (!(ea.argt & EXTRA) && *arg != NUL && - vim_strchr((char_u *)"|\"", *arg) == NULL) + // no arguments allowed + if (!(ea.argt & EXTRA) && *arg != NUL + && vim_strchr((char_u *)"|\"", *arg) == NULL) { return NULL; + } /* Find start of last argument (argument just before cursor): */ p = buff; @@ -4772,14 +4772,15 @@ static void uc_list(char_u *name, size_t name_len) IObuff[len++] = ' '; } while (len < 11); - /* Address Type */ - for (j = 0; addr_type_complete[j].expand != -1; ++j) - if (addr_type_complete[j].expand != ADDR_LINES && - addr_type_complete[j].expand == cmd->uc_addr_type) { + // Address Type + for (j = 0; addr_type_complete[j].expand != -1; j++) { + if (addr_type_complete[j].expand != ADDR_LINES + && addr_type_complete[j].expand == cmd->uc_addr_type) { STRCPY(IObuff + len, addr_type_complete[j].name); len += (int)STRLEN(IObuff + len); break; } + } do { IObuff[len++] = ' '; @@ -5654,12 +5655,13 @@ static void ex_quit(exarg_T *eap) wp = curwin; } - apply_autocmds(EVENT_QUITPRE, NULL, NULL, FALSE, curbuf); - /* Refuse to quit when locked or when the buffer in the last window is - * being closed (can only happen in autocommands). */ - if (curbuf_locked() || - (wp->w_buffer->b_nwindows == 1 && wp->w_buffer->b_closing)) + apply_autocmds(EVENT_QUITPRE, NULL, NULL, false, curbuf); + // Refuse to quit when locked or when the buffer in the last window is + // being closed (can only happen in autocommands). + if (curbuf_locked() + || (wp->w_buffer->b_nwindows == 1 && wp->w_buffer->b_closing)) { return; + } /* @@ -7071,9 +7073,9 @@ static void ex_operators(exarg_T *eap) oa.start.lnum = eap->line1; oa.end.lnum = eap->line2; oa.line_count = eap->line2 - eap->line1 + 1; - oa.motion_type = MLINE; - virtual_op = FALSE; - if (eap->cmdidx != CMD_yank) { /* position cursor for undo */ + oa.motion_type = kMTLineWise; + virtual_op = false; + if (eap->cmdidx != CMD_yank) { // position cursor for undo setpcmark(); curwin->w_cursor.lnum = eap->line1; beginline(BL_SOL | BL_FIX); @@ -9185,16 +9187,15 @@ static char *get_view_file(int c) */ int put_eol(FILE *fd) { - if ( -#ifdef USE_CRNL - ( -# ifdef MKSESSION_NL - !mksession_nl && -# endif - (putc('\r', fd) < 0)) || +#if defined(USE_CRNL) && defined(MKSESSION_NL) + if ((!mksession_nl && putc('\r', fd) < 0) || putc('\n', fd) < 0) { +#elif defined(USE_CRNL) + if (putc('\r', fd) < 0 || putc('\n', fd) < 0) { +#else + if (putc('\n', fd) < 0) { #endif - (putc('\n', fd) < 0)) return FAIL; + } return OK; } diff --git a/src/nvim/ex_eval.c b/src/nvim/ex_eval.c index 41ad96a378..82d4c2b2d5 100644 --- a/src/nvim/ex_eval.c +++ b/src/nvim/ex_eval.c @@ -403,14 +403,15 @@ char_u *get_exception_string(void *value, int type, char_u *cmdname, int *should && (p[3] == ':' || (ascii_isdigit(p[3]) && p[4] == ':')))))) { - if (*p == NUL || p == mesg) - STRCAT(val, mesg); /* 'E123' missing or at beginning */ - else { - /* '"filename" E123: message text' */ - if (mesg[0] != '"' || p-2 < &mesg[1] || - p[-2] != '"' || p[-1] != ' ') - /* "E123:" is part of the file name. */ + if (*p == NUL || p == mesg) { + STRCAT(val, mesg); // 'E123' missing or at beginning + } else { + // '"filename" E123: message text' + if (mesg[0] != '"' || p-2 < &mesg[1] + || p[-2] != '"' || p[-1] != ' ') { + // "E123:" is part of the file name. continue; + } STRCAT(val, p); p[-2] = NUL; @@ -1565,22 +1566,21 @@ void ex_endtry(exarg_T *eap) void *rettv = NULL; 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"); - else { - /* - * Don't do something after an error, interrupt or throw in the try - * block, catch clause, or finally clause preceding this ":endtry" or - * when an error or interrupt occurred after a ":continue", ":break", - * ":return", or ":finish" in a try block or catch clause preceding this - * ":endtry" or when the try block never got active (because of an - * inactive surrounding conditional or after an error or interrupt or - * throw) or when there is a surrounding conditional and it has been - * made inactive by a ":continue", ":break", ":return", or ":finish" in - * the finally clause. The latter case need not be tested since then - * anything pending has already been discarded. */ - skip = did_emsg || got_int || did_throw || - !(cstack->cs_flags[cstack->cs_idx] & CSF_TRUE); + } else { + // Don't do something after an error, interrupt or throw in the try + // block, catch clause, or finally clause preceding this ":endtry" or + // when an error or interrupt occurred after a ":continue", ":break", + // ":return", or ":finish" in a try block or catch clause preceding this + // ":endtry" or when the try block never got active (because of an + // inactive surrounding conditional or after an error or interrupt or + // throw) or when there is a surrounding conditional and it has been + // made inactive by a ":continue", ":break", ":return", or ":finish" in + // the finally clause. The latter case need not be tested since then + // anything pending has already been discarded. + skip = (did_emsg || got_int || did_throw + || !(cstack->cs_flags[cstack->cs_idx] & CSF_TRUE)); if (!(cstack->cs_flags[cstack->cs_idx] & CSF_TRY)) { eap->errmsg = get_end_emsg(cstack); diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index a9e9ee76d5..a4e5a4dcd7 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -289,7 +289,9 @@ static uint8_t *command_line_enter(int firstc, long count, int indent) if (ccline.cmdbuff != NULL) { // Put line in history buffer (":" and "=" only when it was typed). - if (ccline.cmdlen && s->firstc != NUL + if (s->histype != HIST_INVALID + && ccline.cmdlen + && s->firstc != NUL && (s->some_key_typed || s->histype == HIST_SEARCH)) { add_to_history(s->histype, ccline.cmdbuff, true, s->histype == HIST_SEARCH ? s->firstc : NUL); @@ -622,8 +624,8 @@ static int command_line_execute(VimState *state, int key) // CTRL-\ e doesn't work when obtaining an expression, unless it // is in a mapping. if (s->c != Ctrl_N && s->c != Ctrl_G && (s->c != 'e' - || (ccline.cmdfirstc == '=' && - KeyTyped))) { + || (ccline.cmdfirstc == '=' + && KeyTyped))) { vungetc(s->c); s->c = Ctrl_BSL; } else if (s->c == 'e') { @@ -1268,7 +1270,7 @@ static int command_line_handle_key(CommandLineState *s) case K_KPAGEUP: case K_PAGEDOWN: case K_KPAGEDOWN: - if (hislen == 0 || s->firstc == NUL) { + if (s->histype == HIST_INVALID || hislen == 0 || s->firstc == NUL) { // no history return command_line_not_changed(s); } @@ -3981,6 +3983,7 @@ static void expand_shellcmd(char_u *filepat, int *num_file, char_u ***file, char_u *s, *e; int flags = flagsarg; int ret; + bool did_curdir = false; /* for ":set path=" and ":set tags=" halve backslashes for escaped * space */ @@ -3989,7 +3992,7 @@ static void expand_shellcmd(char_u *filepat, int *num_file, char_u ***file, if (pat[i] == '\\' && pat[i + 1] == ' ') STRMOVE(pat + i, pat + i + 1); - flags |= EW_FILE | EW_EXEC; + flags |= EW_FILE | EW_EXEC | EW_SHELLCMD; bool mustfree = false; // Track memory allocation for *path. /* For an absolute name we don't use $PATH. */ @@ -4009,12 +4012,24 @@ static void expand_shellcmd(char_u *filepat, int *num_file, char_u ***file, /* * Go over all directories in $PATH. Expand matches in that directory and - * collect them in "ga". + * collect them in "ga". When "." is not in $PATH also expaned for the + * current directory, to find "subdir/cmd". */ ga_init(&ga, (int)sizeof(char *), 10); - for (s = path; *s != NUL; s = e) { - if (*s == ' ') - ++s; /* Skip space used for absolute path name. */ + for (s = path; ; s = e) { + if (*s == NUL) { + if (did_curdir) { + break; + } + // Find directories in the current directory, path is empty. + did_curdir = true; + } else if (*s == '.') { + did_curdir = true; + } + + if (*s == ' ') { + s++; // Skip space used for absolute path name. + } e = vim_strchr(s, ':'); if (e == NULL) @@ -4294,7 +4309,7 @@ static HistoryType hist_char2type(const int c) return HIST_SEARCH; } default: { - assert(false); + return HIST_INVALID; } } // Silence -Wreturn-type @@ -4485,7 +4500,7 @@ HistoryType get_histtype(const char_u *const name, const size_t len, { // No argument: use current history. if (len == 0) { - return return_default ? HIST_DEFAULT :hist_char2type(ccline.cmdfirstc); + return return_default ? HIST_DEFAULT : hist_char2type(ccline.cmdfirstc); } for (HistoryType i = 0; history_names[i] != NULL; i++) { @@ -4519,8 +4534,10 @@ add_to_history ( histentry_T *hisptr; int len; - if (hislen == 0) /* no history */ + if (hislen == 0 || histype == HIST_INVALID) { // no history return; + } + assert(histype != HIST_DEFAULT); if (cmdmod.keeppatterns && histype == HIST_SEARCH) return; @@ -4991,7 +5008,6 @@ static int ex_window(void) win_T *wp; int i; linenr_T lnum; - int histtype; garray_T winsizes; char_u typestr[2]; int save_restart_edit = restart_edit; @@ -5040,7 +5056,7 @@ static int ex_window(void) /* Showing the prompt may have set need_wait_return, reset it. */ need_wait_return = FALSE; - histtype = hist_char2type(cmdwin_type); + const int histtype = hist_char2type(cmdwin_type); if (histtype == HIST_CMD || histtype == HIST_DEBUG) { if (p_wc == TAB) { add_map((char_u *)"<buffer> <Tab> <C-X><C-V>", INSERT); @@ -5055,7 +5071,7 @@ static int ex_window(void) /* Fill the buffer with the history. */ init_history(); - if (hislen > 0) { + if (hislen > 0 && histtype != HIST_INVALID) { i = hisidx[histtype]; if (i >= 0) { lnum = 0; diff --git a/src/nvim/farsi.c b/src/nvim/farsi.c index 47a132c0d0..61e17128ea 100644 --- a/src/nvim/farsi.c +++ b/src/nvim/farsi.c @@ -100,8 +100,9 @@ static char_u toF_Xor_X_(int c) case F_HE : tempc = _HE; - if (p_ri && - (curwin->w_cursor.col + 1 < (colnr_T)STRLEN(get_cursor_line_ptr()))) { + if (p_ri + && (curwin->w_cursor.col + 1 + < (colnr_T)STRLEN(get_cursor_line_ptr()))) { inc_cursor(); if (F_is_TyB_TyC_TyD(SRC_EDT, AT_CURSOR)) { tempc = _HE_; @@ -526,8 +527,8 @@ static void chg_l_toXor_X(void) { char_u tempc; - if ((curwin->w_cursor.col != 0) && - (curwin->w_cursor.col + 1 == (colnr_T)STRLEN(get_cursor_line_ptr()))) { + if ((curwin->w_cursor.col != 0) + && (curwin->w_cursor.col + 1 == (colnr_T)STRLEN(get_cursor_line_ptr()))) { return; } @@ -680,17 +681,17 @@ int fkmap(int c) } } - if ((c < 0x100) && - (isalpha(c) || - (c == '&') || - (c == '^') || - (c == ';') || - (c == '\'') || - (c == ',') || - (c == '[') || - (c == ']') || - (c == '{') || - (c == '}'))) { + if ((c < 0x100) + && (isalpha(c) + || (c == '&') + || (c == '^') + || (c == ';') + || (c == '\'') + || (c == ',') + || (c == '[') + || (c == ']') + || (c == '{') + || (c == '}'))) { chg_r_to_Xor_X_(); } diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index b9d9ea5457..6c0bc59d93 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -605,13 +605,14 @@ readfile ( * Don't do this for a "nofile" or "nowrite" buffer type. */ if (!bt_dontwrite(curbuf)) { check_need_swap(newfile); - if (!read_stdin && (curbuf != old_curbuf - || (using_b_ffname && (old_b_ffname != curbuf->b_ffname)) - || (using_b_fname && - (old_b_fname != curbuf->b_fname)))) { + if (!read_stdin + && (curbuf != old_curbuf + || (using_b_ffname && (old_b_ffname != curbuf->b_ffname)) + || (using_b_fname && (old_b_fname != curbuf->b_fname)))) { EMSG(_(e_auchangedbuf)); - if (!read_buffer) + if (!read_buffer) { close(fd); + } return FAIL; } #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). if (fname == NULL || *fname == NUL) { retval = xmalloc(MAXPATHL + extlen + 3); // +3 for PATHSEP, "_" (Win), NUL - if (os_dirname((char_u *)retval, MAXPATHL) == FAIL || - (fnamelen = strlen(retval)) == 0) { + if (os_dirname((char_u *)retval, MAXPATHL) == FAIL + || (fnamelen = strlen(retval)) == 0) { xfree(retval); return NULL; } diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 43cdd7a033..050862d811 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -2669,13 +2669,14 @@ do_map ( p = keys; do_backslash = (vim_strchr(p_cpo, CPO_BSLASH) == NULL); while (*p && (maptype == 1 || !ascii_iswhite(*p))) { - if ((p[0] == Ctrl_V || (do_backslash && p[0] == '\\')) && - p[1] != NUL) - ++p; /* skip CTRL-V or backslash */ - ++p; + if ((p[0] == Ctrl_V || (do_backslash && p[0] == '\\')) && p[1] != NUL) { + p++; // skip CTRL-V or backslash + } + p++; } - if (*p != NUL) + if (*p != NUL) { *p++ = NUL; + } p = skipwhite(p); rhs = p; diff --git a/src/nvim/hardcopy.c b/src/nvim/hardcopy.c index 6ce8954fef..916d27a964 100644 --- a/src/nvim/hardcopy.c +++ b/src/nvim/hardcopy.c @@ -2190,18 +2190,19 @@ int mch_print_init(prt_settings_T *psettings, char_u *jobname, int forceit) mbfont_opts[OPT_MBFONT_BOLDOBLIQUE].strlen); } - /* Check if need to use Courier for ASCII code range, and if so pick up - * the encoding to use */ - prt_use_courier = mbfont_opts[OPT_MBFONT_USECOURIER].present && - (TOLOWER_ASC(mbfont_opts[OPT_MBFONT_USECOURIER].string[0]) - == 'y'); + // Check if need to use Courier for ASCII code range, and if so pick up + // the encoding to use + prt_use_courier = ( + mbfont_opts[OPT_MBFONT_USECOURIER].present + && (TOLOWER_ASC(mbfont_opts[OPT_MBFONT_USECOURIER].string[0]) == 'y')); if (prt_use_courier) { - /* Use national ASCII variant unless ASCII wanted */ - if (mbfont_opts[OPT_MBFONT_ASCII].present && - (TOLOWER_ASC(mbfont_opts[OPT_MBFONT_ASCII].string[0]) == 'y')) + // Use national ASCII variant unless ASCII wanted + if (mbfont_opts[OPT_MBFONT_ASCII].present + && (TOLOWER_ASC(mbfont_opts[OPT_MBFONT_ASCII].string[0]) == 'y')) { prt_ascii_encoding = "ascii"; - else + } else { prt_ascii_encoding = prt_ps_mbfonts[cmap].ascii_enc; + } } 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_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; - need_break = (next_pos > prt_right_margin) && - ((next_pos - prt_right_margin) > (prt_right_margin*1e-5)); + need_break = ((next_pos > prt_right_margin) + && ((next_pos - prt_right_margin) > (prt_right_margin * 1e-5))); if (need_break) prt_flush_buffer(); diff --git a/src/nvim/indent_c.c b/src/nvim/indent_c.c index 17fadc4bfd..efe8e73a3c 100644 --- a/src/nvim/indent_c.c +++ b/src/nvim/indent_c.c @@ -2282,15 +2282,14 @@ int get_c_indent(void) * 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; - lookfor_cpp_namespace = TRUE; - } else if (start_brace == BRACE_AT_START && - lookfor_cpp_namespace) { /* '{' is at start */ - - lookfor_cpp_namespace = TRUE; + lookfor_cpp_namespace = true; + } else if (start_brace == BRACE_AT_START + && lookfor_cpp_namespace) { // '{' is at start + lookfor_cpp_namespace = true; } 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; l = skipwhite(get_cursor_line_ptr()); diff --git a/src/nvim/memline.c b/src/nvim/memline.c index f82f88a88f..4e35dd481f 100644 --- a/src/nvim/memline.c +++ b/src/nvim/memline.c @@ -786,9 +786,8 @@ void ml_recover(void) if (fname == NULL) /* When there is no file name */ fname = (char_u *)""; len = (int)STRLEN(fname); - if (len >= 4 && - STRNICMP(fname + len - 4, ".s", 2) - == 0 + if (len >= 4 + && STRNICMP(fname + len - 4, ".s", 2) == 0 && vim_strchr((char_u *)"UVWuvw", fname[len - 2]) != NULL && ASCII_ISALPHA(fname[len - 1])) { directly = TRUE; diff --git a/src/nvim/message.c b/src/nvim/message.c index 97b098c6d2..f60b128712 100644 --- a/src/nvim/message.c +++ b/src/nvim/message.c @@ -1570,39 +1570,31 @@ static void msg_puts_display(char_u *str, int maxlen, int attr, int recurse) int wrap; int did_last_char; - did_wait_return = FALSE; + did_wait_return = false; while ((maxlen < 0 || (int)(s - str) < maxlen) && *s != NUL) { - /* - * We are at the end of the screen line when: - * - When outputting a newline. - * - When outputting a character in the last column. - */ - if (!recurse && msg_row >= Rows - 1 && (*s == '\n' || ( - cmdmsg_rl - ? ( - msg_col <= 1 - || (*s == TAB && msg_col <= 7) - || (has_mbyte && - (*mb_ptr2cells)(s) > 1 && - msg_col <= 2) - ) - : - (msg_col + t_col >= Columns - 1 - || (*s == TAB && msg_col + - t_col >= ((Columns - 1) & ~7)) - || (has_mbyte && - (*mb_ptr2cells)(s) > 1 - && msg_col + t_col >= - Columns - 2) - )))) { - /* - * The screen is scrolled up when at the last row (some terminals - * scroll automatically, some don't. To avoid problems we scroll - * ourselves). - */ - if (t_col > 0) - /* output postponed text */ + // We are at the end of the screen line when: + // - When outputting a newline. + // - When outputting a character in the last column. + if (!recurse && msg_row >= Rows - 1 + && (*s == '\n' || (cmdmsg_rl + ? (msg_col <= 1 + || (*s == TAB && msg_col <= 7) + || (has_mbyte + && (*mb_ptr2cells)(s) > 1 + && msg_col <= 2)) + : (msg_col + t_col >= Columns - 1 + || (*s == TAB + && msg_col + t_col >= ((Columns - 1) & ~7)) + || (has_mbyte + && (*mb_ptr2cells)(s) > 1 + && msg_col + t_col >= Columns - 2))))) { + // The screen is scrolled up when at the last row (some terminals + // scroll automatically, some don't. To avoid problems we scroll + // ourselves). + if (t_col > 0) { + // output postponed text t_puts(&t_col, t_s, s, attr); + } /* When no more prompt and no more room, truncate here */ 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; l = 1; } - /* When drawing from right to left or when a double-wide character - * doesn't fit, draw a single character here. Otherwise collect - * characters and draw them all at once later. */ - if ( - cmdmsg_rl - || - (cw > 1 && msg_col + t_col >= Columns - 1) - ) { - if (l > 1) + // When drawing from right to left or when a double-wide character + // doesn't fit, draw a single character here. Otherwise collect + // characters and draw them all at once later. + if (cmdmsg_rl || (cw > 1 && msg_col + t_col >= Columns - 1)) { + if (l > 1) { s = screen_puts_mbyte(s, l, attr) - 1; - else + } else { msg_screen_putchar(*s, attr); + } } else { /* postpone this character until later */ 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 // avoid handling tricky cases like (short int)-32768 } else if (alternate_form) { - if (arg_sign != 0 && (fmt_spec == 'x' || fmt_spec == 'X' || - fmt_spec == 'b' || fmt_spec == 'B')) { + if (arg_sign != 0 && (fmt_spec == 'x' || fmt_spec == 'X' + || fmt_spec == 'b' || fmt_spec == 'B')) { tmp[str_arg_l++] = '0'; tmp[str_arg_l++] = fmt_spec; } diff --git a/src/nvim/misc1.c b/src/nvim/misc1.c index 43e0dd0c1a..53eceaa4ef 100644 --- a/src/nvim/misc1.c +++ b/src/nvim/misc1.c @@ -204,15 +204,12 @@ open_line ( else lead_len = 0; if (dir == FORWARD) { - /* - * Skip preprocessor directives, unless they are - * recognised as comments. - */ - if ( - lead_len == 0 && - ptr[0] == '#') { - while (ptr[0] == '#' && curwin->w_cursor.lnum > 1) + // Skip preprocessor directives, unless they are + // recognised as comments. + if (lead_len == 0 && ptr[0] == '#') { + while (ptr[0] == '#' && curwin->w_cursor.lnum > 1) { ptr = ml_get(--curwin->w_cursor.lnum); + } newindent = get_indent(); } if (flags & OPENLINE_DO_COM) @@ -296,28 +293,26 @@ open_line ( && cin_is_cinword(ptr)) did_si = TRUE; } - } else { /* dir == BACKWARD */ - /* - * Skip preprocessor directives, unless they are - * recognised as comments. - */ - if ( - lead_len == 0 && - ptr[0] == '#') { - int was_backslashed = FALSE; - - while ((ptr[0] == '#' || was_backslashed) && - curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) { - if (*ptr && ptr[STRLEN(ptr) - 1] == '\\') - was_backslashed = TRUE; - else - was_backslashed = FALSE; + } else { // dir == BACKWARD + // Skip preprocessor directives, unless they are + // recognised as comments. + if (lead_len == 0 && ptr[0] == '#') { + bool was_backslashed = false; + + while ((ptr[0] == '#' || was_backslashed) + && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) { + if (*ptr && ptr[STRLEN(ptr) - 1] == '\\') { + was_backslashed = true; + } else { + was_backslashed = false; + } ptr = ml_get(++curwin->w_cursor.lnum); } - if (was_backslashed) - newindent = 0; /* Got to end of file */ - else + if (was_backslashed) { + newindent = 0; // Got to end of file + } else { newindent = get_indent(); + } } p = skipwhite(ptr); if (*p == '}') /* if line starts with '}': do indent */ @@ -667,16 +662,12 @@ open_line ( did_si = can_si = FALSE; } else if (comment_end != NULL) { - /* - * 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 - * indent to align with the line containing the start of the - * comment. - */ - if (comment_end[0] == '*' && comment_end[1] == '/' && - (curbuf->b_p_ai - || do_si - )) { + // 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 + // indent to align with the line containing the start of the + // comment. + if (comment_end[0] == '*' && comment_end[1] == '/' + && (curbuf->b_p_ai || do_si)) { old_cursor = curwin->w_cursor; curwin->w_cursor.col = (colnr_T)(comment_end - saved_line); if ((pos = findmatch(NULL, NUL)) != NULL) { diff --git a/src/nvim/mouse.c b/src/nvim/mouse.c index 4611b69424..2f499e477c 100644 --- a/src/nvim/mouse.c +++ b/src/nvim/mouse.c @@ -535,9 +535,9 @@ static linenr_T find_longest_lnum(void) // Calculate maximum for horizontal scrollbar. Check for reasonable // line numbers, topline and botline can be invalid when displaying is // postponed. - if (curwin->w_topline <= curwin->w_cursor.lnum && - curwin->w_botline > curwin->w_cursor.lnum && - curwin->w_botline <= curbuf->b_ml.ml_line_count + 1) { + if (curwin->w_topline <= curwin->w_cursor.lnum + && curwin->w_botline > curwin->w_cursor.lnum + && curwin->w_botline <= curbuf->b_ml.ml_line_count + 1) { long max = 0; // Use maximum of all visible lines. Remember the lnum of the diff --git a/src/nvim/move.c b/src/nvim/move.c index ba79c0411a..b129c5cb7a 100644 --- a/src/nvim/move.c +++ b/src/nvim/move.c @@ -1010,12 +1010,9 @@ scrollup ( int byfold /* true: count a closed fold as one line */ ) { - if ( - (byfold && hasAnyFolding(curwin)) - || - curwin->w_p_diff - ) { - /* count each sequence of folded lines as one logical line */ + if ((byfold && hasAnyFolding(curwin)) + || curwin->w_p_diff) { + // count each sequence of folded lines as one logical line linenr_T lnum = curwin->w_topline; while (line_count--) { if (curwin->w_topfill > 0) diff --git a/src/nvim/msgpack_rpc/helpers.c b/src/nvim/msgpack_rpc/helpers.c index 5ef81721d4..0049ae6b95 100644 --- a/src/nvim/msgpack_rpc/helpers.c +++ b/src/nvim/msgpack_rpc/helpers.c @@ -419,8 +419,8 @@ void msgpack_rpc_validate(uint64_t *response_id, return; } - if ((type == kMessageTypeRequest && req->via.array.size != 4) || - (type == kMessageTypeNotification && req->via.array.size != 3)) { + if ((type == kMessageTypeRequest && req->via.array.size != 4) + || (type == kMessageTypeNotification && req->via.array.size != 3)) { api_set_error(err, Validation, _("Request array size should be 4 (request) " "or 3 (notification)")); return; diff --git a/src/nvim/normal.c b/src/nvim/normal.c index 75ee11bc9d..57638ee388 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -569,36 +569,33 @@ static bool normal_need_aditional_char(NormalState *s) static bool normal_need_redraw_mode_message(NormalState *s) { return ( - ( // 'showmode' is set and messages can be printed - p_smd && msg_silent == 0 - // must restart insert mode(ctrl+o or ctrl+l) or we just entered visual - // mode - && (restart_edit != 0 || (VIsual_active - && s->old_pos.lnum == curwin->w_cursor.lnum - && s->old_pos.col == curwin->w_cursor.col)) - // command-line must be cleared or redrawn - && (clear_cmdline || redraw_cmdline) - // some message was printed or scrolled - && (msg_didout || (msg_didany && msg_scroll)) - // it is fine to remove the current message - && !msg_nowait - // the command was the result of direct user input and not a mapping - && KeyTyped - ) - || - // must restart insert mode, not in visual mode and error message is - // being shown - (restart_edit != 0 && !VIsual_active && (msg_scroll && emsg_on_display)) - ) - // no register was used - && s->oa.regname == 0 - && !(s->ca.retval & CA_COMMAND_BUSY) - && stuff_empty() - && typebuf_typed() - && emsg_silent == 0 - && !did_wait_return - && s->oa.op_type == OP_NOP; + ((p_smd && msg_silent == 0 + // must restart insert mode(ctrl+o or ctrl+l) or we just entered visual + // mode + && (restart_edit != 0 || (VIsual_active + && s->old_pos.lnum == curwin->w_cursor.lnum + && s->old_pos.col == curwin->w_cursor.col)) + // command-line must be cleared or redrawn + && (clear_cmdline || redraw_cmdline) + // some message was printed or scrolled + && (msg_didout || (msg_didany && msg_scroll)) + // it is fine to remove the current message + && !msg_nowait + // the command was the result of direct user input and not a mapping + && KeyTyped) + // must restart insert mode, not in visual mode and error message is + // being shown + || (restart_edit != 0 && !VIsual_active && msg_scroll + && emsg_on_display)) + // no register was used + && s->oa.regname == 0 + && !(s->ca.retval & CA_COMMAND_BUSY) + && stuff_empty() + && typebuf_typed() + && emsg_silent == 0 + && !did_wait_return + && s->oa.op_type == OP_NOP); } static void normal_redraw_mode_message(NormalState *s) @@ -1436,19 +1433,20 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) } curwin->w_p_lbr = false; oap->is_VIsual = VIsual_active; - if (oap->motion_force == 'V') - oap->motion_type = MLINE; - else if (oap->motion_force == 'v') { - /* If the motion was linewise, "inclusive" will not have been set. - * Use "exclusive" to be consistent. Makes "dvj" work nice. */ - if (oap->motion_type == MLINE) + if (oap->motion_force == 'V') { + oap->motion_type = kMTLineWise; + } else if (oap->motion_force == 'v') { + // If the motion was linewise, "inclusive" will not have been set. + // Use "exclusive" to be consistent. Makes "dvj" work nice. + if (oap->motion_type == kMTLineWise) { oap->inclusive = false; - /* If the motion already was characterwise, toggle "inclusive" */ - else if (oap->motion_type == MCHAR) + } else if (oap->motion_type == kMTCharWise) { + // If the motion already was characterwise, toggle "inclusive" oap->inclusive = !oap->inclusive; - oap->motion_type = MCHAR; + } + oap->motion_type = kMTCharWise; } else if (oap->motion_force == Ctrl_V) { - /* Change line- or characterwise motion into Visual block mode. */ + // Change line- or characterwise motion into Visual block mode. VIsual_active = true; VIsual = oap->start; VIsual_mode = Ctrl_V; @@ -1586,13 +1584,15 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) * automatically. */ curwin->w_valid &= ~VALID_VIRTCOL; } else { - /* Include folded lines completely. */ - if (!VIsual_active && oap->motion_type == MLINE) { + // Include folded lines completely. + if (!VIsual_active && oap->motion_type == kMTLineWise) { if (hasFolding(curwin->w_cursor.lnum, &curwin->w_cursor.lnum, - NULL)) + NULL)) { curwin->w_cursor.col = 0; - if (hasFolding(oap->start.lnum, NULL, &oap->start.lnum)) + } + if (hasFolding(oap->start.lnum, NULL, &oap->start.lnum)) { oap->start.col = (colnr_T)STRLEN(ml_get(oap->start.lnum)); + } } oap->end = oap->start; oap->start = curwin->w_cursor; @@ -1663,17 +1663,16 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) } } - /* - * oap->inclusive defaults to true. - * If oap->end is on a NUL (empty line) oap->inclusive becomes - * false. This makes "d}P" and "v}dP" work the same. - */ - if (oap->motion_force == NUL || oap->motion_type == MLINE) + // oap->inclusive defaults to true. + // If oap->end is on a NUL (empty line) oap->inclusive becomes + // false. This makes "d}P" and "v}dP" work the same. + if (oap->motion_force == NUL || oap->motion_type == kMTLineWise) { oap->inclusive = true; + } if (VIsual_mode == 'V') { - oap->motion_type = MLINE; + oap->motion_type = kMTLineWise; } else if (VIsual_mode == 'v') { - oap->motion_type = MCHAR; + oap->motion_type = kMTCharWise; if (*ml_get_pos(&(oap->end)) == NUL && (include_line_break || !virtual_op) ) { @@ -1731,7 +1730,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) * oap->empty is set when start and end are the same. The inclusive * flag affects this too, unless yanking and the end is on a NUL. */ - oap->empty = (oap->motion_type != MLINE + oap->empty = (oap->motion_type != kMTLineWise && (!oap->inclusive || (oap->op_type == OP_YANK && gchar_pos(&oap->end) == NUL)) @@ -1756,23 +1755,23 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) /* * If the end of an operator is in column one while oap->motion_type - * is MCHAR and oap->inclusive is false, we put op_end after the last + * is kMTCharWise and oap->inclusive is false, we put op_end after the last * character in the previous line. If op_start is on or before the * first non-blank in the line, the operator becomes linewise * (strange, but that's the way vi does it). */ - if (oap->motion_type == MCHAR + if (oap->motion_type == kMTCharWise && oap->inclusive == false && !(cap->retval & CA_NO_ADJ_OP_END) && oap->end.col == 0 && (!oap->is_VIsual || *p_sel == 'o') && oap->line_count > 1) { oap->end_adjusted = true; // remember that we did this - --oap->line_count; - --oap->end.lnum; - if (inindent(0)) - oap->motion_type = MLINE; - else { + oap->line_count--; + oap->end.lnum--; + if (inindent(0)) { + oap->motion_type = kMTLineWise; + } else { oap->end.col = (colnr_T)STRLEN(ml_get(oap->end.lnum)); if (oap->end.col) { --oap->end.col; @@ -1811,8 +1810,9 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) CancelRedo(); } else { (void)op_delete(oap); - if (oap->motion_type == MLINE && has_format_option(FO_AUTO)) - u_save_cursor(); /* cursor line wasn't saved yet */ + if (oap->motion_type == kMTLineWise && has_format_option(FO_AUTO)) { + u_save_cursor(); // cursor line wasn't saved yet + } auto_format(false, true); } break; @@ -2011,7 +2011,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) /* * if 'sol' not set, go back to old column for some commands */ - if (!p_sol && oap->motion_type == MLINE && !oap->end_adjusted + if (!p_sol && oap->motion_type == kMTLineWise && !oap->end_adjusted && (oap->op_type == OP_LSHIFT || oap->op_type == OP_RSHIFT || oap->op_type == OP_DELETE)) { curwin->w_p_lbr = false; @@ -2086,13 +2086,14 @@ static void op_function(oparg_T *oap) /* Set '[ and '] marks to text to be operated on. */ curbuf->b_op_start = oap->start; curbuf->b_op_end = oap->end; - if (oap->motion_type != MLINE && !oap->inclusive) - /* Exclude the end position. */ + if (oap->motion_type != kMTLineWise && !oap->inclusive) { + // Exclude the end position. decl(&curbuf->b_op_end); + } - if (oap->motion_type == MBLOCK) { + if (oap->motion_type == kMTBlockWise) { argv[0] = (char_u *)"block"; - } else if (oap->motion_type == MLINE) { + } else if (oap->motion_type == kMTLineWise) { argv[0] = (char_u *)"line"; } else { argv[0] = (char_u *)"char"; @@ -2530,7 +2531,7 @@ do_mouse ( */ if (!is_drag && oap != NULL && oap->op_type != OP_NOP) { got_click = false; - oap->motion_type = MCHAR; + oap->motion_type = kMTCharWise; } /* When releasing the button let jump_to_mouse() know. */ @@ -2769,21 +2770,23 @@ do_mouse ( end_visual = curwin->w_cursor; while (gc = gchar_pos(&end_visual), ascii_iswhite(gc)) inc(&end_visual); - if (oap != NULL) - oap->motion_type = MCHAR; + if (oap != NULL) { + oap->motion_type = kMTCharWise; + } if (oap != NULL && VIsual_mode == 'v' && !vim_iswordc(gchar_pos(&end_visual)) && equalpos(curwin->w_cursor, VIsual) && (pos = findmatch(oap, NUL)) != NULL) { curwin->w_cursor = *pos; - if (oap->motion_type == MLINE) + if (oap->motion_type == kMTLineWise) { VIsual_mode = 'V'; - else if (*p_sel == 'e') { - if (lt(curwin->w_cursor, VIsual)) - ++VIsual.col; - else - ++curwin->w_cursor.col; + } else if (*p_sel == 'e') { + if (lt(curwin->w_cursor, VIsual)) { + VIsual.col++; + } else { + curwin->w_cursor.col++; + } } } } @@ -3781,7 +3784,7 @@ static bool nv_screengo(oparg_T *oap, int dir, long dist) int width1; /* text width for first screen line */ int width2; /* test width for wrapped screen line */ - oap->motion_type = MCHAR; + oap->motion_type = kMTCharWise; oap->inclusive = (curwin->w_curswant == MAXCOL); col_off1 = curwin_col_off(); @@ -4054,16 +4057,15 @@ static void nv_zet(cmdarg_T *cap) } dozet: - if ( - /* "zf" and "zF" are always an operator, "zd", "zo", "zO", "zc" - * and "zC" only in Visual mode. "zj" and "zk" are motion - * commands. */ - cap->nchar != 'f' && cap->nchar != 'F' - && !(VIsual_active && vim_strchr((char_u *)"dcCoO", cap->nchar)) - && cap->nchar != 'j' && cap->nchar != 'k' - && - checkclearop(cap->oap)) + // "zf" and "zF" are always an operator, "zd", "zo", "zO", "zc" + // and "zC" only in Visual mode. "zj" and "zk" are motion + // commands. */ + if (cap->nchar != 'f' && cap->nchar != 'F' + && !(VIsual_active && vim_strchr((char_u *)"dcCoO", cap->nchar)) + && cap->nchar != 'j' && cap->nchar != 'k' + && checkclearop(cap->oap)) { return; + } /* * For "z+", "z<CR>", "zt", "z.", "zz", "z^", "z-", "zb": @@ -4464,8 +4466,8 @@ static void nv_colon(cmdarg_T *cap) nv_operator(cap); else { if (cap->oap->op_type != OP_NOP) { - /* Using ":" as a movement is characterwise exclusive. */ - cap->oap->motion_type = MCHAR; + // Using ":" as a movement is characterwise exclusive. + cap->oap->motion_type = kMTCharWise; cap->oap->inclusive = false; } else if (cap->count0) { /* translate "count:" into ":.,.+(count - 1)" */ @@ -4864,7 +4866,7 @@ static void nv_scroll(cmdarg_T *cap) linenr_T lnum; int half; - cap->oap->motion_type = MLINE; + cap->oap->motion_type = kMTLineWise; setpcmark(); if (cap->cmdchar == 'L') { @@ -4944,7 +4946,7 @@ static void nv_right(cmdarg_T *cap) return; } - cap->oap->motion_type = MCHAR; + cap->oap->motion_type = kMTCharWise; cap->oap->inclusive = false; PAST_LINE = (VIsual_active && *p_sel != 'o'); @@ -5031,7 +5033,7 @@ static void nv_left(cmdarg_T *cap) return; } - cap->oap->motion_type = MCHAR; + cap->oap->motion_type = kMTCharWise; cap->oap->inclusive = false; for (n = cap->count1; n > 0; --n) { if (oneleft() == false) { @@ -5093,11 +5095,12 @@ static void nv_up(cmdarg_T *cap) cap->arg = BACKWARD; nv_page(cap); } else { - cap->oap->motion_type = MLINE; - if (cursor_up(cap->count1, cap->oap->op_type == OP_NOP) == false) + cap->oap->motion_type = kMTLineWise; + if (cursor_up(cap->count1, cap->oap->op_type == OP_NOP) == false) { clearopbeep(cap->oap); - else if (cap->arg) + } else if (cap->arg) { beginline(BL_WHITE | BL_FIX); + } } } @@ -5111,23 +5114,24 @@ static void nv_down(cmdarg_T *cap) /* <S-Down> is page down */ cap->arg = FORWARD; nv_page(cap); - } else - /* In a quickfix window a <CR> jumps to the error under the cursor. */ - if (bt_quickfix(curbuf) && cap->cmdchar == CAR) - if (curwin->w_llist_ref == NULL) - do_cmdline_cmd(".cc"); /* quickfix window */ - else - do_cmdline_cmd(".ll"); /* location list window */ - else { - /* In the cmdline window a <CR> executes the command. */ - if (cmdwin_type != 0 && cap->cmdchar == CAR) + } else if (bt_quickfix(curbuf) && cap->cmdchar == CAR) { + // In a quickfix window a <CR> jumps to the error under the cursor. + if (curwin->w_llist_ref == NULL) { + do_cmdline_cmd(".cc"); // quickfix window + } else { + do_cmdline_cmd(".ll"); // location list window + } + } else { + // In the cmdline window a <CR> executes the command. + if (cmdwin_type != 0 && cap->cmdchar == CAR) { cmdwin_result = CAR; - else { - cap->oap->motion_type = MLINE; - if (cursor_down(cap->count1, cap->oap->op_type == OP_NOP) == false) + } else { + cap->oap->motion_type = kMTLineWise; + if (cursor_down(cap->count1, cap->oap->op_type == OP_NOP) == false) { clearopbeep(cap->oap); - else if (cap->arg) + } else if (cap->arg) { beginline(BL_WHITE | BL_FIX); + } } } } @@ -5188,7 +5192,7 @@ static void nv_end(cmdarg_T *cap) */ static void nv_dollar(cmdarg_T *cap) { - cap->oap->motion_type = MCHAR; + cap->oap->motion_type = kMTCharWise; cap->oap->inclusive = true; /* In virtual mode when off the edge of a line and an operator * is pending (whew!) keep the cursor where it is. @@ -5263,18 +5267,19 @@ static int normal_search( { int i; - cap->oap->motion_type = MCHAR; + cap->oap->motion_type = kMTCharWise; cap->oap->inclusive = false; cap->oap->use_reg_one = true; curwin->w_set_curswant = true; i = do_search(cap->oap, dir, pat, cap->count1, - opt | SEARCH_OPT | SEARCH_ECHO | SEARCH_MSG, NULL); - if (i == 0) + opt | SEARCH_OPT | SEARCH_ECHO | SEARCH_MSG, NULL); + if (i == 0) { clearop(cap->oap); - else { - if (i == 2) - cap->oap->motion_type = MLINE; + } else { + if (i == 2) { + cap->oap->motion_type = kMTLineWise; + } curwin->w_cursor.coladd = 0; if (cap->oap->op_type == OP_NOP && (fdo_flags & FDO_SEARCH) && KeyTyped) foldOpenCursor(); @@ -5301,10 +5306,10 @@ static void nv_csearch(cmdarg_T *cap) else t_cmd = false; - cap->oap->motion_type = MCHAR; - if (IS_SPECIAL(cap->nchar) || searchc(cap, t_cmd) == false) + cap->oap->motion_type = kMTCharWise; + if (IS_SPECIAL(cap->nchar) || searchc(cap, t_cmd) == false) { clearopbeep(cap->oap); - else { + } else { curwin->w_set_curswant = true; /* Include a Tab for "tx" and for "dfx". */ if (gchar_cursor() == TAB && virtual_active() && cap->arg == FORWARD @@ -5336,7 +5341,7 @@ static void nv_brackets(cmdarg_T *cap) int findc; int c; - cap->oap->motion_type = MCHAR; + cap->oap->motion_type = kMTCharWise; cap->oap->inclusive = false; old_pos = curwin->w_cursor; curwin->w_cursor.coladd = 0; /* TODO: don't do this for an error. */ @@ -5626,11 +5631,11 @@ static void nv_percent(cmdarg_T *cap) linenr_T lnum = curwin->w_cursor.lnum; cap->oap->inclusive = true; - if (cap->count0) { /* {cnt}% : goto {cnt} percentage in file */ - if (cap->count0 > 100) + if (cap->count0) { // {cnt}% : goto {cnt} percentage in file + if (cap->count0 > 100) { clearopbeep(cap->oap); - else { - cap->oap->motion_type = MLINE; + } else { + cap->oap->motion_type = kMTLineWise; setpcmark(); /* Round up, so CTRL-G will give same value. Watch out for a * large line count, the line number must not go negative! */ @@ -5644,8 +5649,8 @@ static void nv_percent(cmdarg_T *cap) curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; beginline(BL_SOL | BL_FIX); } - } else { /* "%" : go to matching paren */ - cap->oap->motion_type = MCHAR; + } else { // "%" : go to matching paren + cap->oap->motion_type = kMTCharWise; cap->oap->use_reg_one = true; if ((pos = findmatch(cap->oap, NUL)) == NULL) clearopbeep(cap->oap); @@ -5670,7 +5675,7 @@ static void nv_percent(cmdarg_T *cap) */ static void nv_brace(cmdarg_T *cap) { - cap->oap->motion_type = MCHAR; + cap->oap->motion_type = kMTCharWise; cap->oap->use_reg_one = true; /* The motion used to be inclusive for "(", but that is not what Vi does. */ cap->oap->inclusive = false; @@ -5704,7 +5709,7 @@ static void nv_mark(cmdarg_T *cap) */ static void nv_findpar(cmdarg_T *cap) { - cap->oap->motion_type = MCHAR; + cap->oap->motion_type = kMTCharWise; cap->oap->inclusive = false; cap->oap->use_reg_one = true; curwin->w_set_curswant = true; @@ -5808,14 +5813,11 @@ static void nv_replace(cmdarg_T *cap) return; } - /* - * 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. - * Other characters are done below to avoid problems with things like - * 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)) { + // 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. + // Other characters are done below to avoid problems with things like + // 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)) { stuffnumReadbuff(cap->count1); stuffcharReadbuff('R'); stuffcharReadbuff('\t'); @@ -6082,10 +6084,11 @@ static void nv_cursormark(cmdarg_T *cap, int flag, pos_T *pos) else check_cursor(); } - cap->oap->motion_type = flag ? MLINE : MCHAR; - if (cap->cmdchar == '`') + cap->oap->motion_type = flag ? kMTLineWise : kMTCharWise; + if (cap->cmdchar == '`') { cap->oap->use_reg_one = true; - cap->oap->inclusive = false; /* ignored if not MCHAR */ + } + cap->oap->inclusive = false; // ignored if not kMTCharWise curwin->w_set_curswant = true; } @@ -6562,7 +6565,7 @@ static void nv_g_cmd(cmdarg_T *cap) if (!curwin->w_p_wrap || hasFolding(curwin->w_cursor.lnum, NULL, NULL) ) { - oap->motion_type = MLINE; + oap->motion_type = kMTLineWise; i = cursor_down(cap->count1, oap->op_type == OP_NOP); } else i = nv_screengo(oap, FORWARD, cap->count1); @@ -6577,7 +6580,7 @@ static void nv_g_cmd(cmdarg_T *cap) if (!curwin->w_p_wrap || hasFolding(curwin->w_cursor.lnum, NULL, NULL) ) { - oap->motion_type = MLINE; + oap->motion_type = kMTLineWise; i = cursor_up(cap->count1, oap->op_type == OP_NOP); } else i = nv_screengo(oap, BACKWARD, cap->count1); @@ -6604,7 +6607,7 @@ static void nv_g_cmd(cmdarg_T *cap) case 'm': case K_HOME: case K_KHOME: - oap->motion_type = MCHAR; + oap->motion_type = kMTCharWise; oap->inclusive = false; if (curwin->w_p_wrap && curwin->w_width != 0 @@ -6637,7 +6640,7 @@ static void nv_g_cmd(cmdarg_T *cap) case '_': /* "g_": to the last non-blank character in the line or <count> lines * downward. */ - cap->oap->motion_type = MCHAR; + cap->oap->motion_type = kMTCharWise; cap->oap->inclusive = true; curwin->w_curswant = MAXCOL; if (cursor_down(cap->count1 - 1, @@ -6665,7 +6668,7 @@ static void nv_g_cmd(cmdarg_T *cap) { int col_off = curwin_col_off(); - oap->motion_type = MCHAR; + oap->motion_type = kMTCharWise; oap->inclusive = true; if (curwin->w_p_wrap && curwin->w_width != 0 @@ -6727,7 +6730,7 @@ static void nv_g_cmd(cmdarg_T *cap) */ case 'e': case 'E': - oap->motion_type = MCHAR; + oap->motion_type = kMTCharWise; curwin->w_set_curswant = true; oap->inclusive = true; if (bckend_word(cap->count1, cap->nchar == 'E', false) == false) @@ -7087,17 +7090,19 @@ static void set_op_var(int optype) */ static void nv_lineop(cmdarg_T *cap) { - cap->oap->motion_type = MLINE; - if (cursor_down(cap->count1 - 1L, cap->oap->op_type == OP_NOP) == false) + cap->oap->motion_type = kMTLineWise; + if (cursor_down(cap->count1 - 1L, cap->oap->op_type == OP_NOP) == false) { clearopbeep(cap->oap); - else if ( (cap->oap->op_type == OP_DELETE /* only with linewise motions */ + } else if ((cap->oap->op_type == OP_DELETE + // only with linewise motions && cap->oap->motion_force != 'v' && cap->oap->motion_force != Ctrl_V) || cap->oap->op_type == OP_LSHIFT - || cap->oap->op_type == OP_RSHIFT) + || cap->oap->op_type == OP_RSHIFT) { beginline(BL_SOL | BL_FIX); - else if (cap->oap->op_type != OP_YANK) /* 'Y' does not move cursor */ + } else if (cap->oap->op_type != OP_YANK) { // 'Y' does not move cursor beginline(BL_WHITE | BL_FIX); + } } /* @@ -7121,7 +7126,7 @@ static void nv_home(cmdarg_T *cap) */ static void nv_pipe(cmdarg_T *cap) { - cap->oap->motion_type = MCHAR; + cap->oap->motion_type = kMTCharWise; cap->oap->inclusive = false; beginline(0); if (cap->count0 > 0) { @@ -7140,7 +7145,7 @@ static void nv_pipe(cmdarg_T *cap) */ static void nv_bck_word(cmdarg_T *cap) { - cap->oap->motion_type = MCHAR; + cap->oap->motion_type = kMTCharWise; cap->oap->inclusive = false; curwin->w_set_curswant = true; if (bck_word(cap->count1, cap->arg, false) == false) @@ -7189,7 +7194,7 @@ static void nv_wordcmd(cmdarg_T *cap) } } - cap->oap->motion_type = MCHAR; + cap->oap->motion_type = kMTCharWise; curwin->w_set_curswant = true; if (word_end) n = end_word(cap->count1, cap->arg, flag, false); @@ -7240,7 +7245,7 @@ static void adjust_cursor(oparg_T *oap) */ static void nv_beginline(cmdarg_T *cap) { - cap->oap->motion_type = MCHAR; + cap->oap->motion_type = kMTCharWise; cap->oap->inclusive = false; beginline(cap->arg); if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) @@ -7319,7 +7324,7 @@ static void nv_goto(cmdarg_T *cap) lnum = curbuf->b_ml.ml_line_count; else lnum = 1L; - cap->oap->motion_type = MLINE; + cap->oap->motion_type = kMTLineWise; setpcmark(); /* When a count is given, use it instead of the default lnum */ @@ -7805,7 +7810,7 @@ static void get_op_vcol( return; } - oap->motion_type = MBLOCK; + oap->motion_type = kMTBlockWise; // prevent from moving onto a trail byte if (has_mbyte) { diff --git a/src/nvim/normal.h b/src/nvim/normal.h index 95619c7ef6..51170105ed 100644 --- a/src/nvim/normal.h +++ b/src/nvim/normal.h @@ -10,18 +10,29 @@ #define FIND_STRING 2 /* find any string (WORD) */ #define FIND_EVAL 4 /* include "->", "[]" and "." */ +/// Motion types, used for operators and for yank/delete registers. +/// +/// The three valid numerical values must not be changed, as they +/// are used in external communication and serialization. +typedef enum { + kMTCharWise = 0, ///< character-wise movement/register + kMTLineWise = 1, ///< line-wise movement/register + kMTBlockWise = 2, ///< block-wise movement/register + kMTUnknown = -1 ///< Unknown or invalid motion type +} MotionType; + /* * Arguments for operators. */ typedef struct oparg_S { int op_type; // current pending operator type int regname; // register to use for the operator - int motion_type; // type of the current cursor motion + MotionType motion_type; // type of the current cursor motion int motion_force; // force motion type: 'v', 'V' or CTRL-V bool use_reg_one; // true if delete uses reg 1 even when not // linewise bool inclusive; // true if char motion is inclusive (only - // valid when motion_type is MCHAR) + // valid when motion_type is kMTCharWise) bool end_adjusted; // backuped b_op_end one char (only used by // do_format()) pos_T start; // start of the operator diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 601890d133..a6ff68a8f8 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -191,7 +191,7 @@ void op_shift(oparg_T *oap, int curs_top, int amount) (linenr_T)(oap->end.lnum + 1)) == FAIL) return; - if (oap->motion_type == MBLOCK) { + if (oap->motion_type == kMTBlockWise) { block_col = curwin->w_cursor.col; } @@ -199,7 +199,7 @@ void op_shift(oparg_T *oap, int curs_top, int amount) first_char = *get_cursor_line_ptr(); if (first_char == NUL) { // empty line curwin->w_cursor.col = 0; - } else if (oap->motion_type == MBLOCK) { + } else if (oap->motion_type == kMTBlockWise) { shift_block(oap, amount); } else if (first_char != '#' || !preprocs_left()) { // Move the line right if it doesn't start with '#', 'smartindent' @@ -213,7 +213,7 @@ void op_shift(oparg_T *oap, int curs_top, int amount) /* The cursor line is not in a closed fold */ foldOpenCursor(); - if (oap->motion_type == MBLOCK) { + if (oap->motion_type == kMTBlockWise) { curwin->w_cursor.lnum = oap->start.lnum; curwin->w_cursor.col = block_col; } else if (curs_top) { /* put cursor on first line, for ">>" */ @@ -811,17 +811,17 @@ yankreg_T *copy_register(int name) return copy; } -/* - * return TRUE if the current yank register has type MLINE - */ -int yank_register_mline(int regname) +/// check if the current yank register has kMTLineWise register type +bool yank_register_mline(int regname) { - if (regname != 0 && !valid_yank_reg(regname, false)) - return FALSE; - if (regname == '_') /* black hole is always empty */ - return FALSE; + if (regname != 0 && !valid_yank_reg(regname, false)) { + return false; + } + if (regname == '_') { // black hole is always empty + return false; + } yankreg_T *reg = get_yank_register(regname, YREG_PASTE); - return reg->y_type == MLINE; + return reg->y_type == kMTLineWise; } /* @@ -919,7 +919,7 @@ static int stuff_yank(int regname, char_u *p) reg->y_array = (char_u **)xmalloc(sizeof(char_u *)); reg->y_array[0] = p; reg->y_size = 1; - reg->y_type = MCHAR; /* used to be MLINE, why? */ + reg->y_type = kMTCharWise; } reg->timestamp = os_time(); return OK; @@ -1011,8 +1011,8 @@ do_execreg ( for (i = reg->y_size - 1; i >= 0; i--) { char_u *escaped; - /* insert NL between lines and after last line if type is MLINE */ - if (reg->y_type == MLINE || i < reg->y_size - 1 + // insert NL between lines and after last line if type is kMTLineWise + if (reg->y_type == kMTLineWise || i < reg->y_size - 1 || addcr) { if (ins_typebuf((char_u *)"\n", remap, 0, TRUE, silent) == FAIL) return FAIL; @@ -1137,12 +1137,11 @@ insert_reg ( else { for (i = 0; i < reg->y_size; i++) { stuffescaped(reg->y_array[i], literally); - /* - * Insert a newline between lines and after last line if - * y_type is MLINE. - */ - if (reg->y_type == MLINE || i < reg->y_size - 1) + // Insert a newline between lines and after last line if + // y_type is kMTLineWise. + if (reg->y_type == kMTLineWise || i < reg->y_size - 1) { stuffcharReadbuff('\n'); + } } } } @@ -1283,9 +1282,9 @@ bool cmdline_paste_reg(int regname, bool literally, bool remcr) for (i = 0; i < reg->y_size; i++) { cmdline_paste_str(reg->y_array[i], literally); - // Insert ^M between lines and after last line if type is MLINE. + // Insert ^M between lines and after last line if type is kMTLineWise. // Don't do this when "remcr" is true. - if ((reg->y_type == MLINE || i < reg->y_size - 1) && !remcr) { + if ((reg->y_type == kMTLineWise || i < reg->y_size - 1) && !remcr) { cmdline_paste_str((char_u *)"\r", literally); } @@ -1329,10 +1328,10 @@ int op_delete(oparg_T *oap) /* * Imitate the strange Vi behaviour: If the delete spans more than one - * line and motion_type == MCHAR and the result is a blank line, make the + * line and motion_type == kMTCharWise and the result is a blank line, make the * delete linewise. Don't do this for the change command or Visual mode. */ - if (oap->motion_type == MCHAR + if (oap->motion_type == kMTCharWise && !oap->is_VIsual && oap->line_count > 1 && oap->motion_force == NUL @@ -1341,15 +1340,16 @@ int op_delete(oparg_T *oap) if (*ptr != NUL) ptr += oap->inclusive; ptr = skipwhite(ptr); - if (*ptr == NUL && inindent(0)) - oap->motion_type = MLINE; + if (*ptr == NUL && inindent(0)) { + oap->motion_type = kMTLineWise; + } } /* * Check for trying to delete (e.g. "D") in an empty line. * Note: For the change operator it is ok. */ - if (oap->motion_type != MLINE + if (oap->motion_type != kMTLineWise && oap->line_count == 1 && oap->op_type == OP_DELETE && *ml_get(oap->start.lnum) == NUL) { @@ -1385,7 +1385,7 @@ int op_delete(oparg_T *oap) * Put deleted text into register 1 and shift number registers if the * delete contains a line break, or when a regname has been specified. */ - if (oap->regname != 0 || oap->motion_type == MLINE + if (oap->regname != 0 || oap->motion_type == kMTLineWise || oap->line_count > 1 || oap->use_reg_one) { free_register(&y_regs[9]); /* free register "9 */ for (n = 9; n > 1; n--) @@ -1398,7 +1398,7 @@ int op_delete(oparg_T *oap) /* Yank into small delete register when no named register specified * and the delete is within one line. */ - if (oap->regname == 0 && oap->motion_type != MLINE + if (oap->regname == 0 && oap->motion_type != kMTLineWise && oap->line_count == 1) { reg = get_yank_register('-', YREG_YANK); op_yank_reg(oap, false, reg, false); @@ -1414,7 +1414,7 @@ int op_delete(oparg_T *oap) /* * block mode delete */ - if (oap->motion_type == MBLOCK) { + if (oap->motion_type == kMTBlockWise) { if (u_save((linenr_T)(oap->start.lnum - 1), (linenr_T)(oap->end.lnum + 1)) == FAIL) { return FAIL; @@ -1452,9 +1452,9 @@ int op_delete(oparg_T *oap) check_cursor_col(); changed_lines(curwin->w_cursor.lnum, curwin->w_cursor.col, - oap->end.lnum + 1, 0L); - oap->line_count = 0; /* no lines deleted */ - } else if (oap->motion_type == MLINE) { + oap->end.lnum + 1, 0L); + oap->line_count = 0; // no lines deleted + } else if (oap->motion_type == kMTLineWise) { if (oap->op_type == OP_CHANGE) { /* Delete the lines except the first one. Temporarily move the * cursor to the next line. Save the current line number, if the @@ -1582,7 +1582,7 @@ int op_delete(oparg_T *oap) msgmore(curbuf->b_ml.ml_line_count - old_lcount); setmarks: - if (oap->motion_type == MBLOCK) { + if (oap->motion_type == kMTBlockWise) { curbuf->b_op_end.lnum = oap->end.lnum; curbuf->b_op_end.col = oap->start.col; } else @@ -1643,7 +1643,7 @@ int op_replace(oparg_T *oap, int c) /* * block mode replace */ - if (oap->motion_type == MBLOCK) { + if (oap->motion_type == kMTBlockWise) { bd.is_MAX = (curwin->w_curswant == MAXCOL); for (; curwin->w_cursor.lnum <= oap->end.lnum; ++curwin->w_cursor.lnum) { curwin->w_cursor.col = 0; /* make sure cursor position is valid */ @@ -1732,10 +1732,8 @@ int op_replace(oparg_T *oap, int c) } } } else { - /* - * MCHAR and MLINE motion replace. - */ - if (oap->motion_type == MLINE) { + // Characterwise or linewise motion replace. + if (oap->motion_type == kMTLineWise) { oap->start.col = 0; curwin->w_cursor.col = 0; oap->end.col = (colnr_T)STRLEN(ml_get(oap->end.lnum)); @@ -1825,8 +1823,8 @@ void op_tilde(oparg_T *oap) return; pos = oap->start; - if (oap->motion_type == MBLOCK) { // Visual block mode - for (; pos.lnum <= oap->end.lnum; ++pos.lnum) { + if (oap->motion_type == kMTBlockWise) { // Visual block mode + for (; pos.lnum <= oap->end.lnum; pos.lnum++) { int one_change; block_prep(oap, &bd, pos.lnum, FALSE); @@ -1837,8 +1835,8 @@ void op_tilde(oparg_T *oap) } if (did_change) changed_lines(oap->start.lnum, 0, oap->end.lnum + 1, 0L); - } else { /* not block mode */ - if (oap->motion_type == MLINE) { + } else { // not block mode + if (oap->motion_type == kMTLineWise) { oap->start.col = 0; pos.col = 0; oap->end.col = (colnr_T)STRLEN(ml_get(oap->end.lnum)); @@ -1988,7 +1986,7 @@ void op_insert(oparg_T *oap, long count1) curwin->w_cursor.lnum = oap->start.lnum; update_screen(INVERTED); - if (oap->motion_type == MBLOCK) { + if (oap->motion_type == kMTBlockWise) { // When 'virtualedit' is used, need to insert the extra spaces before // doing block_prep(). When only "block" is used, virtual edit is // already disabled, but still need it when calling @@ -2014,7 +2012,7 @@ void op_insert(oparg_T *oap, long count1) } if (oap->op_type == OP_APPEND) { - if (oap->motion_type == MBLOCK + if (oap->motion_type == kMTBlockWise && curwin->w_cursor.coladd == 0 ) { /* Move the cursor to the character right of the block. */ @@ -2048,8 +2046,8 @@ void op_insert(oparg_T *oap, long count1) // 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 // might have actually been reduced, so need to adjust here. */ - if (t1.lnum == curbuf->b_op_start_orig.lnum && - lt(curbuf->b_op_start_orig, t1)) { + if (t1.lnum == curbuf->b_op_start_orig.lnum + && lt(curbuf->b_op_start_orig, t1)) { oap->start = curbuf->b_op_start_orig; } @@ -2059,7 +2057,7 @@ void op_insert(oparg_T *oap, long count1) if (curwin->w_cursor.lnum != oap->start.lnum || got_int) return; - if (oap->motion_type == MBLOCK) { + if (oap->motion_type == kMTBlockWise) { struct block_def bd2; /* The user may have moved the cursor before inserting something, try @@ -2146,7 +2144,7 @@ int op_change(oparg_T *oap) struct block_def bd; l = oap->start.col; - if (oap->motion_type == MLINE) { + if (oap->motion_type == kMTLineWise) { l = 0; if (!p_paste && curbuf->b_p_si && !curbuf->b_p_cin @@ -2168,7 +2166,7 @@ int op_change(oparg_T *oap) // check for still on same line (<CR> in inserted text meaningless) // skip blank lines too - if (oap->motion_type == MBLOCK) { + if (oap->motion_type == kMTBlockWise) { // Add spaces before getting the current line length. if (virtual_op && (curwin->w_cursor.coladd > 0 || gchar_cursor() == NUL)) { @@ -2180,8 +2178,9 @@ int op_change(oparg_T *oap) bd.textcol = curwin->w_cursor.col; } - if (oap->motion_type == MLINE) + if (oap->motion_type == kMTLineWise) { fix_indent(); + } retval = edit(NUL, FALSE, (linenr_T)1); @@ -2190,7 +2189,7 @@ int op_change(oparg_T *oap) * block. * Don't repeat the insert when Insert mode ended with CTRL-C. */ - if (oap->motion_type == MBLOCK + if (oap->motion_type == kMTBlockWise && oap->start.lnum != oap->end.lnum && !got_int) { // Auto-indenting may have changed the indent. If the cursor was past // the indent, exclude that indent change from the inserted text. @@ -2318,7 +2317,7 @@ static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append) char_u **new_ptr; linenr_T lnum; /* current line number */ long j; - int yanktype = oap->motion_type; + MotionType yank_type = oap->motion_type; long yanklines = oap->line_count; linenr_T yankendlnum = oap->end.lnum; char_u *p; @@ -2336,19 +2335,19 @@ static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append) * If the cursor was in column 1 before and after the movement, and the * operator is not inclusive, the yank is always linewise. */ - if (oap->motion_type == MCHAR + if (oap->motion_type == kMTCharWise && oap->start.col == 0 && !oap->inclusive && (!oap->is_VIsual || *p_sel == 'o') && oap->end.col == 0 && yanklines > 1) { - yanktype = MLINE; - --yankendlnum; - --yanklines; + yank_type = kMTLineWise; + yankendlnum--; + yanklines--; } reg->y_size = yanklines; - reg->y_type = yanktype; /* set the yank register type */ + reg->y_type = yank_type; // set the yank register type reg->y_width = 0; reg->y_array = xcalloc(yanklines, sizeof(char_u *)); reg->additional_data = NULL; @@ -2357,7 +2356,7 @@ static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append) y_idx = 0; lnum = oap->start.lnum; - if (yanktype == MBLOCK) { + if (yank_type == kMTBlockWise) { // Visual block mode reg->y_width = oap->end_vcol - oap->start_vcol; @@ -2367,16 +2366,16 @@ static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append) for (; lnum <= yankendlnum; lnum++, y_idx++) { switch (reg->y_type) { - case MBLOCK: - block_prep(oap, &bd, lnum, FALSE); + case kMTBlockWise: + block_prep(oap, &bd, lnum, false); yank_copy_line(reg, &bd, y_idx); break; - case MLINE: + case kMTLineWise: reg->y_array[y_idx] = vim_strsave(ml_get(lnum)); break; - case MCHAR: + case kMTCharWise: { colnr_T startcol = 0, endcol = MAXCOL; int is_oneChar = FALSE; @@ -2437,7 +2436,9 @@ static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append) yank_copy_line(reg, &bd, y_idx); break; } - /* NOTREACHED */ + // NOTREACHED + case kMTUnknown: + assert(false); } } @@ -2448,12 +2449,15 @@ static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append) xfree(curr->y_array); curr->y_array = new_ptr; - if (yanktype == MLINE) /* MLINE overrides MCHAR and MBLOCK */ - curr->y_type = MLINE; + if (yank_type == kMTLineWise) { + // kMTLineWise overrides kMTCharWise and kMTBlockWise + curr->y_type = kMTLineWise; + } - /* Concatenate the last line of the old block with the first line of - * the new block, unless being Vi compatible. */ - if (curr->y_type == MCHAR && vim_strchr(p_cpo, CPO_REGAPPEND) == NULL) { + // Concatenate the last line of the old block with the first line of + // the new block, unless being Vi compatible. + if (curr->y_type == kMTCharWise + && vim_strchr(p_cpo, CPO_REGAPPEND) == NULL) { pnew = xmalloc(STRLEN(curr->y_array[curr->y_size - 1]) + STRLEN(reg->y_array[0]) + 1); STRCPY(pnew, curr->y_array[--j]); @@ -2473,7 +2477,7 @@ static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append) redraw_later(SOME_VALID); // cursor moved to start } if (message) { // Display message about yank? - if (yanktype == MCHAR && yanklines == 1) { + if (yank_type == kMTCharWise && yanklines == 1) { yanklines = 0; } // Some versions of Vi use ">=" here, some don't... @@ -2481,12 +2485,12 @@ static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append) // redisplay now, so message is not deleted update_topline_redraw(); if (yanklines == 1) { - if (yanktype == MBLOCK) { + if (yank_type == kMTBlockWise) { MSG(_("block of 1 line yanked")); } else { MSG(_("1 line yanked")); } - } else if (yanktype == MBLOCK) { + } else if (yank_type == kMTBlockWise) { smsg(_("block of %" PRId64 " lines yanked"), (int64_t)yanklines); } else { @@ -2500,7 +2504,7 @@ static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append) */ curbuf->b_op_start = oap->start; curbuf->b_op_end = oap->end; - if (yanktype == MLINE) { + if (yank_type == kMTLineWise) { curbuf->b_op_start.col = 0; curbuf->b_op_end.col = MAXCOL; } @@ -2590,8 +2594,8 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) int totlen = 0; /* init for gcc */ linenr_T lnum; colnr_T col; - long i; /* index in y_array[] */ - int y_type; + long i; // index in y_array[] + MotionType y_type; long y_size; int oldlen; long y_width = 0; @@ -2652,7 +2656,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) } if (insert_string != NULL) { - y_type = MCHAR; + y_type = kMTCharWise; if (regname == '=') { /* For the = register we need to split the string at NL * characters. @@ -2671,7 +2675,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) ++ptr; /* A trailing '\n' makes the register linewise. */ if (*ptr == NUL) { - y_type = MLINE; + y_type = kMTLineWise; break; } } @@ -2712,7 +2716,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) return; } - if (y_type == MLINE) { + if (y_type == kMTLineWise) { if (flags & PUT_LINE_SPLIT) { // "p" or "P" in Visual mode: split the lines to put the text in // between. @@ -2746,8 +2750,9 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) curbuf->b_op_end = curwin->w_cursor; /* default for '] mark */ } - if (flags & PUT_LINE) /* :put command or "p" in Visual line mode. */ - y_type = MLINE; + if (flags & PUT_LINE) { // :put command or "p" in Visual line mode. + y_type = kMTLineWise; + } if (y_size == 0 || y_array == NULL) { EMSG2(_("E353: Nothing in register %s"), @@ -2755,13 +2760,13 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) goto end; } - if (y_type == MBLOCK) { + if (y_type == kMTBlockWise) { lnum = curwin->w_cursor.lnum + y_size + 1; if (lnum > curbuf->b_ml.ml_line_count) lnum = curbuf->b_ml.ml_line_count + 1; if (u_save(curwin->w_cursor.lnum - 1, lnum) == FAIL) goto end; - } else if (y_type == MLINE) { + } else if (y_type == kMTLineWise) { lnum = curwin->w_cursor.lnum; /* Correct line number for closed fold. Don't move the cursor yet, * u_save() uses it. */ @@ -2785,7 +2790,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) yanklen = (int)STRLEN(y_array[0]); - if (ve_flags == VE_ALL && y_type == MCHAR) { + if (ve_flags == VE_ALL && y_type == kMTCharWise) { if (gchar_cursor() == TAB) { /* Don't need to insert spaces when "p" on the last position of a * tab or "P" on the first position. */ @@ -2805,7 +2810,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) /* * Block mode */ - if (y_type == MBLOCK) { + if (y_type == kMTBlockWise) { char c = gchar_cursor(); colnr_T endcol2 = 0; @@ -2953,12 +2958,10 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) } else curwin->w_cursor.lnum = lnum; } else { - /* - * Character or Line mode - */ - if (y_type == MCHAR) { - /* if type is MCHAR, FORWARD is the same as BACKWARD on the next - * char */ + // Character or Line mode + if (y_type == kMTCharWise) { + // if type is kMTCharWise, FORWARD is the same as BACKWARD on the next + // char if (dir == FORWARD && gchar_cursor() != NUL) { if (has_mbyte) { int bytelen = (*mb_ptr2len)(get_cursor_pos_ptr()); @@ -2989,7 +2992,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) /* * simple case: insert into current line */ - if (y_type == MCHAR && y_size == 1) { + if (y_type == kMTCharWise && y_size == 1) { do { totlen = count * yanklen; if (totlen > 0) { @@ -3024,18 +3027,14 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) ++curwin->w_cursor.col; changed_bytes(lnum, col); } else { - /* - * Insert at least one line. When y_type is MCHAR, break the first - * line in two. - */ - for (cnt = 1; cnt <= count; ++cnt) { + // Insert at least one line. When y_type is kMTCharWise, break the first + // line in two. + for (cnt = 1; cnt <= count; cnt++) { i = 0; - if (y_type == MCHAR) { - /* - * Split the current line in two at the insert position. - * First insert y_array[size - 1] in front of second line. - * Then append y_array[0] to first line. - */ + if (y_type == kMTCharWise) { + // Split the current line in two at the insert position. + // First insert y_array[size - 1] in front of second line. + // Then append y_array[0] to first line. lnum = new_cursor.lnum; ptr = ml_get(lnum) + col; totlen = (int)STRLEN(y_array[y_size - 1]); @@ -3059,10 +3058,11 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) } for (; i < y_size; i++) { - if ((y_type != MCHAR || i < y_size - 1) - && ml_append(lnum, y_array[i], (colnr_T)0, FALSE) - == FAIL) + if ((y_type != kMTCharWise || i < y_size - 1) + && ml_append(lnum, y_array[i], (colnr_T)0, false) + == FAIL) { goto error; + } lnum++; ++nr_lines; if (flags & PUT_FIXINDENT) { @@ -3091,22 +3091,23 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) } error: - /* Adjust marks. */ - if (y_type == MLINE) { + // Adjust marks. + if (y_type == kMTLineWise) { curbuf->b_op_start.col = 0; if (dir == FORWARD) curbuf->b_op_start.lnum++; } - mark_adjust(curbuf->b_op_start.lnum + (y_type == MCHAR), - (linenr_T)MAXLNUM, nr_lines, 0L); + mark_adjust(curbuf->b_op_start.lnum + (y_type == kMTCharWise), + (linenr_T)MAXLNUM, nr_lines, 0L); - /* note changed text for displaying and folding */ - if (y_type == MCHAR) + // note changed text for displaying and folding + if (y_type == kMTCharWise) { changed_lines(curwin->w_cursor.lnum, col, - curwin->w_cursor.lnum + 1, nr_lines); - else + curwin->w_cursor.lnum + 1, nr_lines); + } else { changed_lines(curbuf->b_op_start.lnum, 0, - curbuf->b_op_start.lnum, nr_lines); + curbuf->b_op_start.lnum, nr_lines); + } /* put '] mark at last inserted character */ curbuf->b_op_end.lnum = lnum; @@ -3122,19 +3123,20 @@ error: curwin->w_cursor.lnum = lnum; beginline(BL_WHITE | BL_FIX); } else if (flags & PUT_CURSEND) { - /* put cursor after inserted text */ - if (y_type == MLINE) { - if (lnum >= curbuf->b_ml.ml_line_count) + // put cursor after inserted text + if (y_type == kMTLineWise) { + if (lnum >= curbuf->b_ml.ml_line_count) { curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; - else + } else { curwin->w_cursor.lnum = lnum + 1; + } curwin->w_cursor.col = 0; } else { curwin->w_cursor.lnum = lnum; curwin->w_cursor.col = col; } - } else if (y_type == MLINE) { - /* put cursor on first non-blank in first inserted line */ + } else if (y_type == kMTLineWise) { + // put cursor on first non-blank in first inserted line curwin->w_cursor.col = 0; if (dir == FORWARD) ++curwin->w_cursor.lnum; @@ -3187,11 +3189,9 @@ void adjust_cursor_eol(void) */ int preprocs_left(void) { - return - (curbuf->b_p_si && !curbuf->b_p_cin) || - (curbuf->b_p_cin && in_cinkeys('#', ' ', TRUE) - && curbuf->b_ind_hash_comment == 0) - ; + return ((curbuf->b_p_si && !curbuf->b_p_cin) + || (curbuf->b_p_cin && in_cinkeys('#', ' ', true) + && curbuf->b_ind_hash_comment == 0)); } /* Return the character name of the register with the given number */ @@ -3273,9 +3273,10 @@ void ex_display(exarg_T *eap) p += clen - 1; } } - if (n > 1 && yb->y_type == MLINE) + if (n > 1 && yb->y_type == kMTLineWise) { MSG_PUTS_ATTR("^J", attr); - ui_flush(); /* show one line at a time */ + } + ui_flush(); // show one line at a time } os_breakcheck(); } @@ -4265,18 +4266,18 @@ void op_addsub(oparg_T *oap, linenr_T Prenum1, bool g_cmd) } pos = oap->start; - for (; pos.lnum <= oap->end.lnum; ++pos.lnum) { - if (oap->motion_type == MBLOCK) { + for (; pos.lnum <= oap->end.lnum; pos.lnum++) { + if (oap->motion_type == kMTBlockWise) { // Visual block mode block_prep(oap, &bd, pos.lnum, false); pos.col = bd.textcol; length = bd.textlen; - } else if (oap->motion_type == MLINE) { + } else if (oap->motion_type == kMTLineWise) { curwin->w_cursor.col = 0; pos.col = 0; length = (colnr_T)STRLEN(ml_get(pos.lnum)); } else { - // oap->motion_type == MCHAR + // oap->motion_type == kMTCharWise if (!oap->inclusive) { dec(&(oap->end)); } @@ -4396,8 +4397,7 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1) if (dobin && dohex && !((col > 0 - && (ptr[col] == 'X' || - ptr[col] == 'x') + && (ptr[col] == 'X' || ptr[col] == 'x') && ptr[col - 1] == '0' && ascii_isxdigit(ptr[col + 1])))) { // In case of binary/hexadecimal pattern overlap match, rescan @@ -4411,17 +4411,15 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1) if ((dohex && col > 0 - && (ptr[col] == 'X' - || ptr[col] == 'x') + && (ptr[col] == 'X' || ptr[col] == 'x') && ptr[col - 1] == '0' - && ascii_isxdigit(ptr[col + 1])) || - (dobin - && col > 0 - && (ptr[col] == 'B' - || ptr[col] == 'b') - && ptr[col - 1] == '0' - && ascii_isbdigit(ptr[col + 1]))) { - // Found hexadecimal or binary number, move to its start. + && ascii_isxdigit(ptr[col + 1])) + || (dobin + && col > 0 + && (ptr[col] == 'B' || ptr[col] == 'b') + && ptr[col - 1] == '0' + && ascii_isbdigit(ptr[col + 1]))) { + // Found hexadecimal or binary number, move to its start. col--; } else { // Search forward and then backward to find the start of number. @@ -4442,8 +4440,8 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1) } if (visual) { - while (ptr[col] != NUL && length > 0 && !ascii_isdigit(ptr[col]) && - !(doalp && ASCII_ISALPHA(ptr[col]))) { + while (ptr[col] != NUL && length > 0 && !ascii_isdigit(ptr[col]) + && !(doalp && ASCII_ISALPHA(ptr[col]))) { col++; length--; } @@ -4605,8 +4603,7 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1) *ptr++ = '0'; length--; } - if (pre == 'b' || pre == 'B' || - pre == 'x' || pre == 'X') { + if (pre == 'b' || pre == 'B' || pre == 'x' || pre == 'X') { *ptr++ = pre; length--; } @@ -4679,64 +4676,65 @@ theend: /* * Return the type of a register. * Used for getregtype() - * Returns MAUTO for error. + * Returns kMTUnknown for error. */ -char_u get_reg_type(int regname, colnr_T *reg_width) +MotionType get_reg_type(int regname, colnr_T *reg_width) { switch (regname) { - case '%': /* file name */ - case '#': /* alternate file name */ - case '=': /* expression */ - case ':': /* last command line */ - case '/': /* last search-pattern */ - case '.': /* last inserted text */ - case Ctrl_F: /* Filename under cursor */ - case Ctrl_P: /* Path under cursor, expand via "path" */ - case Ctrl_W: /* word under cursor */ - case Ctrl_A: /* WORD (mnemonic All) under cursor */ - case '_': /* black hole: always empty */ - return MCHAR; + case '%': // file name + case '#': // alternate file name + case '=': // expression + case ':': // last command line + case '/': // last search-pattern + case '.': // last inserted text + case Ctrl_F: // Filename under cursor + case Ctrl_P: // Path under cursor, expand via "path" + case Ctrl_W: // word under cursor + case Ctrl_A: // WORD (mnemonic All) under cursor + case '_': // black hole: always empty + return kMTCharWise; } - if (regname != NUL && !valid_yank_reg(regname, false)) - return MAUTO; + if (regname != NUL && !valid_yank_reg(regname, false)) { + return kMTUnknown; + } yankreg_T *reg = get_yank_register(regname, YREG_PASTE); if (reg->y_array != NULL) { - if (reg_width != NULL && reg->y_type == MBLOCK) { + if (reg_width != NULL && reg->y_type == kMTBlockWise) { *reg_width = reg->y_width; } return reg->y_type; } - return MAUTO; + return kMTUnknown; } /// Format the register type as a string. /// /// @param reg_type The register type. -/// @param reg_width The width, only used if "reg_type" is MBLOCK. +/// @param reg_width The width, only used if "reg_type" is kMTBlockWise. /// @param[out] buf Buffer to store formatted string. The allocated size should /// be at least NUMBUFLEN+2 to always fit the value. /// @param buf_len The allocated size of the buffer. -void format_reg_type(char_u reg_type, colnr_T reg_width, - char* buf, size_t buf_len) +void format_reg_type(MotionType reg_type, colnr_T reg_width, + char *buf, size_t buf_len) FUNC_ATTR_NONNULL_ALL { assert(buf_len > 1); switch (reg_type) { - case MLINE: + case kMTLineWise: buf[0] = 'V'; buf[1] = NUL; break; - case MCHAR: + case kMTCharWise: buf[0] = 'v'; buf[1] = NUL; break; - case MBLOCK: + case kMTBlockWise: snprintf(buf, buf_len, CTRL_V_STR "%" PRIdCOLNR, reg_width + 1); break; - case MAUTO: + case kMTUnknown: buf[0] = NUL; break; } @@ -4821,10 +4819,11 @@ void *get_reg_contents(int regname, int flags) len += STRLEN(reg->y_array[i]); /* * Insert a newline between lines and after last line if - * y_type is MLINE. + * y_type is kMTLineWise. */ - if (reg->y_type == MLINE || i < reg->y_size - 1) - ++len; + if (reg->y_type == kMTLineWise || i < reg->y_size - 1) { + len++; + } } retval = xmalloc(len + 1); @@ -4839,10 +4838,11 @@ void *get_reg_contents(int regname, int flags) /* * Insert a NL between lines and after the last line if y_type is - * MLINE. + * kMTLineWise. */ - if (reg->y_type == MLINE || i < reg->y_size - 1) + if (reg->y_type == kMTLineWise || i < reg->y_size - 1) { retval[len++] = '\n'; + } } retval[len] = NUL; @@ -4883,11 +4883,12 @@ static void finish_write_reg(int name, yankreg_T *reg, yankreg_T *old_y_previous void write_reg_contents(int name, const char_u *str, ssize_t len, int must_append) { - write_reg_contents_ex(name, str, len, must_append, MAUTO, 0L); + write_reg_contents_ex(name, str, len, must_append, kMTUnknown, 0L); } void write_reg_contents_lst(int name, char_u **strings, int maxlen, - bool must_append, int yank_type, long block_len) + bool must_append, MotionType yank_type, + long block_len) { if (name == '/' || name == '=') { char_u *s = strings[0]; @@ -4933,13 +4934,13 @@ void write_reg_contents_lst(int name, char_u **strings, int maxlen, /// contents of the register. Note that regardless of /// `must_append`, this function will append when `name` /// is an uppercase letter. -/// @param yank_type MCHAR, MLINE, MBLOCK or MAUTO +/// @param yank_type The motion type (kMTUnknown to auto detect) /// @param block_len width of visual block void write_reg_contents_ex(int name, const char_u *str, ssize_t len, bool must_append, - int yank_type, + MotionType yank_type, long block_len) { if (len < 0) { @@ -5013,24 +5014,24 @@ void write_reg_contents_ex(int name, /// When the register is not empty, the string is appended. /// /// @param y_ptr pointer to yank register -/// @param yank_type MCHAR, MLINE, MBLOCK or MAUTO +/// @param yank_type The motion type (kMTUnknown to auto detect) /// @param str string or list of strings to put in register /// @param len length of the string (Ignored when str_list=true.) /// @param blocklen width of visual block, or -1 for "I don't know." /// @param str_list True if str is `char_u **`. -static void str_to_reg(yankreg_T *y_ptr, int yank_type, const char_u *str, - size_t len, colnr_T blocklen, bool str_list) +static void str_to_reg(yankreg_T *y_ptr, MotionType yank_type, + const char_u *str, size_t len, colnr_T blocklen, + bool str_list) FUNC_ATTR_NONNULL_ALL { if (y_ptr->y_array == NULL) { // NULL means empty register y_ptr->y_size = 0; } - int type = yank_type; // MCHAR, MLINE or MBLOCK - if (yank_type == MAUTO) { - type = ((str_list || - (len > 0 && (str[len - 1] == NL || str[len - 1] == CAR))) - ? MLINE : MCHAR); + if (yank_type == kMTUnknown) { + yank_type = ((str_list + || (len > 0 && (str[len - 1] == NL || str[len - 1] == CAR))) + ? kMTLineWise : kMTCharWise); } size_t newlines = 0; @@ -5044,11 +5045,11 @@ static void str_to_reg(yankreg_T *y_ptr, int yank_type, const char_u *str, } } else { newlines = memcnt(str, '\n', len); - if (type == MCHAR || len == 0 || str[len - 1] != '\n') { + if (yank_type == kMTCharWise || len == 0 || str[len - 1] != '\n') { extraline = 1; ++newlines; // count extra newline at the end } - if (y_ptr->y_size > 0 && y_ptr->y_type == MCHAR) { + if (y_ptr->y_size > 0 && y_ptr->y_type == kMTCharWise) { append = true; --newlines; // uncount newline when appending first line } @@ -5101,11 +5102,11 @@ static void str_to_reg(yankreg_T *y_ptr, int yank_type, const char_u *str, memchrsub(pp[lnum], NUL, '\n', s_len); } } - y_ptr->y_type = type; + y_ptr->y_type = yank_type; y_ptr->y_size = lnum; set_yreg_additional_data(y_ptr, NULL); y_ptr->timestamp = os_time(); - if (type == MBLOCK) { + if (yank_type == kMTBlockWise) { y_ptr->y_width = (blocklen == -1 ? (colnr_T) maxlen - 1 : blocklen); } else { y_ptr->y_width = 0; @@ -5218,7 +5219,7 @@ void cursor_pos_info(void) /* Make 'sbr' empty for a moment to get the correct size. */ p_sbr = empty_option; oparg.is_VIsual = true; - oparg.motion_type = MBLOCK; + oparg.motion_type = kMTBlockWise; oparg.op_type = OP_NOP; getvcols(curwin, &min_pos, &max_pos, &oparg.start_vcol, &oparg.end_vcol); @@ -5473,16 +5474,16 @@ static bool get_clipboard(int name, yankreg_T **target, bool quiet) } switch (regtype[0]) { case 0: - reg->y_type = MAUTO; + reg->y_type = kMTUnknown; break; case 'v': case 'c': - reg->y_type = MCHAR; + reg->y_type = kMTCharWise; break; case 'V': case 'l': - reg->y_type = MLINE; + reg->y_type = kMTLineWise; break; case 'b': case Ctrl_V: - reg->y_type = MBLOCK; + reg->y_type = kMTBlockWise; break; default: goto err; @@ -5490,7 +5491,7 @@ static bool get_clipboard(int name, yankreg_T **target, bool quiet) } else { lines = res; // provider did not specify regtype, calculate it below - reg->y_type = MAUTO; + reg->y_type = kMTUnknown; } reg->y_array = xcalloc(lines->lv_len, sizeof(uint8_t *)); @@ -5511,20 +5512,20 @@ static bool get_clipboard(int name, yankreg_T **target, bool quiet) if (reg->y_size > 0 && strlen((char*)reg->y_array[reg->y_size-1]) == 0) { // a known-to-be charwise yank might have a final linebreak // but otherwise there is no line after the final newline - if (reg->y_type != MCHAR) { + if (reg->y_type != kMTCharWise) { xfree(reg->y_array[reg->y_size-1]); reg->y_size--; - if (reg->y_type == MAUTO) { - reg->y_type = MLINE; + if (reg->y_type == kMTUnknown) { + reg->y_type = kMTLineWise; } } } else { - if (reg->y_type == MAUTO) { - reg->y_type = MCHAR; + if (reg->y_type == kMTUnknown) { + reg->y_type = kMTCharWise; } } - if (reg->y_type == MBLOCK) { + if (reg->y_type == kMTBlockWise) { int maxlen = 0; for (int i = 0; i < reg->y_size; i++) { int rowlen = STRLEN(reg->y_array[i]); @@ -5573,17 +5574,19 @@ static void set_clipboard(int name, yankreg_T *reg) char_u regtype; switch (reg->y_type) { - case MLINE: + case kMTLineWise: regtype = 'V'; list_append_string(lines, (char_u*)"", 0); break; - case MCHAR: + case kMTCharWise: regtype = 'v'; break; - case MBLOCK: + case kMTBlockWise: regtype = 'b'; list_append_string(lines, (char_u*)"", 0); break; + case kMTUnknown: + assert(false); } list_append_string(args, ®type, 1); @@ -5624,7 +5627,7 @@ static inline bool reg_empty(const yankreg_T *const reg) return (reg->y_array == NULL || reg->y_size == 0 || (reg->y_size == 1 - && reg->y_type == MCHAR + && reg->y_type == kMTCharWise && *(reg->y_array[0]) == NUL)); } diff --git a/src/nvim/ops.h b/src/nvim/ops.h index f33e87572f..8c8a586957 100644 --- a/src/nvim/ops.h +++ b/src/nvim/ops.h @@ -78,10 +78,10 @@ enum GRegFlags { /// Definition of one register typedef struct yankreg { - char_u **y_array; ///< Pointer to an array of line pointers. - linenr_T y_size; ///< Number of lines in y_array. - char_u y_type; ///< Register type: MLINE, MCHAR or MBLOCK. - colnr_T y_width; ///< Register width (only valid for y_type == MBLOCK). + char_u **y_array; ///< Pointer to an array of line pointers. + linenr_T y_size; ///< Number of lines in y_array. + MotionType y_type; ///< Register type + colnr_T y_width; ///< Register width (only valid for y_type == kBlockWise). Timestamp timestamp; ///< Time when register was last modified. dict_T *additional_data; ///< Additional data from ShaDa file. } yankreg_T; diff --git a/src/nvim/option.c b/src/nvim/option.c index 402da42912..2f22c245dd 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -4782,9 +4782,10 @@ showoptions ( option_value2string(p, opt_flags); len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1; } - if ((len <= INC - GAP && run == 1) || - (len > INC - GAP && run == 2)) + if ((len <= INC - GAP && run == 1) + || (len > INC - GAP && run == 2)) { items[item_count++] = p; + } } } @@ -4973,18 +4974,15 @@ int makeset(FILE *fd, int opt_flags, int local_only) } else { /* P_STRING */ int do_endif = FALSE; - /* Don't set 'syntax' and 'filetype' again if the value is - * already right, avoids reloading the syntax file. */ - if ( - p->indir == PV_SYN - || - p->indir == PV_FT - ) { + // Don't set 'syntax' and 'filetype' again if the value is + // already right, avoids reloading the syntax file. + if (p->indir == PV_SYN || p->indir == PV_FT) { if (fprintf(fd, "if &%s != '%s'", p->fullname, - *(char_u **)(varp)) < 0 - || put_eol(fd) < 0) + *(char_u **)(varp)) < 0 + || put_eol(fd) < 0) { return FAIL; - do_endif = TRUE; + } + do_endif = true; } if (put_setstring(fd, cmd, p->fullname, (char_u **)varp, (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. bool shortmess(int x) { - return p_shm != NULL && - (vim_strchr(p_shm, x) != NULL - || (vim_strchr(p_shm, 'a') != NULL - && vim_strchr((char_u *)SHM_ALL_ABBREVIATIONS, x) != NULL)); + return (p_shm != NULL + && (vim_strchr(p_shm, x) != NULL + || (vim_strchr(p_shm, 'a') != NULL + && vim_strchr((char_u *)SHM_ALL_ABBREVIATIONS, x) != NULL))); } /* diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index b6613caa45..a9c9eb608b 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -164,6 +164,7 @@ int os_nodetype(const char *name) /// /// @param[in] name Name of the executable. /// @param[out] abspath Path of the executable, if found and not `NULL`. +/// @param[in] use_path If 'false', only check if "name" is executable /// /// @return `true` if `name` is executable and /// - can be found in $PATH, @@ -171,14 +172,18 @@ int os_nodetype(const char *name) /// - is absolute. /// /// @return `false` otherwise. -bool os_can_exe(const char_u *name, char_u **abspath) +bool os_can_exe(const char_u *name, char_u **abspath, bool use_path) FUNC_ATTR_NONNULL_ARG(1) { - // If it's an absolute or relative path don't need to use $PATH. - if (path_is_absolute_path(name) || - (name[0] == '.' && (name[1] == '/' || - (name[1] == '.' && name[2] == '/')))) { - if (is_executable(name)) { + // when use_path is false or if it's an absolute or relative path don't + // need to use $PATH. + if (!use_path || path_is_absolute_path(name) + || (name[0] == '.' + && (name[1] == '/' + || (name[1] == '.' && name[2] == '/')))) { + // There must be a path separator, files in the current directory + // can't be executed + if (gettail_dir(name) != name && is_executable(name)) { if (abspath != NULL) { *abspath = save_absolute_path(name); } diff --git a/src/nvim/os/input.c b/src/nvim/os/input.c index e0826aa272..7687b14f02 100644 --- a/src/nvim/os/input.c +++ b/src/nvim/os/input.c @@ -403,9 +403,9 @@ static int push_event_key(uint8_t *buf, int maxlen) // Check if there's pending input static bool input_ready(void) { - return typebuf_was_filled || // API call filled typeahead - rbuffer_size(input_buffer) || // Input buffer filled - pending_events(); // Events must be processed + return (typebuf_was_filled // API call filled typeahead + || rbuffer_size(input_buffer) // Input buffer filled + || pending_events()); // Events must be processed } // Exit because of an input read error. diff --git a/src/nvim/os/mem.c b/src/nvim/os/mem.c index 5e483c0c3d..871ece7a0e 100644 --- a/src/nvim/os/mem.c +++ b/src/nvim/os/mem.c @@ -8,5 +8,5 @@ uint64_t os_get_total_mem_kib(void) { // Convert bytes to KiB. - return uv_get_total_memory() >> 10; + return uv_get_total_memory() / 1024; } diff --git a/src/nvim/os/win_defs.h b/src/nvim/os/win_defs.h index 242d355f77..55894e4d12 100644 --- a/src/nvim/os/win_defs.h +++ b/src/nvim/os/win_defs.h @@ -1,6 +1,9 @@ #ifndef NVIM_OS_WIN_DEFS_H #define NVIM_OS_WIN_DEFS_H +// winsock2.h must be first to avoid incompatibilities +// with winsock.h (included by windows.h) +#include <winsock2.h> #include <windows.h> #include <sys/stat.h> #include <io.h> diff --git a/src/nvim/os_unix.c b/src/nvim/os_unix.c index 63a3dbc054..2ed0c2c856 100644 --- a/src/nvim/os_unix.c +++ b/src/nvim/os_unix.c @@ -576,9 +576,11 @@ int mch_expand_wildcards(int num_pat, char_u **pat, int *num_file, if ((dir && !(flags & EW_DIR)) || (!dir && !(flags & EW_FILE))) continue; - /* Skip files that are not executable if we check for that. */ - if (!dir && (flags & EW_EXEC) && !os_can_exe((*file)[i], NULL)) + // Skip files that are not executable if we check for that. + if (!dir && (flags & EW_EXEC) + && !os_can_exe((*file)[i], NULL, !(flags & EW_SHELLCMD))) { continue; + } p = xmalloc(STRLEN((*file)[i]) + 1 + dir); STRCPY(p, (*file)[i]); diff --git a/src/nvim/path.c b/src/nvim/path.c index 29ff62ef77..aff0ee2d48 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -981,12 +981,12 @@ static void uniquefy_paths(garray_T *gap, char_u *pattern) * "/path/file", "/path/dir/", "/path//dir", "/file" * ^ ^ ^ ^ */ -static char_u *gettail_dir(char_u *fname) +char_u *gettail_dir(const char_u *fname) { - char_u *dir_end = fname; - char_u *next_dir_end = fname; + const char_u *dir_end = fname; + const char_u *next_dir_end = fname; bool look_for_sep = true; - char_u *p; + const char_u *p; for (p = fname; *p != NUL; ) { if (vim_ispathsep(*p)) { @@ -1001,7 +1001,7 @@ static char_u *gettail_dir(char_u *fname) } mb_ptr_adv(p); } - return dir_end; + return (char_u *)dir_end; } @@ -1301,9 +1301,10 @@ void addfile( FileInfo file_info; // if the file/dir/link doesn't exist, may not add it - if (!(flags & EW_NOTFOUND) && - ((flags & EW_ALLLINKS) ? - !os_fileinfo_link((char *)f, &file_info) : !os_file_exists(f))) { + if (!(flags & EW_NOTFOUND) + && ((flags & EW_ALLLINKS) + ? !os_fileinfo_link((char *)f, &file_info) + : !os_file_exists(f))) { return; } @@ -1317,9 +1318,12 @@ void addfile( if ((isdir && !(flags & EW_DIR)) || (!isdir && !(flags & EW_FILE))) return; - /* If the file isn't executable, may not add it. Do accept directories. */ - if (!isdir && (flags & EW_EXEC) && !os_can_exe(f, NULL)) + // If the file isn't executable, may not add it. Do accept directories. + // When invoked from expand_shellcmd() do not use $PATH. + if (!isdir && (flags & EW_EXEC) + && !os_can_exe(f, NULL, !(flags & EW_SHELLCMD))) { return; + } char_u *p = xmalloc(STRLEN(f) + 1 + isdir); @@ -1383,9 +1387,9 @@ void simplify_filename(char_u *filename) --p; /* strip preceding path separator */ STRMOVE(p, tail); } - } else if (p[0] == '.' && p[1] == '.' && - (vim_ispathsep(p[2]) || p[2] == NUL)) { - /* Skip to after ".." or "../" or "..///". */ + } else if (p[0] == '.' && p[1] == '.' + && (vim_ispathsep(p[2]) || p[2] == NUL)) { + // Skip to after ".." or "../" or "..///". tail = p + 2; while (vim_ispathsep(*tail)) mb_ptr_adv(tail); @@ -2016,8 +2020,8 @@ int match_suffix(char_u *fname) break; } } else { - if (fnamelen >= setsuflen && - fnamencmp(suf_buf, fname + fnamelen - setsuflen, setsuflen) == 0) { + if (fnamelen >= setsuflen + && fnamencmp(suf_buf, fname + fnamelen - setsuflen, setsuflen) == 0) { break; } setsuflen = 0; diff --git a/src/nvim/path.h b/src/nvim/path.h index 88e5935c24..4e466d1b71 100644 --- a/src/nvim/path.h +++ b/src/nvim/path.h @@ -21,6 +21,8 @@ /* Note: mostly EW_NOTFOUND and EW_SILENT are mutually exclusive: EW_NOTFOUND * is used when executing commands and EW_SILENT for interactive expanding. */ #define EW_ALLLINKS 0x1000 // also links not pointing to existing file +#define EW_SHELLCMD 0x2000 // called from expand_shellcmd(), don't check + // if executable is in $PATH #define EW_DODOT 0x4000 // also files starting with a dot #define EW_EMPTYOK 0x8000 // no matches is not an error diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c index 97db69d3f3..17cb8a86aa 100644 --- a/src/nvim/quickfix.c +++ b/src/nvim/quickfix.c @@ -2757,8 +2757,8 @@ void ex_cc(exarg_T *eap) // For cdo and ldo commands, jump to the nth valid error. // For cfdo and lfdo commands, jump to the nth valid file entry. - if (eap->cmdidx == CMD_cdo || eap->cmdidx == CMD_ldo || - eap->cmdidx == CMD_cfdo || eap->cmdidx == CMD_lfdo) { + if (eap->cmdidx == CMD_cdo || eap->cmdidx == CMD_ldo + || eap->cmdidx == CMD_cfdo || eap->cmdidx == CMD_lfdo) { size_t n; if (eap->addr_count > 0) { assert(eap->line1 >= 0); @@ -2801,9 +2801,9 @@ void ex_cnext(exarg_T *eap) } int errornr; - if (eap->addr_count > 0 && - (eap->cmdidx != CMD_cdo && eap->cmdidx != CMD_ldo && - eap->cmdidx != CMD_cfdo && eap->cmdidx != CMD_lfdo)) { + if (eap->addr_count > 0 + && (eap->cmdidx != CMD_cdo && eap->cmdidx != CMD_ldo + && eap->cmdidx != CMD_cfdo && eap->cmdidx != CMD_lfdo)) { errornr = (int)eap->line2; } else { errornr = 1; @@ -2972,16 +2972,18 @@ void ex_vimgrep(exarg_T *eap) goto theend; } - if ((eap->cmdidx != CMD_grepadd && eap->cmdidx != CMD_lgrepadd && - eap->cmdidx != CMD_vimgrepadd && eap->cmdidx != CMD_lvimgrepadd) - || qi->qf_curlist == qi->qf_listcount) - /* make place for a new list */ + if ((eap->cmdidx != CMD_grepadd && eap->cmdidx != CMD_lgrepadd + && eap->cmdidx != CMD_vimgrepadd && eap->cmdidx != CMD_lvimgrepadd) + || qi->qf_curlist == qi->qf_listcount) { + // make place for a new list qf_new_list(qi, *eap->cmdlinep); - else if (qi->qf_lists[qi->qf_curlist].qf_count > 0) - /* Adding to existing list, find last entry. */ + } else if (qi->qf_lists[qi->qf_curlist].qf_count > 0) { + // Adding to existing list, find last entry. 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 */ if (get_arglist_exp(p, &fcount, &fnames, true) == FAIL) diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c index 608aa38466..886a48e7c5 100644 --- a/src/nvim/regexp.c +++ b/src/nvim/regexp.c @@ -3445,13 +3445,14 @@ static long bt_regexec_both(char_u *line, c = regline[col]; if (prog->regstart == NUL || prog->regstart == c - || (ireg_ic && (( - (enc_utf8 && utf_fold(prog->regstart) == utf_fold(c))) - || (c < 255 && prog->regstart < 255 && - vim_tolower(prog->regstart) == vim_tolower(c))))) + || (ireg_ic + && (((enc_utf8 && utf_fold(prog->regstart) == utf_fold(c))) + || (c < 255 && prog->regstart < 255 + && vim_tolower(prog->regstart) == vim_tolower(c))))) { retval = regtry(prog, col); - else + } else { retval = 0; + } } else { int tm_count = 0; /* Messy cases: unanchored match. */ @@ -4121,15 +4122,15 @@ regmatch ( char_u *opnd; opnd = OPERAND(scan); - /* Inline the first byte, for speed. */ + // Inline the first byte, for speed. if (*opnd != *reginput - && (!ireg_ic || ( - !enc_utf8 && - vim_tolower(*opnd) != vim_tolower(*reginput)))) + && (!ireg_ic + || (!enc_utf8 + && vim_tolower(*opnd) != vim_tolower(*reginput)))) { status = RA_NOMATCH; - else if (*opnd == NUL) { - /* match empty string always works; happens when "~" is - * empty. */ + } else if (*opnd == NUL) { + // match empty string always works; happens when "~" is + // empty. } else { if (opnd[1] == NUL && !(enc_utf8 && ireg_ic)) { len = 1; /* matched a single byte above */ diff --git a/src/nvim/regexp_nfa.c b/src/nvim/regexp_nfa.c index 27409352b5..7e53b2ccd1 100644 --- a/src/nvim/regexp_nfa.c +++ b/src/nvim/regexp_nfa.c @@ -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 = PTR2CHAR(s2); - if ((c1 != c2 && (!ireg_ic || vim_tolower(c1) != vim_tolower(c2))) || - c1_len != c2_len) { + if ((c1 != c2 && (!ireg_ic || vim_tolower(c1) != vim_tolower(c2))) + || c1_len != c2_len) { match = false; break; } diff --git a/src/nvim/screen.c b/src/nvim/screen.c index 1cc270023c..59168b29a0 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -387,14 +387,15 @@ void update_screen(int type) if (wp->w_buffer->b_mod_set) { win_T *wwp; - /* Check if we already did this buffer. */ - for (wwp = firstwin; wwp != wp; wwp = wwp->w_next) - if (wwp->w_buffer == wp->w_buffer) + // Check if we already did this buffer. + for (wwp = firstwin; wwp != wp; wwp = wwp->w_next) { + if (wwp->w_buffer == wp->w_buffer) { break; - if ( - wwp == wp && - syntax_present(wp)) + } + } + if (wwp == wp && syntax_present(wp)) { 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_LINE && syntax_present(wp) - && ( - (foldmethodIsSyntax(wp) - && hasAnyFolding(wp)) || - syntax_check_changed(lnum))) + && ((foldmethodIsSyntax(wp) + && hasAnyFolding(wp)) + || syntax_check_changed(lnum))) // match in fixed position might need redraw // if lines were inserted or deleted - || (wp->w_match_head != NULL && buf->b_mod_xlines != 0) - ))))) { - if (lnum == mod_top) - top_to_mod = FALSE; + || (wp->w_match_head != NULL + && buf->b_mod_xlines != 0)))))) { + if (lnum == mod_top) { + top_to_mod = false; + } /* * When at start of changed lines: May scroll following lines @@ -2472,21 +2473,16 @@ win_line ( mb_ptr_adv(ptr); } - /* When: - * - 'cuc' is set, or - * - 'colorcolumn' is set, or - * - 'virtualedit' is set, or - * - the visual mode is active, - * the end of the line may be before the start of the displayed part. - */ - if (vcol < v && ( - wp->w_p_cuc - || draw_color_col - || - virtual_active() - || - (VIsual_active && wp->w_buffer == curwin->w_buffer) - )) { + // When: + // - 'cuc' is set, or + // - 'colorcolumn' is set, or + // - 'virtualedit' is set, or + // - the visual mode is active, + // the end of the line may be before the start of the displayed part. + if (vcol < v && (wp->w_p_cuc + || draw_color_col + || virtual_active() + || (VIsual_active && wp->w_buffer == curwin->w_buffer))) { vcol = v; } @@ -3273,12 +3269,12 @@ win_line ( * contains the @Spell cluster. */ if (has_spell && v >= word_end && v > cur_checked_col) { spell_attr = 0; - if (!attr_pri) + if (!attr_pri) { char_attr = syntax_attr; - if (c != 0 && ( - !has_syntax || - can_spell)) { - char_u *prev_ptr, *p; + } + if (c != 0 && (!has_syntax || can_spell)) { + char_u *prev_ptr; + char_u *p; int len; hlf_T spell_hlf = HLF_COUNT; if (has_mbyte) { @@ -3607,25 +3603,22 @@ win_line ( wp->w_p_rl ? (col >= 0) : (col < wp->w_width))) { c = ' '; - --ptr; /* put it back at the NUL */ - } else if (( - diff_hlf != (hlf_T)0 || - line_attr != 0 - ) && ( - wp->w_p_rl ? (col >= 0) : - (col - - boguscols - < wp->w_width))) { - /* Highlight until the right side of the window */ + ptr--; // put it back at the NUL + } else if ((diff_hlf != (hlf_T)0 || line_attr != 0) + && (wp->w_p_rl + ? (col >= 0) + : (col - boguscols < wp->w_width))) { + // Highlight until the right side of the window c = ' '; - --ptr; /* put it back at the NUL */ + ptr--; // put it back at the NUL - /* Remember we do the char for line highlighting. */ - ++did_line_attr; + // Remember we do the char for line highlighting. + did_line_attr++; - /* don't do search HL for the rest of the line */ - if (line_attr != 0 && char_attr == search_attr && col > 0) + // don't do search HL for the rest of the line + if (line_attr != 0 && char_attr == search_attr && col > 0) { char_attr = line_attr; + } if (diff_hlf == HLF_TXD) { diff_hlf = HLF_CHD; if (attr == 0 || char_attr != attr) { @@ -3639,8 +3632,8 @@ win_line ( } if (wp->w_p_cole > 0 - && (wp != curwin || lnum != wp->w_cursor.lnum || - conceal_cursor_line(wp)) + && (wp != curwin || lnum != wp->w_cursor.lnum + || conceal_cursor_line(wp)) && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc) && !(lnum_in_visual_area && vim_strchr(wp->w_p_cocu, 'v') == NULL)) { diff --git a/src/nvim/search.c b/src/nvim/search.c index faf70472bf..6e2b69fff7 100644 --- a/src/nvim/search.c +++ b/src/nvim/search.c @@ -638,9 +638,9 @@ int searchit( break; } - if (ptr[matchcol] == NUL || - (nmatched = vim_regexec_multi(®match, win, buf, lnum, - matchcol, tm)) == 0) { + if (ptr[matchcol] == NUL + || (nmatched = vim_regexec_multi(®match, win, buf, lnum, + matchcol, tm)) == 0) { match_ok = false; break; } @@ -1027,19 +1027,18 @@ int do_search( spats[0].off.line = FALSE; spats[0].off.end = FALSE; spats[0].off.off = 0; - /* - * Check for a line offset or a character offset. - * For get_address (echo off) we don't check for a character - * offset, because it is meaningless and the 's' could be a - * substitute command. - */ - if (*p == '+' || *p == '-' || ascii_isdigit(*p)) - spats[0].off.line = TRUE; - else if ((options & SEARCH_OPT) && - (*p == 'e' || *p == 's' || *p == 'b')) { - if (*p == 'e') /* end */ + // Check for a line offset or a character offset. + // For get_address (echo off) we don't check for a character + // offset, because it is meaningless and the 's' could be a + // substitute command. + if (*p == '+' || *p == '-' || ascii_isdigit(*p)) { + spats[0].off.line = true; + } else if ((options & SEARCH_OPT) + && (*p == 'e' || *p == 's' || *p == 'b')) { + if (*p == 'e') { // end spats[0].off.end = true; - ++p; + } + p++; } if (ascii_isdigit(*p) || *p == '+' || *p == '-') { /* got an offset */ /* 'nr' or '+nr' or '-nr' */ @@ -1647,8 +1646,9 @@ pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int64_t maxtravel) /* * Look for matching #if, #else, #elif, or #endif */ - if (oap != NULL) - oap->motion_type = MLINE; /* Linewise for this case only */ + if (oap != NULL) { + oap->motion_type = kMTLineWise; // Linewise for this case only + } if (initc != '#') { ptr = skipwhite(skipwhite(linep) + 1); if (STRNCMP(ptr, "if", 2) == 0 || STRNCMP(ptr, "el", 2) == 0) @@ -1783,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 (pos.col == 0 && (flags & FM_BLOCKSTOP) && - (linep[0] == '{' || linep[0] == '}')) { - if (linep[0] == findc && count == 0) /* match! */ + // If FM_BLOCKSTOP given, stop at a '{' or '}' in column 0. + if (pos.col == 0 && (flags & FM_BLOCKSTOP) + && (linep[0] == '{' || linep[0] == '}')) { + if (linep[0] == findc && count == 0) { // match! return &pos; - break; /* out of scope */ + } + break; // out of scope } if (comment_dir) { @@ -1959,15 +1958,15 @@ pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int64_t maxtravel) if (linep[pos.col - 2] == '\'') { pos.col -= 2; break; - } else if (linep[pos.col - 2] == '\\' && - pos.col > 2 && linep[pos.col - 3] == '\'') { + } else if (linep[pos.col - 2] == '\\' + && pos.col > 2 && linep[pos.col - 3] == '\'') { pos.col -= 3; break; } } - } else if (linep[pos.col + 1]) { /* forward search */ - if (linep[pos.col + 1] == '\\' && - linep[pos.col + 2] && linep[pos.col + 3] == '\'') { + } else if (linep[pos.col + 1]) { // forward search + if (linep[pos.col + 1] == '\\' + && linep[pos.col + 2] && linep[pos.col + 3] == '\'') { pos.col += 3; break; } else if (linep[pos.col + 2] == '\'') { @@ -2184,30 +2183,32 @@ int findsent(int dir, long count) * if on an empty line, skip up to a non-empty line */ if (gchar_pos(&pos) == NUL) { - do - if ((*func)(&pos) == -1) + do { + if ((*func)(&pos) == -1) { break; - while (gchar_pos(&pos) == NUL); - if (dir == FORWARD) + } + } while (gchar_pos(&pos) == NUL); + if (dir == FORWARD) { goto found; - } - /* - * if on the start of a paragraph or a section and searching forward, - * go to the next line - */ - else if (dir == FORWARD && pos.col == 0 && - startPS(pos.lnum, NUL, FALSE)) { - if (pos.lnum == curbuf->b_ml.ml_line_count) + } + // if on the start of a paragraph or a section and searching forward, + // go to the next line + } else if (dir == FORWARD && pos.col == 0 + && startPS(pos.lnum, NUL, false)) { + if (pos.lnum == curbuf->b_ml.ml_line_count) { return FAIL; - ++pos.lnum; + } + pos.lnum++; goto found; - } else if (dir == BACKWARD) + } else if (dir == BACKWARD) { decl(&pos); + } - /* go back to the previous non-blank char */ - found_dot = FALSE; - while ((c = gchar_pos(&pos)) == ' ' || c == '\t' || - (dir == BACKWARD && vim_strchr((char_u *)".!?)]\"'", c) != NULL)) { + // go back to the previous non-blank char + found_dot = false; + while ((c = gchar_pos(&pos)) == ' ' || c == '\t' + || (dir == BACKWARD + && vim_strchr((char_u *)".!?)]\"'", c) != NULL)) { if (vim_strchr((char_u *)".!?", c) != NULL) { /* Only skip over a '.', '!' and '?' once. */ if (found_dot) @@ -2371,12 +2372,14 @@ int startPS(linenr_T lnum, int para, int both) char_u *s; s = ml_get(lnum); - if (*s == para || *s == '\f' || (both && *s == '}')) - return TRUE; - if (*s == '.' && (inmacro(p_sections, s + 1) || - (!para && inmacro(p_para, s + 1)))) - return TRUE; - return FALSE; + if (*s == para || *s == '\f' || (both && *s == '}')) { + return true; + } + if (*s == '.' && (inmacro(p_sections, s + 1) + || (!para && inmacro(p_para, s + 1)))) { + return true; + } + return false; } /* @@ -2793,7 +2796,7 @@ current_word ( redraw_curbuf_later(INVERTED); /* update the inversion */ } else { oap->start = start_pos; - oap->motion_type = MCHAR; + oap->motion_type = kMTCharWise; } --count; } @@ -3028,7 +3031,7 @@ extend: else oap->inclusive = false; oap->start = start_pos; - oap->motion_type = MCHAR; + oap->motion_type = kMTCharWise; } return OK; } @@ -3152,7 +3155,7 @@ current_block ( showmode(); } else { oap->start = start_pos; - oap->motion_type = MCHAR; + oap->motion_type = kMTCharWise; oap->inclusive = false; if (sol) incl(&curwin->w_cursor); @@ -3399,7 +3402,7 @@ again: showmode(); } else { oap->start = start_pos; - oap->motion_type = MCHAR; + oap->motion_type = kMTCharWise; if (lt(end_pos, start_pos)) { /* End is before the start: there is no text between tags; operate * on an empty area. */ @@ -3564,7 +3567,7 @@ extend: } else { oap->start.lnum = start_lnum; oap->start.col = 0; - oap->motion_type = MLINE; + oap->motion_type = kMTLineWise; } curwin->w_cursor.lnum = end_lnum; curwin->w_cursor.col = 0; @@ -3806,7 +3809,7 @@ current_quote ( } } else { oap->start = curwin->w_cursor; - oap->motion_type = MCHAR; + oap->motion_type = kMTCharWise; } /* Set end position. */ @@ -4150,19 +4153,20 @@ find_pattern_in_path ( FNAME_EXP|FNAME_INCL|FNAME_REL, 1L, p_fname, NULL); already_searched = FALSE; 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++) { - if (i == depth + 1) + if (i == depth + 1) { i = old_files; - if (i == max_path_depth) + } + if (i == max_path_depth) { break; - if (path_full_compare(new_fname, files[i].name, TRUE) & kEqualFiles) { - if (type != CHECK_PATH && - action == ACTION_SHOW_ALL && files[i].matched) { - msg_putchar('\n'); /* cursor below last one */ - if (!got_int) { /* don't display if 'q' - typed at "--more--" - message */ + } + if (path_full_compare(new_fname, files[i].name, true) & kEqualFiles) { + if (type != CHECK_PATH + && action == ACTION_SHOW_ALL && files[i].matched) { + msg_putchar('\n'); // cursor below last one */ + if (!got_int) { // don't display if 'q' typed at "--more--" + // message msg_home_replace_hl(new_fname); MSG_PUTS(_(" (includes previously listed match)")); prev_fname = NULL; @@ -4177,15 +4181,15 @@ find_pattern_in_path ( } if (type == CHECK_PATH && (action == ACTION_SHOW_ALL - || (new_fname == NULL && - !already_searched))) { - if (did_show) - msg_putchar('\n'); /* cursor below last one */ - else { - gotocmdline(TRUE); /* cursor at status line */ + || (new_fname == NULL && !already_searched))) { + if (did_show) { + msg_putchar('\n'); // cursor below last one + } else { + gotocmdline(true); // cursor at status line MSG_PUTS_TITLE(_("--- Included files ")); - if (action != ACTION_SHOW_ALL) + if (action != ACTION_SHOW_ALL) { MSG_PUTS_TITLE(_("not found ")); + } MSG_PUTS_TITLE(_("in path ---\n")); } did_show = TRUE; @@ -4344,16 +4348,15 @@ search_line: && vim_regexec(®match, line, (colnr_T)(p - line))) { matched = TRUE; startp = regmatch.startp[0]; - /* - * Check if the line is not a comment line (unless we are - * looking for a define). A line starting with "# define" - * is not considered to be a comment line. - */ + // Check if the line is not a comment line (unless we are + // looking for a define). A line starting with "# define" + // is not considered to be a comment line. if (skip_comments) { - if ((*line != '#' || - STRNCMP(skipwhite(line + 1), "define", 6) != 0) - && get_leader_len(line, NULL, FALSE, TRUE)) - matched = FALSE; + if ((*line != '#' + || STRNCMP(skipwhite(line + 1), "define", 6) != 0) + && get_leader_len(line, NULL, false, true)) { + matched = false; + } /* * Also check for a "/ *" or "/ /" before the match. diff --git a/src/nvim/shada.c b/src/nvim/shada.c index 32a02b0fb7..3192be1b3c 100644 --- a/src/nvim/shada.c +++ b/src/nvim/shada.c @@ -283,7 +283,7 @@ typedef struct { } history_item; struct reg { char name; - uint8_t type; + MotionType type; char **contents; size_t contents_size; size_t width; @@ -475,7 +475,7 @@ static const ShadaEntry sd_default_values[] = { .additional_elements = NULL), DEF_SDE(Register, reg, .name = NUL, - .type = MCHAR, + .type = kMTCharWise, .contents = NULL, .contents_size = 0, .width = 0, @@ -1407,9 +1407,9 @@ static void shada_read(ShaDaReadDef *const sd_reader, const int flags) break; } case kSDItemRegister: { - if (cur_entry.data.reg.type != MCHAR - && cur_entry.data.reg.type != MLINE - && cur_entry.data.reg.type != MBLOCK) { + if (cur_entry.data.reg.type != kMTCharWise + && cur_entry.data.reg.type != kMTLineWise + && cur_entry.data.reg.type != kMTBlockWise) { shada_free_shada_entry(&cur_entry); break; } @@ -1882,7 +1882,7 @@ static ShaDaWriteResult shada_pack_entry(msgpack_packer *const packer, msgpack_pack_char(spacker, entry.data.reg.name); if (!CHECK_DEFAULT(entry, reg.type)) { PACK_STATIC_STR(REG_KEY_TYPE); - msgpack_pack_uint8(spacker, entry.data.reg.type); + msgpack_pack_uint8(spacker, (uint8_t)entry.data.reg.type); } if (!CHECK_DEFAULT(entry, reg.width)) { PACK_STATIC_STR(REG_KEY_WIDTH); @@ -2757,8 +2757,8 @@ static ShaDaWriteResult shada_write(ShaDaWriteDef *const sd_writer, .reg = { .contents = (char **) reg.y_array, .contents_size = (size_t) reg.y_size, - .type = (uint8_t) reg.y_type, - .width = (size_t) (reg.y_type == MBLOCK ? reg.y_width : 0), + .type = reg.y_type, + .width = (size_t) (reg.y_type == kMTBlockWise ? reg.y_width : 0), .additional_data = reg.additional_data, .name = name, } diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index 26f0a6c94b..41af7af55c 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -4478,12 +4478,10 @@ syn_cmd_region ( if (illegal || not_enough) rest = NULL; - /* - * Must have a "start" and "end" pattern. - */ - if (rest != NULL && (pat_ptrs[ITEM_START] == NULL || - pat_ptrs[ITEM_END] == NULL)) { - not_enough = TRUE; + // Must have a "start" and "end" pattern. + if (rest != NULL && (pat_ptrs[ITEM_START] == NULL + || pat_ptrs[ITEM_END] == NULL)) { + not_enough = true; rest = NULL; } diff --git a/src/nvim/tag.c b/src/nvim/tag.c index da84106454..7885d467d8 100644 --- a/src/nvim/tag.c +++ b/src/nvim/tag.c @@ -526,19 +526,17 @@ do_tag ( taglen_advance(taglen); 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); - if (!new_tag && ( - (g_do_tagpreview != 0 - && i == ptag_entry.cur_match) || - (use_tagstack - && i == tagstack[tagstackidx].cur_match))) + if (!new_tag && ((g_do_tagpreview != 0 && i == ptag_entry.cur_match) + || (use_tagstack + && i == tagstack[tagstackidx].cur_match))) { *IObuff = '>'; - else + } else { *IObuff = ' '; - vim_snprintf((char *)IObuff + 1, IOSIZE - 1, - "%2d %s ", i + 1, - mt_names[matches[i][0] & MT_MASK]); + } + vim_snprintf((char *)IObuff + 1, IOSIZE - 1, "%2d %s ", i + 1, + mt_names[matches[i][0] & MT_MASK]); msg_puts(IObuff); if (tagp.tagkind != NULL) msg_outtrans_len(tagp.tagkind, @@ -1226,20 +1224,15 @@ find_tags ( for (round = 1; round <= 2; ++round) { linear = (orgpat.headlen == 0 || !p_tbs || round == 2); - /* - * Try tag file names from tags option one by one. - */ - for (first_file = TRUE; - use_cscope || - get_tagfname(&tn, first_file, tag_fname) == OK; - first_file = FALSE) { - /* - * A file that doesn't exist is silently ignored. Only when not a - * single file is found, an error message is given (further on). - */ - if (use_cscope) - fp = NULL; /* avoid GCC warning */ - else { + // Try tag file names from tags option one by one. + for (first_file = true; + use_cscope || get_tagfname(&tn, first_file, tag_fname) == OK; + first_file = false) { + // A file that doesn't exist is silently ignored. Only when not a + // single file is found, an error message is given (further on). + if (use_cscope) { + fp = NULL; // avoid GCC warning + } else { if (curbuf->b_help) { /* Prefer help tags according to 'helplang'. Put the * two-letter language name in help_lang[]. */ diff --git a/src/nvim/tui/input.c b/src/nvim/tui/input.c index b41e4d2fba..99eb230a88 100644 --- a/src/nvim/tui/input.c +++ b/src/nvim/tui/input.c @@ -224,9 +224,9 @@ static void tk_getkeys(TermInput *input, bool force) while ((result = tk_getkey(input->tk, &key, force)) == TERMKEY_RES_KEY) { if (key.type == TERMKEY_TYPE_UNICODE && !key.modifiers) { forward_simple_utf8(input, &key); - } else if (key.type == TERMKEY_TYPE_UNICODE || - key.type == TERMKEY_TYPE_FUNCTION || - key.type == TERMKEY_TYPE_KEYSYM) { + } else if (key.type == TERMKEY_TYPE_UNICODE + || key.type == TERMKEY_TYPE_FUNCTION + || key.type == TERMKEY_TYPE_KEYSYM) { forward_modified_utf8(input, &key); } else if (key.type == TERMKEY_TYPE_MOUSE) { forward_mouse_event(input, &key); @@ -282,9 +282,9 @@ static bool handle_focus_event(TermInput *input) static bool handle_bracketed_paste(TermInput *input) { - if (rbuffer_size(input->read_stream.buffer) > 5 && - (!rbuffer_cmp(input->read_stream.buffer, "\x1b[200~", 6) || - !rbuffer_cmp(input->read_stream.buffer, "\x1b[201~", 6))) { + if (rbuffer_size(input->read_stream.buffer) > 5 + && (!rbuffer_cmp(input->read_stream.buffer, "\x1b[200~", 6) + || !rbuffer_cmp(input->read_stream.buffer, "\x1b[201~", 6))) { bool enable = *rbuffer_get(input->read_stream.buffer, 4) == '0'; // Advance past the sequence rbuffer_consumed(input->read_stream.buffer, 6); diff --git a/src/nvim/tui/tui.c b/src/nvim/tui/tui.c index 00e2821075..e1c0407b27 100644 --- a/src/nvim/tui/tui.c +++ b/src/nvim/tui/tui.c @@ -628,8 +628,8 @@ static void tui_suspend(UI *ui) static void tui_set_title(UI *ui, char *title) { TUIData *data = ui->data; - if (!(title && unibi_get_str(data->ut, unibi_to_status_line) && - unibi_get_str(data->ut, unibi_from_status_line))) { + if (!(title && unibi_get_str(data->ut, unibi_to_status_line) + && unibi_get_str(data->ut, unibi_from_status_line))) { return; } 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) - if (data->out_isatty && - !uv_tty_get_winsize(&data->output_handle.tty, &width, &height)) { + if (data->out_isatty + && !uv_tty_get_winsize(&data->output_handle.tty, &width, &height)) { goto end; } diff --git a/src/nvim/undo.c b/src/nvim/undo.c index 7d9b2c7c3b..f16b4264d7 100644 --- a/src/nvim/undo.c +++ b/src/nvim/undo.c @@ -2876,9 +2876,7 @@ static char_u *u_save_line(linenr_T lnum) /// @return true if the buffer has changed bool bufIsChanged(buf_T *buf) { - return - !bt_dontwrite(buf) && - (buf->b_changed || file_ff_differs(buf, true)); + return !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 @@ -2888,9 +2886,8 @@ bool bufIsChanged(buf_T *buf) /// @return true if the current buffer has changed bool curbufIsChanged(void) { - return - !bt_dontwrite(curbuf) && - (curbuf->b_changed || file_ff_differs(curbuf, true)); + return (!bt_dontwrite(curbuf) + && (curbuf->b_changed || file_ff_differs(curbuf, true))); } /* diff --git a/src/nvim/version.c b/src/nvim/version.c index 3de61ea69f..7afd4c2e99 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -796,7 +796,7 @@ static int included_patches[] = { 885, // 884 NA 883, - // 882, + 882, 881, // 880 NA 879, @@ -1006,7 +1006,7 @@ static int included_patches[] = { 675, // 674 NA 673, - // 672, + 672, 671, 670, // 669 NA diff --git a/src/nvim/vim.h b/src/nvim/vim.h index 623ea19e36..165a44a148 100644 --- a/src/nvim/vim.h +++ b/src/nvim/vim.h @@ -201,15 +201,6 @@ enum { #define MAYBE 2 /* sometimes used for a variant on TRUE */ -/* - * Motion types, used for operators and for yank/delete registers. - */ -#define MCHAR 0 /* character-wise movement/register */ -#define MLINE 1 /* line-wise movement/register */ -#define MBLOCK 2 /* block-wise register */ - -#define MAUTO 0xff /* Decide between MLINE/MCHAR */ - #define STATUS_HEIGHT 1 /* height of a status line under a window */ #define QF_WINHEIGHT 10 /* default height for quickfix window */ |