neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

commit ac0fda2e46708f474a810e16407341c9f7b47dfe
parent aac85b8d6b803318d9cbf6e496aac1cd223b4550
Author: zeertzjq <zeertzjq@outlook.com>
Date:   Sun, 17 Sep 2023 10:59:36 +0800

vim-patch:8.2.2356: Vim9: ":put =expr" does not handle a list properly

Problem:    Vim9: ":put =expr" does not handle a list properly.
Solution:   Use the same logic as eval_to_string_eap(). (closes vim/vim#7684)

https://github.com/vim/vim/commit/883cf97f109d2ff281cf77f7b2e3bb44aced7cb3

Co-authored-by: Bram Moolenaar <Bram@vim.org>

Diffstat:
Msrc/nvim/eval.c | 47+++++++++++++++++++++++++++++------------------
1 file changed, 29 insertions(+), 18 deletions(-)

diff --git a/src/nvim/eval.c b/src/nvim/eval.c @@ -947,6 +947,34 @@ int skip_expr(char **pp, evalarg_T *const evalarg) return res; } +/// Convert "tv" to a string. +/// +/// @param convert when true convert a List into a sequence of lines and convert +/// a Float to a String. +/// +/// @return an allocated string. +static char *typval2string(typval_T *tv, bool convert) +{ + if (convert && tv->v_type == VAR_LIST) { + garray_T ga; + ga_init(&ga, (int)sizeof(char), 80); + if (tv->vval.v_list != NULL) { + tv_list_join(&ga, tv->vval.v_list, "\n"); + if (tv_list_len(tv->vval.v_list) > 0) { + ga_append(&ga, NL); + } + } + ga_append(&ga, NUL); + return (char *)ga.ga_data; + } + if (convert && tv->v_type == VAR_FLOAT) { + char numbuf[NUMBUFLEN]; + vim_snprintf(numbuf, NUMBUFLEN, "%g", tv->vval.v_float); + return xstrdup(numbuf); + } + return xstrdup(tv_get_string(tv)); +} + /// Top level evaluation function, returning a string. /// /// @param convert when true convert a List into a sequence of lines and convert @@ -957,28 +985,11 @@ char *eval_to_string(char *arg, bool convert) { typval_T tv; char *retval; - garray_T ga; if (eval0(arg, &tv, NULL, &EVALARG_EVALUATE) == FAIL) { retval = NULL; } else { - if (convert && tv.v_type == VAR_LIST) { - ga_init(&ga, (int)sizeof(char), 80); - if (tv.vval.v_list != NULL) { - tv_list_join(&ga, tv.vval.v_list, "\n"); - if (tv_list_len(tv.vval.v_list) > 0) { - ga_append(&ga, NL); - } - } - ga_append(&ga, NUL); - retval = (char *)ga.ga_data; - } else if (convert && tv.v_type == VAR_FLOAT) { - char numbuf[NUMBUFLEN]; - vim_snprintf(numbuf, NUMBUFLEN, "%g", tv.vval.v_float); - retval = xstrdup(numbuf); - } else { - retval = xstrdup(tv_get_string(&tv)); - } + retval = typval2string(&tv, convert); tv_clear(&tv); } clear_evalarg(&EVALARG_EVALUATE, NULL);