Skip to content

Commit e11d61a

Browse files
committed
patch 7.4.2231
Problem: ":oldfiles" output is a very long list. Solution: Add a pattern argument. (Coot, closes #575)
1 parent 66e29d7 commit e11d61a

8 files changed

Lines changed: 120 additions & 57 deletions

File tree

runtime/doc/starting.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1611,11 +1611,20 @@ most of the information will be restored).
16111611
*:ol* *:oldfiles*
16121612
:ol[dfiles] List the files that have marks stored in the viminfo
16131613
file. This list is read on startup and only changes
1614-
afterwards with ":rviminfo!". Also see |v:oldfiles|.
1614+
afterwards with `:rviminfo!`. Also see |v:oldfiles|.
16151615
The number can be used with |c_#<|.
16161616
{not in Vi, only when compiled with the |+eval|
16171617
feature}
16181618

1619+
:ol[dfiles] {pat}
1620+
:ol[dfiles] /{pat}/
1621+
Like `:oldfiles` but only files matching {pat} will
1622+
be included. {pat} is a Vim search pattern. Instead
1623+
of enclosing it in / any non-ID character (see
1624+
|'isident'|) can be used, so long as it does not
1625+
appear in {pat}. Without the enclosing character the
1626+
pattern cannot include the bar character.
1627+
16191628
:bro[wse] ol[dfiles][!]
16201629
List file names as with |:oldfiles|, and then prompt
16211630
for a number. When the number is valid that file from

src/eval.c

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -8929,60 +8929,6 @@ last_set_msg(scid_T scriptID)
89298929
}
89308930
}
89318931

8932-
/*
8933-
* List v:oldfiles in a nice way.
8934-
*/
8935-
void
8936-
ex_oldfiles(exarg_T *eap UNUSED)
8937-
{
8938-
list_T *l = vimvars[VV_OLDFILES].vv_list;
8939-
listitem_T *li;
8940-
int nr = 0;
8941-
8942-
if (l == NULL)
8943-
msg((char_u *)_("No old files"));
8944-
else
8945-
{
8946-
msg_start();
8947-
msg_scroll = TRUE;
8948-
for (li = l->lv_first; li != NULL && !got_int; li = li->li_next)
8949-
{
8950-
msg_outnum((long)++nr);
8951-
MSG_PUTS(": ");
8952-
msg_outtrans(get_tv_string(&li->li_tv));
8953-
msg_putchar('\n');
8954-
out_flush(); /* output one line at a time */
8955-
ui_breakcheck();
8956-
}
8957-
/* Assume "got_int" was set to truncate the listing. */
8958-
got_int = FALSE;
8959-
8960-
#ifdef FEAT_BROWSE_CMD
8961-
if (cmdmod.browse)
8962-
{
8963-
quit_more = FALSE;
8964-
nr = prompt_for_number(FALSE);
8965-
msg_starthere();
8966-
if (nr > 0)
8967-
{
8968-
char_u *p = list_find_str(get_vim_var_list(VV_OLDFILES),
8969-
(long)nr);
8970-
8971-
if (p != NULL)
8972-
{
8973-
p = expand_env_save(p);
8974-
eap->arg = p;
8975-
eap->cmdidx = CMD_edit;
8976-
cmdmod.browse = FALSE;
8977-
do_exedit(eap, NULL);
8978-
vim_free(p);
8979-
}
8980-
}
8981-
}
8982-
#endif
8983-
}
8984-
}
8985-
89868932
/* reset v:option_new, v:option_old and v:option_type */
89878933
void
89888934
reset_v_option_vars(void)

src/ex_cmds.c

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8391,3 +8391,84 @@ ex_drop(exarg_T *eap)
83918391
}
83928392
}
83938393
#endif
8394+
8395+
#if defined(FEAT_EVAL) || defined(PROTO)
8396+
/*
8397+
* List v:oldfiles in a nice way.
8398+
*/
8399+
void
8400+
ex_oldfiles(exarg_T *eap UNUSED)
8401+
{
8402+
list_T *l = get_vim_var_list(VV_OLDFILES);
8403+
listitem_T *li;
8404+
int nr = 0;
8405+
char_u *reg_pat = NULL;
8406+
char_u *fname;
8407+
regmatch_T regmatch;
8408+
8409+
if (l == NULL)
8410+
msg((char_u *)_("No old files"));
8411+
else
8412+
{
8413+
if (*eap->arg != NUL)
8414+
{
8415+
if (skip_vimgrep_pat(eap->arg, &reg_pat, NULL) == NULL)
8416+
{
8417+
EMSG(_(e_invalpat));
8418+
return;
8419+
}
8420+
regmatch.regprog = vim_regcomp(reg_pat, p_magic ? RE_MAGIC : 0);
8421+
if (regmatch.regprog == NULL)
8422+
return;
8423+
}
8424+
8425+
msg_start();
8426+
msg_scroll = TRUE;
8427+
for (li = l->lv_first; li != NULL && !got_int; li = li->li_next)
8428+
{
8429+
++nr;
8430+
fname = get_tv_string(&li->li_tv);
8431+
if (reg_pat == NULL || *reg_pat == NUL
8432+
|| vim_regexec(&regmatch, fname, (colnr_T)0))
8433+
{
8434+
msg_outnum((long)nr);
8435+
MSG_PUTS(": ");
8436+
msg_outtrans(fname);
8437+
msg_putchar('\n');
8438+
out_flush(); /* output one line at a time */
8439+
ui_breakcheck();
8440+
}
8441+
}
8442+
if (*eap->arg != NUL)
8443+
vim_regfree(regmatch.regprog);
8444+
8445+
/* Assume "got_int" was set to truncate the listing. */
8446+
got_int = FALSE;
8447+
8448+
# ifdef FEAT_BROWSE_CMD
8449+
if (cmdmod.browse)
8450+
{
8451+
quit_more = FALSE;
8452+
nr = prompt_for_number(FALSE);
8453+
msg_starthere();
8454+
if (nr > 0)
8455+
{
8456+
char_u *p = list_find_str(get_vim_var_list(VV_OLDFILES),
8457+
(long)nr);
8458+
8459+
if (p != NULL)
8460+
{
8461+
p = expand_env_save(p);
8462+
eap->arg = p;
8463+
eap->cmdidx = CMD_edit;
8464+
cmdmod.browse = FALSE;
8465+
do_exedit(eap, NULL);
8466+
vim_free(p);
8467+
}
8468+
}
8469+
}
8470+
# endif
8471+
}
8472+
}
8473+
#endif
8474+

src/ex_cmds.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,7 @@ EX(CMD_open, "open", ex_open,
992992
RANGE|BANG|EXTRA,
993993
ADDR_LINES),
994994
EX(CMD_oldfiles, "oldfiles", ex_oldfiles,
995-
BANG|TRLBAR|SBOXOK|CMDWIN,
995+
BANG|TRLBAR|NOTADR|EXTRA|SBOXOK|CMDWIN,
996996
ADDR_LINES),
997997
EX(CMD_omap, "omap", ex_map,
998998
EXTRA|TRLBAR|NOTRLCOM|USECTRLV|CMDWIN,

src/proto/eval.pro

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ int read_viminfo_varlist(vir_T *virp, int writing);
117117
void write_viminfo_varlist(FILE *fp);
118118
int store_session_globals(FILE *fd);
119119
void last_set_msg(scid_T scriptID);
120-
void ex_oldfiles(exarg_T *eap);
121120
void reset_v_option_vars(void);
122121
void prepare_assert_error(garray_T *gap);
123122
void assert_error(garray_T *gap);

src/proto/ex_cmds.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,5 @@ char_u *get_sign_name(expand_T *xp, int idx);
6565
void set_context_in_sign_cmd(expand_T *xp, char_u *arg);
6666
void ex_smile(exarg_T *eap);
6767
void ex_drop(exarg_T *eap);
68+
void ex_oldfiles(exarg_T *eap);
6869
/* vim: set ft=c : */

src/testdir/test_viminfo.vim

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,3 +455,28 @@ func Test_viminfo_file_mark_tabclose()
455455
call delete('Xviminfo')
456456
silent! bwipe Xtestfileintab
457457
endfunc
458+
459+
func Test_oldfiles()
460+
let v:oldfiles = []
461+
let lines = [
462+
\ '# comment line',
463+
\ '*encoding=utf-8',
464+
\ '',
465+
\ "> /tmp/file_one.txt",
466+
\ "\t\"\t11\t0",
467+
\ "",
468+
\ "> /tmp/file_two.txt",
469+
\ "\t\"\t11\t0",
470+
\ "",
471+
\ "> /tmp/another.txt",
472+
\ "\t\"\t11\t0",
473+
\ "",
474+
\ ]
475+
call writefile(lines, 'Xviminfo')
476+
rviminfo! Xviminfo
477+
call delete('Xviminfo')
478+
479+
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/'}))
480+
call assert_equal(['1: /tmp/file_one.txt', '2: /tmp/file_two.txt'], filter(split(execute('oldfile file_'), "\n"), {i, v -> v =~ '/tmp/'}))
481+
call assert_equal(['3: /tmp/another.txt'], filter(split(execute('oldfile /another/'), "\n"), {i, v -> v =~ '/tmp/'}))
482+
endfunc

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,8 @@ static char *(features[]) =
763763

764764
static int included_patches[] =
765765
{ /* Add new patch number below this line */
766+
/**/
767+
2231,
766768
/**/
767769
2230,
768770
/**/

0 commit comments

Comments
 (0)