Merge #5257 from jbradaric/vim-7.4.1893

vim-patch:7.4.{1893,1895}
This commit is contained in:
Justin M. Keyes 2016-10-13 01:19:09 +02:00 committed by GitHub
commit 5a61ff188c
8 changed files with 94 additions and 26 deletions

View File

@ -1813,6 +1813,7 @@ buflisted({expr}) Number TRUE if buffer {expr} is listed
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}
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}
byteidx({expr}, {nr}) Number byte index of {nr}'th char in {expr} byteidx({expr}, {nr}) Number byte index of {nr}'th char in {expr}
@ -2244,6 +2245,7 @@ arglistid([{winnr} [, {tabnr}]])
With {winnr} only use this window in the current tab page. With {winnr} only use this window in the current tab page.
With {winnr} and {tabnr} use the window in the specified tab With {winnr} and {tabnr} use the window in the specified tab
page. page.
{winnr} can be the window number or the window ID.
*argv()* *argv()*
argv([{nr}]) The result is the {nr}th file in the argument list of the argv([{nr}]) The result is the {nr}th file in the argument list of the
@ -2469,6 +2471,16 @@ bufnr({expr} [, {create}])
number necessarily exist, because ":bwipeout" may have removed number necessarily exist, because ":bwipeout" may have removed
them. Use bufexists() to test for the existence of a buffer. them. Use bufexists() to test for the existence of a buffer.
bufwinid({expr}) *bufwinid()*
The result is a Number, which is the window ID of the first
window associated with buffer {expr}. For the use of {expr},
see |bufname()| above. If buffer {expr} doesn't exist or
there is no such window, -1 is returned. Example: >
echo "A window containing buffer 1 is " . (bufwinid(1))
<
Only deals with the current tab page.
bufwinnr({expr}) *bufwinnr()* bufwinnr({expr}) *bufwinnr()*
The result is a Number, which is the number of the first The result is a Number, which is the number of the first
window associated with buffer {expr}. For the use of {expr}, window associated with buffer {expr}. For the use of {expr},
@ -3721,6 +3733,7 @@ getcwd([{winnr}[, {tabnr}]]) *getcwd()*
getcwd(0) getcwd(0)
getcwd(0, 0) getcwd(0, 0)
< If {winnr} is -1 it is ignored, only the tab is resolved. < If {winnr} is -1 it is ignored, only the tab is resolved.
{winnr} can be the window number or the window ID.
getfsize({fname}) *getfsize()* getfsize({fname}) *getfsize()*
@ -3815,7 +3828,9 @@ getline({lnum} [, {end}])
getloclist({nr}) *getloclist()* getloclist({nr}) *getloclist()*
Returns a list with all the entries in the location list for Returns a list with all the entries in the location list for
window {nr}. When {nr} is zero the current window is used. window {nr}. {nr} can be the window number or the window ID.
When {nr} is zero the current window is used.
For a location list window, the displayed location list is For a location list window, the displayed location list is
returned. For an invalid window number {nr}, an empty list is returned. For an invalid window number {nr}, an empty list is
returned. Otherwise, same as |getqflist()|. returned. Otherwise, same as |getqflist()|.
@ -3943,6 +3958,7 @@ gettabwinvar({tabnr}, {winnr}, {varname} [, {def}]) *gettabwinvar()*
Note that {varname} must be the name without "w:". Note that {varname} must be the name without "w:".
Tabs are numbered starting with one. For the current tabpage Tabs are numbered starting with one. For the current tabpage
use |getwinvar()|. use |getwinvar()|.
{winnr} can be the window number or the window ID.
When {winnr} is zero the current window is used. When {winnr} is zero the current window is used.
This also works for a global option, buffer-local option and This also works for a global option, buffer-local option and
window-local option, but it doesn't work for a global variable window-local option, but it doesn't work for a global variable
@ -4070,7 +4086,8 @@ haslocaldir([{winnr}[, {tabnr}]]) *haslocaldir()*
haslocaldir() haslocaldir()
haslocaldir(0) haslocaldir(0)
haslocaldir(0, 0) haslocaldir(0, 0)
< If {winnr} is -1 it is ignored, only the tab is resolved. < {winnr} can be the window number or the window ID.
If {winnr} is -1 it is ignored, only the tab is resolved.
hasmapto({what} [, {mode} [, {abbr}]]) *hasmapto()* hasmapto({what} [, {mode} [, {abbr}]]) *hasmapto()*
The result is a Number, which is 1 if there is a mapping that The result is a Number, which is 1 if there is a mapping that
@ -6059,11 +6076,13 @@ setline({lnum}, {text}) *setline()*
setloclist({nr}, {list} [, {action}[, {title}]]) *setloclist()* setloclist({nr}, {list} [, {action}[, {title}]]) *setloclist()*
Create or replace or add to the location list for window {nr}. Create or replace or add to the location list for window {nr}.
When {nr} is zero the current window is used. For a location {nr} can be the window number or the window ID.
list window, the displayed location list is modified. For an When {nr} is zero the current window is used.
invalid window number {nr}, -1 is returned. If {title} is
given, it will be used to set |w:quickfix_title| after opening For a location list window, the displayed location list is
the location window. modified. For an invalid window number {nr}, -1 is returned. If
{title} is given, it will be used to set |w:quickfix_title|
after opening the location window.
Otherwise, same as |setqflist()|. Otherwise, same as |setqflist()|.
Also see |location-list|. Also see |location-list|.
@ -6227,6 +6246,7 @@ settabwinvar({tabnr}, {winnr}, {varname}, {val}) *settabwinvar()*
{val}. {val}.
Tabs are numbered starting with one. For the current tabpage Tabs are numbered starting with one. For the current tabpage
use |setwinvar()|. use |setwinvar()|.
{winnr} can be the window number or the window ID.
When {winnr} is zero the current window is used. When {winnr} is zero the current window is used.
This also works for a global or local buffer option, but it This also works for a global or local buffer option, but it
doesn't work for a global or local buffer variable. doesn't work for a global or local buffer variable.
@ -7255,9 +7275,11 @@ win_id2win({expr}) *win_id2win()*
*winbufnr()* *winbufnr()*
winbufnr({nr}) The result is a Number, which is the number of the buffer winbufnr({nr}) The result is a Number, which is the number of the buffer
associated with window {nr}. When {nr} is zero, the number of associated with window {nr}. {nr} can be the window number or
the buffer in the current window is returned. When window the window ID.
{nr} doesn't exist, -1 is returned. When {nr} is zero, the number of the buffer in the current
window is returned.
When window {nr} doesn't exist, -1 is returned.
Example: > Example: >
:echo "The file in the current window is " . bufname(winbufnr(0)) :echo "The file in the current window is " . bufname(winbufnr(0))
< <
@ -7268,6 +7290,7 @@ wincol() The result is a Number, which is the virtual column of the
winheight({nr}) *winheight()* winheight({nr}) *winheight()*
The result is a Number, which is the height of window {nr}. The result is a Number, which is the height of window {nr}.
{nr} can be the window number or the window ID.
When {nr} is zero, the height of the current window is When {nr} is zero, the height of the current window is
returned. When window {nr} doesn't exist, -1 is returned. returned. When window {nr} doesn't exist, -1 is returned.
An existing window always has a height of zero or more. An existing window always has a height of zero or more.
@ -7347,6 +7370,7 @@ winsaveview() Returns a |Dictionary| that contains information to restore
winwidth({nr}) *winwidth()* winwidth({nr}) *winwidth()*
The result is a Number, which is the width of window {nr}. The result is a Number, which is the width of window {nr}.
{nr} can be the window number or the window ID.
When {nr} is zero, the width of the current window is When {nr} is zero, the width of the current window is
returned. When window {nr} doesn't exist, -1 is returned. returned. When window {nr} doesn't exist, -1 is returned.
An existing window always has a width of zero or more. An existing window always has a width of zero or more.

View File

@ -6709,7 +6709,6 @@ static int get_env_tv(char_u **arg, typval_T *rettv, int evaluate)
# include "funcs.generated.h" # include "funcs.generated.h"
#endif #endif
/* /*
* Function given to ExpandGeneric() to obtain the list of internal * Function given to ExpandGeneric() to obtain the list of internal
* or user defined function names. * or user defined function names.
@ -7712,26 +7711,47 @@ static void f_bufnr(typval_T *argvars, typval_T *rettv, FunPtr fptr)
rettv->vval.v_number = -1; rettv->vval.v_number = -1;
} }
/* static void buf_win_common(typval_T *argvars, typval_T *rettv, bool get_nr)
* "bufwinnr(nr)" function
*/
static void f_bufwinnr(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{ {
(void)get_tv_number(&argvars[0]); /* issue errmsg if type error */ int error = false;
++emsg_off; (void)get_tv_number_chk(&argvars[0], &error); // issue errmsg if type error
if (error) { // the argument has an invalid type
rettv->vval.v_number = -1;
return;
}
emsg_off++;
buf_T *buf = get_buf_tv(&argvars[0], true);
if (buf == NULL) { // no need to search if buffer was not found
rettv->vval.v_number = -1;
goto end;
}
buf_T *buf = get_buf_tv(&argvars[0], TRUE);
int winnr = 0; int winnr = 0;
int winid;
bool found_buf = false; bool found_buf = false;
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) { FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
++winnr; winnr++;
if (wp->w_buffer == buf) { if (wp->w_buffer == buf) {
found_buf = true; found_buf = true;
winid = wp->handle;
break; break;
} }
} }
rettv->vval.v_number = (found_buf ? winnr : -1); rettv->vval.v_number = (found_buf ? (get_nr ? winnr : winid) : -1);
--emsg_off; end:
emsg_off--;
}
/// "bufwinid(nr)" function
static void f_bufwinid(typval_T *argvars, typval_T *rettv, FunPtr fptr) {
buf_win_common(argvars, rettv, false);
}
/// "bufwinnr(nr)" function
static void f_bufwinnr(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
buf_win_common(argvars, rettv, true);
} }
/* /*
@ -10279,7 +10299,11 @@ find_win_by_nr (
} }
FOR_ALL_WINDOWS_IN_TAB(wp, tp) { FOR_ALL_WINDOWS_IN_TAB(wp, tp) {
if (--nr <= 0) { if (nr >= LOWEST_WIN_ID) {
if (wp->handle == nr) {
return wp;
}
} else if (--nr <= 0) {
return wp; return wp;
} }
} }

View File

@ -45,6 +45,7 @@ return {
bufloaded={args=1}, bufloaded={args=1},
bufname={args=1}, bufname={args=1},
bufnr={args={1, 2}}, bufnr={args={1, 2}},
bufwinid={args=1},
bufwinnr={args=1}, bufwinnr={args=1},
byte2line={args=1}, byte2line={args=1},
byteidx={args=2}, byteidx={args=2},

View File

@ -3,17 +3,22 @@
func Test_win_getid() func Test_win_getid()
edit one edit one
let id1 = win_getid() let id1 = win_getid()
let w:one = 'one'
split two split two
let id2 = win_getid() let id2 = win_getid()
let bufnr2 = bufnr('%') let bufnr2 = bufnr('%')
let w:two = 'two'
split three split three
let id3 = win_getid() let id3 = win_getid()
let w:three = 'three'
tabnew tabnew
edit four edit four
let id4 = win_getid() let id4 = win_getid()
let w:four = 'four'
split five split five
let id5 = win_getid() let id5 = win_getid()
let bufnr5 = bufnr('%') let bufnr5 = bufnr('%')
let w:five = 'five'
tabnext tabnext
wincmd w wincmd w
@ -28,6 +33,9 @@ func Test_win_getid()
call assert_equal("three", expand("%")) call assert_equal("three", expand("%"))
call assert_equal(id3, win_getid()) call assert_equal(id3, win_getid())
let nr3 = winnr() let nr3 = winnr()
call assert_equal('one', getwinvar(id1, 'one'))
call assert_equal('two', getwinvar(id2, 'two'))
call assert_equal('three', getwinvar(id3, 'three'))
tabnext tabnext
call assert_equal("five", expand("%")) call assert_equal("five", expand("%"))
call assert_equal(id5, win_getid()) call assert_equal(id5, win_getid())
@ -36,7 +44,14 @@ func Test_win_getid()
call assert_equal("four", expand("%")) call assert_equal("four", expand("%"))
call assert_equal(id4, win_getid()) call assert_equal(id4, win_getid())
let nr4 = winnr() let nr4 = winnr()
call assert_equal('four', getwinvar(id4, 'four'))
call assert_equal('five', getwinvar(id5, 'five'))
call settabwinvar(1, id2, 'two', '2')
call setwinvar(id4, 'four', '4')
tabnext tabnext
call assert_equal('4', gettabwinvar(2, id4, 'four'))
call assert_equal('five', gettabwinvar(2, id5, 'five'))
call assert_equal('2', getwinvar(id2, 'two'))
exe nr1 . "wincmd w" exe nr1 . "wincmd w"
call assert_equal(id1, win_getid()) call assert_equal(id1, win_getid())

View File

@ -546,9 +546,9 @@ static int included_patches[] = {
1898, 1898,
// 1897, // 1897,
1896, 1896,
// 1895, 1895,
// 1894 NA // 1894 NA
// 1893, 1893,
// 1892 NA // 1892 NA
// 1891 NA // 1891 NA
// 1890 NA // 1890 NA

View File

@ -316,4 +316,7 @@ enum {
#define DIP_OPT 0x10 // also use "opt" directory in 'packpath' #define DIP_OPT 0x10 // also use "opt" directory in 'packpath'
#define DIP_NORTP 0x20 // do not use 'runtimepath' #define DIP_NORTP 0x20 // do not use 'runtimepath'
// Lowest number used for window ID. Cannot have this many windows per tab.
#define LOWEST_WIN_ID 1000
#endif /* NVIM_VIM_H */ #endif /* NVIM_VIM_H */

View File

@ -3694,7 +3694,7 @@ win_T *buf_jump_open_tab(buf_T *buf)
*/ */
static win_T *win_alloc(win_T *after, int hidden) static win_T *win_alloc(win_T *after, int hidden)
{ {
static int last_win_id = 0; static int last_win_id = LOWEST_WIN_ID - 1;
// allocate window structure and linesizes arrays // allocate window structure and linesizes arrays
win_T *new_wp = xcalloc(1, sizeof(win_T)); win_T *new_wp = xcalloc(1, sizeof(win_T));

View File

@ -164,7 +164,8 @@ describe('server -> client', function()
it('can communicate buffers, tabpages, and windows', function() it('can communicate buffers, tabpages, and windows', function()
eq({1}, eval("rpcrequest(vim, 'nvim_list_tabpages')")) eq({1}, eval("rpcrequest(vim, 'nvim_list_tabpages')"))
eq({1}, eval("rpcrequest(vim, 'nvim_list_wins')")) -- Window IDs start at 1000 (LOWEST_WIN_ID in vim.h)
eq({1000}, eval("rpcrequest(vim, 'nvim_list_wins')"))
local buf = eval("rpcrequest(vim, 'nvim_list_bufs')")[1] local buf = eval("rpcrequest(vim, 'nvim_list_bufs')")[1]
eq(1, buf) eq(1, buf)