Skip to content

Commit

Permalink
patch 8.0.0761: options not set properly for a terminal buffer
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
brammool committed Jul 23, 2017
1 parent 065f41c commit 1f2903c
Show file tree
Hide file tree
Showing 12 changed files with 184 additions and 133 deletions.
25 changes: 15 additions & 10 deletions runtime/doc/options.txt
@@ -1,4 +1,4 @@
*options.txt* For Vim version 8.0. Last change: 2017 Jul 15 *options.txt* For Vim version 8.0. Last change: 2017 Jul 23




VIM REFERENCE MANUAL by Bram Moolenaar VIM REFERENCE MANUAL by Bram Moolenaar
Expand Down Expand Up @@ -1319,8 +1319,6 @@ A jump table for the options with a short description can be found at |Q_op|.
'bufhidden' 'bh' string (default: "") 'bufhidden' 'bh' string (default: "")
local to buffer local to buffer
{not in Vi} {not in Vi}
{not available when compiled without the |+quickfix|
feature}
This option specifies what happens when a buffer is no longer This option specifies what happens when a buffer is no longer
displayed in a window: displayed in a window:
<empty> follow the global 'hidden' option <empty> follow the global 'hidden' option
Expand Down Expand Up @@ -1355,8 +1353,6 @@ A jump table for the options with a short description can be found at |Q_op|.
'buftype' 'bt' string (default: "") 'buftype' 'bt' string (default: "")
local to buffer local to buffer
{not in Vi} {not in Vi}
{not available when compiled without the |+quickfix|
feature}
The value of this option specifies the type of a buffer: The value of this option specifies the type of a buffer:
<empty> normal buffer <empty> normal buffer
nofile buffer which is not related to a file and will not be nofile buffer which is not related to a file and will not be
Expand All @@ -1369,6 +1365,8 @@ A jump table for the options with a short description can be found at |Q_op|.
or list of locations |:lwindow| or list of locations |:lwindow|
help help buffer (you are not supposed to set this help help buffer (you are not supposed to set this
manually) manually)
terminal buffer for a |terminal| (you are not supposed to set
this manually)


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




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


*'terse'* *'noterse'* *'terse'* *'noterse'*
'terse' boolean (default off) 'terse' boolean (default off)
Expand Down
26 changes: 16 additions & 10 deletions src/buffer.c
Expand Up @@ -468,7 +468,6 @@ close_buffer(
int del_buf = (action == DOBUF_DEL || action == DOBUF_WIPE); int del_buf = (action == DOBUF_DEL || action == DOBUF_WIPE);
int wipe_buf = (action == DOBUF_WIPE); int wipe_buf = (action == DOBUF_WIPE);


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


#ifdef FEAT_AUTOCMD #ifdef FEAT_AUTOCMD
/* Disallow deleting the buffer when it is locked (already being closed or /* Disallow deleting the buffer when it is locked (already being closed or
Expand Down Expand Up @@ -1982,16 +1980,14 @@ buflist_new(
return NULL; return NULL;
# endif # endif
#endif #endif
#ifdef FEAT_QUICKFIX #ifdef FEAT_AUTOCMD
# ifdef FEAT_AUTOCMD
if (buf == curbuf) if (buf == curbuf)
# endif #endif
{ {
/* Make sure 'bufhidden' and 'buftype' are empty */ /* Make sure 'bufhidden' and 'buftype' are empty */
clear_string_option(&buf->b_p_bh); clear_string_option(&buf->b_p_bh);
clear_string_option(&buf->b_p_bt); clear_string_option(&buf->b_p_bt);
} }
#endif
} }
if (buf != curbuf || curbuf == NULL) if (buf != curbuf || curbuf == NULL)
{ {
Expand Down Expand Up @@ -2165,10 +2161,8 @@ free_buf_options(
clear_string_option(&buf->b_p_fenc); clear_string_option(&buf->b_p_fenc);
#endif #endif
clear_string_option(&buf->b_p_ff); clear_string_option(&buf->b_p_ff);
#ifdef FEAT_QUICKFIX
clear_string_option(&buf->b_p_bh); clear_string_option(&buf->b_p_bh);
clear_string_option(&buf->b_p_bt); clear_string_option(&buf->b_p_bt);
#endif
} }
#ifdef FEAT_FIND_ID #ifdef FEAT_FIND_ID
clear_string_option(&buf->b_p_def); clear_string_option(&buf->b_p_def);
Expand Down Expand Up @@ -3668,9 +3662,21 @@ maketitle(void)
/* remove the file name */ /* remove the file name */
p = gettail_sep(buf + off); p = gettail_sep(buf + off);
if (p == buf + off) if (p == buf + off)
/* must be a help buffer */ {
vim_strncpy(buf + off, (char_u *)_("help"), char *txt;

#ifdef FEAT_TERMINAL
if (curbuf->b_term != NULL)
txt = term_job_running(curbuf)
? _("running") : _("finished");
else
#endif
txt = _("help");

/* must be a help or terminal buffer */
vim_strncpy(buf + off, (char_u *)txt,
(size_t)(SPACE_FOR_DIR - off - 1)); (size_t)(SPACE_FOR_DIR - off - 1));
}
else else
*p = NUL; *p = NUL;


Expand Down
4 changes: 4 additions & 0 deletions src/channel.c
Expand Up @@ -4696,6 +4696,10 @@ job_cleanup(job_T *job)
* not use "job" after this! */ * not use "job" after this! */
job_free(job); job_free(job);
} }

#ifdef FEAT_TERMINAL
term_job_ended(job);
#endif
} }


/* /*
Expand Down
7 changes: 2 additions & 5 deletions src/ex_docmd.c
Expand Up @@ -8548,7 +8548,7 @@ ex_resize(exarg_T *eap)
{ {
if (*eap->arg == '-' || *eap->arg == '+') if (*eap->arg == '-' || *eap->arg == '+')
n += curwin->w_height; n += curwin->w_height;
else if (n == 0 && eap->arg[0] == NUL) /* default is very wide */ else if (n == 0 && eap->arg[0] == NUL) /* default is very high */
n = 9999; n = 9999;
win_setheight_win((int)n, wp); win_setheight_win((int)n, wp);
} }
Expand Down Expand Up @@ -11679,10 +11679,7 @@ put_view(
*/ */
if ((*flagp & SSOP_FOLDS) if ((*flagp & SSOP_FOLDS)
&& wp->w_buffer->b_ffname != NULL && wp->w_buffer->b_ffname != NULL
# ifdef FEAT_QUICKFIX && (*wp->w_buffer->b_p_bt == NUL || wp->w_buffer->b_help))
&& (*wp->w_buffer->b_p_bt == NUL || wp->w_buffer->b_help)
# endif
)
{ {
if (put_folds(fd, wp) == FAIL) if (put_folds(fd, wp) == FAIL)
return FAIL; return FAIL;
Expand Down
2 changes: 0 additions & 2 deletions src/fileio.c
Expand Up @@ -6882,9 +6882,7 @@ buf_check_timestamp(
* this buffer. */ * this buffer. */
if (buf->b_ffname == NULL if (buf->b_ffname == NULL
|| buf->b_ml.ml_mfp == NULL || buf->b_ml.ml_mfp == NULL
#if defined(FEAT_QUICKFIX)
|| *buf->b_p_bt != NUL || *buf->b_p_bt != NUL
#endif
|| buf->b_saving || buf->b_saving
#ifdef FEAT_AUTOCMD #ifdef FEAT_AUTOCMD
|| busy || busy
Expand Down
42 changes: 9 additions & 33 deletions src/option.c
Expand Up @@ -287,10 +287,8 @@ static int p_bin;
#ifdef FEAT_MBYTE #ifdef FEAT_MBYTE
static int p_bomb; static int p_bomb;
#endif #endif
#if defined(FEAT_QUICKFIX)
static char_u *p_bh; static char_u *p_bh;
static char_u *p_bt; static char_u *p_bt;
#endif
static int p_bl; static int p_bl;
static int p_ci; static int p_ci;
#ifdef FEAT_CINDENT #ifdef FEAT_CINDENT
Expand Down Expand Up @@ -720,26 +718,16 @@ static struct vimoption options[] =
#endif #endif
SCRIPTID_INIT}, SCRIPTID_INIT},
{"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB, {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
#if defined(FEAT_QUICKFIX)
(char_u *)&p_bh, PV_BH, (char_u *)&p_bh, PV_BH,
{(char_u *)"", (char_u *)0L} {(char_u *)"", (char_u *)0L}
#else
(char_u *)NULL, PV_NONE,
{(char_u *)0L, (char_u *)0L}
#endif
SCRIPTID_INIT}, SCRIPTID_INIT},
{"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB, {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
(char_u *)&p_bl, PV_BL, (char_u *)&p_bl, PV_BL,
{(char_u *)1L, (char_u *)0L} {(char_u *)1L, (char_u *)0L}
SCRIPTID_INIT}, SCRIPTID_INIT},
{"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB, {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
#if defined(FEAT_QUICKFIX)
(char_u *)&p_bt, PV_BT, (char_u *)&p_bt, PV_BT,
{(char_u *)"", (char_u *)0L} {(char_u *)"", (char_u *)0L}
#else
(char_u *)NULL, PV_NONE,
{(char_u *)0L, (char_u *)0L}
#endif
SCRIPTID_INIT}, SCRIPTID_INIT},
{"casemap", "cmp", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP, {"casemap", "cmp", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
#ifdef FEAT_MBYTE #ifdef FEAT_MBYTE
Expand Down Expand Up @@ -3254,14 +3242,12 @@ static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
#ifdef FEAT_WINDOWS #ifdef FEAT_WINDOWS
static char *(p_ead_values[]) = {"both", "ver", "hor", NULL}; static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
#endif #endif
#if defined(FEAT_QUICKFIX) #ifdef FEAT_AUTOCMD
# ifdef FEAT_AUTOCMD static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "terminal", "acwrite", NULL};
static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL}; #else
# else static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "terminal", NULL};
static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
# endif
static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
#endif #endif
static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
static char *(p_bs_values[]) = {"indent", "eol", "start", NULL}; static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
#ifdef FEAT_FOLDING #ifdef FEAT_FOLDING
static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax", static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Expand Down Expand Up @@ -5649,10 +5635,8 @@ check_options(void)
void void
check_buf_options(buf_T *buf) check_buf_options(buf_T *buf)
{ {
#if defined(FEAT_QUICKFIX)
check_string_option(&buf->b_p_bh); check_string_option(&buf->b_p_bh);
check_string_option(&buf->b_p_bt); check_string_option(&buf->b_p_bt);
#endif
#ifdef FEAT_MBYTE #ifdef FEAT_MBYTE
check_string_option(&buf->b_p_fenc); check_string_option(&buf->b_p_fenc);
#endif #endif
Expand Down Expand Up @@ -7115,7 +7099,6 @@ did_set_string_option(
} }
#endif #endif


#ifdef FEAT_QUICKFIX
/* When 'bufhidden' is set, check for valid value. */ /* When 'bufhidden' is set, check for valid value. */
else if (gvarp == &p_bh) else if (gvarp == &p_bh)
{ {
Expand All @@ -7130,20 +7113,19 @@ did_set_string_option(
errmsg = e_invarg; errmsg = e_invarg;
else else
{ {
# ifdef FEAT_WINDOWS #ifdef FEAT_WINDOWS
if (curwin->w_status_height) if (curwin->w_status_height)
{ {
curwin->w_redr_status = TRUE; curwin->w_redr_status = TRUE;
redraw_later(VALID); redraw_later(VALID);
} }
# endif #endif
curbuf->b_help = (curbuf->b_p_bt[0] == 'h'); curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
# ifdef FEAT_TITLE #ifdef FEAT_TITLE
redraw_titles(); redraw_titles();
# endif #endif
} }
} }
#endif


#ifdef FEAT_STL_OPT #ifdef FEAT_STL_OPT
/* 'statusline' or 'rulerformat' */ /* 'statusline' or 'rulerformat' */
Expand Down Expand Up @@ -10722,10 +10704,8 @@ get_varp(struct vimoption *p)
#ifdef FEAT_MBYTE #ifdef FEAT_MBYTE
case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb); case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
#endif #endif
#if defined(FEAT_QUICKFIX)
case PV_BH: return (char_u *)&(curbuf->b_p_bh); case PV_BH: return (char_u *)&(curbuf->b_p_bh);
case PV_BT: return (char_u *)&(curbuf->b_p_bt); case PV_BT: return (char_u *)&(curbuf->b_p_bt);
#endif
case PV_BL: return (char_u *)&(curbuf->b_p_bl); case PV_BL: return (char_u *)&(curbuf->b_p_bl);
case PV_CI: return (char_u *)&(curbuf->b_p_ci); case PV_CI: return (char_u *)&(curbuf->b_p_ci);
#ifdef FEAT_CINDENT #ifdef FEAT_CINDENT
Expand Down Expand Up @@ -11119,10 +11099,8 @@ buf_copy_options(buf_T *buf, int flags)
} }
if (buf->b_p_ff != NULL) if (buf->b_p_ff != NULL)
buf->b_start_ffc = *buf->b_p_ff; buf->b_start_ffc = *buf->b_p_ff;
#if defined(FEAT_QUICKFIX)
buf->b_p_bh = empty_option; buf->b_p_bh = empty_option;
buf->b_p_bt = empty_option; buf->b_p_bt = empty_option;
#endif
} }
else else
free_buf_options(buf, FALSE); free_buf_options(buf, FALSE);
Expand Down Expand Up @@ -11284,10 +11262,8 @@ buf_copy_options(buf_T *buf, int flags)
did_isk = TRUE; did_isk = TRUE;
buf->b_p_ts = p_ts; buf->b_p_ts = p_ts;
buf->b_help = FALSE; buf->b_help = FALSE;
#ifdef FEAT_QUICKFIX
if (buf->b_p_bt[0] == 'h') if (buf->b_p_bt[0] == 'h')
clear_string_option(&buf->b_p_bt); clear_string_option(&buf->b_p_bt);
#endif
buf->b_p_ma = p_ma; buf->b_p_ma = p_ma;
} }
} }
Expand Down
11 changes: 6 additions & 5 deletions src/proto/quickfix.pro
Expand Up @@ -12,11 +12,6 @@ void ex_cclose(exarg_T *eap);
void ex_copen(exarg_T *eap); void ex_copen(exarg_T *eap);
void ex_cbottom(exarg_T *eap); void ex_cbottom(exarg_T *eap);
linenr_T qf_current_entry(win_T *wp); linenr_T qf_current_entry(win_T *wp);
int bt_quickfix(buf_T *buf);
int bt_nofile(buf_T *buf);
int bt_dontwrite(buf_T *buf);
int bt_dontwrite_msg(buf_T *buf);
int buf_hide(buf_T *buf);
int grep_internal(cmdidx_T cmdidx); int grep_internal(cmdidx_T cmdidx);
void ex_make(exarg_T *eap); void ex_make(exarg_T *eap);
int qf_get_size(exarg_T *eap); int qf_get_size(exarg_T *eap);
Expand All @@ -33,4 +28,10 @@ int set_ref_in_quickfix(int copyID);
void ex_cbuffer(exarg_T *eap); void ex_cbuffer(exarg_T *eap);
void ex_cexpr(exarg_T *eap); void ex_cexpr(exarg_T *eap);
void ex_helpgrep(exarg_T *eap); void ex_helpgrep(exarg_T *eap);
int bt_quickfix(buf_T *buf);
int bt_terminal(buf_T *buf);
int bt_nofile(buf_T *buf);
int bt_dontwrite(buf_T *buf);
int bt_dontwrite_msg(buf_T *buf);
int buf_hide(buf_T *buf);
/* vim: set ft=c : */ /* vim: set ft=c : */
4 changes: 3 additions & 1 deletion src/proto/terminal.pro
Expand Up @@ -2,6 +2,8 @@
void ex_terminal(exarg_T *eap); void ex_terminal(exarg_T *eap);
void free_terminal(term_T *term); void free_terminal(term_T *term);
void write_to_term(buf_T *buffer, char_u *msg, channel_T *channel); void write_to_term(buf_T *buffer, char_u *msg, channel_T *channel);
void term_update_window(win_T *wp);
void terminal_loop(void); void terminal_loop(void);
void term_job_ended(job_T *job);
int term_job_running(buf_T *buf);
void term_update_window(win_T *wp);
/* vim: set ft=c : */ /* vim: set ft=c : */

0 comments on commit 1f2903c

Please sign in to comment.