mirror of
https://github.com/vim/vim.git
synced 2025-09-25 03:54:15 -04:00
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().
This commit is contained in:
@@ -2335,8 +2335,8 @@ bufexists({expr}) Number |TRUE| if buffer {expr} exists
|
||||
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}
|
||||
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}
|
||||
@@ -3217,9 +3217,10 @@ bufloaded({expr}) *bufloaded()*
|
||||
Can also be used as a |method|: >
|
||||
let loaded = 'somename'->bufloaded()
|
||||
|
||||
bufname({expr}) *bufname()*
|
||||
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
|
||||
@@ -3251,7 +3252,7 @@ bufname({expr}) *bufname()*
|
||||
Obsolete name: buffer_name().
|
||||
|
||||
*bufnr()*
|
||||
bufnr({expr} [, {create}])
|
||||
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.
|
||||
@@ -3259,7 +3260,7 @@ bufnr({expr} [, {create}])
|
||||
{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("$")
|
||||
: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
|
||||
@@ -7201,7 +7202,7 @@ prompt_setcallback({buf}, {expr}) *prompt_setcallback()*
|
||||
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'))
|
||||
call prompt_setcallback(bufnr(), function('s:TextEntered'))
|
||||
func s:TextEntered(text)
|
||||
if a:text == 'exit' || a:text == 'quit'
|
||||
stopinsert
|
||||
@@ -7227,7 +7228,7 @@ prompt_setprompt({buf}, {text}) *prompt_setprompt()*
|
||||
{text} to end in a space.
|
||||
The result is only visible if {buf} has 'buftype' set to
|
||||
"prompt". Example: >
|
||||
call prompt_setprompt(bufnr(''), 'command: ')
|
||||
call prompt_setprompt(bufnr(), 'command: ')
|
||||
<
|
||||
prop_ functions are documented here: |text-prop-functions|.
|
||||
|
||||
|
@@ -457,13 +457,13 @@ static funcentry_T global_functions[] =
|
||||
{"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
|
||||
{"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", 1, 1, FEARG_1, f_bufname},
|
||||
{"bufnr", 1, 2, FEARG_1, f_bufnr},
|
||||
{"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,15 +1820,20 @@ f_bufname(typval_T *argvars, typval_T *rettv)
|
||||
{
|
||||
buf_T *buf;
|
||||
|
||||
(void)tv_get_number(&argvars[0]); /* issue errmsg if type error */
|
||||
++emsg_off;
|
||||
buf = tv_get_buf(&argvars[0], FALSE);
|
||||
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;
|
||||
--emsg_off;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1841,13 +1846,18 @@ f_bufnr(typval_T *argvars, typval_T *rettv)
|
||||
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 (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 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
|
||||
|
@@ -398,10 +398,10 @@ func Test_argedit()
|
||||
" make sure to use a new buffer number for x when it is loaded
|
||||
bw! x
|
||||
new
|
||||
let a = bufnr('')
|
||||
let a = bufnr()
|
||||
argedit x
|
||||
call assert_equal(a, bufnr(''))
|
||||
call assert_equal('x', bufname(''))
|
||||
call assert_equal(a, bufnr())
|
||||
call assert_equal('x', bufname())
|
||||
%argd
|
||||
bw! x
|
||||
endfunc
|
||||
|
@@ -761,6 +761,8 @@ static char *(features[]) =
|
||||
|
||||
static int included_patches[] =
|
||||
{ /* Add new patch number below this line */
|
||||
/**/
|
||||
1924,
|
||||
/**/
|
||||
1923,
|
||||
/**/
|
||||
|
Reference in New Issue
Block a user