aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/ex_cmds.c
diff options
context:
space:
mode:
authorJames McCoy <jamessan@jamessan.com>2017-04-28 21:04:17 -0400
committerJames McCoy <jamessan@jamessan.com>2017-04-29 21:46:12 -0400
commitdbdc2d40bb7a950e294c6e50906f546707ccf390 (patch)
tree72eadcf95cf00567554ef2e2a2a5c557e15d3237 /src/nvim/ex_cmds.c
parent0df1b6655be5385c9cbb70dca1c042c6447ec50b (diff)
downloadrneovim-dbdc2d40bb7a950e294c6e50906f546707ccf390.tar.gz
rneovim-dbdc2d40bb7a950e294c6e50906f546707ccf390.tar.bz2
rneovim-dbdc2d40bb7a950e294c6e50906f546707ccf390.zip
vim-patch:7.4.2231
Problem: ":oldfiles" output is a very long list. Solution: Add a pattern argument. (Coot, closes vim/vim#575) https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Diffstat (limited to 'src/nvim/ex_cmds.c')
-rw-r--r--src/nvim/ex_cmds.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c
index 7726e0fc6d..ab85bb766f 100644
--- a/src/nvim/ex_cmds.c
+++ b/src/nvim/ex_cmds.c
@@ -6158,3 +6158,71 @@ void ex_substitute(exarg_T *eap)
ga_clear(&save_view);
unblock_autocmds();
}
+
+/// List v:oldfiles in a nice way.
+void ex_oldfiles(exarg_T *eap)
+{
+ list_T *l = get_vim_var_list(VV_OLDFILES);
+ listitem_T *li;
+ long nr = 0;
+
+ if (l == NULL) {
+ msg((char_u *)_("No old files"));
+ } else {
+ char_u *reg_pat = NULL;
+ regmatch_T regmatch;
+
+ 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++;
+ const char *fname = tv_get_string(&li->li_tv);
+ if (reg_pat == NULL || *reg_pat == NUL
+ || vim_regexec(&regmatch, (char_u *)fname, (colnr_T)0)) {
+ msg_outnum(nr);
+ MSG_PUTS(": ");
+ msg_outtrans((char_u *)tv_get_string(&li->li_tv));
+ msg_clr_eos();
+ msg_putchar('\n');
+ ui_flush(); // output one line at a time
+ os_breakcheck();
+ }
+ }
+ if (*eap->arg != NUL) {
+ vim_regfree(regmatch.regprog);
+ }
+
+ /* Assume "got_int" was set to truncate the listing. */
+ got_int = FALSE;
+
+ // File selection prompt on ":browse oldfiles"
+ if (cmdmod.browse) {
+ quit_more = false;
+ nr = prompt_for_number(false);
+ msg_starthere();
+ if (nr > 0 && nr <= l->lv_len) {
+ const char *const p = tv_list_find_str(l, nr - 1);
+ if (p == NULL) {
+ return;
+ }
+ char *const s = (char *)expand_env_save((char_u *)p);
+ eap->arg = (char_u *)s;
+ eap->cmdidx = CMD_edit;
+ cmdmod.browse = false;
+ do_exedit(eap, NULL);
+ xfree(s);
+ }
+ }
+ }
+}