To: vim_dev@googlegroups.com Subject: Patch 9.0.1546 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 9.0.1546 Problem: Some commands for opening a file don't use 'switchbuf'. Solution: Use 'switchbuf' for more commands. (Yegappan Lakshmanan, closes #12383, closes #12381) Files: runtime/doc/options.txt, src/buffer.c, src/window.c, src/testdir/test_gf.vim *** ../vim-9.0.1545/runtime/doc/options.txt 2023-04-23 17:50:14.849935960 +0100 --- runtime/doc/options.txt 2023-05-12 17:37:27.868363091 +0100 *************** *** 7876,7891 **** 'switchbuf' 'swb' string (default "") global This option controls the behavior when switching between buffers. ! Mostly for |quickfix| commands some values are also used for other ! commands, as mentioned below. Possible values (comma-separated list): ! useopen If included, jump to the first open window that ! contains the specified buffer (if there is one). ! Otherwise: Do not examine other windows. ! This setting is checked with |quickfix| commands, when ! jumping to errors (":cc", ":cn", "cp", etc.). It is ! also used in all buffer related split commands, for ! example ":sbuffer", ":sbnext", or ":sbrewind". usetab Like "useopen", but also consider windows in other tab pages. split If included, split the current window before loading --- 7931,7948 ---- 'switchbuf' 'swb' string (default "") global This option controls the behavior when switching between buffers. ! This option is checked, when ! - jumping to errors with the |quickfix| commands (|:cc|, |:cn|, |:cp|, ! etc.) ! - jumping to a tag using the |:stag| command. ! - opening a file using the |CTRL-W_f| or |CTRL-W_F| command. ! - jumping to a buffer using a buffer split command (e.g. |:sbuffer|, ! |:sbnext|, or |:sbrewind|). Possible values (comma-separated list): ! useopen If included, jump to the first open window in the ! current tab page that contains the specified buffer ! (if there is one). Otherwise: Do not examine other ! windows. usetab Like "useopen", but also consider windows in other tab pages. split If included, split the current window before loading *** ../vim-9.0.1545/src/buffer.c 2023-04-29 12:09:50.118286706 +0100 --- src/buffer.c 2023-05-12 17:37:27.872363092 +0100 *************** *** 2560,2566 **** } } - #if defined(FEAT_QUICKFIX) || defined(FEAT_EVAL) || defined(FEAT_SPELL) || defined(PROTO) /* * Find file in buffer list by name (it has to be for the current window). * Returns NULL if not found. --- 2560,2565 ---- *************** *** 2586,2592 **** } return buf; } - #endif /* * Find file in buffer list by name (it has to be for the current window). --- 2585,2590 ---- *** ../vim-9.0.1545/src/window.c 2023-05-06 12:53:33.707345003 +0100 --- src/window.c 2023-05-12 17:37:27.872363092 +0100 *************** *** 580,586 **** need_mouse_correct = TRUE; #endif setpcmark(); ! if (win_split(0, 0) == OK) { RESET_BINDING(curwin); if (do_ecmd(0, ptr, NULL, NULL, ECMD_LASTL, --- 580,608 ---- need_mouse_correct = TRUE; #endif setpcmark(); ! ! // If 'switchbuf' is set to 'useopen' or 'usetab' and the ! // file is already opened in a window, then jump to it. ! wp = NULL; ! if ((swb_flags & (SWB_USEOPEN | SWB_USETAB)) ! && cmdmod.cmod_tab == 0) ! { ! buf_T *existing_buf = buflist_findname_exp(ptr); ! ! if (existing_buf != NULL) ! { ! if (swb_flags & SWB_USEOPEN) ! wp = buf_jump_open_win(existing_buf); ! ! // If 'switchbuf' contains "usetab": jump to first ! // window in any tab page containing "existing_buf" ! // if one exists. ! if (wp == NULL && (swb_flags & SWB_USETAB)) ! wp = buf_jump_open_tab(existing_buf); ! } ! } ! ! if (wp == NULL && win_split(0, 0) == OK) { RESET_BINDING(curwin); if (do_ecmd(0, ptr, NULL, NULL, ECMD_LASTL, *************** *** 591,602 **** win_close(curwin, FALSE); goto_tabpage_win(oldtab, oldwin); } ! else if (nchar == 'F' && lnum >= 0) ! { ! curwin->w_cursor.lnum = lnum; ! check_cursor_lnum(); ! beginline(BL_SOL | BL_FIX); ! } } vim_free(ptr); } --- 613,627 ---- win_close(curwin, FALSE); goto_tabpage_win(oldtab, oldwin); } ! else ! wp = curwin; ! } ! ! if (wp != NULL && nchar == 'F' && lnum >= 0) ! { ! curwin->w_cursor.lnum = lnum; ! check_cursor_lnum(); ! beginline(BL_SOL | BL_FIX); } vim_free(ptr); } *** ../vim-9.0.1545/src/testdir/test_gf.vim 2023-01-25 15:31:24.358723462 +0000 --- src/testdir/test_gf.vim 2023-05-12 17:37:27.872363092 +0100 *************** *** 292,295 **** --- 292,356 ---- set path& endfunc + " Test for 'switchbuf' with gf and gF commands + func Test_gf_switchbuf() + call writefile(repeat(["aaa"], 10), "Xtest1", 'D') + edit Xtest1 + new + call setline(1, ['Xtest1']) + + " Test for 'useopen' + set switchbuf=useopen + call cursor(1, 1) + exe "normal \f" + call assert_equal([2, 2], [winnr(), winnr('$')]) + close + + " If the file is opened in another tabpage, then it should not be considered + tabedit Xtest1 + tabfirst + exe "normal \f" + call assert_equal([1, 2], [winnr(), winnr('$')]) + call assert_equal([1, 2], [tabpagenr(), tabpagenr('$')]) + close + + " Test for 'usetab' + set switchbuf=usetab + exe "normal \f" + call assert_equal([1, 1], [winnr(), winnr('$')]) + call assert_equal([2, 2], [tabpagenr(), tabpagenr('$')]) + %bw! + + " Test for CTRL-W_F with 'useopen' + set isfname-=: + call setline(1, ['Xtest1:5']) + set switchbuf=useopen + split +1 Xtest1 + wincmd b + exe "normal \F" + call assert_equal([1, 2], [winnr(), winnr('$')]) + call assert_equal(5, line('.')) + close + + " If the file is opened in another tabpage, then it should not be considered + tabedit +1 Xtest1 + tabfirst + exe "normal \F" + call assert_equal([1, 2], [winnr(), winnr('$')]) + call assert_equal(5, line('.')) + call assert_equal([1, 2], [tabpagenr(), tabpagenr('$')]) + close + + " Test for CTRL_W_F with 'usetab' + set switchbuf=usetab + exe "normal \F" + call assert_equal([2, 2], [tabpagenr(), tabpagenr('$')]) + call assert_equal([1, 1], [winnr(), winnr('$')]) + call assert_equal(5, line('.')) + + set switchbuf= + set isfname& + %bw! + endfunc + " vim: shiftwidth=2 sts=2 expandtab *** ../vim-9.0.1545/src/version.c 2023-05-12 15:47:21.860773278 +0100 --- src/version.c 2023-05-12 17:40:33.320341765 +0100 *************** *** 697,698 **** --- 697,700 ---- { /* Add new patch number below this line */ + /**/ + 1546, /**/ -- Apparently, 1 in 5 people in the world are Chinese. And there are 5 people in my family, so it must be one of them. It's either my mum or my dad. Or my older brother Colin. Or my younger brother Ho-Cha-Chu. But I think it's Colin. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///