Patch 9.0.1554
Problem: Code for handling 'switchbuf' is repeated.
Solution: Add a function to handle 'switchbuf'. (Yegappan Lakshmanan,
closes #12397)
Files: src/buffer.c, src/tag.c, src/window.c, src/proto/window.pro
*** ../vim-9.0.1553/src/buffer.c 2023-05-12 17:49:09.824299513 +0100
--- src/buffer.c 2023-05-14 17:22:28.289560175 +0100
***************
*** 1570,1583 ****
*/
if (action == DOBUF_SPLIT) // split window first
{
! // If 'switchbuf' contains "useopen": jump to first window containing
! // "buf" if one exists
! if ((swb_flags & SWB_USEOPEN) && buf_jump_open_win(buf))
! return OK;
! // If 'switchbuf' contains "usetab": jump to first window in any tab
! // page containing "buf" if one exists
! if ((swb_flags & SWB_USETAB) && buf_jump_open_tab(buf))
return OK;
if (win_split(0, 0) == FAIL)
return FAIL;
}
--- 1570,1579 ----
*/
if (action == DOBUF_SPLIT) // split window first
{
! // If 'switchbuf' is set jump to the window containing "buf".
! if (swbuf_goto_win_with_buf(buf) != NULL)
return OK;
+
if (win_split(0, 0) == FAIL)
return FAIL;
}
***************
*** 2492,2506 ****
if (options & GETF_SWITCH)
{
! // If 'switchbuf' contains "useopen": jump to first window containing
! // "buf" if one exists
! if (swb_flags & SWB_USEOPEN)
! wp = buf_jump_open_win(buf);
!
! // If 'switchbuf' contains "usetab": jump to first window in any tab
! // page containing "buf" if one exists
! if (wp == NULL && (swb_flags & SWB_USETAB))
! wp = buf_jump_open_tab(buf);
// If 'switchbuf' contains "split", "vsplit" or "newtab" and the
// current buffer isn't empty: open new tab or window
--- 2488,2495 ----
if (options & GETF_SWITCH)
{
! // If 'switchbuf' is set jump to the window containing "buf".
! wp = swbuf_goto_win_with_buf(buf);
// If 'switchbuf' contains "split", "vsplit" or "newtab" and the
// current buffer isn't empty: open new tab or window
*** ../vim-9.0.1553/src/tag.c 2023-02-20 12:16:33.340269410 +0000
--- src/tag.c 2023-05-14 17:20:45.189537045 +0100
***************
*** 3816,3833 ****
if (existing_buf != NULL)
{
! win_T *wp = 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);
! // We've switched to the buffer, the usual loading of the file must
! // be skipped.
! if (wp != NULL)
getfile_result = GETFILE_SAME_FILE;
}
}
--- 3816,3825 ----
if (existing_buf != NULL)
{
! // If 'switchbuf' is set jump to the window containing "buf".
! if (swbuf_goto_win_with_buf(existing_buf) != NULL)
! // We've switched to the buffer, the usual loading of the file
! // must be skipped.
getfile_result = GETFILE_SAME_FILE;
}
}
*** ../vim-9.0.1553/src/window.c 2023-05-12 17:49:09.824299513 +0100
--- src/window.c 2023-05-14 17:23:58.673100399 +0100
***************
*** 168,173 ****
--- 168,199 ----
}
/*
+ * If the 'switchbuf' option contains "useopen" or "usetab", then try to jump
+ * to a window containing "buf".
+ * Returns the pointer to the window that was jumped to or NULL.
+ */
+ win_T *
+ swbuf_goto_win_with_buf(buf_T *buf)
+ {
+ win_T *wp = NULL;
+
+ if (buf == NULL)
+ return wp;
+
+ // If 'switchbuf' contains "useopen": jump to first window in the current
+ // tab page containing "buf" if one exists.
+ if (swb_flags & SWB_USEOPEN)
+ wp = buf_jump_open_win(buf);
+
+ // If 'switchbuf' contains "usetab": jump to first window in any tab page
+ // containing "buf" if one exists.
+ if (wp == NULL && (swb_flags & SWB_USETAB))
+ wp = buf_jump_open_tab(buf);
+
+ return wp;
+ }
+
+ /*
* All CTRL-W window commands are handled here, called from normal_cmd().
*/
void
***************
*** 586,606 ****
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)
{
--- 612,618 ----
wp = NULL;
if ((swb_flags & (SWB_USEOPEN | SWB_USETAB))
&& cmdmod.cmod_tab == 0)
! wp = swbuf_goto_win_with_buf(buflist_findname_exp(ptr));
if (wp == NULL && win_split(0, 0) == OK)
{
*** ../vim-9.0.1553/src/proto/window.pro 2023-04-02 22:05:09.786319296
+0100
--- src/proto/window.pro 2023-05-14 17:18:25.665506214 +0100
***************
*** 1,6 ****
--- 1,7 ----
/* window.c */
int window_layout_locked(enum CMD_index cmd);
win_T *prevwin_curwin(void);
+ win_T *swbuf_goto_win_with_buf(buf_T *buf);
void do_window(int nchar, long Prenum, int xchar);
void get_wincmd_addr_type(char_u *arg, exarg_T *eap);
int win_split(int size, int flags);
*** ../vim-9.0.1553/src/version.c 2023-05-13 18:05:15.788057907 +0100
--- src/version.c 2023-05-14 17:18:19.761504920 +0100
***************
*** 697,698 ****
--- 697,700 ----
{ /* Add new patch number below this line */
+ /**/
+ 1554,
/**/
--
hundred-and-one symptoms of being an internet addict:
31. You code your homework in HTML and give your instructor the URL.
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/20230514162502.0E18F1C1B27%40moolenaar.net.