Skip to content

Commit 1f2903c

Browse files
committed
patch 8.0.0761: options not set properly for a terminal buffer
Problem: Options of a buffer for a terminal window are not set properly. Solution: Add "terminal" value for 'buftype'. Make 'buftype' and 'bufhidden' not depend on the quickfix feature. Also set the buffer name and show "running" or "finished" in the window title.
1 parent 065f41c commit 1f2903c

12 files changed

Lines changed: 184 additions & 133 deletions

File tree

runtime/doc/options.txt

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*options.txt* For Vim version 8.0. Last change: 2017 Jul 15
1+
*options.txt* For Vim version 8.0. Last change: 2017 Jul 23
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -1319,8 +1319,6 @@ A jump table for the options with a short description can be found at |Q_op|.
13191319
'bufhidden' 'bh' string (default: "")
13201320
local to buffer
13211321
{not in Vi}
1322-
{not available when compiled without the |+quickfix|
1323-
feature}
13241322
This option specifies what happens when a buffer is no longer
13251323
displayed in a window:
13261324
<empty> follow the global 'hidden' option
@@ -1355,8 +1353,6 @@ A jump table for the options with a short description can be found at |Q_op|.
13551353
'buftype' 'bt' string (default: "")
13561354
local to buffer
13571355
{not in Vi}
1358-
{not available when compiled without the |+quickfix|
1359-
feature}
13601356
The value of this option specifies the type of a buffer:
13611357
<empty> normal buffer
13621358
nofile buffer which is not related to a file and will not be
@@ -1369,6 +1365,8 @@ A jump table for the options with a short description can be found at |Q_op|.
13691365
or list of locations |:lwindow|
13701366
help help buffer (you are not supposed to set this
13711367
manually)
1368+
terminal buffer for a |terminal| (you are not supposed to set
1369+
this manually)
13721370

13731371
This option is used together with 'bufhidden' and 'swapfile' to
13741372
specify special kinds of buffers. See |special-buffers|.
@@ -7760,19 +7758,26 @@ A jump table for the options with a short description can be found at |Q_op|.
77607758
{not in Vi}
77617759
The key that precedes a Vim command in a terminal window. Other keys
77627760
are sent to the job running in the window.
7763-
The string must be one key stroke.
7761+
The string must be one key stroke but can be multiple bytes.
77647762
NOT IMPLEMENTED YET
77657763

77667764

7767-
*'thesaurus'* *'tsr'*
7765+
*'termsize'* *'tms'*
77687766
'termsize' 'tms' string (default "")
77697767
local to window
77707768
{not in Vi}
77717769
Size of the |terminal| window. Format: {rows}x{columns}.
77727770
- When empty the terminal gets the size from the window.
7773-
- When set (e.g., "24x80") the terminal size is fixed. If the window
7774-
is smaller only the top-left part is displayed.
7775-
NOT IMPLEMENTED YET
7771+
- When set (e.g., "24x80") the terminal size is not adjusted to the
7772+
window size. If the window is smaller only the top-left part is
7773+
displayed.
7774+
When rows is zero then use the height of the window.
7775+
When columns is zero then use the width of the window.
7776+
For example: "30x0" uses 30 rows with the current window width.
7777+
Using "0x0" is the same as empty.
7778+
Note that the command running in the terminal window may still change
7779+
the size of the terminal. In that case the Vim window will be
7780+
adjusted to that size, if possible.
77767781

77777782
*'terse'* *'noterse'*
77787783
'terse' boolean (default off)

src/buffer.c

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,6 @@ close_buffer(
468468
int del_buf = (action == DOBUF_DEL || action == DOBUF_WIPE);
469469
int wipe_buf = (action == DOBUF_WIPE);
470470

471-
#ifdef FEAT_QUICKFIX
472471
/*
473472
* Force unloading or deleting when 'bufhidden' says so.
474473
* The caller must take care of NOT deleting/freeing when 'bufhidden' is
@@ -487,7 +486,6 @@ close_buffer(
487486
}
488487
else if (buf->b_p_bh[0] == 'u') /* 'bufhidden' == "unload" */
489488
unload_buf = TRUE;
490-
#endif
491489

492490
#ifdef FEAT_AUTOCMD
493491
/* Disallow deleting the buffer when it is locked (already being closed or
@@ -1982,16 +1980,14 @@ buflist_new(
19821980
return NULL;
19831981
# endif
19841982
#endif
1985-
#ifdef FEAT_QUICKFIX
1986-
# ifdef FEAT_AUTOCMD
1983+
#ifdef FEAT_AUTOCMD
19871984
if (buf == curbuf)
1988-
# endif
1985+
#endif
19891986
{
19901987
/* Make sure 'bufhidden' and 'buftype' are empty */
19911988
clear_string_option(&buf->b_p_bh);
19921989
clear_string_option(&buf->b_p_bt);
19931990
}
1994-
#endif
19951991
}
19961992
if (buf != curbuf || curbuf == NULL)
19971993
{
@@ -2165,10 +2161,8 @@ free_buf_options(
21652161
clear_string_option(&buf->b_p_fenc);
21662162
#endif
21672163
clear_string_option(&buf->b_p_ff);
2168-
#ifdef FEAT_QUICKFIX
21692164
clear_string_option(&buf->b_p_bh);
21702165
clear_string_option(&buf->b_p_bt);
2171-
#endif
21722166
}
21732167
#ifdef FEAT_FIND_ID
21742168
clear_string_option(&buf->b_p_def);
@@ -3668,9 +3662,21 @@ maketitle(void)
36683662
/* remove the file name */
36693663
p = gettail_sep(buf + off);
36703664
if (p == buf + off)
3671-
/* must be a help buffer */
3672-
vim_strncpy(buf + off, (char_u *)_("help"),
3665+
{
3666+
char *txt;
3667+
3668+
#ifdef FEAT_TERMINAL
3669+
if (curbuf->b_term != NULL)
3670+
txt = term_job_running(curbuf)
3671+
? _("running") : _("finished");
3672+
else
3673+
#endif
3674+
txt = _("help");
3675+
3676+
/* must be a help or terminal buffer */
3677+
vim_strncpy(buf + off, (char_u *)txt,
36733678
(size_t)(SPACE_FOR_DIR - off - 1));
3679+
}
36743680
else
36753681
*p = NUL;
36763682

src/channel.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4696,6 +4696,10 @@ job_cleanup(job_T *job)
46964696
* not use "job" after this! */
46974697
job_free(job);
46984698
}
4699+
4700+
#ifdef FEAT_TERMINAL
4701+
term_job_ended(job);
4702+
#endif
46994703
}
47004704

47014705
/*

src/ex_docmd.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8548,7 +8548,7 @@ ex_resize(exarg_T *eap)
85488548
{
85498549
if (*eap->arg == '-' || *eap->arg == '+')
85508550
n += curwin->w_height;
8551-
else if (n == 0 && eap->arg[0] == NUL) /* default is very wide */
8551+
else if (n == 0 && eap->arg[0] == NUL) /* default is very high */
85528552
n = 9999;
85538553
win_setheight_win((int)n, wp);
85548554
}
@@ -11679,10 +11679,7 @@ put_view(
1167911679
*/
1168011680
if ((*flagp & SSOP_FOLDS)
1168111681
&& wp->w_buffer->b_ffname != NULL
11682-
# ifdef FEAT_QUICKFIX
11683-
&& (*wp->w_buffer->b_p_bt == NUL || wp->w_buffer->b_help)
11684-
# endif
11685-
)
11682+
&& (*wp->w_buffer->b_p_bt == NUL || wp->w_buffer->b_help))
1168611683
{
1168711684
if (put_folds(fd, wp) == FAIL)
1168811685
return FAIL;

src/fileio.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6882,9 +6882,7 @@ buf_check_timestamp(
68826882
* this buffer. */
68836883
if (buf->b_ffname == NULL
68846884
|| buf->b_ml.ml_mfp == NULL
6885-
#if defined(FEAT_QUICKFIX)
68866885
|| *buf->b_p_bt != NUL
6887-
#endif
68886886
|| buf->b_saving
68896887
#ifdef FEAT_AUTOCMD
68906888
|| busy

src/option.c

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -287,10 +287,8 @@ static int p_bin;
287287
#ifdef FEAT_MBYTE
288288
static int p_bomb;
289289
#endif
290-
#if defined(FEAT_QUICKFIX)
291290
static char_u *p_bh;
292291
static char_u *p_bt;
293-
#endif
294292
static int p_bl;
295293
static int p_ci;
296294
#ifdef FEAT_CINDENT
@@ -720,26 +718,16 @@ static struct vimoption options[] =
720718
#endif
721719
SCRIPTID_INIT},
722720
{"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
723-
#if defined(FEAT_QUICKFIX)
724721
(char_u *)&p_bh, PV_BH,
725722
{(char_u *)"", (char_u *)0L}
726-
#else
727-
(char_u *)NULL, PV_NONE,
728-
{(char_u *)0L, (char_u *)0L}
729-
#endif
730723
SCRIPTID_INIT},
731724
{"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
732725
(char_u *)&p_bl, PV_BL,
733726
{(char_u *)1L, (char_u *)0L}
734727
SCRIPTID_INIT},
735728
{"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
736-
#if defined(FEAT_QUICKFIX)
737729
(char_u *)&p_bt, PV_BT,
738730
{(char_u *)"", (char_u *)0L}
739-
#else
740-
(char_u *)NULL, PV_NONE,
741-
{(char_u *)0L, (char_u *)0L}
742-
#endif
743731
SCRIPTID_INIT},
744732
{"casemap", "cmp", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
745733
#ifdef FEAT_MBYTE
@@ -3254,14 +3242,12 @@ static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
32543242
#ifdef FEAT_WINDOWS
32553243
static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
32563244
#endif
3257-
#if defined(FEAT_QUICKFIX)
3258-
# ifdef FEAT_AUTOCMD
3259-
static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
3260-
# else
3261-
static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
3262-
# endif
3263-
static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
3245+
#ifdef FEAT_AUTOCMD
3246+
static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "terminal", "acwrite", NULL};
3247+
#else
3248+
static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "terminal", NULL};
32643249
#endif
3250+
static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
32653251
static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
32663252
#ifdef FEAT_FOLDING
32673253
static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
@@ -5649,10 +5635,8 @@ check_options(void)
56495635
void
56505636
check_buf_options(buf_T *buf)
56515637
{
5652-
#if defined(FEAT_QUICKFIX)
56535638
check_string_option(&buf->b_p_bh);
56545639
check_string_option(&buf->b_p_bt);
5655-
#endif
56565640
#ifdef FEAT_MBYTE
56575641
check_string_option(&buf->b_p_fenc);
56585642
#endif
@@ -7115,7 +7099,6 @@ did_set_string_option(
71157099
}
71167100
#endif
71177101

7118-
#ifdef FEAT_QUICKFIX
71197102
/* When 'bufhidden' is set, check for valid value. */
71207103
else if (gvarp == &p_bh)
71217104
{
@@ -7130,20 +7113,19 @@ did_set_string_option(
71307113
errmsg = e_invarg;
71317114
else
71327115
{
7133-
# ifdef FEAT_WINDOWS
7116+
#ifdef FEAT_WINDOWS
71347117
if (curwin->w_status_height)
71357118
{
71367119
curwin->w_redr_status = TRUE;
71377120
redraw_later(VALID);
71387121
}
7139-
# endif
7122+
#endif
71407123
curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
7141-
# ifdef FEAT_TITLE
7124+
#ifdef FEAT_TITLE
71427125
redraw_titles();
7143-
# endif
7126+
#endif
71447127
}
71457128
}
7146-
#endif
71477129

71487130
#ifdef FEAT_STL_OPT
71497131
/* 'statusline' or 'rulerformat' */
@@ -10722,10 +10704,8 @@ get_varp(struct vimoption *p)
1072210704
#ifdef FEAT_MBYTE
1072310705
case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
1072410706
#endif
10725-
#if defined(FEAT_QUICKFIX)
1072610707
case PV_BH: return (char_u *)&(curbuf->b_p_bh);
1072710708
case PV_BT: return (char_u *)&(curbuf->b_p_bt);
10728-
#endif
1072910709
case PV_BL: return (char_u *)&(curbuf->b_p_bl);
1073010710
case PV_CI: return (char_u *)&(curbuf->b_p_ci);
1073110711
#ifdef FEAT_CINDENT
@@ -11119,10 +11099,8 @@ buf_copy_options(buf_T *buf, int flags)
1111911099
}
1112011100
if (buf->b_p_ff != NULL)
1112111101
buf->b_start_ffc = *buf->b_p_ff;
11122-
#if defined(FEAT_QUICKFIX)
1112311102
buf->b_p_bh = empty_option;
1112411103
buf->b_p_bt = empty_option;
11125-
#endif
1112611104
}
1112711105
else
1112811106
free_buf_options(buf, FALSE);
@@ -11284,10 +11262,8 @@ buf_copy_options(buf_T *buf, int flags)
1128411262
did_isk = TRUE;
1128511263
buf->b_p_ts = p_ts;
1128611264
buf->b_help = FALSE;
11287-
#ifdef FEAT_QUICKFIX
1128811265
if (buf->b_p_bt[0] == 'h')
1128911266
clear_string_option(&buf->b_p_bt);
11290-
#endif
1129111267
buf->b_p_ma = p_ma;
1129211268
}
1129311269
}

src/proto/quickfix.pro

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@ void ex_cclose(exarg_T *eap);
1212
void ex_copen(exarg_T *eap);
1313
void ex_cbottom(exarg_T *eap);
1414
linenr_T qf_current_entry(win_T *wp);
15-
int bt_quickfix(buf_T *buf);
16-
int bt_nofile(buf_T *buf);
17-
int bt_dontwrite(buf_T *buf);
18-
int bt_dontwrite_msg(buf_T *buf);
19-
int buf_hide(buf_T *buf);
2015
int grep_internal(cmdidx_T cmdidx);
2116
void ex_make(exarg_T *eap);
2217
int qf_get_size(exarg_T *eap);
@@ -33,4 +28,10 @@ int set_ref_in_quickfix(int copyID);
3328
void ex_cbuffer(exarg_T *eap);
3429
void ex_cexpr(exarg_T *eap);
3530
void ex_helpgrep(exarg_T *eap);
31+
int bt_quickfix(buf_T *buf);
32+
int bt_terminal(buf_T *buf);
33+
int bt_nofile(buf_T *buf);
34+
int bt_dontwrite(buf_T *buf);
35+
int bt_dontwrite_msg(buf_T *buf);
36+
int buf_hide(buf_T *buf);
3637
/* vim: set ft=c : */

src/proto/terminal.pro

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
void ex_terminal(exarg_T *eap);
33
void free_terminal(term_T *term);
44
void write_to_term(buf_T *buffer, char_u *msg, channel_T *channel);
5-
void term_update_window(win_T *wp);
65
void terminal_loop(void);
6+
void term_job_ended(job_T *job);
7+
int term_job_running(buf_T *buf);
8+
void term_update_window(win_T *wp);
79
/* vim: set ft=c : */

0 commit comments

Comments
 (0)