]> granicus.if.org Git - vim/commitdiff
patch 7.4.2231 v7.4.2231
authorBram Moolenaar <Bram@vim.org>
Sat, 20 Aug 2016 16:36:54 +0000 (18:36 +0200)
committerBram Moolenaar <Bram@vim.org>
Sat, 20 Aug 2016 16:36:54 +0000 (18:36 +0200)
Problem:    ":oldfiles" output is a very long list.
Solution:   Add a pattern argument. (Coot, closes #575)

runtime/doc/starting.txt
src/eval.c
src/ex_cmds.c
src/ex_cmds.h
src/proto/eval.pro
src/proto/ex_cmds.pro
src/testdir/test_viminfo.vim
src/version.c

index a4847c2e292cd3dd6c6ba599b66a9e8a83f5769e..015f68ea52feb0df715ee26ee9684b08e0f8b507 100644 (file)
@@ -1611,11 +1611,20 @@ most of the information will be restored).
                                                *: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|.
+                       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
index 9b3f248b0e265fdeb3ecb449472911881e9da34d..cbfd98feacd52d11012d947fd91127f789749968 100644 (file)
@@ -8929,60 +8929,6 @@ last_set_msg(scid_T scriptID)
     }
 }
 
-/*
- * 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)
index 919aafc7cc57d7fe6e3be50e9fbc478bfa3b98c1..e727ecc18646f78143c76f5b7b0e22e712280d30 100644 (file)
@@ -8391,3 +8391,84 @@ ex_drop(exarg_T *eap)
     }
 }
 #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, &reg_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(&regmatch, 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
+
index eb6eb25b76c6a934ea0aa2e990cdb522111f661e..b6e9488ddc936e982777d4d1d76ae9b481945f86 100644 (file)
@@ -992,7 +992,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,
index 7a246838020029379f7a4c7554126ed686d6c930..edca43e4335872c4bafd06b1a1d72e1a76fd1979 100644 (file)
@@ -117,7 +117,6 @@ int read_viminfo_varlist(vir_T *virp, int writing);
 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);
index b3713140c04d588b260aedc738103f198e318e8a..324608f33e5bfcf646b42ed6a1a43afd1e32f21a 100644 (file)
@@ -65,4 +65,5 @@ char_u *get_sign_name(expand_T *xp, int idx);
 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 : */
index cbe481c594d24f4fa26838d38a2eeaabf59d27c5..d4ec6f78f7195bd2582183cc1bc78883f2bc9420 100644 (file)
@@ -455,3 +455,28 @@ func Test_viminfo_file_mark_tabclose()
   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
index e892a95daf2e5ddf168b064a3ced58c6632d746c..c2a308dca196a4c1ed6c7ab80ea63d82c33066d2 100644 (file)
@@ -763,6 +763,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2231,
 /**/
     2230,
 /**/