To: vim_dev@googlegroups.com Subject: Patch 7.4.2231 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 7.4.2231 Problem: ":oldfiles" output is a very long list. Solution: Add a pattern argument. (Coot, closes #575) Files: runtime/doc/starting.txt, src/ex_cmds.h, src/eval.c, src/ex_cmds.c, src/proto/eval.pro, src/proto/ex_cmds.pro, src/testdir/test_viminfo.vim *** ../vim-7.4.2230/runtime/doc/starting.txt 2016-08-06 19:01:33.984856713 +0200 --- runtime/doc/starting.txt 2016-08-20 18:08:24.744295631 +0200 *************** *** 1561,1571 **** *:ol* *:oldfiles* :ol[dfiles] 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_#<|. {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 --- 1611,1630 ---- *:ol* *:oldfiles* :ol[dfiles] 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_#<|. {not in Vi, only when compiled with the |+eval| feature} + :ol[dfiles] {pat} + :ol[dfiles] /{pat}/ + Like `:oldfiles` but only files matching {pat} will + be included. {pat} is a Vim search pattern. Instead + of enclosing it in / any non-ID character (see + |'isident'|) can be used, so long as it does not + appear in {pat}. Without the enclosing character the + pattern cannot include the bar character. + :bro[wse] ol[dfiles][!] List file names as with |:oldfiles|, and then prompt for a number. When the number is valid that file from *** ../vim-7.4.2230/src/ex_cmds.h 2016-07-16 16:54:18.330699629 +0200 --- src/ex_cmds.h 2016-08-20 18:09:40.947603814 +0200 *************** *** 992,998 **** RANGE|BANG|EXTRA, ADDR_LINES), EX(CMD_oldfiles, "oldfiles", ex_oldfiles, ! BANG|TRLBAR|SBOXOK|CMDWIN, ADDR_LINES), EX(CMD_omap, "omap", ex_map, EXTRA|TRLBAR|NOTRLCOM|USECTRLV|CMDWIN, --- 992,998 ---- RANGE|BANG|EXTRA, ADDR_LINES), EX(CMD_oldfiles, "oldfiles", ex_oldfiles, ! BANG|TRLBAR|NOTADR|EXTRA|SBOXOK|CMDWIN, ADDR_LINES), EX(CMD_omap, "omap", ex_map, EXTRA|TRLBAR|NOTRLCOM|USECTRLV|CMDWIN, *** ../vim-7.4.2230/src/eval.c 2016-08-17 21:51:52.251045689 +0200 --- src/eval.c 2016-08-20 18:11:43.594490724 +0200 *************** *** 8929,8988 **** } } - /* - * List v:oldfiles in a nice way. - */ - void - ex_oldfiles(exarg_T *eap UNUSED) - { - list_T *l = vimvars[VV_OLDFILES].vv_list; - listitem_T *li; - int nr = 0; - - if (l == NULL) - msg((char_u *)_("No old files")); - else - { - msg_start(); - msg_scroll = TRUE; - for (li = l->lv_first; li != NULL && !got_int; li = li->li_next) - { - msg_outnum((long)++nr); - MSG_PUTS(": "); - msg_outtrans(get_tv_string(&li->li_tv)); - msg_putchar('\n'); - out_flush(); /* output one line at a time */ - ui_breakcheck(); - } - /* Assume "got_int" was set to truncate the listing. */ - got_int = FALSE; - - #ifdef FEAT_BROWSE_CMD - if (cmdmod.browse) - { - quit_more = FALSE; - nr = prompt_for_number(FALSE); - msg_starthere(); - if (nr > 0) - { - char_u *p = list_find_str(get_vim_var_list(VV_OLDFILES), - (long)nr); - - if (p != NULL) - { - p = expand_env_save(p); - eap->arg = p; - eap->cmdidx = CMD_edit; - cmdmod.browse = FALSE; - do_exedit(eap, NULL); - vim_free(p); - } - } - } - #endif - } - } - /* reset v:option_new, v:option_old and v:option_type */ void reset_v_option_vars(void) --- 8929,8934 ---- *** ../vim-7.4.2230/src/ex_cmds.c 2016-08-17 22:29:06.158531366 +0200 --- src/ex_cmds.c 2016-08-20 18:28:15.629502620 +0200 *************** *** 8391,8393 **** --- 8391,8474 ---- } } #endif + + #if defined(FEAT_EVAL) || defined(PROTO) + /* + * List v:oldfiles in a nice way. + */ + void + ex_oldfiles(exarg_T *eap UNUSED) + { + list_T *l = get_vim_var_list(VV_OLDFILES); + listitem_T *li; + int nr = 0; + char_u *reg_pat = NULL; + char_u *fname; + regmatch_T regmatch; + + if (l == NULL) + msg((char_u *)_("No old files")); + else + { + 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; + } + + msg_start(); + msg_scroll = TRUE; + for (li = l->lv_first; li != NULL && !got_int; li = li->li_next) + { + ++nr; + fname = get_tv_string(&li->li_tv); + if (reg_pat == NULL || *reg_pat == NUL + || vim_regexec(®match, fname, (colnr_T)0)) + { + msg_outnum((long)nr); + MSG_PUTS(": "); + msg_outtrans(fname); + 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; + + # ifdef FEAT_BROWSE_CMD + if (cmdmod.browse) + { + quit_more = FALSE; + nr = prompt_for_number(FALSE); + msg_starthere(); + if (nr > 0) + { + char_u *p = list_find_str(get_vim_var_list(VV_OLDFILES), + (long)nr); + + if (p != NULL) + { + p = expand_env_save(p); + eap->arg = p; + eap->cmdidx = CMD_edit; + cmdmod.browse = FALSE; + do_exedit(eap, NULL); + vim_free(p); + } + } + } + # endif + } + } + #endif + *** ../vim-7.4.2230/src/proto/eval.pro 2016-08-01 15:40:24.179878441 +0200 --- src/proto/eval.pro 2016-08-20 18:15:16.756557201 +0200 *************** *** 117,123 **** void write_viminfo_varlist(FILE *fp); int store_session_globals(FILE *fd); void last_set_msg(scid_T scriptID); - void ex_oldfiles(exarg_T *eap); void reset_v_option_vars(void); void prepare_assert_error(garray_T *gap); void assert_error(garray_T *gap); --- 117,122 ---- *** ../vim-7.4.2230/src/proto/ex_cmds.pro 2016-06-26 16:44:19.519620863 +0200 --- src/proto/ex_cmds.pro 2016-08-20 18:15:14.028581937 +0200 *************** *** 65,68 **** --- 65,69 ---- void set_context_in_sign_cmd(expand_T *xp, char_u *arg); void ex_smile(exarg_T *eap); void ex_drop(exarg_T *eap); + void ex_oldfiles(exarg_T *eap); /* vim: set ft=c : */ *** ../vim-7.4.2230/src/testdir/test_viminfo.vim 2016-08-14 19:08:41.838022274 +0200 --- src/testdir/test_viminfo.vim 2016-08-20 18:28:38.189298508 +0200 *************** *** 455,457 **** --- 455,482 ---- call delete('Xviminfo') silent! bwipe Xtestfileintab endfunc + + func Test_oldfiles() + let v:oldfiles = [] + let lines = [ + \ '# comment line', + \ '*encoding=utf-8', + \ '', + \ "> /tmp/file_one.txt", + \ "\t\"\t11\t0", + \ "", + \ "> /tmp/file_two.txt", + \ "\t\"\t11\t0", + \ "", + \ "> /tmp/another.txt", + \ "\t\"\t11\t0", + \ "", + \ ] + call writefile(lines, 'Xviminfo') + rviminfo! Xviminfo + call delete('Xviminfo') + + call assert_equal(['1: /tmp/file_one.txt', '2: /tmp/file_two.txt', '3: /tmp/another.txt'], filter(split(execute('oldfile'), "\n"), {i, v -> v =~ '/tmp/'})) + call assert_equal(['1: /tmp/file_one.txt', '2: /tmp/file_two.txt'], filter(split(execute('oldfile file_'), "\n"), {i, v -> v =~ '/tmp/'})) + call assert_equal(['3: /tmp/another.txt'], filter(split(execute('oldfile /another/'), "\n"), {i, v -> v =~ '/tmp/'})) + endfunc *** ../vim-7.4.2230/src/version.c 2016-08-20 16:56:48.258624268 +0200 --- src/version.c 2016-08-20 18:08:46.720096104 +0200 *************** *** 765,766 **** --- 765,768 ---- { /* Add new patch number below this line */ + /**/ + 2231, /**/ -- The 50-50-90 rule: Anytime you have a 50-50 chance of getting something right, there's a 90% probability you'll get it wrong. /// 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 ///