To: vim_dev@googlegroups.com Subject: Patch 8.1.1967 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.1.1967 Problem: Line() only works for the current window. Solution: Add an optional argument for the window to use. Files: runtime/eval.txt, src/evalfunc.c, src/testdir/test_popupwin.vim *** ../vim-8.1.1966/src/evalfunc.c 2019-09-02 22:31:08.010296361 +0200 --- src/evalfunc.c 2019-09-02 22:54:27.657439030 +0200 *************** *** 634,640 **** {"len", 1, 1, FEARG_1, f_len}, {"libcall", 3, 3, FEARG_3, f_libcall}, {"libcallnr", 3, 3, FEARG_3, f_libcallnr}, ! {"line", 1, 1, FEARG_1, f_line}, {"line2byte", 1, 1, FEARG_1, f_line2byte}, {"lispindent", 1, 1, FEARG_1, f_lispindent}, {"list2str", 1, 2, FEARG_1, f_list2str}, --- 634,640 ---- {"len", 1, 1, FEARG_1, f_len}, {"libcall", 3, 3, FEARG_3, f_libcall}, {"libcallnr", 3, 3, FEARG_3, f_libcallnr}, ! {"line", 1, 2, FEARG_1, f_line}, {"line2byte", 1, 1, FEARG_1, f_line2byte}, {"lispindent", 1, 1, FEARG_1, f_lispindent}, {"list2str", 1, 2, FEARG_1, f_list2str}, *************** *** 1154,1167 **** --- 1154,1171 ---- { typval_T rettv; linenr_T lnum; + int save_type; lnum = (linenr_T)tv_get_number_chk(&argvars[0], NULL); if (lnum == 0) /* no valid number, try using line() */ { rettv.v_type = VAR_NUMBER; + save_type = argvars[1].v_type; + argvars[1].v_type = VAR_UNKNOWN; f_line(argvars, &rettv); lnum = (linenr_T)rettv.vval.v_number; clear_tv(&rettv); + argvars[1].v_type = save_type; } return lnum; } *************** *** 6658,6673 **** } /* ! * "line(string)" function */ static void f_line(typval_T *argvars, typval_T *rettv) { linenr_T lnum = 0; ! pos_T *fp; int fnum; - fp = var2fpos(&argvars[0], TRUE, &fnum); if (fp != NULL) lnum = fp->lnum; rettv->vval.v_number = lnum; --- 6662,6701 ---- } /* ! * "line(string, [winid])" function */ static void f_line(typval_T *argvars, typval_T *rettv) { linenr_T lnum = 0; ! pos_T *fp = NULL; int fnum; + int id; + tabpage_T *tp; + win_T *wp; + win_T *save_curwin; + tabpage_T *save_curtab; + + if (argvars[1].v_type != VAR_UNKNOWN) + { + // use window specified in the second argument + id = (int)tv_get_number(&argvars[1]); + wp = win_id2wp_tp(id, &tp); + if (wp != NULL && tp != NULL) + { + if (switch_win_noblock(&save_curwin, &save_curtab, wp, tp, TRUE) + == OK) + { + check_cursor(); + fp = var2fpos(&argvars[0], TRUE, &fnum); + } + restore_win_noblock(save_curwin, save_curtab, TRUE); + } + } + else + // use current window + fp = var2fpos(&argvars[0], TRUE, &fnum); if (fp != NULL) lnum = fp->lnum; rettv->vval.v_number = lnum; *** ../vim-8.1.1966/src/testdir/test_popupwin.vim 2019-09-01 23:27:02.142724494 +0200 --- src/testdir/test_popupwin.vim 2019-09-02 22:50:18.503535794 +0200 *************** *** 346,351 **** --- 346,355 ---- redraw call assert_equal(11, popup_getoptions(winid).firstline) call assert_equal(11, popup_getpos(winid).firstline) + " check line() works with popup window + call assert_equal(11, line('.', winid)) + call assert_equal(50, line('$', winid)) + call assert_equal(0, line('$', 123456)) " Normal command changes what is displayed but not "firstline" call win_execute(winid, "normal! \") *** ../vim-8.1.1966/src/version.c 2019-09-02 22:31:08.014296345 +0200 --- src/version.c 2019-09-02 22:45:22.014357069 +0200 *************** *** 763,764 **** --- 763,766 ---- { /* Add new patch number below this line */ + /**/ + 1967, /**/ -- An error has occurred. Hit any user to continue. /// 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 ///