diff options
Diffstat (limited to 'src/nvim/ex_docmd.c')
-rw-r--r-- | src/nvim/ex_docmd.c | 130 |
1 files changed, 67 insertions, 63 deletions
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 27c98a13a6..3afcd9ec5a 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -97,7 +97,7 @@ static garray_T ucmds = {0, 0, sizeof(ucmd_T), 4, NULL}; #define USER_CMD(i) (&((ucmd_T *)(ucmds.ga_data))[i]) #define USER_CMD_GA(gap, i) (&((ucmd_T *)((gap)->ga_data))[i]) -/* Wether a command index indicates a user command. */ +// Whether a command index indicates a user command. # define IS_USER_CMDIDX(idx) ((int)(idx) < 0) /* Struct for storing a line inside a while/for loop */ @@ -186,17 +186,14 @@ static void restore_dbg_stuff(struct dbg_stuff *dsp) } /// Repeatedly get commands for Ex mode, until the ":vi" command is given. -void do_exmode(int improved) +void do_exmode(void) { int save_msg_scroll; int prev_msg_row; linenr_T prev_line; int changedtick; - if (improved) - exmode_active = EXMODE_VIM; - else - exmode_active = EXMODE_NORMAL; + exmode_active = true; State = NORMAL; /* When using ":global /pat/ visual" and then "Q" we return to continue @@ -212,7 +209,7 @@ void do_exmode(int improved) while (exmode_active) { /* Check for a ":normal" command and no more characters left. */ if (ex_normal_busy > 0 && typebuf.tb_len == 0) { - exmode_active = 0; + exmode_active = false; break; } msg_scroll = true; @@ -309,13 +306,13 @@ int do_cmdline(char_u *cmdline, LineGetter fgetline, void *cookie, /* argument for fgetline() */ int flags) { - char_u *next_cmdline; /* next cmd to execute */ - char_u *cmdline_copy = NULL; /* copy of cmd line */ - int used_getline = FALSE; /* used "fgetline" to obtain command */ - static int recursive = 0; /* recursive depth */ - int msg_didout_before_start = 0; - int count = 0; /* line number count */ - int did_inc = FALSE; /* incremented RedrawingDisabled */ + char_u *next_cmdline; // next cmd to execute + char_u *cmdline_copy = NULL; // copy of cmd line + bool used_getline = false; // used "fgetline" to obtain command + static int recursive = 0; // recursive depth + bool msg_didout_before_start = false; + int count = 0; // line number count + int did_inc = FALSE; // incremented RedrawingDisabled int retval = OK; cstack_T cstack = { // conditional stack .cs_idx = -1, @@ -535,7 +532,7 @@ int do_cmdline(char_u *cmdline, LineGetter fgetline, retval = FAIL; break; } - used_getline = TRUE; + used_getline = true; /* * Keep the first typed line. Clear it when more lines are typed. @@ -565,7 +562,7 @@ int do_cmdline(char_u *cmdline, LineGetter fgetline, && (cstack.cs_looplevel || has_loop_cmd(next_cmdline))) { store_loop_line(&lines_ga, next_cmdline); } - did_endif = FALSE; + did_endif = false; if (count++ == 0) { /* @@ -576,7 +573,7 @@ int do_cmdline(char_u *cmdline, LineGetter fgetline, */ if (!(flags & DOCMD_NOWAIT) && !recursive) { msg_didout_before_start = msg_didout; - msg_didany = FALSE; /* no output yet */ + msg_didany = false; // no output yet msg_start(); msg_scroll = TRUE; /* put messages below each other */ ++no_wait_return; /* don't wait for return until finished */ @@ -750,14 +747,13 @@ int do_cmdline(char_u *cmdline, LineGetter fgetline, * the :endtry to be missed. */ && (cstack.cs_trylevel == 0 || did_emsg_syntax) && used_getline - && (getline_equal(fgetline, cookie, getexmodeline) - || getline_equal(fgetline, cookie, getexline))) + && getline_equal(fgetline, cookie, getexline)) && (next_cmdline != NULL || cstack.cs_idx >= 0 || (flags & DOCMD_REPEAT))); xfree(cmdline_copy); - did_emsg_syntax = FALSE; + did_emsg_syntax = false; GA_DEEP_CLEAR(&lines_ga, wcmd_T, FREE_WCMD); if (cstack.cs_idx >= 0) { @@ -931,8 +927,8 @@ int do_cmdline(char_u *cmdline, LineGetter fgetline, if (retval == FAIL || (did_endif && KeyTyped && !did_emsg) ) { - need_wait_return = FALSE; - msg_didany = FALSE; /* don't wait when restarting edit */ + need_wait_return = false; + msg_didany = false; // don't wait when restarting edit } else if (need_wait_return) { /* * The msg_start() above clears msg_didout. The wait_return we do @@ -944,7 +940,7 @@ int do_cmdline(char_u *cmdline, LineGetter fgetline, } } - did_endif = FALSE; /* in case do_cmdline used recursively */ + did_endif = false; // in case do_cmdline used recursively call_depth--; end_batch_changes(); @@ -1518,7 +1514,7 @@ static char_u * do_one_cmd(char_u **cmdlinep, goto doend; } - // Disallow editing another buffer when "curbuf_lock" is set. + // Disallow editing another buffer when "curbuf->b_ro_locked" is set. // Do allow ":checktime" (it is postponed). // Do allow ":edit" (check for an argument later). // Do allow ":file" with no arguments (check for an argument later). @@ -1601,7 +1597,7 @@ static char_u * do_one_cmd(char_u **cmdlinep, else ea.arg = skipwhite(p); - // ":file" cannot be run with an argument when "curbuf_lock" is set + // ":file" cannot be run with an argument when "curbuf->b_ro_locked" is set if (ea.cmdidx == CMD_file && *ea.arg != NUL && curbuf_locked()) { goto doend; } @@ -2056,8 +2052,7 @@ int parse_command_modifiers(exarg_T *eap, char_u **errormsg, bool skip_only) // in ex mode, an empty line works like :+ if (*eap->cmd == NUL && exmode_active - && (getline_equal(eap->getline, eap->cookie, getexmodeline) - || getline_equal(eap->getline, eap->cookie, getexline)) + && getline_equal(eap->getline, eap->cookie, getexline) && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) { eap->cmd = (char_u *)"+"; if (!skip_only) { @@ -2956,12 +2951,13 @@ const char * set_one_cmd_context( } } - /* - * If the cursor is touching the command, and it ends in an alpha-numeric - * character, complete the command name. - */ - if (*p == NUL && ASCII_ISALNUM(p[-1])) + // + // If the cursor is touching the command, and it ends in an alphanumeric + // character, complete the command name. + // + if (*p == NUL && ASCII_ISALNUM(p[-1])) { return NULL; + } if (ea.cmdidx == CMD_SIZE) { if (*cmd == 's' && vim_strchr((const char_u *)"cgriI", cmd[1]) != NULL) { @@ -5518,6 +5514,9 @@ invalid_count: return OK; } +static char e_complete_used_without_nargs[] = N_( + "E1208: -complete used without -nargs"); + /* * ":command ..." */ @@ -5569,10 +5568,10 @@ static void ex_command(exarg_T *eap) uc_list(name, end - name); } else if (!ASCII_ISUPPER(*name)) { EMSG(_("E183: User defined commands must start with an uppercase letter")); - return; } else if (name_len <= 4 && STRNCMP(name, "Next", name_len) == 0) { EMSG(_("E841: Reserved name, cannot be used for user defined command")); - return; + } else if (compl > 0 && (argt & EX_EXTRA) == 0) { + EMSG(_(e_complete_used_without_nargs)); } else { uc_add_command(name, end - name, p, argt, def, flags, compl, compl_arg, addr_type_arg, eap->forceit); @@ -6656,9 +6655,10 @@ void tabpage_close_other(tabpage_T *tp, int forceit) break; } - redraw_tabline = TRUE; - if (h != tabline_height()) + redraw_tabline = true; + if (h != tabline_height()) { shell_new_rows(); + } } /* @@ -6802,7 +6802,7 @@ static void ex_print(exarg_T *eap) beginline(BL_SOL | BL_FIX); } - ex_no_reprint = TRUE; + ex_no_reprint = true; } static void ex_goto(exarg_T *eap) @@ -7302,7 +7302,7 @@ do_exedit( */ if (exmode_active && (eap->cmdidx == CMD_visual || eap->cmdidx == CMD_view)) { - exmode_active = 0; + exmode_active = false; ex_pressedreturn = false; if (*eap->arg == NUL) { /* Special case: ":global/pat/visual\NLvi-commands" */ @@ -7318,7 +7318,7 @@ do_exedit( RedrawingDisabled = 0; no_wait_return = 0; - need_wait_return = FALSE; + need_wait_return = false; msg_scroll = 0; redraw_all_later(NOT_VALID); @@ -7344,16 +7344,18 @@ do_exedit( old_curwin == NULL ? curwin : NULL); } else if ((eap->cmdidx != CMD_split && eap->cmdidx != CMD_vsplit) || *eap->arg != NUL) { - /* Can't edit another file when "curbuf_lock" is set. Only ":edit" - * can bring us here, others are stopped earlier. */ - if (*eap->arg != NUL && curbuf_locked()) + // Can't edit another file when "curbuf->b_ro_lockec" is set. Only ":edit" + // can bring us here, others are stopped earlier. + if (*eap->arg != NUL && curbuf_locked()) { return; + } n = readonlymode; - if (eap->cmdidx == CMD_view || eap->cmdidx == CMD_sview) - readonlymode = TRUE; - else if (eap->cmdidx == CMD_enew) - readonlymode = FALSE; /* 'readonly' doesn't make sense in an - empty buffer */ + if (eap->cmdidx == CMD_view || eap->cmdidx == CMD_sview) { + readonlymode = true; + } else if (eap->cmdidx == CMD_enew) { + readonlymode = false; // 'readonly' doesn't make sense + // in an empty buffer + } if (eap->cmdidx != CMD_balt && eap->cmdidx != CMD_badd) { setpcmark(); } @@ -7412,7 +7414,7 @@ do_exedit( && !cmdmod.keepalt) old_curwin->w_alt_fnum = curbuf->b_fnum; - ex_no_reprint = TRUE; + ex_no_reprint = true; } /// ":gui" and ":gvim" when there is no GUI. @@ -7488,7 +7490,7 @@ static void ex_syncbind(exarg_T *eap) curwin = save_curwin; curbuf = save_curbuf; if (curwin->w_p_scb) { - did_syncbind = TRUE; + did_syncbind = true; checkpcmark(); if (old_linenr != curwin->w_cursor.lnum) { char_u ctrl_o[2]; @@ -7911,8 +7913,8 @@ void ex_may_print(exarg_T *eap) { if (eap->flags != 0) { print_line(curwin->w_cursor.lnum, (eap->flags & EXFLAG_NR), - (eap->flags & EXFLAG_LIST)); - ex_no_reprint = TRUE; + (eap->flags & EXFLAG_LIST)); + ex_no_reprint = true; } } @@ -7967,9 +7969,9 @@ static void ex_at(exarg_T *eap) == FAIL) { beep_flush(); } else { - int save_efr = exec_from_reg; + bool save_efr = exec_from_reg; - exec_from_reg = TRUE; + exec_from_reg = true; /* * Execute from the typeahead buffer. @@ -8007,16 +8009,16 @@ static void ex_wundo(exarg_T *eap) { char_u hash[UNDO_HASH_SIZE]; - u_compute_hash(hash); - u_write_undo((char *) eap->arg, eap->forceit, curbuf, hash); + u_compute_hash(curbuf, hash); + u_write_undo((char *)eap->arg, eap->forceit, curbuf, hash); } static void ex_rundo(exarg_T *eap) { char_u hash[UNDO_HASH_SIZE]; - u_compute_hash(hash); - u_read_undo((char *) eap->arg, hash, NULL); + u_compute_hash(curbuf, hash); + u_read_undo((char *)eap->arg, hash, NULL); } /// ":redo". @@ -8133,7 +8135,7 @@ static void ex_redir(exarg_T *eap) if (redir_fd != NULL || redir_reg || redir_vname ) - redir_off = FALSE; + redir_off = false; } /// ":redraw": force redraw @@ -8160,12 +8162,12 @@ static void ex_redraw(exarg_T *eap) RedrawingDisabled = r; p_lz = p; - /* Reset msg_didout, so that a message that's there is overwritten. */ - msg_didout = FALSE; + // Reset msg_didout, so that a message that's there is overwritten. + msg_didout = false; msg_col = 0; - /* No need to wait after an intentional redraw. */ - need_wait_return = FALSE; + // No need to wait after an intentional redraw. + need_wait_return = false; ui_flush(); } @@ -8348,7 +8350,9 @@ void restore_current_state(save_state_T *sst) finish_op = sst->save_finish_op; opcount = sst->save_opcount; reg_executing = sst->save_reg_executing; - msg_didout |= sst->save_msg_didout; // don't reset msg_didout now + + // don't reset msg_didout now + msg_didout |= sst->save_msg_didout; // Restore the state (needed when called from a function executed for // 'indentexpr'). Update the mouse and cursor, they may have changed. |