From 070f8df4dd0f9202d8ebc412ce267dc9aa7c8e71 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Fri, 2 Feb 2018 20:39:48 +0100 Subject: [PATCH] vim-patch:8.0.1204: a QuitPre autocommand may get the wrong file name Problem: A QuitPre autocommand may get the wrong file name. Solution: Pass the buffer being closed to apply_autocmds(). (Rich Howe) https://github.com/vim/vim/commit/87ffb5c1a3aa506a1be07af4e794b3753f839dc3 --- src/nvim/ex_docmd.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 34d8546653..bd46c65c15 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -5974,16 +5974,18 @@ static void ex_quit(exarg_T *eap) wp = curwin; } - apply_autocmds(EVENT_QUITPRE, NULL, NULL, false, curbuf); + // Refuse to quit when locked. + if (curbuf_locked()) { + return; + } + apply_autocmds(EVENT_QUITPRE, NULL, NULL, false, wp->w_buffer); // Refuse to quit when locked or when the buffer in the last window is // being closed (can only happen in autocommands). - if (curbuf_locked() - || !win_valid(wp) + if (!win_valid(wp) || (wp->w_buffer->b_nwindows == 1 && wp->w_buffer->b_locked > 0)) { return; } - /* * If there are more files or windows we won't exit. */