Mercurial > vim
comparison src/window.c @ 32445:48b95cef8fa2 v9.0.1554
patch 9.0.1554: code for handling 'switchbuf' is repeated
Commit: https://github.com/vim/vim/commit/e42c27d9e8a18e3786f13f17663914cdd0f63f9e
Author: Yegappan Lakshmanan <yegappan@yahoo.com>
Date: Sun May 14 17:24:22 2023 +0100
patch 9.0.1554: code for handling 'switchbuf' is repeated
Problem: Code for handling 'switchbuf' is repeated.
Solution: Add a function to handle 'switchbuf'. (Yegappan Lakshmanan,
closes #12397)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 14 May 2023 18:30:05 +0200 |
parents | bfc23ba1bba5 |
children | 87f59a64efab |
comparison
equal
deleted
inserted
replaced
32444:e01f2a5517a8 | 32445:48b95cef8fa2 |
---|---|
166 // In cmdwin, the alternative buffer should be used. | 166 // In cmdwin, the alternative buffer should be used. |
167 return is_in_cmdwin() && prevwin != NULL ? prevwin : curwin; | 167 return is_in_cmdwin() && prevwin != NULL ? prevwin : curwin; |
168 } | 168 } |
169 | 169 |
170 /* | 170 /* |
171 * If the 'switchbuf' option contains "useopen" or "usetab", then try to jump | |
172 * to a window containing "buf". | |
173 * Returns the pointer to the window that was jumped to or NULL. | |
174 */ | |
175 win_T * | |
176 swbuf_goto_win_with_buf(buf_T *buf) | |
177 { | |
178 win_T *wp = NULL; | |
179 | |
180 if (buf == NULL) | |
181 return wp; | |
182 | |
183 // If 'switchbuf' contains "useopen": jump to first window in the current | |
184 // tab page containing "buf" if one exists. | |
185 if (swb_flags & SWB_USEOPEN) | |
186 wp = buf_jump_open_win(buf); | |
187 | |
188 // If 'switchbuf' contains "usetab": jump to first window in any tab page | |
189 // containing "buf" if one exists. | |
190 if (wp == NULL && (swb_flags & SWB_USETAB)) | |
191 wp = buf_jump_open_tab(buf); | |
192 | |
193 return wp; | |
194 } | |
195 | |
196 /* | |
171 * All CTRL-W window commands are handled here, called from normal_cmd(). | 197 * All CTRL-W window commands are handled here, called from normal_cmd(). |
172 */ | 198 */ |
173 void | 199 void |
174 do_window( | 200 do_window( |
175 int nchar, | 201 int nchar, |
584 // If 'switchbuf' is set to 'useopen' or 'usetab' and the | 610 // If 'switchbuf' is set to 'useopen' or 'usetab' and the |
585 // file is already opened in a window, then jump to it. | 611 // file is already opened in a window, then jump to it. |
586 wp = NULL; | 612 wp = NULL; |
587 if ((swb_flags & (SWB_USEOPEN | SWB_USETAB)) | 613 if ((swb_flags & (SWB_USEOPEN | SWB_USETAB)) |
588 && cmdmod.cmod_tab == 0) | 614 && cmdmod.cmod_tab == 0) |
589 { | 615 wp = swbuf_goto_win_with_buf(buflist_findname_exp(ptr)); |
590 buf_T *existing_buf = buflist_findname_exp(ptr); | |
591 | |
592 if (existing_buf != NULL) | |
593 { | |
594 if (swb_flags & SWB_USEOPEN) | |
595 wp = buf_jump_open_win(existing_buf); | |
596 | |
597 // If 'switchbuf' contains "usetab": jump to first | |
598 // window in any tab page containing "existing_buf" | |
599 // if one exists. | |
600 if (wp == NULL && (swb_flags & SWB_USETAB)) | |
601 wp = buf_jump_open_tab(existing_buf); | |
602 } | |
603 } | |
604 | 616 |
605 if (wp == NULL && win_split(0, 0) == OK) | 617 if (wp == NULL && win_split(0, 0) == OK) |
606 { | 618 { |
607 RESET_BINDING(curwin); | 619 RESET_BINDING(curwin); |
608 if (do_ecmd(0, ptr, NULL, NULL, ECMD_LASTL, | 620 if (do_ecmd(0, ptr, NULL, NULL, ECMD_LASTL, |