Mercurial > vim
comparison src/buffer.c @ 30747:58592b6af4e2 v9.0.0708
patch 9.0.0708: :confirm does not work properly for a terminal buffer
Commit: https://github.com/vim/vim/commit/15b314ffbb93f934b72cb71aa8f881caea026256
Author: Yee Cheng Chin <ychin.git@gmail.com>
Date: Sun Oct 9 18:53:32 2022 +0100
patch 9.0.0708: :confirm does not work properly for a terminal buffer
Problem: :confirm does not work properly for a terminal buffer.
Solution: Handle :confirm for a terminal buffer differently. (Yee Cheng
Chin, closes #11312)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 09 Oct 2022 20:00:04 +0200 |
parents | 37aa9fd2ed72 |
children | 9889ff80547e |
comparison
equal
deleted
inserted
replaced
30746:7497bddb55b3 | 30747:58592b6af4e2 |
---|---|
47 static int value_changed(char_u *str, char_u **last); | 47 static int value_changed(char_u *str, char_u **last); |
48 static int append_arg_number(win_T *wp, char_u *buf, int buflen, int add_file); | 48 static int append_arg_number(win_T *wp, char_u *buf, int buflen, int add_file); |
49 static void free_buffer(buf_T *); | 49 static void free_buffer(buf_T *); |
50 static void free_buffer_stuff(buf_T *buf, int free_options); | 50 static void free_buffer_stuff(buf_T *buf, int free_options); |
51 static int bt_nofileread(buf_T *buf); | 51 static int bt_nofileread(buf_T *buf); |
52 static void no_write_message_buf(buf_T *buf); | |
52 | 53 |
53 #ifdef UNIX | 54 #ifdef UNIX |
54 # define dev_T dev_t | 55 # define dev_T dev_t |
55 #else | 56 #else |
56 # define dev_T unsigned | 57 # define dev_T unsigned |
1365 if ((flags & DOBUF_FORCEIT) == 0 && bufIsChanged(buf)) | 1366 if ((flags & DOBUF_FORCEIT) == 0 && bufIsChanged(buf)) |
1366 { | 1367 { |
1367 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) | 1368 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) |
1368 if ((p_confirm || (cmdmod.cmod_flags & CMOD_CONFIRM)) && p_write) | 1369 if ((p_confirm || (cmdmod.cmod_flags & CMOD_CONFIRM)) && p_write) |
1369 { | 1370 { |
1370 dialog_changed(buf, FALSE); | 1371 # ifdef FEAT_TERMINAL |
1371 if (!bufref_valid(&bufref)) | 1372 if (term_job_running(buf->b_term)) |
1372 // Autocommand deleted buffer, oops! It's not changed | 1373 { |
1373 // now. | 1374 if (term_confirm_stop(buf) == FAIL) |
1374 return FAIL; | 1375 return FAIL; |
1375 // If it's still changed fail silently, the dialog already | 1376 } |
1376 // mentioned why it fails. | 1377 else |
1377 if (bufIsChanged(buf)) | 1378 # endif |
1378 return FAIL; | 1379 { |
1380 dialog_changed(buf, FALSE); | |
1381 if (!bufref_valid(&bufref)) | |
1382 // Autocommand deleted buffer, oops! It's not changed | |
1383 // now. | |
1384 return FAIL; | |
1385 // If it's still changed fail silently, the dialog already | |
1386 // mentioned why it fails. | |
1387 if (bufIsChanged(buf)) | |
1388 return FAIL; | |
1389 } | |
1379 } | 1390 } |
1380 else | 1391 else |
1381 #endif | 1392 #endif |
1382 { | 1393 { |
1383 semsg(_(e_no_write_since_last_change_for_buffer_nr_add_bang_to_override), | 1394 no_write_message_buf(buf); |
1384 buf->b_fnum); | |
1385 return FAIL; | 1395 return FAIL; |
1386 } | 1396 } |
1387 } | 1397 } |
1388 | 1398 |
1389 // When closing the current buffer stop Visual mode. | 1399 // When closing the current buffer stop Visual mode. |
1550 if (action == DOBUF_GOTO && !can_abandon(curbuf, (flags & DOBUF_FORCEIT))) | 1560 if (action == DOBUF_GOTO && !can_abandon(curbuf, (flags & DOBUF_FORCEIT))) |
1551 { | 1561 { |
1552 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) | 1562 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) |
1553 if ((p_confirm || (cmdmod.cmod_flags & CMOD_CONFIRM)) && p_write) | 1563 if ((p_confirm || (cmdmod.cmod_flags & CMOD_CONFIRM)) && p_write) |
1554 { | 1564 { |
1555 bufref_T bufref; | 1565 # ifdef FEAT_TERMINAL |
1556 | 1566 if (term_job_running(curbuf->b_term)) |
1557 set_bufref(&bufref, buf); | 1567 { |
1558 dialog_changed(curbuf, FALSE); | 1568 if (term_confirm_stop(curbuf) == FAIL) |
1559 if (!bufref_valid(&bufref)) | 1569 return FAIL; |
1560 // Autocommand deleted buffer, oops! | 1570 // Manually kill the terminal here because this command will |
1561 return FAIL; | 1571 // hide it otherwise. |
1562 } | 1572 free_terminal(curbuf); |
1563 if (bufIsChanged(curbuf)) | 1573 } |
1574 else | |
1575 # endif | |
1576 { | |
1577 bufref_T bufref; | |
1578 | |
1579 set_bufref(&bufref, buf); | |
1580 dialog_changed(curbuf, FALSE); | |
1581 if (!bufref_valid(&bufref)) | |
1582 // Autocommand deleted buffer, oops! | |
1583 return FAIL; | |
1584 | |
1585 if (bufIsChanged(curbuf)) | |
1586 { | |
1587 no_write_message(); | |
1588 return FAIL; | |
1589 } | |
1590 } | |
1591 } | |
1592 else | |
1564 #endif | 1593 #endif |
1565 { | 1594 { |
1566 no_write_message(); | 1595 no_write_message(); |
1567 return FAIL; | 1596 return FAIL; |
1568 } | 1597 } |
1937 shorten_fnames(TRUE); | 1966 shorten_fnames(TRUE); |
1938 last_chdir_reason = "autochdir"; | 1967 last_chdir_reason = "autochdir"; |
1939 } | 1968 } |
1940 } | 1969 } |
1941 #endif | 1970 #endif |
1971 | |
1972 static void | |
1973 no_write_message_buf(buf_T *buf UNUSED) | |
1974 { | |
1975 #ifdef FEAT_TERMINAL | |
1976 if (term_job_running(buf->b_term)) | |
1977 emsg(_(e_job_still_running_add_bang_to_end_the_job)); | |
1978 else | |
1979 #endif | |
1980 semsg(_(e_no_write_since_last_change_for_buffer_nr_add_bang_to_override), | |
1981 buf->b_fnum); | |
1982 } | |
1942 | 1983 |
1943 void | 1984 void |
1944 no_write_message(void) | 1985 no_write_message(void) |
1945 { | 1986 { |
1946 #ifdef FEAT_TERMINAL | 1987 #ifdef FEAT_TERMINAL |
5749 return buf != NULL && buf->b_p_bt[0] == 'n' && buf->b_p_bt[2] == 'f'; | 5790 return buf != NULL && buf->b_p_bt[0] == 'n' && buf->b_p_bt[2] == 'f'; |
5750 } | 5791 } |
5751 #endif | 5792 #endif |
5752 | 5793 |
5753 /* | 5794 /* |
5754 * Return TRUE if "buf" is a "nowrite", "nofile", "terminal" or "prompt" | 5795 * Return TRUE if "buf" is a "nowrite", "nofile", "terminal", "prompt", or |
5755 * buffer. | 5796 * "popup" buffer. |
5756 */ | 5797 */ |
5757 int | 5798 int |
5758 bt_dontwrite(buf_T *buf) | 5799 bt_dontwrite(buf_T *buf) |
5759 { | 5800 { |
5760 return buf != NULL && (buf->b_p_bt[0] == 'n' | 5801 return buf != NULL && (buf->b_p_bt[0] == 'n' |