To: vim_dev@googlegroups.com Subject: Patch 7.4.2263 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 7.4.2263 Problem: :filter does not work for many commands. Can only get matching messages. Solution: Make :filter work for :command, :map, :list, :number and :print. Make ":filter!" show non-matching lines. Files: src/getchar.c, src/ex_cmds.c, src/ex_cmds.h, src/ex_docmd.c, src/message.c, src/structs.h, src/testdir/test_filter_cmd.vim *** ../vim-7.4.2262/src/getchar.c 2016-08-17 21:31:54.437870436 +0200 --- src/getchar.c 2016-08-26 21:28:53.566285713 +0200 *************** *** 1919,1925 **** * This may do a blocking wait if "advance" is TRUE. * * if "advance" is TRUE (vgetc()): ! * really get the character. * KeyTyped is set to TRUE in the case the user typed the key. * KeyStuffed is TRUE if the character comes from the stuff buffer. * if "advance" is FALSE (vpeekc()): --- 1919,1925 ---- * This may do a blocking wait if "advance" is TRUE. * * if "advance" is TRUE (vgetc()): ! * Really get the character. * KeyTyped is set to TRUE in the case the user typed the key. * KeyStuffed is TRUE if the character comes from the stuff buffer. * if "advance" is FALSE (vpeekc()): *************** *** 3987,3992 **** --- 3987,3995 ---- int len = 1; char_u *mapchars; + if (message_filtered(mp->m_keys) && message_filtered(mp->m_str)) + return; + if (msg_didout || msg_silent != 0) { msg_putchar('\n'); *** ../vim-7.4.2262/src/ex_cmds.c 2016-08-26 20:41:12.566631407 +0200 --- src/ex_cmds.c 2016-08-26 20:55:03.483561214 +0200 *************** *** 2918,2923 **** --- 2918,2927 ---- { int save_silent = silent_mode; + /* apply :filter /pat/ */ + if (message_filtered(ml_get(lnum))) + return; + msg_start(); silent_mode = FALSE; info_message = TRUE; /* use mch_msg(), not mch_errmsg() */ *** ../vim-7.4.2262/src/ex_cmds.h 2016-08-23 23:50:06.872279942 +0200 --- src/ex_cmds.h 2016-08-26 22:16:41.541548222 +0200 *************** *** 545,551 **** EXTRA|TRLBAR|CMDWIN, ADDR_LINES), EX(CMD_filter, "filter", ex_wrongmodifier, ! NEEDARG|EXTRA|NOTRLCOM, ADDR_LINES), EX(CMD_find, "find", ex_find, RANGE|NOTADR|BANG|FILE1|EDITCMD|ARGOPT|TRLBAR, --- 545,551 ---- EXTRA|TRLBAR|CMDWIN, ADDR_LINES), EX(CMD_filter, "filter", ex_wrongmodifier, ! BANG|NEEDARG|EXTRA|NOTRLCOM, ADDR_LINES), EX(CMD_find, "find", ex_find, RANGE|NOTADR|BANG|FILE1|EDITCMD|ARGOPT|TRLBAR, *** ../vim-7.4.2262/src/ex_docmd.c 2016-08-23 23:50:06.868279980 +0200 --- src/ex_docmd.c 2016-08-26 22:14:50.870514612 +0200 *************** *** 1925,1930 **** --- 1925,1937 ---- if (!checkforcmd(&p, "filter", 4) || *p == NUL || ends_excmd(*p)) break; + if (*p == '!') + { + cmdmod.filter_force = TRUE; + p = skipwhite(p + 1); + if (*p == NUL || ends_excmd(*p)) + break; + } p = skip_vimgrep_pat(p, ®_pat, NULL); if (p == NULL || *p == NUL) break; *************** *** 5928,5935 **** cmd = USER_CMD_GA(gap, i); a = (long)cmd->uc_argt; ! /* Skip commands which don't match the requested prefix */ ! if (STRNCMP(name, cmd->uc_name, name_len) != 0) continue; /* Put out the title first time */ --- 5935,5944 ---- cmd = USER_CMD_GA(gap, i); a = (long)cmd->uc_argt; ! /* Skip commands which don't match the requested prefix and ! * commands filtered out. */ ! if (STRNCMP(name, cmd->uc_name, name_len) != 0 ! || message_filtered(cmd->uc_name)) continue; /* Put out the title first time */ *** ../vim-7.4.2262/src/message.c 2016-08-23 23:50:06.872279942 +0200 --- src/message.c 2016-08-26 21:31:13.457085146 +0200 *************** *** 2161,2168 **** int message_filtered(char_u *msg) { ! return cmdmod.filter_regmatch.regprog != NULL ! && !vim_regexec(&cmdmod.filter_regmatch, msg, (colnr_T)0); } /* --- 2161,2172 ---- int message_filtered(char_u *msg) { ! int match; ! ! if (cmdmod.filter_regmatch.regprog == NULL) ! return FALSE; ! match = vim_regexec(&cmdmod.filter_regmatch, msg, (colnr_T)0); ! return cmdmod.filter_force ? match : !match; } /* *** ../vim-7.4.2262/src/structs.h 2016-08-24 22:33:46.466828728 +0200 --- src/structs.h 2016-08-26 21:32:29.500418389 +0200 *************** *** 572,577 **** --- 572,578 ---- char_u *save_ei; /* saved value of 'eventignore' */ # endif regmatch_T filter_regmatch; /* set by :filter /pat/ */ + int filter_force; /* set for :filter! */ } cmdmod_T; #define MF_SEED_LEN 8 *** ../vim-7.4.2262/src/testdir/test_filter_cmd.vim 2016-08-23 23:50:06.872279942 +0200 --- src/testdir/test_filter_cmd.vim 2016-08-26 22:26:08.084694633 +0200 *************** *** 4,9 **** --- 4,42 ---- edit Xdoesnotmatch edit Xwillmatch call assert_equal('"Xwillmatch"', substitute(execute('filter willma ls'), '[^"]*\(".*"\)[^"]*', '\1', '')) + bwipe Xdoesnotmatch + bwipe Xwillmatch + + new + call setline(1, ['foo1', 'foo2', 'foo3', 'foo4', 'foo5']) + call assert_equal("\nfoo2\nfoo4", execute('filter /foo[24]/ 1,$print')) + call assert_equal("\n 2 foo2\n 4 foo4", execute('filter /foo[24]/ 1,$number')) + call assert_equal("\nfoo2$\nfoo4$", execute('filter /foo[24]/ 1,$list')) + + call assert_equal("\nfoo1$\nfoo3$\nfoo5$", execute('filter! /foo[24]/ 1,$list')) + bwipe! + + command XTryThis echo 'this' + command XTryThat echo 'that' + command XDoThat echo 'that' + let lines = split(execute('filter XTry command'), "\n") + call assert_equal(3, len(lines)) + call assert_match("XTryThat", lines[1]) + call assert_match("XTryThis", lines[2]) + delcommand XTryThis + delcommand XTryThat + delcommand XDoThat + + map f1 the first key + map f2 the second key + map f3 not a key + let lines = split(execute('filter the map f'), "\n") + call assert_equal(2, len(lines)) + call assert_match("f2", lines[0]) + call assert_match("f1", lines[1]) + unmap f1 + unmap f2 + unmap f3 endfunc func Test_filter_fails() *************** *** 12,15 **** --- 45,54 ---- call assert_fails('filter /pat', 'E476:') call assert_fails('filter /pat/', 'E476:') call assert_fails('filter /pat/ asdf', 'E492:') + + call assert_fails('filter!', 'E471:') + call assert_fails('filter! pat', 'E476:') + call assert_fails('filter! /pat', 'E476:') + call assert_fails('filter! /pat/', 'E476:') + call assert_fails('filter! /pat/ asdf', 'E492:') endfunc *** ../vim-7.4.2262/src/version.c 2016-08-26 20:41:12.570631374 +0200 --- src/version.c 2016-08-26 21:01:07.876457809 +0200 *************** *** 765,766 **** --- 765,768 ---- { /* Add new patch number below this line */ + /**/ + 2263, /**/ -- From "know your smileys": :-O>-o Smiley American tourist (note big mouth and camera) /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///