On Di, 05 Sep 2017, Christian Brabandt wrote:
> Bram,
> if you run:
>
> :au BufEnter * echomsg printf("Entering buffer: %s buftype: %s",
> expand("<afile>"), &buftype)
>
> and then you type :term
>
> you'll notice that by the time the BufEnter is triggered, the buftype
> option is not set yet. So one cannot detect reliably that the new buffer
> will be a terminal buffer.
>
> So how about this current patch:
I attach a better patch, that cleans up correctly.
Best,
Christian
--
Bei vielen Leuten beginnt das Gewissen erst dort, wo der Vorteil
aufhört.
-- Haile Selassie I.
--
--
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].
For more options, visit https://groups.google.com/d/optout.
diff --git a/src/terminal.c b/src/terminal.c
index 9660c64ba..1d2f3ec4a 100644
--- a/src/terminal.c
+++ b/src/terminal.c
@@ -253,18 +253,23 @@ term_start(typval_T *argvar, jobopt_T *opt, int forceit)
if (check_restricted() || check_secure())
return;
+#ifdef FEAT_AUTOCMD
+ /* Don't execute Win/Buf Enter autocommands here, until the terminal
+ * is proper setup (buftype option is set) */
+ ++autocmd_no_enter;
+#endif
if ((opt->jo_set & (JO_IN_IO + JO_OUT_IO + JO_ERR_IO))
== (JO_IN_IO + JO_OUT_IO + JO_ERR_IO)
|| (!(opt->jo_set & JO_OUT_IO) && (opt->jo_set & JO_OUT_BUF))
|| (!(opt->jo_set & JO_ERR_IO) && (opt->jo_set & JO_ERR_BUF)))
{
EMSG(_(e_invarg));
- return;
+ goto TERMEND;
}
term = (term_T *)alloc_clear(sizeof(term_T));
if (term == NULL)
- return;
+ goto TERMEND;
term->tl_dirty_row_end = MAX_ROW;
term->tl_cursor_visible = TRUE;
term->tl_cursor_shape = VTERM_PROP_CURSORSHAPE_BLOCK;
@@ -279,13 +284,13 @@ term_start(typval_T *argvar, jobopt_T *opt, int forceit)
{
no_write_message();
vim_free(term);
- return;
+ goto TERMEND;
}
if (do_ecmd(0, NULL, NULL, &split_ea, ECMD_ONE,
ECMD_HIDE + (forceit ? ECMD_FORCEIT : 0), curwin) == FAIL)
{
vim_free(term);
- return;
+ goto TERMEND;
}
}
else if (opt->jo_hidden)
@@ -299,7 +304,7 @@ term_start(typval_T *argvar, jobopt_T *opt, int forceit)
if (buf == NULL || ml_open(buf) == FAIL)
{
vim_free(term);
- return;
+ goto TERMEND;
}
old_curbuf = curbuf;
--curbuf->b_nwindows;
@@ -329,7 +334,7 @@ term_start(typval_T *argvar, jobopt_T *opt, int forceit)
{
/* split failed */
vim_free(term);
- return;
+ goto TERMEND;
}
}
term->tl_buffer = curbuf;
@@ -406,7 +411,6 @@ term_start(typval_T *argvar, jobopt_T *opt, int forceit)
set_term_and_win_size(term);
setup_job_options(opt, term->tl_rows, term->tl_cols);
-
/* System dependent: setup the vterm and maybe start the job in it. */
if (argvar->v_type == VAR_STRING
&& argvar->vval.v_string != NULL
@@ -432,6 +436,14 @@ term_start(typval_T *argvar, jobopt_T *opt, int forceit)
curwin->w_buffer = curbuf;
++curbuf->b_nwindows;
}
+
+#ifdef FEAT_AUTOCMD
+ if (autocmd_no_enter)
+ --autocmd_no_enter;
+ apply_autocmds(EVENT_BUFENTER, NULL, NULL, FALSE, curbuf);
+ apply_autocmds(EVENT_BUFWINENTER, NULL, NULL, FALSE, curbuf);
+#endif
+
}
else
{
@@ -450,6 +462,10 @@ term_start(typval_T *argvar, jobopt_T *opt, int forceit)
* free_terminal(). */
do_buffer(DOBUF_WIPE, DOBUF_FIRST, FORWARD, buf->b_fnum, TRUE);
}
+
+TERMEND:
+ if (autocmd_no_enter)
+ --autocmd_no_enter;
}
/*