mirror of
https://github.com/neovim/neovim.git
synced 2025-09-16 08:18:17 +00:00
vim-patch:7.4.1037
Problem: Using "q!" when there is a modified hidden buffer does not unload
the current buffer, resulting in the need to abandon it again.
Solution: When using "q!" unload the current buffer when needed. (Yasuhiro
Matsumoto, Hirohito Higashi)
027387f70c
This commit is contained in:
@@ -1042,10 +1042,10 @@ The names can be in upper- or lowercase.
|
|||||||
the last file in the argument list has not been
|
the last file in the argument list has not been
|
||||||
edited. See |:confirm| and 'confirm'.
|
edited. See |:confirm| and 'confirm'.
|
||||||
|
|
||||||
:q[uit]! Quit without writing, also when currently visible
|
:q[uit]! Quit without writing, also when currentl buffer has
|
||||||
buffers have changes. Does not exit when this is the
|
changes. If this is the last window and there is a
|
||||||
last window and there is a changed hidden buffer.
|
modified hidden buffer, the current buffer is
|
||||||
In this case, the first changed hidden buffer becomes
|
abandoned and the first changed hidden buffer becomes
|
||||||
the current buffer.
|
the current buffer.
|
||||||
Use ":qall!" to exit always.
|
Use ":qall!" to exit always.
|
||||||
|
|
||||||
|
@@ -1241,16 +1241,18 @@ static void add_bufnum(int *bufnrs, int *bufnump, int nr)
|
|||||||
*bufnump = *bufnump + 1;
|
*bufnump = *bufnump + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/// Check if any buffer was changed and cannot be abandoned.
|
||||||
* Return TRUE if any buffer was changed and cannot be abandoned.
|
/// That changed buffer becomes the current buffer.
|
||||||
* That changed buffer becomes the current buffer.
|
/// When "unload" is true the current buffer is unloaded instead of making it
|
||||||
*/
|
/// hidden. This is used for ":q!".
|
||||||
int
|
///
|
||||||
check_changed_any (
|
/// @param[in] hidden specifies whether to check only hidden buffers.
|
||||||
int hidden /* Only check hidden buffers */
|
/// @param[in] unload specifies whether to unload, instead of hide, the buffer.
|
||||||
)
|
///
|
||||||
|
/// @returns true if any buffer is changed and cannot be abandoned
|
||||||
|
int check_changed_any(bool hidden, bool unload)
|
||||||
{
|
{
|
||||||
int ret = FALSE;
|
bool ret = false;
|
||||||
int save;
|
int save;
|
||||||
int i;
|
int i;
|
||||||
int bufnum = 0;
|
int bufnum = 0;
|
||||||
@@ -1346,9 +1348,10 @@ check_changed_any (
|
|||||||
}
|
}
|
||||||
buf_found:
|
buf_found:
|
||||||
|
|
||||||
/* Open the changed buffer in the current window. */
|
// Open the changed buffer in the current window.
|
||||||
if (buf != curbuf)
|
if (buf != curbuf) {
|
||||||
set_curbuf(buf, DOBUF_GOTO);
|
set_curbuf(buf, unload ? DOBUF_UNLOAD : DOBUF_GOTO);
|
||||||
|
}
|
||||||
|
|
||||||
theend:
|
theend:
|
||||||
xfree(bufnrs);
|
xfree(bufnrs);
|
||||||
|
@@ -5674,7 +5674,7 @@ static void ex_quit(exarg_T *eap)
|
|||||||
| (eap->forceit ? CCGD_FORCEIT : 0)
|
| (eap->forceit ? CCGD_FORCEIT : 0)
|
||||||
| CCGD_EXCMD))
|
| CCGD_EXCMD))
|
||||||
|| check_more(TRUE, eap->forceit) == FAIL
|
|| check_more(TRUE, eap->forceit) == FAIL
|
||||||
|| (only_one_window() && check_changed_any(eap->forceit))) {
|
|| (only_one_window() && check_changed_any(eap->forceit, true))) {
|
||||||
not_exiting();
|
not_exiting();
|
||||||
} else {
|
} else {
|
||||||
// quit last window
|
// quit last window
|
||||||
@@ -5723,9 +5723,10 @@ static void ex_quit_all(exarg_T *eap)
|
|||||||
if (curbuf_locked() || (curbuf->b_nwindows == 1 && curbuf->b_closing))
|
if (curbuf_locked() || (curbuf->b_nwindows == 1 && curbuf->b_closing))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
exiting = TRUE;
|
exiting = true;
|
||||||
if (eap->forceit || !check_changed_any(FALSE))
|
if (eap->forceit || !check_changed_any(false, false)) {
|
||||||
getout(0);
|
getout(0);
|
||||||
|
}
|
||||||
not_exiting();
|
not_exiting();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -6019,7 +6020,7 @@ static void ex_exit(exarg_T *eap)
|
|||||||
|| curbufIsChanged())
|
|| curbufIsChanged())
|
||||||
&& do_write(eap) == FAIL)
|
&& do_write(eap) == FAIL)
|
||||||
|| check_more(TRUE, eap->forceit) == FAIL
|
|| check_more(TRUE, eap->forceit) == FAIL
|
||||||
|| (only_one_window() && check_changed_any(eap->forceit))) {
|
|| (only_one_window() && check_changed_any(eap->forceit, false))) {
|
||||||
not_exiting();
|
not_exiting();
|
||||||
} else {
|
} else {
|
||||||
if (only_one_window()) /* quit last window, exit Vim */
|
if (only_one_window()) /* quit last window, exit Vim */
|
||||||
|
@@ -645,7 +645,7 @@ static int included_patches[] = {
|
|||||||
// 1040 NA
|
// 1040 NA
|
||||||
// 1039,
|
// 1039,
|
||||||
// 1038 NA
|
// 1038 NA
|
||||||
// 1037,
|
1037,
|
||||||
// 1036,
|
// 1036,
|
||||||
1035,
|
1035,
|
||||||
// 1034,
|
// 1034,
|
||||||
|
@@ -10,7 +10,7 @@
|
|||||||
-- :edit
|
-- :edit
|
||||||
|
|
||||||
local helpers = require('test.functional.helpers')
|
local helpers = require('test.functional.helpers')
|
||||||
local feed, insert = helpers.feed, helpers.insert
|
local feed, insert, source = helpers.feed, helpers.insert, helpers.source
|
||||||
local clear, execute, expect = helpers.clear, helpers.execute, helpers.expect
|
local clear, execute, expect = helpers.clear, helpers.execute, helpers.expect
|
||||||
|
|
||||||
describe('Commands that close windows and/or buffers', function()
|
describe('Commands that close windows and/or buffers', function()
|
||||||
@@ -84,6 +84,28 @@ describe('Commands that close windows and/or buffers', function()
|
|||||||
feed('GA 4<Esc>:all!<CR>')
|
feed('GA 4<Esc>:all!<CR>')
|
||||||
execute('1wincmd w')
|
execute('1wincmd w')
|
||||||
expect('testtext 2 2 2')
|
expect('testtext 2 2 2')
|
||||||
|
|
||||||
|
-- Test ":q!" and hidden buffer.
|
||||||
|
execute('bw! Xtest1 Xtest2 Xtest3 Xtest4')
|
||||||
|
execute('sp Xtest1')
|
||||||
|
execute('wincmd w')
|
||||||
|
execute('bw!')
|
||||||
|
execute('set modified')
|
||||||
|
execute('bot sp Xtest2')
|
||||||
|
execute('set modified')
|
||||||
|
execute('bot sp Xtest3')
|
||||||
|
execute('set modified')
|
||||||
|
execute('wincmd t')
|
||||||
|
execute('hide')
|
||||||
|
execute('q!')
|
||||||
|
expect('testtext 3')
|
||||||
|
execute('q!')
|
||||||
|
feed('<CR>')
|
||||||
|
expect('testtext 1')
|
||||||
|
source([[
|
||||||
|
q!
|
||||||
|
" Now nvim should have exited
|
||||||
|
throw "Oh, Not finished yet."]])
|
||||||
end)
|
end)
|
||||||
|
|
||||||
teardown(function()
|
teardown(function()
|
||||||
|
Reference in New Issue
Block a user