Merge #9798 'aucmd_prepbuf: Use floating window'

This commit is contained in:
Justin M. Keyes
2019-05-06 23:10:16 +02:00
2 changed files with 29 additions and 44 deletions

View File

@@ -6520,21 +6520,17 @@ bool check_nomodeline(char_u **argp)
return true; return true;
} }
/* /// Prepare for executing autocommands for (hidden) buffer `buf`.
* Prepare for executing autocommands for (hidden) buffer "buf". /// If the current buffer is not in any visible window, put it in a temporary
* Search for a visible window containing the current buffer. If there isn't /// floating window `aucmd_win`.
* one then use "aucmd_win". /// Set `curbuf` and `curwin` to match `buf`.
* Set "curbuf" and "curwin" to match "buf". ///
*/ /// @param aco structure to save values in
void /// @param buf new curbuf
aucmd_prepbuf ( void aucmd_prepbuf(aco_save_T *aco, buf_T *buf)
aco_save_T *aco, /* structure to save values in */
buf_T *buf /* new curbuf */
)
{ {
win_T *win; win_T *win;
int save_ea; bool need_append = true; // Append `aucmd_win` to the window list.
int save_acd;
/* Find a window that is for the new buffer */ /* Find a window that is for the new buffer */
if (buf == curbuf) { /* be quick when buf is curbuf */ if (buf == curbuf) { /* be quick when buf is curbuf */
@@ -6549,9 +6545,10 @@ aucmd_prepbuf (
} }
} }
/* Allocate "aucmd_win" when needed. */ // Allocate the `aucmd_win` dummy floating window.
if (win == NULL && aucmd_win == NULL) { if (win == NULL && aucmd_win == NULL) {
win_alloc_aucmd_win(); win_alloc_aucmd_win();
need_append = false;
} }
if (win == NULL && aucmd_win_used) if (win == NULL && aucmd_win_used)
/* Strange recursive autocommand, fall back to using the current /* Strange recursive autocommand, fall back to using the current
@@ -6586,21 +6583,14 @@ aucmd_prepbuf (
aco->globaldir = globaldir; aco->globaldir = globaldir;
globaldir = NULL; globaldir = NULL;
block_autocmds(); // We don't want BufEnter/WinEnter autocommands.
/* Split the current window, put the aucmd_win in the upper half. if (need_append) {
* We don't want the BufEnter or WinEnter autocommands. */ win_append(lastwin, aucmd_win);
block_autocmds(); }
make_snapshot(SNAP_AUCMD_IDX); // Prevent chdir() call in win_enter_ext(), through do_autochdir()
save_ea = p_ea; int save_acd = p_acd;
p_ea = false;
/* Prevent chdir() call in win_enter_ext(), through do_autochdir(). */
save_acd = p_acd;
p_acd = false; p_acd = false;
win_enter(aucmd_win, false);
(void)win_split_ins(0, WSP_TOP, aucmd_win, 0);
(void)win_comp_pos(); /* recompute window positions */
p_ea = save_ea;
p_acd = save_acd; p_acd = save_acd;
unblock_autocmds(); unblock_autocmds();
curwin = aucmd_win; curwin = aucmd_win;
@@ -6616,8 +6606,6 @@ aucmd_prepbuf (
/// @param aco structure holding saved values /// @param aco structure holding saved values
void aucmd_restbuf(aco_save_T *aco) void aucmd_restbuf(aco_save_T *aco)
{ {
int dummy;
if (aco->use_aucmd_win) { if (aco->use_aucmd_win) {
curbuf->b_nwindows--; curbuf->b_nwindows--;
// Find "aucmd_win", it can't be closed, but it may be in another tab page. // Find "aucmd_win", it can't be closed, but it may be in another tab page.
@@ -6636,8 +6624,6 @@ void aucmd_restbuf(aco_save_T *aco)
} }
win_found: win_found:
// Remove the window and frame from the tree of frames.
(void)winframe_remove(curwin, &dummy, NULL);
win_remove(curwin, NULL); win_remove(curwin, NULL);
aucmd_win_used = false; aucmd_win_used = false;
last_status(false); // may need to remove last status line last_status(false); // may need to remove last status line
@@ -6647,8 +6633,6 @@ win_found:
close_tabpage(curtab); close_tabpage(curtab);
} }
restore_snapshot(SNAP_AUCMD_IDX, false);
(void)win_comp_pos(); // recompute window positions
unblock_autocmds(); unblock_autocmds();
if (win_valid(aco->save_curwin)) { if (win_valid(aco->save_curwin)) {

View File

@@ -2295,8 +2295,7 @@ int win_close(win_T *win, bool free_buf)
EMSG(_("E813: Cannot close autocmd window")); EMSG(_("E813: Cannot close autocmd window"));
return FAIL; return FAIL;
} }
if ((firstwin == aucmd_win || lastwin_nofloating() == aucmd_win) if ((firstwin == aucmd_win || lastwin == aucmd_win) && one_window()) {
&& one_window()) {
EMSG(_("E814: Cannot close window, only autocmd window would remain")); EMSG(_("E814: Cannot close window, only autocmd window would remain"));
return FAIL; return FAIL;
} }
@@ -3413,16 +3412,18 @@ int win_alloc_first(void)
return OK; return OK;
} }
/* // Init `aucmd_win`. This can only be done after the first window
* Init "aucmd_win". This can only be done after the first // is fully initialized, thus it can't be in win_alloc_first().
* window is fully initialized, thus it can't be in win_alloc_first().
*/
void win_alloc_aucmd_win(void) void win_alloc_aucmd_win(void)
{ {
aucmd_win = win_alloc(NULL, TRUE); Error err = ERROR_INIT;
win_init_some(aucmd_win, curwin); FloatConfig fconfig = FLOAT_CONFIG_INIT;
fconfig.width = 20;
fconfig.height = 20;
fconfig.focusable = false;
aucmd_win = win_new_float(NULL, fconfig, &err);
aucmd_win->w_buffer->b_nwindows--;
RESET_BINDING(aucmd_win); RESET_BINDING(aucmd_win);
new_frame(aucmd_win);
} }
/* /*