aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/eval.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/eval.c')
-rw-r--r--src/nvim/eval.c64
1 files changed, 43 insertions, 21 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index fa037b59d7..8a1556320c 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -7,6 +7,8 @@
#include <math.h>
+#include "auto/config.h"
+
#ifdef HAVE_LOCALE_H
# include <locale.h>
#endif
@@ -74,9 +76,6 @@ static char_u * const namespace_char = (char_u *)"abglstvw";
/// Variable used for g:
static ScopeDictDictItem globvars_var;
-/// g: value
-#define globvarht globvardict.dv_hashtab
-
/*
* Old Vim variables such as "v:version" are also available without the "v:".
* Also in functions. We need a special hashtable for them.
@@ -2554,6 +2553,7 @@ void free_for_info(void *fi_void)
void set_context_for_expression(expand_T *xp, char_u *arg, cmdidx_T cmdidx)
+ FUNC_ATTR_NONNULL_ALL
{
int got_eq = FALSE;
int c;
@@ -2636,6 +2636,23 @@ void set_context_for_expression(expand_T *xp, char_u *arg, cmdidx_T cmdidx)
}
}
}
+
+ // ":exe one two" completes "two"
+ if ((cmdidx == CMD_execute
+ || cmdidx == CMD_echo
+ || cmdidx == CMD_echon
+ || cmdidx == CMD_echomsg)
+ && xp->xp_context == EXPAND_EXPRESSION) {
+ for (;;) {
+ char_u *const n = skiptowhite(arg);
+
+ if (n == arg || ascii_iswhite_or_nul(*skipwhite(n))) {
+ break;
+ }
+ arg = skipwhite(n);
+ }
+ }
+
xp->xp_pattern = arg;
}
@@ -5402,7 +5419,7 @@ static int get_literal_key(char_u **arg, typval_T *tv)
for (p = *arg; ASCII_ISALNUM(*p) || *p == '_' || *p == '-'; p++) {
}
tv->v_type = VAR_STRING;
- tv->vval.v_string = vim_strnsave(*arg, (int)(p - *arg));
+ tv->vval.v_string = vim_strnsave(*arg, p - *arg);
*arg = skipwhite(p);
return OK;
@@ -5931,6 +5948,19 @@ int assert_exception(typval_T *argvars)
return 0;
}
+static void assert_append_cmd_or_arg(garray_T *gap, typval_T *argvars,
+ const char *cmd)
+ FUNC_ATTR_NONNULL_ALL
+{
+ if (argvars[1].v_type != VAR_UNKNOWN && argvars[2].v_type != VAR_UNKNOWN) {
+ char *const tofree = encode_tv2echo(&argvars[2], NULL);
+ ga_concat(gap, (char_u *)tofree);
+ xfree(tofree);
+ } else {
+ ga_concat(gap, (char_u *)cmd);
+ }
+}
+
int assert_fails(typval_T *argvars)
FUNC_ATTR_NONNULL_ALL
{
@@ -5949,14 +5979,7 @@ int assert_fails(typval_T *argvars)
if (!called_emsg) {
prepare_assert_error(&ga);
ga_concat(&ga, (const char_u *)"command did not fail: ");
- if (argvars[1].v_type != VAR_UNKNOWN
- && argvars[2].v_type != VAR_UNKNOWN) {
- char *const tofree = encode_tv2echo(&argvars[2], NULL);
- ga_concat(&ga, (char_u *)tofree);
- xfree(tofree);
- } else {
- ga_concat(&ga, (const char_u *)cmd);
- }
+ assert_append_cmd_or_arg(&ga, argvars, cmd);
assert_error(&ga);
ga_clear(&ga);
ret = 1;
@@ -5969,6 +5992,8 @@ int assert_fails(typval_T *argvars)
prepare_assert_error(&ga);
fill_assert_error(&ga, &argvars[2], NULL, &argvars[1],
&vimvars[VV_ERRMSG].vv_tv, ASSERT_OTHER);
+ ga_concat(&ga, (char_u *)": ");
+ assert_append_cmd_or_arg(&ga, argvars, cmd);
assert_error(&ga);
ga_clear(&ga);
ret = 1;
@@ -7068,7 +7093,7 @@ void set_buffer_lines(buf_T *buf, linenr_T lnum_arg, bool append,
}
}
check_cursor_col();
- update_topline();
+ update_topline(curwin);
}
if (!is_curbuf) {
@@ -7780,13 +7805,13 @@ pos_T *var2fpos(const typval_T *const tv, const int dollar_lnum,
if (name[0] == 'w' && dollar_lnum) {
pos.col = 0;
if (name[1] == '0') { // "w0": first visible line
- update_topline();
+ update_topline(curwin);
// In silent Ex mode topline is zero, but that's not a valid line
// number; use one instead.
pos.lnum = curwin->w_topline > 0 ? curwin->w_topline : 1;
return &pos;
} else if (name[1] == '$') { // "w$": last visible line
- validate_botline();
+ validate_botline(curwin);
// In silent Ex mode botline is zero, return zero then.
pos.lnum = curwin->w_botline > 0 ? curwin->w_botline - 1 : 0;
return &pos;
@@ -10244,9 +10269,6 @@ repeat:
if (src[*usedlen] == ':'
&& (src[*usedlen + 1] == 's'
|| (src[*usedlen + 1] == 'g' && src[*usedlen + 2] == 's'))) {
- char_u *str;
- char_u *pat;
- char_u *sub;
int sep;
char_u *flags;
int didit = FALSE;
@@ -10263,13 +10285,13 @@ repeat:
// find end of pattern
p = vim_strchr(s, sep);
if (p != NULL) {
- pat = vim_strnsave(s, (int)(p - s));
+ char_u *const pat = vim_strnsave(s, p - s);
s = p + 1;
// find end of substitution
p = vim_strchr(s, sep);
if (p != NULL) {
- sub = vim_strnsave(s, (int)(p - s));
- str = vim_strnsave(*fnamep, *fnamelen);
+ char_u *const sub = vim_strnsave(s, p - s);
+ char_u *const str = vim_strnsave(*fnamep, *fnamelen);
*usedlen = (size_t)(p + 1 - src);
s = do_string_sub(str, pat, sub, NULL, flags);
*fnamep = s;