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
|
buflisted({expr}) Number |TRUE| if buffer {expr} is listed
|
||||||
bufload({expr}) Number load buffer {expr} if not loaded yet
|
bufload({expr}) Number load buffer {expr} if not loaded yet
|
||||||
bufloaded({expr}) Number |TRUE| if buffer {expr} is loaded
|
bufloaded({expr}) Number |TRUE| if buffer {expr} is loaded
|
||||||
bufname({expr}) String Name of the buffer {expr}
|
bufname([{expr}]) String Name of the buffer {expr}
|
||||||
bufnr({expr} [, {create}]) Number Number of the buffer {expr}
|
bufnr([{expr} [, {create}]]) Number Number of the buffer {expr}
|
||||||
bufwinid({expr}) Number window ID of buffer {expr}
|
bufwinid({expr}) Number window ID of buffer {expr}
|
||||||
bufwinnr({expr}) Number window number of buffer {expr}
|
bufwinnr({expr}) Number window number of buffer {expr}
|
||||||
byte2line({byte}) Number line number at byte count {byte}
|
byte2line({byte}) Number line number at byte count {byte}
|
||||||
@@ -3217,9 +3217,10 @@ bufloaded({expr}) *bufloaded()*
|
|||||||
Can also be used as a |method|: >
|
Can also be used as a |method|: >
|
||||||
let loaded = 'somename'->bufloaded()
|
let loaded = 'somename'->bufloaded()
|
||||||
|
|
||||||
bufname({expr}) *bufname()*
|
bufname([{expr}]) *bufname()*
|
||||||
The result is the name of a buffer, as it is displayed by the
|
The result is the name of a buffer, as it is displayed by the
|
||||||
":ls" command.
|
":ls" command.
|
||||||
|
If {expr} is omitted the current buffer is used.
|
||||||
If {expr} is a Number, that buffer number's name is given.
|
If {expr} is a Number, that buffer number's name is given.
|
||||||
Number zero is the alternate buffer for the current window.
|
Number zero is the alternate buffer for the current window.
|
||||||
If {expr} is a String, it is used as a |file-pattern| to match
|
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().
|
Obsolete name: buffer_name().
|
||||||
|
|
||||||
*bufnr()*
|
*bufnr()*
|
||||||
bufnr({expr} [, {create}])
|
bufnr([{expr} [, {create}]])
|
||||||
The result is the number of a buffer, as it is displayed by
|
The result is the number of a buffer, as it is displayed by
|
||||||
the ":ls" command. For the use of {expr}, see |bufname()|
|
the ":ls" command. For the use of {expr}, see |bufname()|
|
||||||
above.
|
above.
|
||||||
@@ -7201,7 +7202,7 @@ prompt_setcallback({buf}, {expr}) *prompt_setcallback()*
|
|||||||
that was entered at the prompt. This can be an empty string
|
that was entered at the prompt. This can be an empty string
|
||||||
if the user only typed Enter.
|
if the user only typed Enter.
|
||||||
Example: >
|
Example: >
|
||||||
call prompt_setcallback(bufnr(''), function('s:TextEntered'))
|
call prompt_setcallback(bufnr(), function('s:TextEntered'))
|
||||||
func s:TextEntered(text)
|
func s:TextEntered(text)
|
||||||
if a:text == 'exit' || a:text == 'quit'
|
if a:text == 'exit' || a:text == 'quit'
|
||||||
stopinsert
|
stopinsert
|
||||||
@@ -7227,7 +7228,7 @@ prompt_setprompt({buf}, {text}) *prompt_setprompt()*
|
|||||||
{text} to end in a space.
|
{text} to end in a space.
|
||||||
The result is only visible if {buf} has 'buftype' set to
|
The result is only visible if {buf} has 'buftype' set to
|
||||||
"prompt". Example: >
|
"prompt". Example: >
|
||||||
call prompt_setprompt(bufnr(''), 'command: ')
|
call prompt_setprompt(bufnr(), 'command: ')
|
||||||
<
|
<
|
||||||
prop_ functions are documented here: |text-prop-functions|.
|
prop_ functions are documented here: |text-prop-functions|.
|
||||||
|
|
||||||
|
@@ -457,13 +457,13 @@ static funcentry_T global_functions[] =
|
|||||||
{"bufadd", 1, 1, FEARG_1, f_bufadd},
|
{"bufadd", 1, 1, FEARG_1, f_bufadd},
|
||||||
{"bufexists", 1, 1, FEARG_1, f_bufexists},
|
{"bufexists", 1, 1, FEARG_1, f_bufexists},
|
||||||
{"buffer_exists", 1, 1, FEARG_1, f_bufexists}, // obsolete
|
{"buffer_exists", 1, 1, FEARG_1, f_bufexists}, // obsolete
|
||||||
{"buffer_name", 1, 1, 0, f_bufname}, // obsolete
|
{"buffer_name", 0, 1, FEARG_1, f_bufname}, // obsolete
|
||||||
{"buffer_number", 1, 1, 0, f_bufnr}, // obsolete
|
{"buffer_number", 0, 1, FEARG_1, f_bufnr}, // obsolete
|
||||||
{"buflisted", 1, 1, FEARG_1, f_buflisted},
|
{"buflisted", 1, 1, FEARG_1, f_buflisted},
|
||||||
{"bufload", 1, 1, FEARG_1, f_bufload},
|
{"bufload", 1, 1, FEARG_1, f_bufload},
|
||||||
{"bufloaded", 1, 1, FEARG_1, f_bufloaded},
|
{"bufloaded", 1, 1, FEARG_1, f_bufloaded},
|
||||||
{"bufname", 1, 1, FEARG_1, f_bufname},
|
{"bufname", 0, 1, FEARG_1, f_bufname},
|
||||||
{"bufnr", 1, 2, FEARG_1, f_bufnr},
|
{"bufnr", 0, 2, FEARG_1, f_bufnr},
|
||||||
{"bufwinid", 1, 1, FEARG_1, f_bufwinid},
|
{"bufwinid", 1, 1, FEARG_1, f_bufwinid},
|
||||||
{"bufwinnr", 1, 1, FEARG_1, f_bufwinnr},
|
{"bufwinnr", 1, 1, FEARG_1, f_bufwinnr},
|
||||||
{"byte2line", 1, 1, FEARG_1, f_byte2line},
|
{"byte2line", 1, 1, FEARG_1, f_byte2line},
|
||||||
@@ -1820,15 +1820,20 @@ f_bufname(typval_T *argvars, typval_T *rettv)
|
|||||||
{
|
{
|
||||||
buf_T *buf;
|
buf_T *buf;
|
||||||
|
|
||||||
(void)tv_get_number(&argvars[0]); /* issue errmsg if type error */
|
if (argvars[0].v_type == VAR_UNKNOWN)
|
||||||
|
buf = curbuf;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
(void)tv_get_number(&argvars[0]); // issue errmsg if type error
|
||||||
++emsg_off;
|
++emsg_off;
|
||||||
buf = tv_get_buf(&argvars[0], FALSE);
|
buf = tv_get_buf(&argvars[0], FALSE);
|
||||||
|
--emsg_off;
|
||||||
|
}
|
||||||
rettv->v_type = VAR_STRING;
|
rettv->v_type = VAR_STRING;
|
||||||
if (buf != NULL && buf->b_fname != NULL)
|
if (buf != NULL && buf->b_fname != NULL)
|
||||||
rettv->vval.v_string = vim_strsave(buf->b_fname);
|
rettv->vval.v_string = vim_strsave(buf->b_fname);
|
||||||
else
|
else
|
||||||
rettv->vval.v_string = NULL;
|
rettv->vval.v_string = NULL;
|
||||||
--emsg_off;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -1841,13 +1846,18 @@ f_bufnr(typval_T *argvars, typval_T *rettv)
|
|||||||
int error = FALSE;
|
int error = FALSE;
|
||||||
char_u *name;
|
char_u *name;
|
||||||
|
|
||||||
(void)tv_get_number(&argvars[0]); /* issue errmsg if type error */
|
if (argvars[0].v_type == VAR_UNKNOWN)
|
||||||
|
buf = curbuf;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
(void)tv_get_number(&argvars[0]); // issue errmsg if type error
|
||||||
++emsg_off;
|
++emsg_off;
|
||||||
buf = tv_get_buf(&argvars[0], FALSE);
|
buf = tv_get_buf(&argvars[0], FALSE);
|
||||||
--emsg_off;
|
--emsg_off;
|
||||||
|
}
|
||||||
|
|
||||||
/* If the buffer isn't found and the second argument is not zero create a
|
// If the buffer isn't found and the second argument is not zero create a
|
||||||
* new buffer. */
|
// new buffer.
|
||||||
if (buf == NULL
|
if (buf == NULL
|
||||||
&& argvars[1].v_type != VAR_UNKNOWN
|
&& argvars[1].v_type != VAR_UNKNOWN
|
||||||
&& tv_get_number_chk(&argvars[1], &error) != 0
|
&& 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
|
" make sure to use a new buffer number for x when it is loaded
|
||||||
bw! x
|
bw! x
|
||||||
new
|
new
|
||||||
let a = bufnr('')
|
let a = bufnr()
|
||||||
argedit x
|
argedit x
|
||||||
call assert_equal(a, bufnr(''))
|
call assert_equal(a, bufnr())
|
||||||
call assert_equal('x', bufname(''))
|
call assert_equal('x', bufname())
|
||||||
%argd
|
%argd
|
||||||
bw! x
|
bw! x
|
||||||
endfunc
|
endfunc
|
||||||
|
@@ -761,6 +761,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
1924,
|
||||||
/**/
|
/**/
|
||||||
1923,
|
1923,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user