To: vim_dev@googlegroups.com Subject: Patch 7.4.1895 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 7.4.1895 Problem: Cannot use a window ID where a window number is expected. Solution: Add LOWEST_WIN_ID, so that the window ID can be used where a number is expected. Files: src/window.c, src/eval.c, src/vim.h, runtime/doc/eval.txt, src/testdir/test_window_id.vim *** ../vim-7.4.1894/src/window.c 2016-05-24 11:31:10.523505120 +0200 --- src/window.c 2016-06-04 18:13:00.770099953 +0200 *************** *** 4422,4428 **** } #endif ! static int last_win_id = 0; /* * Allocate a window structure and link it in the window list when "hidden" is --- 4422,4428 ---- } #endif ! static int last_win_id = LOWEST_WIN_ID - 1; /* * Allocate a window structure and link it in the window list when "hidden" is *** ../vim-7.4.1894/src/eval.c 2016-06-04 18:09:39.466102722 +0200 --- src/eval.c 2016-06-04 18:25:35.962089565 +0200 *************** *** 13566,13576 **** for (wp = (tp == NULL || tp == curtab) ? firstwin : tp->tp_firstwin; wp != NULL; wp = wp->w_next) ! if (--nr <= 0) break; return wp; #else ! if (nr == 0 || nr == 1) return curwin; return NULL; #endif --- 13566,13583 ---- for (wp = (tp == NULL || tp == curtab) ? firstwin : tp->tp_firstwin; wp != NULL; wp = wp->w_next) ! if (nr >= LOWEST_WIN_ID) ! { ! if (wp->w_id == nr) ! return wp; ! } ! else if (--nr <= 0) break; + if (nr >= LOWEST_WIN_ID) + return NULL; return wp; #else ! if (nr == 0 || nr == 1 || nr == curwin->w_id) return curwin; return NULL; #endif *** ../vim-7.4.1894/src/vim.h 2016-06-04 18:09:39.470102722 +0200 --- src/vim.h 2016-06-04 18:14:50.506098443 +0200 *************** *** 2334,2337 **** --- 2334,2340 ---- #define DIP_OPT 0x10 /* also use "opt" directory in 'packpath' */ #define DIP_NORTP 0x20 /* do not use 'runtimepath' */ + /* Lowest number used for window ID. Cannot have this many windows. */ + #define LOWEST_WIN_ID 1000 + #endif /* VIM__H */ *** ../vim-7.4.1894/runtime/doc/eval.txt 2016-06-04 18:09:39.474102722 +0200 --- runtime/doc/eval.txt 2016-06-04 18:24:47.266090235 +0200 *************** *** 1341,1346 **** --- 1358,1367 ---- window has number zero (unlike most other places where a window gets a number). + *v:beval_winid* *beval_winid-variable* + v:beval_winid The window ID of the window, over which the mouse pointer is. + Otherwise like v:beval_winnr. + *v:char* *char-variable* v:char Argument for evaluating 'formatexpr' and used for the typed character when using in an abbreviation |:map-|. *************** *** 2297,2312 **** the first file. argc() - 1 is the last one. See |arglist|. *arglistid()* ! arglistid([{winnr}, [ {tabnr} ]]) Return the argument list ID. This is a number which identifies the argument list being used. Zero is used for the ! global argument list. ! Return zero if the arguments are invalid. Without arguments use the current window. With {winnr} only use this window in the current tab page. With {winnr} and {tabnr} use the window in the specified tab page. *argv()* argv([{nr}]) The result is the {nr}th file in the argument list of the --- 2320,2336 ---- the first file. argc() - 1 is the last one. See |arglist|. *arglistid()* ! arglistid([{winnr} [, {tabnr}]]) Return the argument list ID. This is a number which identifies the argument list being used. Zero is used for the ! global argument list. See |arglist|. ! Return -1 if the arguments are invalid. Without arguments use the current window. With {winnr} only use this window in the current tab page. With {winnr} and {tabnr} use the window in the specified tab page. + {winnr} can be the window number or the window ID. *argv()* argv([{nr}]) The result is the {nr}th file in the argument list of the *************** *** 3921,3926 **** --- 3988,3994 ---- in the current tab page. With {winnr} and {tabnr} return the local current directory of the window in the specified tab page. + {winnr} can be the window number or the window ID. Return an empty string if the arguments are invalid. getfsize({fname}) *getfsize()* *************** *** 4016,4022 **** getloclist({nr}) *getloclist()* Returns a list with all the entries in the location list for ! window {nr}. When {nr} is zero the current window is used. For a location list window, the displayed location list is returned. For an invalid window number {nr}, an empty list is returned. Otherwise, same as |getqflist()|. --- 4085,4093 ---- getloclist({nr}) *getloclist()* Returns a list with all the entries in the location list for ! 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 returned. For an invalid window number {nr}, an empty list is returned. Otherwise, same as |getqflist()|. *************** *** 4117,4122 **** --- 4221,4227 ---- Note that {varname} must be the name without "w:". Tabs are numbered starting with one. For the current tabpage use |getwinvar()|. + {winnr} can be the window number or the window ID. When {winnr} is zero the current window is used. This also works for a global option, buffer-local option and window-local option, but it doesn't work for a global variable *************** *** 4234,4239 **** --- 4346,4352 ---- With {winnr} use this window in the current tab page. With {winnr} and {tabnr} use the window in the specified tab page. + {winnr} can be the window number or the window ID. Return 0 if the arguments are invalid. hasmapto({what} [, {mode} [, {abbr}]]) *hasmapto()* *************** *** 6191,6199 **** setloclist({nr}, {list} [, {action}]) *setloclist()* Create or replace or add to the location list for window {nr}. ! When {nr} is zero the current window is used. For a location ! list window, the displayed location list is modified. For an ! invalid window number {nr}, -1 is returned. Otherwise, same as |setqflist()|. Also see |location-list|. --- 6293,6303 ---- setloclist({nr}, {list} [, {action}]) *setloclist()* Create or replace or add to the location list for 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 ! modified. For an invalid window number {nr}, -1 is returned. Otherwise, same as |setqflist()|. Also see |location-list|. *************** *** 6354,6359 **** --- 6464,6470 ---- {val}. Tabs are numbered starting with one. For the current tabpage use |setwinvar()|. + {winnr} can be the window number or the window ID. When {winnr} is zero the current window is used. This also works for a global or local buffer option, but it doesn't work for a global or local buffer variable. *************** *** 7378,7386 **** *winbufnr()* 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 ! the buffer in the current window is returned. When window ! {nr} doesn't exist, -1 is returned. Example: > :echo "The file in the current window is " . bufname(winbufnr(0)) < --- 7537,7547 ---- *winbufnr()* winbufnr({nr}) The result is a Number, which is the number of the buffer ! associated with window {nr}. {nr} can be the window number or ! the window ID. ! 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: > :echo "The file in the current window is " . bufname(winbufnr(0)) < *************** *** 7391,7396 **** --- 7552,7558 ---- winheight({nr}) *winheight()* 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 returned. When window {nr} doesn't exist, -1 is returned. An existing window always has a height of zero or more. *************** *** 7470,7475 **** --- 7632,7638 ---- winwidth({nr}) *winwidth()* 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 returned. When window {nr} doesn't exist, -1 is returned. An existing window always has a width of zero or more. *** ../vim-7.4.1894/src/testdir/test_window_id.vim 2016-03-13 19:04:45.381224860 +0100 --- src/testdir/test_window_id.vim 2016-06-04 18:45:17.826073307 +0200 *************** *** 3,19 **** --- 3,24 ---- func Test_win_getid() edit one let id1 = win_getid() + let w:one = 'one' split two let id2 = win_getid() let bufnr2 = bufnr('%') + let w:two = 'two' split three let id3 = win_getid() + let w:three = 'three' tabnew edit four let id4 = win_getid() + let w:four = 'four' split five let id5 = win_getid() let bufnr5 = bufnr('%') + let w:five = 'five' tabnext wincmd w *************** *** 28,33 **** --- 33,41 ---- call assert_equal("three", expand("%")) call assert_equal(id3, win_getid()) 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 call assert_equal("five", expand("%")) call assert_equal(id5, win_getid()) *************** *** 36,42 **** --- 44,57 ---- call assert_equal("four", expand("%")) call assert_equal(id4, win_getid()) 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 + 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" call assert_equal(id1, win_getid()) *** ../vim-7.4.1894/src/version.c 2016-06-04 18:09:39.474102722 +0200 --- src/version.c 2016-06-04 18:25:20.974089771 +0200 *************** *** 755,756 **** --- 755,758 ---- { /* Add new patch number below this line */ + /**/ + 1895, /**/ -- hundred-and-one symptoms of being an internet addict: 43. You tell the kids they can't use the computer because "Daddy's got work to do" and you don't even have a job. /// 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 ///