To: vim_dev@googlegroups.com Subject: Patch 8.1.1924 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.1.1924 Problem: Using empty string for current buffer is unexpected. Solution: Make the argument optional for bufname() and bufnr(). Files: src/evalfunc.c, src/testdir/test_arglist.vim, runtime/doc/eval.txt *** ../vim-8.1.1923/src/evalfunc.c 2019-08-24 20:49:58.825320302 +0200 --- src/evalfunc.c 2019-08-24 22:11:16.163188153 +0200 *************** *** 457,469 **** {"bufadd", 1, 1, FEARG_1, f_bufadd}, {"bufexists", 1, 1, FEARG_1, f_bufexists}, {"buffer_exists", 1, 1, FEARG_1, f_bufexists}, // obsolete ! {"buffer_name", 1, 1, 0, f_bufname}, // obsolete ! {"buffer_number", 1, 1, 0, f_bufnr}, // obsolete {"buflisted", 1, 1, FEARG_1, f_buflisted}, {"bufload", 1, 1, FEARG_1, f_bufload}, {"bufloaded", 1, 1, FEARG_1, f_bufloaded}, ! {"bufname", 1, 1, FEARG_1, f_bufname}, ! {"bufnr", 1, 2, FEARG_1, f_bufnr}, {"bufwinid", 1, 1, FEARG_1, f_bufwinid}, {"bufwinnr", 1, 1, FEARG_1, f_bufwinnr}, {"byte2line", 1, 1, FEARG_1, f_byte2line}, --- 457,469 ---- {"bufadd", 1, 1, FEARG_1, f_bufadd}, {"bufexists", 1, 1, FEARG_1, f_bufexists}, {"buffer_exists", 1, 1, FEARG_1, f_bufexists}, // obsolete ! {"buffer_name", 0, 1, FEARG_1, f_bufname}, // obsolete ! {"buffer_number", 0, 1, FEARG_1, f_bufnr}, // obsolete {"buflisted", 1, 1, FEARG_1, f_buflisted}, {"bufload", 1, 1, FEARG_1, f_bufload}, {"bufloaded", 1, 1, FEARG_1, f_bufloaded}, ! {"bufname", 0, 1, FEARG_1, f_bufname}, ! {"bufnr", 0, 2, FEARG_1, f_bufnr}, {"bufwinid", 1, 1, FEARG_1, f_bufwinid}, {"bufwinnr", 1, 1, FEARG_1, f_bufwinnr}, {"byte2line", 1, 1, FEARG_1, f_byte2line}, *************** *** 1820,1834 **** { buf_T *buf; ! (void)tv_get_number(&argvars[0]); /* issue errmsg if type error */ ! ++emsg_off; ! buf = tv_get_buf(&argvars[0], FALSE); rettv->v_type = VAR_STRING; if (buf != NULL && buf->b_fname != NULL) rettv->vval.v_string = vim_strsave(buf->b_fname); else rettv->vval.v_string = NULL; - --emsg_off; } /* --- 1820,1839 ---- { buf_T *buf; ! if (argvars[0].v_type == VAR_UNKNOWN) ! buf = curbuf; ! else ! { ! (void)tv_get_number(&argvars[0]); // issue errmsg if type error ! ++emsg_off; ! buf = tv_get_buf(&argvars[0], FALSE); ! --emsg_off; ! } rettv->v_type = VAR_STRING; if (buf != NULL && buf->b_fname != NULL) rettv->vval.v_string = vim_strsave(buf->b_fname); else rettv->vval.v_string = NULL; } /* *************** *** 1841,1853 **** int error = FALSE; char_u *name; ! (void)tv_get_number(&argvars[0]); /* issue errmsg if type error */ ! ++emsg_off; ! 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. */ if (buf == NULL && argvars[1].v_type != VAR_UNKNOWN && tv_get_number_chk(&argvars[1], &error) != 0 --- 1846,1863 ---- int error = FALSE; char_u *name; ! if (argvars[0].v_type == VAR_UNKNOWN) ! buf = curbuf; ! else ! { ! (void)tv_get_number(&argvars[0]); // issue errmsg if type error ! ++emsg_off; ! 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. if (buf == NULL && argvars[1].v_type != VAR_UNKNOWN && tv_get_number_chk(&argvars[1], &error) != 0 *** ../vim-8.1.1923/src/testdir/test_arglist.vim 2019-08-18 23:01:33.725885954 +0200 --- src/testdir/test_arglist.vim 2019-08-24 22:00:35.866048714 +0200 *************** *** 398,407 **** " make sure to use a new buffer number for x when it is loaded bw! x new ! let a = bufnr('') argedit x ! call assert_equal(a, bufnr('')) ! call assert_equal('x', bufname('')) %argd bw! x endfunc --- 398,407 ---- " make sure to use a new buffer number for x when it is loaded bw! x new ! let a = bufnr() argedit x ! call assert_equal(a, bufnr()) ! call assert_equal('x', bufname()) %argd bw! x endfunc *** ../vim-8.1.1923/runtime/doc/eval.txt 2019-08-24 20:49:58.825320302 +0200 --- runtime/doc/eval.txt 2019-08-24 22:13:24.134613987 +0200 *************** *** 2330,2337 **** buflisted({expr}) Number |TRUE| if buffer {expr} is listed bufload({expr}) Number load buffer {expr} if not loaded yet bufloaded({expr}) Number |TRUE| if buffer {expr} is loaded ! bufname({expr}) String Name of the buffer {expr} ! bufnr({expr} [, {create}]) Number Number of the buffer {expr} bufwinid({expr}) Number window ID of buffer {expr} bufwinnr({expr}) Number window number of buffer {expr} byte2line({byte}) Number line number at byte count {byte} --- 2335,2342 ---- buflisted({expr}) Number |TRUE| if buffer {expr} is listed bufload({expr}) Number load buffer {expr} if not loaded yet bufloaded({expr}) Number |TRUE| if buffer {expr} is loaded ! bufname([{expr}]) String Name of the buffer {expr} ! bufnr([{expr} [, {create}]]) Number Number of the buffer {expr} bufwinid({expr}) Number window ID of buffer {expr} bufwinnr({expr}) Number window number of buffer {expr} byte2line({byte}) Number line number at byte count {byte} *************** *** 3212,3220 **** Can also be used as a |method|: > let loaded = 'somename'->bufloaded() ! bufname({expr}) *bufname()* The result is the name of a buffer, as it is displayed by the ":ls" command. If {expr} is a Number, that buffer number's name is given. Number zero is the alternate buffer for the current window. If {expr} is a String, it is used as a |file-pattern| to match --- 3217,3226 ---- Can also be used as a |method|: > let loaded = 'somename'->bufloaded() ! bufname([{expr}]) *bufname()* The result is the name of a buffer, as it is displayed by the ":ls" command. + If {expr} is omitted the current buffer is used. If {expr} is a Number, that buffer number's name is given. Number zero is the alternate buffer for the current window. If {expr} is a String, it is used as a |file-pattern| to match *************** *** 3246,3252 **** Obsolete name: buffer_name(). *bufnr()* ! bufnr({expr} [, {create}]) The result is the number of a buffer, as it is displayed by the ":ls" command. For the use of {expr}, see |bufname()| above. --- 3252,3258 ---- Obsolete name: buffer_name(). *bufnr()* ! bufnr([{expr} [, {create}]]) The result is the number of a buffer, as it is displayed by the ":ls" command. For the use of {expr}, see |bufname()| above. *************** *** 3254,3260 **** {create} argument is present and not zero, a new, unlisted, buffer is created and its number is returned. bufnr("$") is the last buffer: > ! :let last_buffer = bufnr("$") < The result is a Number, which is the highest buffer number of existing buffers. Note that not all buffers with a smaller number necessarily exist, because ":bwipeout" may have removed --- 3260,3266 ---- {create} argument is present and not zero, a new, unlisted, buffer is created and its number is returned. bufnr("$") is the last buffer: > ! :let last_buffer = bufnr("$") < The result is a Number, which is the highest buffer number of existing buffers. Note that not all buffers with a smaller number necessarily exist, because ":bwipeout" may have removed *************** *** 7192,7198 **** that was entered at the prompt. This can be an empty string if the user only typed Enter. Example: > ! call prompt_setcallback(bufnr(''), function('s:TextEntered')) func s:TextEntered(text) if a:text == 'exit' || a:text == 'quit' stopinsert --- 7202,7208 ---- that was entered at the prompt. This can be an empty string if the user only typed Enter. Example: > ! call prompt_setcallback(bufnr(), function('s:TextEntered')) func s:TextEntered(text) if a:text == 'exit' || a:text == 'quit' stopinsert *************** *** 7218,7224 **** {text} to end in a space. The result is only visible if {buf} has 'buftype' set to "prompt". Example: > ! call prompt_setprompt(bufnr(''), 'command: ') < prop_ functions are documented here: |text-prop-functions|. --- 7228,7234 ---- {text} to end in a space. The result is only visible if {buf} has 'buftype' set to "prompt". Example: > ! call prompt_setprompt(bufnr(), 'command: ') < prop_ functions are documented here: |text-prop-functions|. *** ../vim-8.1.1923/src/version.c 2019-08-24 21:53:12.000023828 +0200 --- src/version.c 2019-08-24 22:13:47.974506989 +0200 *************** *** 763,764 **** --- 763,766 ---- { /* Add new patch number below this line */ + /**/ + 1924, /**/ -- hundred-and-one symptoms of being an internet addict: 114. You are counting items, you go "0,1,2,3,4,5,6,7,8,9,A,B,C,D...". /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///