]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.0.1554: code for handling 'switchbuf' is repeated v9.0.1554
authorYegappan Lakshmanan <yegappan@yahoo.com>
Sun, 14 May 2023 16:24:22 +0000 (17:24 +0100)
committerBram Moolenaar <Bram@vim.org>
Sun, 14 May 2023 16:24:22 +0000 (17:24 +0100)
Problem:    Code for handling 'switchbuf' is repeated.
Solution:   Add a function to handle 'switchbuf'. (Yegappan Lakshmanan,
            closes #12397)

src/buffer.c
src/proto/window.pro
src/tag.c
src/version.c
src/window.c

index 60b7c80971584477eaa3d98e954a66ac6e37cf2f..dc279ffb196e5025f59d79caa00d5b4babe28aff 100644 (file)
@@ -1570,14 +1570,10 @@ do_buffer_ext(
      */
     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))
+       // 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,15 +2488,8 @@ buflist_getfile(
 
     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' 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
index d1108af50b79f45487b3a56f6b618d2a01351968..72612b8d3a63aeebe739294cb7babf6c456b7b10 100644 (file)
@@ -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);
index 86f8ac4bcfaf1be7b0ddb3c5064c3effe096dafd..1ee67b44dd277bde63028ca9010ba0fae82e7400 100644 (file)
--- a/src/tag.c
+++ b/src/tag.c
@@ -3816,18 +3816,10 @@ jumpto_tag(
 
        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)
+           // 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;
        }
     }
index ed51a81a54a3c6f10a4f815e91731955166b121d..8620f9732b07fcc13a5255e9d028db9b60a75874 100644 (file)
@@ -695,6 +695,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1554,
 /**/
     1553,
 /**/
index b4b23d3584bf1bb2c52207785b2dd599b1b0a0d9..18f07b17a4cba34fdc6ecb1d0bc7d5f0090f3d37 100644 (file)
@@ -167,6 +167,32 @@ prevwin_curwin(void)
     return is_in_cmdwin() && prevwin != NULL ? prevwin : curwin;
 }
 
+/*
+ * 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().
  */
@@ -586,21 +612,7 @@ wingotofile:
                    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);
-                       }
-                   }
+                       wp = swbuf_goto_win_with_buf(buflist_findname_exp(ptr));
 
                    if (wp == NULL && win_split(0, 0) == OK)
                    {