Просмотр исходного кода

Add the MruGetFiles() function to return a list of file names from the MRU list. Add the MruRefresh command to remove non-existing files from the MRU list

Yegappan Lakshmanan 4 лет назад
Родитель
Сommit
b0cf14fba3
2 измененных файлов с 48 добавлено и 5 удалено
  1. 20 1
      doc/mru.txt
  2. 28 4
      plugin/mru.vim

+ 20 - 1
doc/mru.txt

@@ -201,11 +201,30 @@ window. By default, this syntax group is linked to the Identifier highlight
 group. You can change the highlight group by adding the following line in
 group. You can change the highlight group by adding the following line in
 your .vimrc:
 your .vimrc:
 >
 >
-   highlight link MRUFileName LineNr
+    highlight link MRUFileName LineNr
 <
 <
 The MRU buffer uses the 'mru file type. You can use this file type to add
 The MRU buffer uses the 'mru file type. You can use this file type to add
 custom auto commands, syntax highlighting, etc.
 custom auto commands, syntax highlighting, etc.
 
 
+						*:MruRefresh*
+After using the MRU plugin for a period of time, the MRU list may contain
+files which are no longer present in the system. The |:MruRefresh| command can
+be used to remove non-existing files from the MRU list.
+
+						*MruGetFiles()*
+The MruGetFiles() function can be used to get the current list of file names
+in the MRU list as a |List|. This can be used with Ex commands that accept one
+or more file names as argument. Some example uses for this function are below:
+>
+    " search for 'my_text' in all the files in the MRU list
+    :vimgrep my_text `=MruGetFiles()`
+    " search for 'my_text' in the files ending in .java in the MRU list
+    :vimgrep my_text `=MruGetFiles('.java')`
+    " add all the .py files in the MRU list to the argument list
+    :n `=MruGetFiles('.py')`
+    " Add the files in MRU list to a quickfix list
+    :call setqflist([], ' ', {'efm' : '%f', 'lines' : MruGetFiles()})
+<
 ==============================================================================
 ==============================================================================
 4. Configuration				*mru-configuration*
 4. Configuration				*mru-configuration*
 
 

+ 28 - 4
plugin/mru.vim

@@ -1,7 +1,7 @@
 " File: mru.vim
 " File: mru.vim
 " Author: Yegappan Lakshmanan (yegappan AT yahoo DOT com)
 " Author: Yegappan Lakshmanan (yegappan AT yahoo DOT com)
 " Version: 3.10
 " Version: 3.10
-" Last Modified: Feb 2, 2021
+" Last Modified: Feb 8, 2021
 " Copyright: Copyright (C) 2003-2021 Yegappan Lakshmanan
 " Copyright: Copyright (C) 2003-2021 Yegappan Lakshmanan
 " License:   Permission is hereby granted to use and distribute this code,
 " License:   Permission is hereby granted to use and distribute this code,
 "            with or without modifications, provided that this copyright
 "            with or without modifications, provided that this copyright
@@ -930,7 +930,15 @@ func! s:MRU_Refresh_Menu() abort
   let &cpoptions = old_cpoptions
   let &cpoptions = old_cpoptions
 endfunc
 endfunc
 
 
-" MRU_Delete_From_List	{{{1
+" MRU_Refresh    {{{1
+" Remove non-existing files from the MRU list
+func s:MRU_Refresh()
+  call filter(s:MRU_files, 'filereadable(v:val)')
+  call s:MRU_SaveList()
+  call s:MRU_Refresh_Menu()
+endfunc
+
+" MRU_Delete_From_List    {{{1
 " remove the entry under cursor in the MRU window from the MRU list
 " remove the entry under cursor in the MRU window from the MRU list
 func s:MRU_Delete_From_List()
 func s:MRU_Delete_From_List()
   call filter(s:MRU_files,
   call filter(s:MRU_files,
@@ -942,6 +950,21 @@ func s:MRU_Delete_From_List()
   call s:MRU_Refresh_Menu()
   call s:MRU_Refresh_Menu()
 endfunc
 endfunc
 
 
+" Return the list of file names in the MRU list {{{1
+func MruGetFiles(...)
+  " Load the latest MRU list
+  call s:MRU_LoadList()
+  if a:0 == 1
+    if g:MRU_FuzzyMatch
+      " Return only the files fuzzy matching the specified pattern
+      return matchfuzzy(s:MRU_files, a:1)
+    endif
+    " Return only the files matching the specified pattern
+    return filter(copy(s:MRU_files), 'v:val =~? a:1')
+  endif
+  return copy(s:MRU_files)
+endfunc
+
 " Load the MRU list on plugin startup
 " Load the MRU list on plugin startup
 call s:MRU_LoadList()
 call s:MRU_LoadList()
 
 
@@ -957,7 +980,7 @@ autocmd BufEnter * call s:MRU_AddFile(expand('<abuf>'))
 autocmd QuickFixCmdPre *vimgrep* let s:mru_list_locked = 1
 autocmd QuickFixCmdPre *vimgrep* let s:mru_list_locked = 1
 autocmd QuickFixCmdPost *vimgrep* let s:mru_list_locked = 0
 autocmd QuickFixCmdPost *vimgrep* let s:mru_list_locked = 0
 
 
-" Command to open the MRU window
+" MRU custom commands {{{1
 if v:version >= 800
 if v:version >= 800
   command! -nargs=? -complete=customlist,s:MRU_Complete -count=0 MRU
   command! -nargs=? -complete=customlist,s:MRU_Complete -count=0 MRU
 	\ call s:MRU_Cmd(<q-args>, <q-mods>, <count>)
 	\ call s:MRU_Cmd(<q-args>, <q-mods>, <count>)
@@ -969,8 +992,9 @@ else
   command! -nargs=? -complete=customlist,s:MRU_Complete -count=0 Mru
   command! -nargs=? -complete=customlist,s:MRU_Complete -count=0 Mru
 	\ call s:MRU_Cmd(<q-args>, '', <count>)
 	\ call s:MRU_Cmd(<q-args>, '', <count>)
 endif
 endif
+command! -nargs=0 MruRefresh call s:MRU_Refresh()
 
 
-" FZF (fuzzy finder) integration
+" FZF (fuzzy finder) integration    {{{1
 func s:MRU_FZF_EditFile(fname) abort
 func s:MRU_FZF_EditFile(fname) abort
   call s:MRU_Window_Edit_File(a:fname, 0, 'edit', 'useopen')
   call s:MRU_Window_Edit_File(a:fname, 0, 'edit', 'useopen')
 endfunc
 endfunc