Skip to content

Commit 027387f

Browse files
committed
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)
1 parent fa03fd6 commit 027387f

10 files changed

Lines changed: 40 additions & 13 deletions

File tree

runtime/doc/editing.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,10 +1105,10 @@ The names can be in upper- or lowercase.
11051105
the last file in the argument list has not been
11061106
edited. See |:confirm| and 'confirm'. {not in Vi}
11071107

1108-
:q[uit]! Quit without writing, also when currently visible
1109-
buffers have changes. Does not exit when this is the
1110-
last window and there is a changed hidden buffer.
1111-
In this case, the first changed hidden buffer becomes
1108+
:q[uit]! Quit without writing, also when currentl buffer has
1109+
changes. If this is the last window and there is a
1110+
modified hidden buffer, the current buffer is
1111+
abandoned and the first changed hidden buffer becomes
11121112
the current buffer.
11131113
Use ":qall!" to exit always.
11141114

src/ex_cmds2.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1636,10 +1636,13 @@ add_bufnum(bufnrs, bufnump, nr)
16361636
/*
16371637
* Return TRUE if any buffer was changed and cannot be abandoned.
16381638
* That changed buffer becomes the current buffer.
1639+
* When "unload" is true the current buffer is unloaded instead of making it
1640+
* hidden. This is used for ":q!".
16391641
*/
16401642
int
1641-
check_changed_any(hidden)
1643+
check_changed_any(hidden, unload)
16421644
int hidden; /* Only check hidden buffers */
1645+
int unload;
16431646
{
16441647
int ret = FALSE;
16451648
buf_T *buf;
@@ -1750,7 +1753,7 @@ check_changed_any(hidden)
17501753

17511754
/* Open the changed buffer in the current window. */
17521755
if (buf != curbuf)
1753-
set_curbuf(buf, DOBUF_GOTO);
1756+
set_curbuf(buf, unload ? DOBUF_UNLOAD : DOBUF_GOTO);
17541757

17551758
theend:
17561759
vim_free(bufnrs);

src/ex_docmd.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7143,7 +7143,7 @@ ex_quit(eap)
71437143
| (eap->forceit ? CCGD_FORCEIT : 0)
71447144
| CCGD_EXCMD))
71457145
|| check_more(TRUE, eap->forceit) == FAIL
7146-
|| (only_one_window() && check_changed_any(eap->forceit)))
7146+
|| (only_one_window() && check_changed_any(eap->forceit, TRUE)))
71477147
{
71487148
not_exiting();
71497149
}
@@ -7214,7 +7214,7 @@ ex_quit_all(eap)
72147214
#endif
72157215

72167216
exiting = TRUE;
7217-
if (eap->forceit || !check_changed_any(FALSE))
7217+
if (eap->forceit || !check_changed_any(FALSE, FALSE))
72187218
getout(0);
72197219
not_exiting();
72207220
}
@@ -7609,7 +7609,7 @@ ex_exit(eap)
76097609
|| curbufIsChanged())
76107610
&& do_write(eap) == FAIL)
76117611
|| check_more(TRUE, eap->forceit) == FAIL
7612-
|| (only_one_window() && check_changed_any(eap->forceit)))
7612+
|| (only_one_window() && check_changed_any(eap->forceit, FALSE)))
76137613
{
76147614
not_exiting();
76157615
}

src/gui.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,7 @@ gui_shell_closed()
825825
# endif
826826
/* If there are changed buffers, present the user with a dialog if
827827
* possible, otherwise give an error message. */
828-
if (!check_changed_any(FALSE))
828+
if (!check_changed_any(FALSE, FALSE))
829829
getout(0);
830830

831831
exiting = FALSE;

src/gui_gtk_x11.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2003,7 +2003,7 @@ sm_client_check_changed_any(GnomeClient *client UNUSED,
20032003
* If there are changed buffers, present the user with
20042004
* a dialog if possible, otherwise give an error message.
20052005
*/
2006-
shutdown_cancelled = check_changed_any(FALSE);
2006+
shutdown_cancelled = check_changed_any(FALSE, FALSE);
20072007

20082008
exiting = FALSE;
20092009
cmdmod = save_cmdmod;

src/os_unix.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7132,7 +7132,7 @@ xsmp_handle_interaction(smc_conn, client_data)
71327132

71337133
save_cmdmod = cmdmod;
71347134
cmdmod.confirm = TRUE;
7135-
if (check_changed_any(FALSE))
7135+
if (check_changed_any(FALSE, FALSE))
71367136
/* Mustn't logout */
71377137
cancel_shutdown = True;
71387138
cmdmod = save_cmdmod;

src/proto/ex_cmds2.pro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ int check_changed __ARGS((buf_T *buf, int flags));
3939
void browse_save_fname __ARGS((buf_T *buf));
4040
void dialog_changed __ARGS((buf_T *buf, int checkall));
4141
int can_abandon __ARGS((buf_T *buf, int forceit));
42-
int check_changed_any __ARGS((int hidden));
42+
int check_changed_any __ARGS((int hidden, int unload));
4343
int check_fname __ARGS((void));
4444
int buf_write_all __ARGS((buf_T *buf, int forceit));
4545
int get_arglist __ARGS((garray_T *gap, char_u *str));

src/testdir/test31.in

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,26 @@ A 3:close!
6969
GA 4:all!
7070
:1wincmd w
7171
:w >>test.out
72+
:"
73+
:" test ":q!" and hidden buffer.
74+
:bw! Xtest1 Xtest2 Xtest3 Xtest4
75+
:sp Xtest1
76+
:wincmd w
77+
:bw!
78+
:set modified
79+
:bot sp Xtest2
80+
:set modified
81+
:bot sp Xtest3
82+
:set modified
83+
:wincmd t
84+
:hide
85+
:q!
86+
:w >>test.out
87+
:q!
88+
:w >>test.out
89+
:q!
90+
:call append(line('$'), "Oh, Not finished yet.")
91+
:w >>test.out
7292
:qa!
7393
ENDTEST
7494

src/testdir/test31.ok

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ testtext 1
1010
testtext 3 3 3
1111
testtext 1
1212
testtext 2 2 2
13+
testtext 3
14+
testtext 1

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,8 @@ static char *(features[]) =
741741

742742
static int included_patches[] =
743743
{ /* Add new patch number below this line */
744+
/**/
745+
1037,
744746
/**/
745747
1036,
746748
/**/

0 commit comments

Comments
 (0)