From 945325ec4f748d92af348f4aa8287eb1a86d048c Mon Sep 17 00:00:00 2001 From: Marcin Szamotulski Date: Fri, 22 Jan 2016 20:13:47 +0000 Subject: [PATCH 1/3] :oldfiles /pattern/ list only files that match a pattern --- runtime/doc/starting.txt | 6 +++++- src/Makefile | 1 + src/eval.c | 25 ++++++++++++++++++++++++- src/ex_cmds.h | 2 +- src/syntax.c | 10 ++++++---- 5 files changed, 37 insertions(+), 7 deletions(-) diff --git a/runtime/doc/starting.txt b/runtime/doc/starting.txt index 773a3b9125b613..f2a92d555a7f7d 100644 --- a/runtime/doc/starting.txt +++ b/runtime/doc/starting.txt @@ -1520,13 +1520,17 @@ most of the information will be restored). {not in Vi} *:ol* *:oldfiles* -:ol[dfiles] List the files that have marks stored in the viminfo +:ol[dfiles] [/{pat}/] List the files that have marks stored in the viminfo file. This list is read on startup and only changes afterwards with ":rviminfo!". Also see |v:oldfiles|. The number can be used with |c_#<|. + If {pat} is given only files matching the pattern will + be included. The pattern must be enclosed in / or any + non-ID character, like for |:vimgrep|. {not in Vi, only when compiled with the |+eval| feature} + :bro[wse] ol[dfiles][!] List file names as with |:oldfiles|, and then prompt for a number. When the number is valid that file from diff --git a/src/Makefile b/src/Makefile index 4aa5a48b2b2a37..4d0384aa340aae 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1955,6 +1955,7 @@ test1 \ test_nested_function \ test_options \ test_qf_title \ + test_oldfiles \ test_ruby \ test_search_mbyte \ test_signs \ diff --git a/src/eval.c b/src/eval.c index de30f712ee495c..267fc1342ee13f 100644 --- a/src/eval.c +++ b/src/eval.c @@ -25336,22 +25336,45 @@ ex_oldfiles(eap) list_T *l = vimvars[VV_OLDFILES].vv_list; listitem_T *li; int nr = 0; + char_u *reg_pat; + char_u *buf; + regmatch_T regmatch; if (l == NULL) msg((char_u *)_("No old files")); else { msg_start(); + msg_putchar('\n'); msg_scroll = TRUE; + if (*eap->arg != NUL) { + if (skip_vimgrep_pat(eap->arg, ®_pat, NULL) == NULL) { + EMSG(_(e_invalpat)); + return; + } + regmatch.regprog = vim_regcomp(reg_pat, p_magic ? RE_MAGIC : 0); + if (regmatch.regprog == NULL) { + return; + } + } for (li = l->lv_first; li != NULL && !got_int; li = li->li_next) { + buf = get_tv_string(&li->li_tv); + if (reg_pat != NULL && *reg_pat != NUL) { + if (!vim_regexec(®match, buf, (colnr_T)0)) { + ++nr; + continue; + } + } msg_outnum((long)++nr); MSG_PUTS(": "); - msg_outtrans(get_tv_string(&li->li_tv)); + msg_outtrans(buf); msg_putchar('\n'); out_flush(); /* output one line at a time */ ui_breakcheck(); } + if (*eap->arg != NUL) + vim_regfree(regmatch.regprog); /* Assume "got_int" was set to truncate the listing. */ got_int = FALSE; diff --git a/src/ex_cmds.h b/src/ex_cmds.h index 4b5f68453afb09..e92ca08cadefe6 100644 --- a/src/ex_cmds.h +++ b/src/ex_cmds.h @@ -980,7 +980,7 @@ EX(CMD_open, "open", ex_open, RANGE|BANG|EXTRA, ADDR_LINES), EX(CMD_oldfiles, "oldfiles", ex_oldfiles, - BANG|TRLBAR|SBOXOK|CMDWIN, + BANG|TRLBAR|NOTADR|EXTRA|SBOXOK|CMDWIN, ADDR_LINES), EX(CMD_omap, "omap", ex_map, EXTRA|TRLBAR|NOTRLCOM|USECTRLV|CMDWIN, diff --git a/src/syntax.c b/src/syntax.c index d9f0ffc9f1880a..9dfdb9bd23b08d 100644 --- a/src/syntax.c +++ b/src/syntax.c @@ -7875,10 +7875,12 @@ do_highlight(line, forceit, init) i = (color < 7 || color == 8); /* Set the 'background' option if the value is * wrong. */ - if (i != (*p_bg == 'd')) - set_option_value((char_u *)"bg", 0L, - i ? (char_u *)"dark" - : (char_u *)"light", 0); + /* + * if (i != (*p_bg == 'd')) + * set_option_value((char_u *)"bg", 0L, + * i ? (char_u *)"dark" + * : (char_u *)"light", 0); + */ } } } From ac23ea332dd848d618f80394468b5c6995a435ad Mon Sep 17 00:00:00 2001 From: Marcin Szamotulski Date: Sat, 23 Jan 2016 20:36:28 +0000 Subject: [PATCH 2/3] oldfiles: add a test, fix a segfault --- src/Makefile | 2 +- src/eval.c | 2 +- src/testdir/test_oldfiles.vim | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 src/testdir/test_oldfiles.vim diff --git a/src/Makefile b/src/Makefile index 4d0384aa340aae..a62eef03ec56f2 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1955,7 +1955,6 @@ test1 \ test_nested_function \ test_options \ test_qf_title \ - test_oldfiles \ test_ruby \ test_search_mbyte \ test_signs \ @@ -1989,6 +1988,7 @@ test_arglist \ test_increment \ test_lispwords \ test_menu \ + test_oldfiles \ test_perl \ test_quickfix \ test_searchpos \ diff --git a/src/eval.c b/src/eval.c index 267fc1342ee13f..4a175f6b9c7ab8 100644 --- a/src/eval.c +++ b/src/eval.c @@ -25360,7 +25360,7 @@ ex_oldfiles(eap) for (li = l->lv_first; li != NULL && !got_int; li = li->li_next) { buf = get_tv_string(&li->li_tv); - if (reg_pat != NULL && *reg_pat != NUL) { + if (*eap->arg != NUL && reg_pat != NULL && *reg_pat != NUL) { if (!vim_regexec(®match, buf, (colnr_T)0)) { ++nr; continue; diff --git a/src/testdir/test_oldfiles.vim b/src/testdir/test_oldfiles.vim new file mode 100644 index 00000000000000..b635d7ba2b4546 --- /dev/null +++ b/src/testdir/test_oldfiles.vim @@ -0,0 +1,19 @@ +"Tests for :olffiles vim: setf=vim : + +func Test_oldfiles() + let ol = ['a.vim', 'b.vim', 'c.txt', 'd.txt'] + call extend(v:oldfiles, ol) + redir @q + ol + return + redir END + call assert_equal(split(@q, "\n"), ['1: a.vim', '2: b.vim', '3: c.txt', '4: d.txt']) + redir @q + ol /\.txt$/ + redir END + call assert_equal(split(@q, "\n"), ['3: c.txt', '4: d.txt']) + redir q + ol /b[^/]*$/ + redir END + call assert_equal(split(@q, "\n"), ['2: b.vim']) +endfunc From 4576a098fc708ad47655533240a2a3bc834d8b7c Mon Sep 17 00:00:00 2001 From: Marcin Szamotulski Date: Sat, 20 Aug 2016 11:25:19 +0100 Subject: [PATCH 3/3] fix the test --- src/testdir/test_oldfiles.vim | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/testdir/test_oldfiles.vim b/src/testdir/test_oldfiles.vim index b635d7ba2b4546..d47f6c5c3308e1 100644 --- a/src/testdir/test_oldfiles.vim +++ b/src/testdir/test_oldfiles.vim @@ -5,14 +5,13 @@ func Test_oldfiles() call extend(v:oldfiles, ol) redir @q ol - return redir END call assert_equal(split(@q, "\n"), ['1: a.vim', '2: b.vim', '3: c.txt', '4: d.txt']) redir @q ol /\.txt$/ redir END call assert_equal(split(@q, "\n"), ['3: c.txt', '4: d.txt']) - redir q + redir @q ol /b[^/]*$/ redir END call assert_equal(split(@q, "\n"), ['2: b.vim'])