Merge pull request #12971 from vigoux/decurbuf

Decrease reliance on curbuf in BUFEMPTY and `undo.c`
This commit is contained in:
Björn Linse
2021-07-09 10:15:18 +02:00
committed by GitHub
24 changed files with 258 additions and 225 deletions

View File

@@ -40,18 +40,18 @@
/// "col" is the column for the message; non-zero when in insert mode and
/// 'showmode' is on.
/// Careful: may trigger autocommands that reload the buffer.
void change_warning(int col)
void change_warning(buf_T *buf, int col)
{
static char *w_readonly = N_("W10: Warning: Changing a readonly file");
if (curbuf->b_did_warn == false
if (buf->b_did_warn == false
&& curbufIsChanged() == 0
&& !autocmd_busy
&& curbuf->b_p_ro) {
curbuf_lock++;
apply_autocmds(EVENT_FILECHANGEDRO, NULL, NULL, false, curbuf);
curbuf_lock--;
if (!curbuf->b_p_ro) {
&& buf->b_p_ro) {
buf->b_ro_locked++;
apply_autocmds(EVENT_FILECHANGEDRO, NULL, NULL, false, buf);
buf->b_ro_locked--;
if (!buf->b_p_ro) {
return;
}
// Do what msg() does, but with a column offset if the warning should
@@ -70,7 +70,7 @@ void change_warning(int col)
ui_flush();
os_delay(1002L, true); // give the user time to think about it
}
curbuf->b_did_warn = true;
buf->b_did_warn = true;
redraw_cmdline = false; // don't redraw and erase the message
if (msg_row < Rows - 1) {
showmode();
@@ -91,7 +91,7 @@ void changed(void)
// Give a warning about changing a read-only file. This may also
// check-out the file, thus change "curbuf"!
change_warning(0);
change_warning(curbuf, 0);
// Create a swap file if that is wanted.
// Don't do this for "nofile" and "nowrite" buffer types.