aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/ex_docmd.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/ex_docmd.c')
-rw-r--r--src/nvim/ex_docmd.c93
1 files changed, 63 insertions, 30 deletions
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c
index 5e418bf099..79a0b5849f 100644
--- a/src/nvim/ex_docmd.c
+++ b/src/nvim/ex_docmd.c
@@ -271,7 +271,7 @@ do_exmode (
int do_cmdline_cmd(char *cmd)
{
return do_cmdline((char_u *)cmd, NULL, NULL,
- DOCMD_VERBOSE|DOCMD_NOWAIT|DOCMD_KEYTYPED);
+ DOCMD_NOWAIT|DOCMD_KEYTYPED);
}
/*
@@ -597,11 +597,11 @@ int do_cmdline(char_u *cmdline, LineGetter fgetline,
* do_one_cmd() will return NULL if there is no trailing '|'.
* "cmdline_copy" can change, e.g. for '%' and '#' expansion.
*/
- ++recursive;
- next_cmdline = do_one_cmd(&cmdline_copy, flags & DOCMD_VERBOSE,
- &cstack,
- cmd_getline, cmd_cookie);
- --recursive;
+ recursive++;
+ next_cmdline = do_one_cmd(&cmdline_copy, flags,
+ &cstack,
+ cmd_getline, cmd_cookie);
+ recursive--;
if (cmd_cookie == (void *)&cmd_loop_cookie)
/* Use "current_line" from "cmd_loop_cookie", it may have been
@@ -1225,7 +1225,7 @@ static void get_wincmd_addr_type(char_u *arg, exarg_T *eap)
* This function may be called recursively!
*/
static char_u * do_one_cmd(char_u **cmdlinep,
- int sourcing,
+ int flags,
struct condstack *cstack,
LineGetter fgetline,
void *cookie /* argument for fgetline() */
@@ -1248,7 +1248,7 @@ static char_u * do_one_cmd(char_u **cmdlinep,
memset(&ea, 0, sizeof(ea));
ea.line1 = 1;
ea.line2 = 1;
- ++ex_nesting_level;
+ ex_nesting_level++;
/* When the last file has not been edited :q has to be typed twice. */
if (quitmore
@@ -1542,7 +1542,8 @@ static char_u * do_one_cmd(char_u **cmdlinep,
break;
}
ea.cmd = skipwhite(ea.cmd);
- lnum = get_address(&ea, &ea.cmd, ea.addr_type, ea.skip, ea.addr_count == 0);
+ lnum = get_address(&ea, &ea.cmd, ea.addr_type, ea.skip,
+ ea.addr_count == 0);
if (ea.cmd == NULL) { // error detected
goto doend;
}
@@ -1726,8 +1727,9 @@ static char_u * do_one_cmd(char_u **cmdlinep,
if (ea.cmdidx == CMD_SIZE) {
if (!ea.skip) {
STRCPY(IObuff, _("E492: Not an editor command"));
- if (!sourcing)
+ if (!(flags & DOCMD_VERBOSE)) {
append_command(*cmdlinep);
+ }
errormsg = IObuff;
did_emsg_syntax = TRUE;
}
@@ -1809,7 +1811,7 @@ static char_u * do_one_cmd(char_u **cmdlinep,
*/
if (!global_busy && ea.line1 > ea.line2) {
if (msg_silent == 0) {
- if (sourcing || exmode_active) {
+ if ((flags & DOCMD_VERBOSE) || exmode_active) {
errormsg = (char_u *)_("E493: Backwards range given");
goto doend;
}
@@ -2221,7 +2223,7 @@ doend:
curwin->w_cursor.lnum = 1;
if (errormsg != NULL && *errormsg != NUL && !did_emsg) {
- if (sourcing) {
+ if (flags & DOCMD_VERBOSE) {
if (errormsg != IObuff) {
STRCPY(IObuff, errormsg);
errormsg = IObuff;
@@ -7293,15 +7295,13 @@ void ex_may_print(exarg_T *eap)
}
}
-/*
- * ":smagic" and ":snomagic".
- */
+/// ":smagic" and ":snomagic".
static void ex_submagic(exarg_T *eap)
{
int magic_save = p_magic;
p_magic = (eap->cmdidx == CMD_smagic);
- do_sub(eap);
+ ex_substitute(eap);
p_magic = magic_save;
}
@@ -7971,7 +7971,8 @@ static void ex_startinsert(exarg_T *eap)
static void ex_stopinsert(exarg_T *eap)
{
restart_edit = 0;
- stop_insert_mode = TRUE;
+ stop_insert_mode = true;
+ clearmode();
}
/*
@@ -8754,17 +8755,18 @@ makeopens (
if (put_line(fd, "wincmd t") == FAIL)
return FAIL;
- /*
- * If more than one window, see if sizes can be restored.
- * First set 'winheight' and 'winwidth' to 1 to avoid the windows being
- * resized when moving between windows.
- * Do this before restoring the view, so that the topline and the
- * cursor can be set. This is done again below.
- */
- if (put_line(fd, "set winheight=1 winwidth=1") == FAIL)
+ // If more than one window, see if sizes can be restored.
+ // First set 'winheight' and 'winwidth' to 1 to avoid the windows being
+ // resized when moving between windows.
+ // Do this before restoring the view, so that the topline and the
+ // cursor can be set. This is done again below.
+ if (put_line(fd, "set winminheight=1 winminwidth=1 winheight=1 winwidth=1")
+ == FAIL) {
return FAIL;
- if (nr > 1 && ses_winsizes(fd, restore_size, tab_firstwin) == FAIL)
+ }
+ if (nr > 1 && ses_winsizes(fd, restore_size, tab_firstwin) == FAIL) {
return FAIL;
+ }
/*
* Restore the view of the window (options, file, cursor, etc.).
@@ -8828,11 +8830,18 @@ makeopens (
if (put_line(fd, "unlet! s:wipebuf") == FAIL)
return FAIL;
- /* Re-apply 'winheight', 'winwidth' and 'shortmess'. */
- if (fprintf(fd, "set winheight=%" PRId64 " winwidth=%" PRId64 " shortmess=%s",
- (int64_t)p_wh, (int64_t)p_wiw, p_shm) < 0
- || put_eol(fd) == FAIL)
+ // Re-apply options.
+ if (fprintf(fd, "set winheight=%" PRId64 " winwidth=%" PRId64
+ " winminheight=%" PRId64 " winminwidth=%" PRId64
+ " shortmess=%s",
+ (int64_t)p_wh,
+ (int64_t)p_wiw,
+ (int64_t)p_wmh,
+ (int64_t)p_wmw,
+ p_shm) < 0
+ || put_eol(fd) == FAIL) {
return FAIL;
+ }
/*
* Lastly, execute the x.vim file if it exists.
@@ -9647,3 +9656,27 @@ static void ex_terminal(exarg_T *eap)
xfree(name);
}
}
+
+/// Checks if `cmd` is "previewable" (i.e. supported by 'inccommand').
+///
+/// @param[in] cmd Commandline to check. May start with a range.
+///
+/// @return true if `cmd` is previewable
+bool cmd_can_preview(char_u *cmd)
+{
+ if (cmd == NULL) {
+ return false;
+ }
+
+ exarg_T ea;
+ // parse the command line
+ ea.cmd = skip_range(cmd, NULL);
+ if (*ea.cmd == '*') {
+ ea.cmd = skipwhite(ea.cmd + 1);
+ }
+ find_command(&ea, NULL);
+
+ return ea.cmdidx == CMD_substitute
+ || ea.cmdidx == CMD_smagic
+ || ea.cmdidx == CMD_snomagic;
+}