Parcourir la source

MRU_Toggle cmd added (#46)

* MRU_Toggle cmd added

* document MRUToggle

* Add :MRUToggle tag for `:help MRUToggle`

* Fix extra args passed to modify location of MRU

Co-authored-by: Andrea Bonomi <andrea.bonomi@gmail.com>
Tama McGlinn il y a 4 ans
Parent
commit
a484baac67
2 fichiers modifiés avec 22 ajouts et 0 suppressions
  1. 4 0
      doc/mru.txt
  2. 18 0
      plugin/mru.vim

+ 4 - 0
doc/mru.txt

@@ -105,6 +105,10 @@ To list and edit files from the Most Recently Used (MRU) list, you can use the
 in a temporary Vim window.  If the MRU window is already opened, then the MRU
 in a temporary Vim window.  If the MRU window is already opened, then the MRU
 list currently displayed in the window is refreshed.
 list currently displayed in the window is refreshed.
 
 
+						*:MRUToggle*
+Alternatively, ":MRUToggle" will toggle the MRU window; so that if it is
+already opened, :MRUToggle again will close the window.
+
 If you are using GUI Vim, then the names of the recently edited files are
 If you are using GUI Vim, then the names of the recently edited files are
 added to the "File->Recent Files" menu. You can select the name of a file
 added to the "File->Recent Files" menu. You can select the name of a file
 from this sub-menu to edit the file.
 from this sub-menu to edit the file.

+ 18 - 0
plugin/mru.vim

@@ -836,6 +836,20 @@ func! s:MRU_Cmd(pat, splitdir, winsz) abort
   call s:MRU_Open_Window(a:pat, a:splitdir, a:winsz)
   call s:MRU_Open_Window(a:pat, a:splitdir, a:winsz)
 endfunc
 endfunc
 
 
+" MRU_Toggle                          {{{1
+" Toggle MRU
+"   pat - File name pattern passed to the MRU command
+function! s:MRU_Toggle(pat, splitdir)
+    " If the MRU window is open, close it
+    let winnum = bufwinnr(s:MRU_buf_name)
+    if winnum != -1
+        exe winnum . 'wincmd w'
+        silent! close
+    else
+        call s:MRU_Cmd(a:pat, a:splitdir, '')
+    endif
+endfunction
+
 " MRU_add_files_to_menu                 {{{1
 " MRU_add_files_to_menu                 {{{1
 " Adds a list of files to the "Recent Files" sub menu under the "File" menu.
 " Adds a list of files to the "Recent Files" sub menu under the "File" menu.
 "   prefix - Prefix to use for each of the menu entries
 "   prefix - Prefix to use for each of the menu entries
@@ -995,11 +1009,15 @@ if v:version >= 800
 	\ call s:MRU_Cmd(<q-args>, <q-mods>, <count>)
 	\ call s:MRU_Cmd(<q-args>, <q-mods>, <count>)
   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>)
+  command! -nargs=? -complete=customlist,s:MRU_Complete MRUToggle
+              \ call s:MRU_Toggle(<q-args>, <q-mods>)
 else
 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>)
   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>)
+  command! -nargs=? -complete=customlist,s:MRU_Complete MRUToggle
+              \ call s:MRU_Toggle(<q-args>, '')
 endif
 endif
 command! -nargs=0 MruRefresh call s:MRU_Refresh()
 command! -nargs=0 MruRefresh call s:MRU_Refresh()