Skip to content

Commit

Permalink
patch 8.0.1651: cannot filter :ls output for terminal buffers
Browse files Browse the repository at this point in the history
Problem:    Cannot filter :ls output for terminal buffers.
Solution:   Add flags for terminal buffers. (Marcin Szamotulski, closes #2751)
  • Loading branch information
brammool committed Mar 29, 2018
1 parent 0c72fe4 commit 0751f51
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
12 changes: 6 additions & 6 deletions runtime/doc/windows.txt
@@ -1,4 +1,4 @@
*windows.txt* For Vim version 8.0. Last change: 2017 Sep 25 *windows.txt* For Vim version 8.0. Last change: 2018 Mar 29




VIM REFERENCE MANUAL by Bram Moolenaar VIM REFERENCE MANUAL by Bram Moolenaar
Expand Down Expand Up @@ -731,8 +731,7 @@ can also get to them with the buffer list commands, like ":bnext".
the current window. the current window.
{cmd} can contain '|' to concatenate several commands. {cmd} can contain '|' to concatenate several commands.
{cmd} must not open or close windows or reorder them. {cmd} must not open or close windows or reorder them.
{not in Vi} {not available when compiled without the {not in Vi}
|+listcmds| feature}
Also see |:tabdo|, |:argdo|, |:bufdo|, |:cdo|, |:ldo|, Also see |:tabdo|, |:argdo|, |:bufdo|, |:cdo|, |:ldo|,
|:cfdo| and |:lfdo| |:cfdo| and |:lfdo|


Expand Down Expand Up @@ -760,8 +759,7 @@ can also get to them with the buffer list commands, like ":bnext".
autocommand event is disabled by adding it to autocommand event is disabled by adding it to
'eventignore'. This considerably speeds up editing 'eventignore'. This considerably speeds up editing
each buffer. each buffer.
{not in Vi} {not available when compiled without the {not in Vi}
|+listcmds| feature}
Also see |:tabdo|, |:argdo|, |:windo|, |:cdo|, |:ldo|, Also see |:tabdo|, |:argdo|, |:windo|, |:cdo|, |:ldo|,
|:cfdo| and |:lfdo| |:cfdo| and |:lfdo|


Expand Down Expand Up @@ -974,7 +972,6 @@ is no word under the cursor, and a few other things: >
A hidden buffer is not displayed in a window, but is still loaded into memory. A hidden buffer is not displayed in a window, but is still loaded into memory.
This makes it possible to jump from file to file, without the need to read or This makes it possible to jump from file to file, without the need to read or
write the file every time you get another buffer in a window. write the file every time you get another buffer in a window.
{not available when compiled without the |+listcmds| feature}


*:buffer-!* *:buffer-!*
If the option 'hidden' ('hid') is set, abandoned buffers are kept for all If the option 'hidden' ('hid') is set, abandoned buffers are kept for all
Expand Down Expand Up @@ -1049,6 +1046,9 @@ list of buffers. |unlisted-buffer|
x buffers with a read error x buffers with a read error
% current buffer % current buffer
# alternate buffer # alternate buffer
R terminal buffers with a running job
F terminal buffers with a finished job
? terminal buffers without a job: `:terminal NONE`
Combining flags means they are "and"ed together, e.g.: Combining flags means they are "and"ed together, e.g.:
h+ hidden buffers which are modified h+ hidden buffers which are modified
a+ active buffers which are modified a+ active buffers which are modified
Expand Down
20 changes: 18 additions & 2 deletions src/buffer.c
Expand Up @@ -2930,18 +2930,34 @@ buflist_list(exarg_T *eap)
int i; int i;
int ro_char; int ro_char;
int changed_char; int changed_char;
#ifdef FEAT_TERMINAL
int job_running;
int job_none_open;
#endif


for (buf = firstbuf; buf != NULL && !got_int; buf = buf->b_next) for (buf = firstbuf; buf != NULL && !got_int; buf = buf->b_next)
{ {
#ifdef FEAT_TERMINAL
job_running = term_job_running(buf->b_term);
job_none_open = job_running && term_none_open(buf->b_term);
#endif
/* skip unlisted buffers, unless ! was used */ /* skip unlisted buffers, unless ! was used */
if ((!buf->b_p_bl && !eap->forceit && !vim_strchr(eap->arg, 'u')) if ((!buf->b_p_bl && !eap->forceit && !vim_strchr(eap->arg, 'u'))
|| (vim_strchr(eap->arg, 'u') && buf->b_p_bl) || (vim_strchr(eap->arg, 'u') && buf->b_p_bl)
|| (vim_strchr(eap->arg, '+') || (vim_strchr(eap->arg, '+')
&& ((buf->b_flags & BF_READERR) || !bufIsChanged(buf))) && ((buf->b_flags & BF_READERR) || !bufIsChanged(buf)))
|| (vim_strchr(eap->arg, 'a') || (vim_strchr(eap->arg, 'a')
&& (buf->b_ml.ml_mfp == NULL || buf->b_nwindows == 0)) && (buf->b_ml.ml_mfp == NULL || buf->b_nwindows == 0))
|| (vim_strchr(eap->arg, 'h') || (vim_strchr(eap->arg, 'h')
&& (buf->b_ml.ml_mfp == NULL || buf->b_nwindows != 0)) && (buf->b_ml.ml_mfp == NULL || buf->b_nwindows != 0))
#ifdef FEAT_TERMINAL
|| (vim_strchr(eap->arg, 'R')
&& (!job_running || (job_running && job_none_open)))
|| (vim_strchr(eap->arg, '?')
&& (!job_running || (job_running && !job_none_open)))
|| (vim_strchr(eap->arg, 'F')
&& (job_running || buf->b_term == NULL))
#endif
|| (vim_strchr(eap->arg, '-') && buf->b_p_ma) || (vim_strchr(eap->arg, '-') && buf->b_p_ma)
|| (vim_strchr(eap->arg, '=') && !buf->b_p_ro) || (vim_strchr(eap->arg, '=') && !buf->b_p_ro)
|| (vim_strchr(eap->arg, 'x') && !(buf->b_flags & BF_READERR)) || (vim_strchr(eap->arg, 'x') && !(buf->b_flags & BF_READERR))
Expand Down
6 changes: 6 additions & 0 deletions src/testdir/test_terminal.vim
Expand Up @@ -45,11 +45,17 @@ func Test_terminal_basic()
call assert_equal('t', mode()) call assert_equal('t', mode())
call assert_equal('yes', b:done) call assert_equal('yes', b:done)
call assert_match('%aR[^\n]*running]', execute('ls')) call assert_match('%aR[^\n]*running]', execute('ls'))
call assert_match('%aR[^\n]*running]', execute('ls R'))
call assert_notmatch('%[^\n]*running]', execute('ls F'))
call assert_notmatch('%[^\n]*running]', execute('ls ?'))


call Stop_shell_in_terminal(buf) call Stop_shell_in_terminal(buf)
call term_wait(buf) call term_wait(buf)
call assert_equal('n', mode()) call assert_equal('n', mode())
call assert_match('%aF[^\n]*finished]', execute('ls')) call assert_match('%aF[^\n]*finished]', execute('ls'))
call assert_match('%aF[^\n]*finished]', execute('ls F'))
call assert_notmatch('%[^\n]*finished]', execute('ls R'))
call assert_notmatch('%[^\n]*finished]', execute('ls ?'))


" closing window wipes out the terminal buffer a with finished job " closing window wipes out the terminal buffer a with finished job
close close
Expand Down
2 changes: 2 additions & 0 deletions src/version.c
Expand Up @@ -762,6 +762,8 @@ static char *(features[]) =


static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
1651,
/**/ /**/
1650, 1650,
/**/ /**/
Expand Down

0 comments on commit 0751f51

Please sign in to comment.