Mercurial > vim
diff src/eval.c @ 15219:dada0b389d4f v8.1.0619
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
commit https://github.com/vim/vim/commit/461a7fcfce3cd6414f990037e6468af3b5ccf119
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Dec 22 13:28:07 2018 +0100
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Problem: :echomsg and :echoerr do not handle List and Dict like :echo does.
(Daniel Hahler)
Solution: Be more tolerant about the expression result type.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 22 Dec 2018 13:30:08 +0100 |
parents | de63593896b3 |
children | 1d2b5c016f17 |
line wrap: on
line diff
--- a/src/eval.c +++ b/src/eval.c @@ -7163,6 +7163,30 @@ tv_get_string_buf_chk(typval_T *varp, ch } /* + * Turn a typeval into a string. Similar to tv_get_string_buf() but uses + * string() on Dict, List, etc. + */ + char_u * +tv_stringify(typval_T *varp, char_u *buf) +{ + if (varp->v_type == VAR_LIST + || varp->v_type == VAR_DICT + || varp->v_type == VAR_FUNC + || varp->v_type == VAR_PARTIAL + || varp->v_type == VAR_FLOAT) + { + typval_T tmp; + + f_string(varp, &tmp); + tv_get_string_buf(&tmp, buf); + clear_tv(varp); + *varp = tmp; + return tmp.vval.v_string; + } + return tv_get_string_buf(varp, buf); +} + +/* * Find variable "name" in the list of variables. * Return a pointer to it if found, NULL if not found. * Careful: "a:0" variables don't have a name. @@ -8142,7 +8166,12 @@ ex_execute(exarg_T *eap) if (!eap->skip) { - p = tv_get_string(&rettv); + char_u buf[NUMBUFLEN]; + + if (eap->cmdidx == CMD_execute) + p = tv_get_string_buf(&rettv, buf); + else + p = tv_stringify(&rettv, buf); len = (int)STRLEN(p); if (ga_grow(&ga, len + 2) == FAIL) {