summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2018-10-25 13:31:37 +0200
committerBram Moolenaar <Bram@vim.org>2018-10-25 13:31:37 +0200
commitf86db78fed78541cefdb706e4779ce5ae9ca7820 (patch)
tree89b16ab5d0a2847b75bbe3c4ae782a0a03d6626f
parentbabfcf54ae9bf9570eddf4958a553635cd589e21 (diff)
downloadvim-git-8.1.0495.tar.gz
patch 8.1.0495: :filter only supports some commandsv8.1.0495
Problem: :filter only supports some commands. Solution: Add :filter support for more commands. (Marcin Szamotulski, closes #2856)
-rw-r--r--runtime/doc/various.txt13
-rw-r--r--src/eval.c8
-rw-r--r--src/mark.c4
-rw-r--r--src/option.c4
-rw-r--r--src/syntax.c7
-rw-r--r--src/testdir/test_filter_cmd.vim40
-rw-r--r--src/userfunc.c2
-rw-r--r--src/version.c2
8 files changed, 76 insertions, 4 deletions
diff --git a/runtime/doc/various.txt b/runtime/doc/various.txt
index fce8ba1ec..af49c3e86 100644
--- a/runtime/doc/various.txt
+++ b/runtime/doc/various.txt
@@ -565,7 +565,18 @@ N *+X11* Unix only: can restore window title |X11|
The pattern is matched against the relevant part of
the output, not necessarily the whole line. Only some
commands support filtering, try it out to check if it
- works.
+ works. Some of the commands that support filtering:
+ |:#| - filter whole line
+ |:command| - filter by command name
+ |:files| - filter by file name
+ |:highlight| - filter by highlight group
+ |:jumps| - filter by file name
+ |:let| - filter by variable name
+ |:list| - filter whole line
+ |:llist| - filter by file name or module name
+ |:oldfiles| - filter by file name
+ |:clist| - filter by file name or module name
+ |:set| - filter by variable name
Only normal messages are filtered, error messages are
not.
diff --git a/src/eval.c b/src/eval.c
index e70bfd8ab..4a3cf9912 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -1425,6 +1425,7 @@ list_hashtable_vars(
hashitem_T *hi;
dictitem_T *di;
int todo;
+ char_u buf[IOSIZE];
todo = (int)ht->ht_used;
for (hi = ht->ht_array; todo > 0 && !got_int; ++hi)
@@ -1433,6 +1434,13 @@ list_hashtable_vars(
{
--todo;
di = HI2DI(hi);
+
+ // apply :filter /pat/ to variable name
+ vim_strncpy((char_u *) buf, prefix, IOSIZE - 1);
+ vim_strcat((char_u *) buf, di->di_key, IOSIZE);
+ if (message_filtered(buf))
+ continue;
+
if (empty || di->di_tv.v_type != VAR_STRING
|| di->di_tv.vval.v_string != NULL)
list_one_var(di, prefix, first);
diff --git a/src/mark.c b/src/mark.c
index c7395f3a0..f9e3ce3cf 100644
--- a/src/mark.c
+++ b/src/mark.c
@@ -901,7 +901,9 @@ ex_jumps(exarg_T *eap UNUSED)
if (curwin->w_jumplist[i].fmark.mark.lnum != 0)
{
name = fm_getname(&curwin->w_jumplist[i].fmark, 16);
- if (name == NULL) /* file name not available */
+
+ // apply :filter /pat/ or file name not available
+ if (name == NULL || message_filtered(name))
continue;
msg_putchar('\n');
diff --git a/src/option.c b/src/option.c
index d1f1d1382..f238abe84 100644
--- a/src/option.c
+++ b/src/option.c
@@ -10083,6 +10083,10 @@ showoptions(
item_count = 0;
for (p = &options[0]; p->fullname != NULL; p++)
{
+ // apply :filter /pat/
+ if (message_filtered((char_u *) p->fullname))
+ continue;
+
varp = NULL;
isterm = istermoption(p);
if (opt_flags != 0)
diff --git a/src/syntax.c b/src/syntax.c
index e00746ec0..5b9aec446 100644
--- a/src/syntax.c
+++ b/src/syntax.c
@@ -352,7 +352,7 @@ static reg_extmatch_T *next_match_extmatch = NULL;
/*
* A state stack is an array of integers or stateitem_T, stored in a
- * garray_T. A state stack is invalid if it's itemsize entry is zero.
+ * garray_T. A state stack is invalid if its itemsize entry is zero.
*/
#define INVALID_STATE(ssp) ((ssp)->ga_itemsize == 0)
#define VALID_STATE(ssp) ((ssp)->ga_itemsize != 0)
@@ -9189,7 +9189,10 @@ highlight_list_one(int id)
struct hl_group *sgp;
int didh = FALSE;
- sgp = &HL_TABLE()[id - 1]; /* index is ID minus one */
+ sgp = &HL_TABLE()[id - 1]; // index is ID minus one
+
+ if (message_filtered(sgp->sg_name))
+ return;
didh = highlight_list_arg(id, didh, LIST_ATTR,
sgp->sg_term, NULL, "term");
diff --git a/src/testdir/test_filter_cmd.vim b/src/testdir/test_filter_cmd.vim
index 86347ab77..3d802f953 100644
--- a/src/testdir/test_filter_cmd.vim
+++ b/src/testdir/test_filter_cmd.vim
@@ -87,3 +87,43 @@ func Test_filter_cmd_with_filter()
call assert_equal('a|b', out)
set shelltemp&
endfunction
+
+func Test_filter_commands()
+ let g:test_filter_a = 1
+ let b:test_filter_b = 2
+ let test_filter_c = 3
+
+ " Test filtering :let command
+ let res = split(execute("filter /^test_filter/ let"), "\n")
+ call assert_equal(["test_filter_a #1"], res)
+
+ let res = split(execute("filter /\\v^(b:)?test_filter/ let"), "\n")
+ call assert_equal(["test_filter_a #1", "b:test_filter_b #2"], res)
+
+ unlet g:test_filter_a
+ unlet b:test_filter_b
+ unlet test_filter_c
+
+ " Test filtering :set command
+ let res = join(split(execute("filter /^help/ set"), "\n")[1:], " ")
+ call assert_match('^\s*helplang=\w*$', res)
+
+ " Test filtering :llist command
+ call setloclist(0, [{"filename": "/path/vim.c"}, {"filename": "/path/vim.h"}, {"module": "Main.Test"}])
+ let res = split(execute("filter /\\.c$/ llist"), "\n")
+ call assert_equal([" 1 /path/vim.c: "], res)
+
+ let res = split(execute("filter /\\.Test$/ llist"), "\n")
+ call assert_equal([" 3 Main.Test: "], res)
+
+ " Test filtering :jump command
+ e file.c
+ e file.h
+ e file.hs
+ let res = split(execute("filter /\.c$/ jumps"), "\n")[1:]
+ call assert_equal([" 2 1 0 file.c", ">"], res)
+
+ bwipe file.c
+ bwipe file.h
+ bwipe file.hs
+endfunc
diff --git a/src/userfunc.c b/src/userfunc.c
index ec239c771..7c3b7f673 100644
--- a/src/userfunc.c
+++ b/src/userfunc.c
@@ -1882,6 +1882,8 @@ ex_function(exarg_T *eap)
{
--todo;
fp = HI2UF(hi);
+ if (message_filtered(fp->uf_name))
+ continue;
if (!func_name_refcount(fp->uf_name))
list_func_head(fp, FALSE);
}
diff --git a/src/version.c b/src/version.c
index 7297ad59a..30c50ab55 100644
--- a/src/version.c
+++ b/src/version.c
@@ -793,6 +793,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 495,
+/**/
494,
/**/
493,