diff options
author | Jan Edmund Lazo <jan.lazo@mail.utoronto.ca> | 2019-08-24 20:48:35 -0400 |
---|---|---|
committer | Jan Edmund Lazo <jan.lazo@mail.utoronto.ca> | 2019-08-24 21:18:15 -0400 |
commit | 66c06dad62638106fadad389f585dc11f482c6b1 (patch) | |
tree | 13629346026378db371b1664ac5f006db23ce92f /src/nvim/eval.c | |
parent | 4fedef51b0bdb641432422b93dd5f3886f3e4283 (diff) | |
download | rneovim-66c06dad62638106fadad389f585dc11f482c6b1.tar.gz rneovim-66c06dad62638106fadad389f585dc11f482c6b1.tar.bz2 rneovim-66c06dad62638106fadad389f585dc11f482c6b1.zip |
vim-patch:8.1.1924: using empty string for current buffer is unexpected
Problem: Using empty string for current buffer is unexpected.
Solution: Make the argument optional for bufname() and bufnr().
https://github.com/vim/vim/commit/a8eee21e75324d199acb1663cb5009e03014a13a
Diffstat (limited to 'src/nvim/eval.c')
-rw-r--r-- | src/nvim/eval.c | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 0a884fdca2..06254953cb 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -7353,14 +7353,19 @@ static buf_T * get_buf_arg(typval_T *arg) */ static void f_bufname(typval_T *argvars, typval_T *rettv, FunPtr fptr) { + const buf_T *buf; rettv->v_type = VAR_STRING; rettv->vval.v_string = NULL; - if (!tv_check_str_or_nr(&argvars[0])) { - return; + if (argvars[0].v_type == VAR_UNKNOWN) { + buf = curbuf; + } else { + if (!tv_check_str_or_nr(&argvars[0])) { + return; + } + emsg_off++; + buf = tv_get_buf(&argvars[0], false); + emsg_off--; } - emsg_off++; - const buf_T *const buf = tv_get_buf(&argvars[0], false); - emsg_off--; if (buf != NULL && buf->b_fname != NULL) { rettv->vval.v_string = (char_u *)xstrdup((char *)buf->b_fname); } @@ -7371,15 +7376,21 @@ static void f_bufname(typval_T *argvars, typval_T *rettv, FunPtr fptr) */ static void f_bufnr(typval_T *argvars, typval_T *rettv, FunPtr fptr) { + const buf_T *buf; bool error = false; rettv->vval.v_number = -1; - if (!tv_check_str_or_nr(&argvars[0])) { - return; + + if (argvars[0].v_type == VAR_UNKNOWN) { + buf = curbuf; + } else { + if (!tv_check_str_or_nr(&argvars[0])) { + return; + } + emsg_off++; + buf = tv_get_buf(&argvars[0], false); + emsg_off--; } - emsg_off++; - const buf_T *buf = tv_get_buf(&argvars[0], false); - emsg_off--; // If the buffer isn't found and the second argument is not zero create a // new buffer. |