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.c28
1 files changed, 26 insertions, 2 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 1640729c94..998d0568ce 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -8331,6 +8331,8 @@ static void f_execute(typval_T *argvars, typval_T *rettv, FunPtr fptr)
const bool save_emsg_noredir = emsg_noredir;
const bool save_redir_off = redir_off;
garray_T *const save_capture_ga = capture_ga;
+ const int save_msg_col = msg_col;
+ bool echo_output = false;
if (check_secure()) {
return;
@@ -8343,6 +8345,9 @@ static void f_execute(typval_T *argvars, typval_T *rettv, FunPtr fptr)
if (s == NULL) {
return;
}
+ if (*s == NUL) {
+ echo_output = true;
+ }
if (strncmp(s, "silent", 6) == 0) {
msg_silent++;
}
@@ -8358,6 +8363,9 @@ static void f_execute(typval_T *argvars, typval_T *rettv, FunPtr fptr)
ga_init(&capture_local, (int)sizeof(char), 80);
capture_ga = &capture_local;
redir_off = false;
+ if (!echo_output) {
+ msg_col = 0; // prevent leading spaces
+ }
if (argvars[0].v_type != VAR_LIST) {
do_cmdline_cmd(tv_get_string(&argvars[0]));
@@ -8376,6 +8384,16 @@ static void f_execute(typval_T *argvars, typval_T *rettv, FunPtr fptr)
emsg_silent = save_emsg_silent;
emsg_noredir = save_emsg_noredir;
redir_off = save_redir_off;
+ // "silent reg" or "silent echo x" leaves msg_col somewhere in the line.
+ if (echo_output) {
+ // When not working silently: put it in column zero. A following
+ // "echon" will overwrite the message, unavoidably.
+ msg_col = 0;
+ } else {
+ // When working silently: Put it back where it was, since nothing
+ // should have been written.
+ msg_col = save_msg_col;
+ }
ga_append(capture_ga, NUL);
rettv->v_type = VAR_STRING;
@@ -20064,9 +20082,15 @@ static void set_var(const char *name, const size_t name_len, typval_T *const tv,
// prevent changing the type.
if (ht == &vimvarht) {
if (v->di_tv.v_type == VAR_STRING) {
- xfree(v->di_tv.vval.v_string);
+ XFREE_CLEAR(v->di_tv.vval.v_string);
if (copy || tv->v_type != VAR_STRING) {
- v->di_tv.vval.v_string = (char_u *)xstrdup(tv_get_string(tv));
+ const char *const val = tv_get_string(tv);
+
+ // Careful: when assigning to v:errmsg and tv_get_string()
+ // causes an error message the variable will alrady be set.
+ if (v->di_tv.vval.v_string == NULL) {
+ v->di_tv.vval.v_string = (char_u *)xstrdup(val);
+ }
} else {
// Take over the string to avoid an extra alloc/free.
v->di_tv.vval.v_string = tv->vval.v_string;