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.c80
1 files changed, 53 insertions, 27 deletions
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c
index 5b9b4fed12..9c4a3f389a 100644
--- a/src/nvim/ex_docmd.c
+++ b/src/nvim/ex_docmd.c
@@ -78,7 +78,7 @@
static int quitmore = 0;
static int ex_pressedreturn = FALSE;
-/* whether ":lcd" was produced for a session */
+/// Whether ":lcd" or ":tcd" was produced for a session.
static int did_lcd;
typedef struct ucmd {
@@ -839,9 +839,10 @@ int do_cmdline(char_u *cmdline, LineGetter fgetline,
sourcing_lnum = current_exception->throw_lnum;
current_exception->throw_name = NULL;
- discard_current_exception(); /* uses IObuff if 'verbose' */
- suppress_errthrow = TRUE;
- force_abort = TRUE;
+ discard_current_exception(); // uses IObuff if 'verbose'
+ suppress_errthrow = true;
+ force_abort = true;
+ msg_ext_set_kind("emsg"); // kind=emsg for :throw, exceptions. #9993
if (messages != NULL) {
do {
@@ -2263,8 +2264,11 @@ static char_u * do_one_cmd(char_u **cmdlinep,
need_rethrow = check_cstack = FALSE;
doend:
- if (curwin->w_cursor.lnum == 0) /* can happen with zero line number */
+ // can happen with zero line number
+ if (curwin->w_cursor.lnum == 0) {
curwin->w_cursor.lnum = 1;
+ curwin->w_cursor.col = 0;
+ }
if (errormsg != NULL && *errormsg != NUL && !did_emsg) {
if (flags & DOCMD_VERBOSE) {
@@ -2440,10 +2444,24 @@ static char_u *find_command(exarg_T *eap, int *full)
}
}
- if (ASCII_ISLOWER(*eap->cmd))
- eap->cmdidx = cmdidxs[CharOrdLow(*eap->cmd)];
- else
- eap->cmdidx = cmdidxs[26];
+ if (ASCII_ISLOWER(eap->cmd[0])) {
+ const int c1 = eap->cmd[0];
+ const int c2 = eap->cmd[1];
+
+ if (command_count != (int)CMD_SIZE) {
+ iemsg((char *)_("E943: Command table needs to be updated, run 'make'"));
+ getout(1);
+ }
+
+ // Use a precomputed index for fast look-up in cmdnames[]
+ // taking into account the first 2 letters of eap->cmd.
+ eap->cmdidx = cmdidxs1[CharOrdLow(c1)];
+ if (ASCII_ISLOWER(c2)) {
+ eap->cmdidx += cmdidxs2[CharOrdLow(c1)][CharOrdLow(c2)];
+ }
+ } else {
+ eap->cmdidx = CMD_bang;
+ }
for (; (int)eap->cmdidx < (int)CMD_SIZE;
eap->cmdidx = (cmdidx_T)((int)eap->cmdidx + 1))
@@ -3235,7 +3253,7 @@ const char * set_one_cmd_context(
case CMD_tjump:
case CMD_stjump:
case CMD_ptjump:
- if (*p_wop != NUL) {
+ if (wop_flags & WOP_TAGFILE) {
xp->xp_context = EXPAND_TAGS_LISTFILES;
} else {
xp->xp_context = EXPAND_TAGS;
@@ -4488,8 +4506,8 @@ static int get_tabpage_arg(exarg_T *eap)
tab_number = 0;
} else {
tab_number = eap->line2;
- if (!unaccept_arg0 && **eap->cmdlinep == '-') {
- --tab_number;
+ if (!unaccept_arg0 && *skipwhite(*eap->cmdlinep) == '-') {
+ tab_number--;
if (tab_number < unaccept_arg0) {
eap->errmsg = e_invarg;
}
@@ -6903,10 +6921,11 @@ static void ex_resize(exarg_T *eap)
n = 9999;
win_setwidth_win(n, wp);
} else {
- if (*eap->arg == '-' || *eap->arg == '+')
+ if (*eap->arg == '-' || *eap->arg == '+') {
n += curwin->w_height;
- else if (n == 0 && eap->arg[0] == NUL) /* default is very wide */
+ } else if (n == 0 && eap->arg[0] == NUL) { // default is very high
n = 9999;
+ }
win_setheight_win(n, wp);
}
}
@@ -7195,10 +7214,11 @@ static void ex_read(exarg_T *eap)
else
lnum = 1;
if (*ml_get(lnum) == NUL && u_savedel(lnum, 1L) == OK) {
- ml_delete(lnum, FALSE);
+ ml_delete(lnum, false);
if (curwin->w_cursor.lnum > 1
- && curwin->w_cursor.lnum >= lnum)
- --curwin->w_cursor.lnum;
+ && curwin->w_cursor.lnum >= lnum) {
+ curwin->w_cursor.lnum--;
+ }
deleted_lines_mark(lnum, 1L);
}
}
@@ -7224,7 +7244,7 @@ void free_cd_dir(void)
/// Deal with the side effects of changing the current directory.
///
/// @param scope Scope of the function call (global, tab or window).
-void post_chdir(CdScope scope)
+void post_chdir(CdScope scope, bool trigger_dirchanged)
{
// Always overwrite the window-local CWD.
xfree(curwin->w_localdir);
@@ -7264,7 +7284,10 @@ void post_chdir(CdScope scope)
}
shorten_fnames(true);
- do_autocmd_dirchanged(cwd, scope);
+
+ if (trigger_dirchanged) {
+ do_autocmd_dirchanged(cwd, scope);
+ }
}
/// `:cd`, `:tcd`, `:lcd`, `:chdir`, `:tchdir` and `:lchdir`.
@@ -7323,10 +7346,10 @@ void ex_cd(exarg_T *eap)
break;
}
- if (vim_chdir(new_dir, scope)) {
+ if (vim_chdir(new_dir)) {
EMSG(_(e_failed));
} else {
- post_chdir(scope);
+ post_chdir(scope, true);
// Echo the new current directory if the command was typed.
if (KeyTyped || p_verbose >= 5) {
ex_pwd(eap);
@@ -7787,11 +7810,12 @@ static void ex_redir(exarg_T *eap)
redir_off = FALSE;
}
-/*
- * ":redraw": force redraw
- */
+/// ":redraw": force redraw
static void ex_redraw(exarg_T *eap)
{
+ if (State & CMDPREVIEW) {
+ return; // Ignore :redraw during 'inccommand' preview. #9777
+ }
int r = RedrawingDisabled;
int p = p_lz;
@@ -7820,11 +7844,12 @@ static void ex_redraw(exarg_T *eap)
ui_flush();
}
-/*
- * ":redrawstatus": force redraw of status line(s)
- */
+/// ":redrawstatus": force redraw of status line(s)
static void ex_redrawstatus(exarg_T *eap)
{
+ if (State & CMDPREVIEW) {
+ return; // Ignore :redrawstatus during 'inccommand' preview. #9777
+ }
int r = RedrawingDisabled;
int p = p_lz;
@@ -9130,6 +9155,7 @@ makeopens(
|| put_eol(fd) == FAIL) {
return FAIL;
}
+ did_lcd = true;
}
/* Don't continue in another tab page when doing only the current one