]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.0420: :browse oldfiles prompts even with single entry v9.1.0420
authorChristian Brabandt <cb@256bit.org>
Sun, 19 May 2024 07:11:09 +0000 (09:11 +0200)
committerChristian Brabandt <cb@256bit.org>
Sun, 19 May 2024 07:11:09 +0000 (09:11 +0200)
Problem:  :browse oldfiles prompts even with single entry
Solution: Do not prompt, but edit the file directly,
          also when using :filter /pat/ browse oldfiles

closes: #14794

Signed-off-by: Christian Brabandt <cb@256bit.org>
runtime/doc/usr_21.txt
src/ex_cmds.c
src/testdir/test_viminfo.vim
src/version.c

index 95ded58eafde0d3b77fc8cc3efdd0726d852c64f..fe3ee3199cd5d6c0ff2a4c9d76cc487af80a0f36 100644 (file)
@@ -1,4 +1,4 @@
-*usr_21.txt*   For Vim version 9.1.  Last change: 2019 Apr 25
+*usr_21.txt*   For Vim version 9.1.  Last change: 2024 May 17
 
                     VIM USER MANUAL - by Bram Moolenaar
 
@@ -207,6 +207,23 @@ You get the same list of files as with |:oldfiles|.  If you want to edit
 
 Type "2" and press <Enter> to edit the second file.
 
+If you know that the filename contains a pattern, you can also |:filter| the
+list of files: >
+
+       :filter /resume/ :browse oldfiles
+<
+Since there is only one single matching filename, Vim will directly edit that
+file without prompting.  If the filter matches several files, you'll get
+prompted for the list of matching files instead: >
+
+       :filter! /resume/ browse oldfiles
+<      1: ~/.viminfo ~
+       3: /tmp/draft ~
+       Type number and <Enter> (q or empty cancels): ~
+
+Note: this time we filtered out all files NOT matching resume.
+
+
 More info at |:oldfiles|, |v:oldfiles| and |c_#<|.
 
 
index 2a5d842fc9c7ab085967b616e02c6306f4f31286..5c34e8645dad5b9c657f112672f2c3f6ae0dafab 100644 (file)
@@ -5622,6 +5622,9 @@ ex_oldfiles(exarg_T *eap UNUSED)
     listitem_T *li;
     int                nr = 0;
     char_u     *fname;
+    // for a single filtered match, remember the number
+    // so we can jump directly to it without prompting
+    int                matches = -1;
 
     if (l == NULL)
     {
@@ -5637,6 +5640,10 @@ ex_oldfiles(exarg_T *eap UNUSED)
        fname = tv_get_string(&li->li_tv);
        if (!message_filtered(fname))
        {
+           if (matches < 0)
+               matches = nr;
+           else
+               matches = 0;
            msg_outnum((long)nr);
            msg_puts(": ");
            msg_outtrans(fname);
@@ -5654,7 +5661,15 @@ ex_oldfiles(exarg_T *eap UNUSED)
     if (cmdmod.cmod_flags & CMOD_BROWSE)
     {
        quit_more = FALSE;
-       nr = prompt_for_number(FALSE);
+       // we only need to prompt if there is more than 1 match
+       if (matches > 0)
+       {
+           nr = matches;
+           // msg_putchar above sets needs_wait_return
+           need_wait_return = FALSE;
+       }
+       else
+           nr = prompt_for_number(FALSE);
        msg_starthere();
        if (nr > 0)
        {
index 1f4a72db16432499c686757b5926589babdda9f4..7aab271336538c3833a8fceeb2d885de49e52c4d 100644 (file)
@@ -1299,4 +1299,34 @@ func Test_viminfo_merge_old_jumplist()
   bw!
 endfunc
 
+func Test_viminfo_oldfiles_filter()
+  let v:oldfiles = []
+  let _viminfofile = &viminfofile
+  let &viminfofile=''
+  let lines = [
+       \ '# comment line',
+       \ '*encoding=utf-8',
+       \ "> /tmp/vimrc_one.vim",
+       \ "\t\"\t11\t0",
+       \ "",
+       \ "> /tmp/foobar.txt",
+       \ "\t\"\t11\t0",
+       \ "",
+       \ ]
+  call writefile(lines, 'Xviminfo1', 'D')
+  rviminfo! Xviminfo1
+  new
+  " filter returns a single item
+  let a = execute('filter /vim/ oldfiles')->split('\n')
+  call assert_equal(1, len(a))
+  " filter returns more than a single match
+  let a = execute('filter #tmp# oldfiles')->split('\n')
+  call assert_equal(2, len(a))
+  " don't get prompted for the file, but directly open it
+  filter /vim/ browse oldfiles
+  call assert_equal("/tmp/vimrc_one.vim", expand("%"))
+  bw
+  let &viminfofile = _viminfofile
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index 34f474da4d644f8d908a06630c9654cf7a4c2624..aafbddcd8e0c4dbe70543db6e90c20ae2688d23b 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    420,
 /**/
     419,
 /**/