Skip to content

Commit 0751f51

Browse files
committed
patch 8.0.1651: cannot filter :ls output for terminal buffers
Problem: Cannot filter :ls output for terminal buffers. Solution: Add flags for terminal buffers. (Marcin Szamotulski, closes #2751)
1 parent 0c72fe4 commit 0751f51

4 files changed

Lines changed: 32 additions & 8 deletions

File tree

‎runtime/doc/windows.txt‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*windows.txt* For Vim version 8.0. Last change: 2017 Sep 25
1+
*windows.txt* For Vim version 8.0. Last change: 2018 Mar 29
22

33

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

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

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

979976
*:buffer-!*
980977
If the option 'hidden' ('hid') is set, abandoned buffers are kept for all
@@ -1049,6 +1046,9 @@ list of buffers. |unlisted-buffer|
10491046
x buffers with a read error
10501047
% current buffer
10511048
# alternate buffer
1049+
R terminal buffers with a running job
1050+
F terminal buffers with a finished job
1051+
? terminal buffers without a job: `:terminal NONE`
10521052
Combining flags means they are "and"ed together, e.g.:
10531053
h+ hidden buffers which are modified
10541054
a+ active buffers which are modified

‎src/buffer.c‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2930,18 +2930,34 @@ buflist_list(exarg_T *eap)
29302930
int i;
29312931
int ro_char;
29322932
int changed_char;
2933+
#ifdef FEAT_TERMINAL
2934+
int job_running;
2935+
int job_none_open;
2936+
#endif
29332937

29342938
for (buf = firstbuf; buf != NULL && !got_int; buf = buf->b_next)
29352939
{
2940+
#ifdef FEAT_TERMINAL
2941+
job_running = term_job_running(buf->b_term);
2942+
job_none_open = job_running && term_none_open(buf->b_term);
2943+
#endif
29362944
/* skip unlisted buffers, unless ! was used */
29372945
if ((!buf->b_p_bl && !eap->forceit && !vim_strchr(eap->arg, 'u'))
29382946
|| (vim_strchr(eap->arg, 'u') && buf->b_p_bl)
29392947
|| (vim_strchr(eap->arg, '+')
29402948
&& ((buf->b_flags & BF_READERR) || !bufIsChanged(buf)))
29412949
|| (vim_strchr(eap->arg, 'a')
2942-
&& (buf->b_ml.ml_mfp == NULL || buf->b_nwindows == 0))
2950+
&& (buf->b_ml.ml_mfp == NULL || buf->b_nwindows == 0))
29432951
|| (vim_strchr(eap->arg, 'h')
2944-
&& (buf->b_ml.ml_mfp == NULL || buf->b_nwindows != 0))
2952+
&& (buf->b_ml.ml_mfp == NULL || buf->b_nwindows != 0))
2953+
#ifdef FEAT_TERMINAL
2954+
|| (vim_strchr(eap->arg, 'R')
2955+
&& (!job_running || (job_running && job_none_open)))
2956+
|| (vim_strchr(eap->arg, '?')
2957+
&& (!job_running || (job_running && !job_none_open)))
2958+
|| (vim_strchr(eap->arg, 'F')
2959+
&& (job_running || buf->b_term == NULL))
2960+
#endif
29452961
|| (vim_strchr(eap->arg, '-') && buf->b_p_ma)
29462962
|| (vim_strchr(eap->arg, '=') && !buf->b_p_ro)
29472963
|| (vim_strchr(eap->arg, 'x') && !(buf->b_flags & BF_READERR))

‎src/testdir/test_terminal.vim‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,17 @@ func Test_terminal_basic()
4545
call assert_equal('t', mode())
4646
call assert_equal('yes', b:done)
4747
call assert_match('%aR[^\n]*running]', execute('ls'))
48+
call assert_match('%aR[^\n]*running]', execute('ls R'))
49+
call assert_notmatch('%[^\n]*running]', execute('ls F'))
50+
call assert_notmatch('%[^\n]*running]', execute('ls ?'))
4851

4952
call Stop_shell_in_terminal(buf)
5053
call term_wait(buf)
5154
call assert_equal('n', mode())
5255
call assert_match('%aF[^\n]*finished]', execute('ls'))
56+
call assert_match('%aF[^\n]*finished]', execute('ls F'))
57+
call assert_notmatch('%[^\n]*finished]', execute('ls R'))
58+
call assert_notmatch('%[^\n]*finished]', execute('ls ?'))
5359

5460
" closing window wipes out the terminal buffer a with finished job
5561
close

‎src/version.c‎

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

763763
static int included_patches[] =
764764
{ /* Add new patch number below this line */
765+
/**/
766+
1651,
765767
/**/
766768
1650,
767769
/**/

0 commit comments

Comments
 (0)