* Deleting the current buffer: Need to find another buffer to go to.
* There should be another, otherwise it would have been handled
* above. However, autocommands may have deleted all buffers.
- * First use au_new_curbuf, if it is valid.
+ * First use au_new_curbuf.br_buf, if it is valid.
* Then prefer the buffer we most recently visited.
* Else try to find one that is loaded, after the current buffer,
* then before the current buffer.
buf = NULL; /* selected buffer */
bp = NULL; /* used when no loaded buffer found */
#ifdef FEAT_AUTOCMD
- if (au_new_curbuf != NULL && buf_valid(au_new_curbuf))
- buf = au_new_curbuf;
+ if (au_new_curbuf.br_buf != NULL && bufref_valid(&au_new_curbuf))
+ buf = au_new_curbuf.br_buf;
# ifdef FEAT_JUMPLIST
else
# endif
}
else
{
+#ifdef FEAT_AUTOCMD
+ bufref_T bufref;
+
+ set_bufref(&bufref, buf);
+#endif
if (buf_write_all(buf, eap->forceit) == FAIL)
++error;
#ifdef FEAT_AUTOCMD
/* an autocommand may have deleted the buffer */
- if (!buf_valid(buf))
+ if (!bufref_valid(&bufref))
buf = firstbuf;
#endif
}
int did_set_swapcommand = FALSE;
#endif
buf_T *buf;
+ bufref_T bufref;
#if defined(FEAT_AUTOCMD) || defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
buf_T *old_curbuf = curbuf;
#endif
else /* existing memfile */
{
oldbuf = TRUE;
+ set_bufref(&bufref, buf);
(void)buf_check_timestamp(buf, FALSE);
/* Check if autocommands made buffer invalid or changed the current
* buffer. */
- if (!buf_valid(buf)
+ if (!bufref_valid(&bufref)
#ifdef FEAT_AUTOCMD
|| curbuf != old_curbuf
#endif
*/
if (buf->b_fname != NULL)
new_name = vim_strsave(buf->b_fname);
- au_new_curbuf = buf;
+ set_bufref(&au_new_curbuf, buf);
apply_autocmds(EVENT_BUFLEAVE, NULL, NULL, FALSE, curbuf);
- if (!buf_valid(buf)) /* new buffer has been deleted */
+ if (!bufref_valid(&au_new_curbuf))
{
+ /* new buffer has been deleted */
delbuf_msg(new_name); /* frees new_name */
goto theend;
}
}
# endif
/* Be careful again, like above. */
- if (!buf_valid(buf)) /* new buffer has been deleted */
+ if (!bufref_valid(&au_new_curbuf))
{
+ /* new buffer has been deleted */
delbuf_msg(new_name); /* frees new_name */
goto theend;
}
#ifdef FEAT_AUTOCMD
}
vim_free(new_name);
- au_new_curbuf = NULL;
+ au_new_curbuf.br_buf = NULL;
#endif
}
new_name = vim_strsave(buf->b_fname);
else
new_name = NULL;
+ set_bufref(&bufref, buf);
#endif
if (p_ur < 0 || curbuf->b_ml.ml_line_count <= p_ur)
{
#ifdef FEAT_AUTOCMD
/* If autocommands deleted the buffer we were going to re-edit, give
* up and jump to the end. */
- if (!buf_valid(buf))
+ if (!bufref_valid(&bufref))
{
delbuf_msg(new_name); /* frees new_name */
goto theend;
EMSG2(_("E143: Autocommands unexpectedly deleted new buffer %s"),
name == NULL ? (char_u *)"" : name);
vim_free(name);
- au_new_curbuf = NULL;
+ au_new_curbuf.br_buf = NULL;
}
#endif
/* When deleting the current buffer, another one must be loaded. If we know
* which one is preferred, au_new_curbuf is set to it */
-EXTERN buf_T *au_new_curbuf INIT(= NULL);
+EXTERN bufref_T au_new_curbuf INIT(= {NULL});
/* When deleting a buffer/window and autocmd_busy is TRUE, do not free the
* buffer/window. but link it in the list starting with