aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/nvim/ascii.h12
-rw-r--r--src/nvim/eval.c18
-rw-r--r--src/nvim/testdir/test_cmdline.vim11
3 files changed, 41 insertions, 0 deletions
diff --git a/src/nvim/ascii.h b/src/nvim/ascii.h
index 2397af27cc..f41068ea70 100644
--- a/src/nvim/ascii.h
+++ b/src/nvim/ascii.h
@@ -89,6 +89,10 @@ static inline bool ascii_iswhite(int)
REAL_FATTR_CONST
REAL_FATTR_ALWAYS_INLINE;
+static inline bool ascii_iswhite_or_nul(int)
+ REAL_FATTR_CONST
+ REAL_FATTR_ALWAYS_INLINE;
+
static inline bool ascii_isdigit(int)
REAL_FATTR_CONST
REAL_FATTR_ALWAYS_INLINE;
@@ -117,6 +121,14 @@ static inline bool ascii_iswhite(int c)
return c == ' ' || c == '\t';
}
+/// Checks if `c` is a space or tab character or NUL.
+///
+/// @see {ascii_isdigit}
+static inline bool ascii_iswhite_or_nul(int c)
+{
+ return ascii_iswhite(c) || c == NUL;
+}
+
/// Check whether character is a decimal digit.
///
/// Library isdigit() function is officially locale-dependent and, for
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index cc707c0c84..10a382ec4e 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -2556,6 +2556,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;
@@ -2638,6 +2639,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;
}
diff --git a/src/nvim/testdir/test_cmdline.vim b/src/nvim/testdir/test_cmdline.vim
index 6d3c6589d3..8fc3361b79 100644
--- a/src/nvim/testdir/test_cmdline.vim
+++ b/src/nvim/testdir/test_cmdline.vim
@@ -577,6 +577,17 @@ funct Test_cmdline_complete_languages()
endif
endfunc
+func Test_cmdline_complete_expression()
+ let g:SomeVar = 'blah'
+ for cmd in ['exe', 'echo', 'echon', 'echomsg']
+ call feedkeys(":" .. cmd .. " SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
+ call assert_match('"' .. cmd .. ' SomeVar', @:)
+ call feedkeys(":" .. cmd .. " foo SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
+ call assert_match('"' .. cmd .. ' foo SomeVar', @:)
+ endfor
+ unlet g:SomeVar
+endfunc
+
func Test_cmdline_write_alternatefile()
new
call setline('.', ['one', 'two'])