aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Pilling <robpilling@gmail.com>2020-03-22 21:23:33 +0000
committerRob Pilling <robpilling@gmail.com>2020-04-19 20:18:41 +0100
commit9d59f066cbbe8893559586eee5bfca9378cf6385 (patch)
treed88371aeafc91dd10500a78568d36ba952b55a05
parentec2d45a8515399e3f23e0a552bcb222ae4836f7a (diff)
downloadrneovim-9d59f066cbbe8893559586eee5bfca9378cf6385.tar.gz
rneovim-9d59f066cbbe8893559586eee5bfca9378cf6385.tar.bz2
rneovim-9d59f066cbbe8893559586eee5bfca9378cf6385.zip
vim-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 vim/vim#2751) https://github.com/vim/vim/commit/0751f51a5b428805a8c1e9fe529693d032bec991
-rw-r--r--runtime/doc/windows.txt2
-rw-r--r--src/nvim/buffer.c5
-rw-r--r--src/nvim/terminal.c5
-rw-r--r--test/functional/ex_cmds/ls_spec.lua12
4 files changed, 24 insertions, 0 deletions
diff --git a/runtime/doc/windows.txt b/runtime/doc/windows.txt
index 977e0daef7..dbe08a71ef 100644
--- a/runtime/doc/windows.txt
+++ b/runtime/doc/windows.txt
@@ -1021,6 +1021,8 @@ list of buffers. |unlisted-buffer|
x buffers with a read error
% current buffer
# alternate buffer
+ R terminal buffers with a running job
+ F terminal buffers with a finished job
Combining flags means they are "and"ed together, e.g.:
h+ hidden buffers which are modified
a+ active buffers which are modified
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c
index ec86663f00..ab86ed6fdc 100644
--- a/src/nvim/buffer.c
+++ b/src/nvim/buffer.c
@@ -2600,6 +2600,9 @@ void buflist_list(exarg_T *eap)
int i;
for (buf = firstbuf; buf != NULL && !got_int; buf = buf->b_next) {
+ const bool is_terminal = buf->terminal;
+ const bool job_running = buf->terminal && terminal_running(buf->terminal);
+
// skip unspecified buffers
if ((!buf->b_p_bl && !eap->forceit && !strchr((char *)eap->arg, 'u'))
|| (strchr((char *)eap->arg, 'u') && buf->b_p_bl)
@@ -2609,6 +2612,8 @@ void buflist_list(exarg_T *eap)
&& (buf->b_ml.ml_mfp == NULL || buf->b_nwindows == 0))
|| (strchr((char *)eap->arg, 'h')
&& (buf->b_ml.ml_mfp == NULL || buf->b_nwindows != 0))
+ || (strchr((char *)eap->arg, 'R') && (!is_terminal || !job_running))
+ || (strchr((char *)eap->arg, 'F') && (!is_terminal || job_running))
|| (strchr((char *)eap->arg, '-') && buf->b_p_ma)
|| (strchr((char *)eap->arg, '=') && !buf->b_p_ro)
|| (strchr((char *)eap->arg, 'x') && !(buf->b_flags & BF_READERR))
diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c
index c5e756905a..6c164b27d2 100644
--- a/src/nvim/terminal.c
+++ b/src/nvim/terminal.c
@@ -650,6 +650,11 @@ Buffer terminal_buf(const Terminal *term)
return term->buf_handle;
}
+bool terminal_running(const Terminal *term)
+{
+ return !term->closed;
+}
+
// }}}
// libvterm callbacks {{{
diff --git a/test/functional/ex_cmds/ls_spec.lua b/test/functional/ex_cmds/ls_spec.lua
index f7bacd7386..9853084c47 100644
--- a/test/functional/ex_cmds/ls_spec.lua
+++ b/test/functional/ex_cmds/ls_spec.lua
@@ -31,6 +31,18 @@ describe(':ls', function()
-- Terminal buffer [F]inished.
eq('\n 3 %aF', string.match(ls_output, '\n *3....'))
end)
+
+ retry(nil, 5000, function()
+ local ls_output = eval('execute("ls R")')
+ -- Just the [R]unning terminal buffer.
+ eq('\n 2 #aR ', string.match(ls_output, '^\n *2 ... '))
+ end)
+
+ retry(nil, 5000, function()
+ local ls_output = eval('execute("ls F")')
+ -- Just the [F]inished terminal buffer.
+ eq('\n 3 %aF ', string.match(ls_output, '^\n *3 ... '))
+ end)
end)
end)