mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
vim-patch:9.0.1554: code for handling 'switchbuf' is repeated (#23632)
Problem: Code for handling 'switchbuf' is repeated.
Solution: Add a function to handle 'switchbuf'. (Yegappan Lakshmanan,
closes vim/vim#12397)
e42c27d9e8
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
This commit is contained in:
parent
4a0005aee9
commit
189e21ae50
@ -1459,16 +1459,11 @@ int do_buffer(int action, int start, int dir, int count, int forceit)
|
|||||||
|
|
||||||
// make "buf" the current buffer
|
// make "buf" the current buffer
|
||||||
if (action == DOBUF_SPLIT) { // split window first
|
if (action == DOBUF_SPLIT) { // split window first
|
||||||
// If 'switchbuf' contains "useopen": jump to first window containing
|
// If 'switchbuf' is set jump to the window containing "buf".
|
||||||
// "buf" if one exists
|
if (swbuf_goto_win_with_buf(buf) != NULL) {
|
||||||
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;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (win_split(0, 0) == FAIL) {
|
if (win_split(0, 0) == FAIL) {
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
@ -2072,17 +2067,8 @@ int buflist_getfile(int n, linenr_T lnum, int options, int forceit)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (options & GETF_SWITCH) {
|
if (options & GETF_SWITCH) {
|
||||||
// If 'switchbuf' contains "useopen": jump to first window containing
|
// If 'switchbuf' is set jump to the window containing "buf".
|
||||||
// "buf" if one exists
|
wp = swbuf_goto_win_with_buf(buf);
|
||||||
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
|
// If 'switchbuf' contains "split", "vsplit" or "newtab" and the
|
||||||
// current buffer isn't empty: open new tab or window
|
// current buffer isn't empty: open new tab or window
|
||||||
|
@ -2901,21 +2901,10 @@ static int jumpto_tag(const char *lbuf_arg, int forceit, int keep_help)
|
|||||||
buf_T *const existing_buf = buflist_findname_exp(fname);
|
buf_T *const existing_buf = buflist_findname_exp(fname);
|
||||||
|
|
||||||
if (existing_buf != NULL) {
|
if (existing_buf != NULL) {
|
||||||
const win_T *wp = NULL;
|
// If 'switchbuf' is set jump to the window containing "buf".
|
||||||
|
if (swbuf_goto_win_with_buf(existing_buf) != NULL) {
|
||||||
if (swb_flags & SWB_USEOPEN) {
|
// We've switched to the buffer, the usual loading of the file
|
||||||
wp = buf_jump_open_win(existing_buf);
|
// must be skipped.
|
||||||
}
|
|
||||||
|
|
||||||
// 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;
|
getfile_result = GETFILE_SAME_FILE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -139,6 +139,32 @@ win_T *prevwin_curwin(void)
|
|||||||
return is_in_cmdwin() && prevwin != NULL ? prevwin : curwin;
|
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().
|
/// all CTRL-W window commands are handled here, called from normal_cmd().
|
||||||
///
|
///
|
||||||
/// @param xchar extra char from ":wincmd gx" or NUL
|
/// @param xchar extra char from ":wincmd gx" or NUL
|
||||||
@ -520,20 +546,7 @@ wingotofile:
|
|||||||
win_T *wp = NULL;
|
win_T *wp = NULL;
|
||||||
if ((swb_flags & (SWB_USEOPEN | SWB_USETAB))
|
if ((swb_flags & (SWB_USEOPEN | SWB_USETAB))
|
||||||
&& cmdmod.cmod_tab == 0) {
|
&& cmdmod.cmod_tab == 0) {
|
||||||
buf_T *existing_buf = buflist_findname_exp(ptr);
|
wp = swbuf_goto_win_with_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) {
|
if (wp == NULL && win_split(0, 0) == OK) {
|
||||||
|
Loading…
Reference in New Issue
Block a user