Most Recently Used (MRU) Vim Plugin
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

701 lines
22 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. " File: mru.vim
  2. " Author: Yegappan Lakshmanan (yegappan AT yahoo DOT com)
  3. " Version: 3.1
  4. " Last Modified: February 17, 2008
  5. "
  6. " Overview
  7. " --------
  8. " The Most Recently Used (MRU) plugin provides an easy access to a list of
  9. " recently opened/edited files in Vim. This plugin automatically stores the
  10. " file names as you open/edit them in Vim.
  11. "
  12. " This plugin will work on all the platforms where Vim is supported. This
  13. " plugin will work in both console and GUI Vim. This version of the MRU
  14. " plugin needs Vim 7.0 and above. If you are using an earlier version of
  15. " Vim, then you should use an older version of the MRU plugin.
  16. "
  17. " The recently used filenames are stored in a file specified by the Vim
  18. " MRU_File variable.
  19. "
  20. " Installation
  21. " ------------
  22. " 1. Copy the mru.vim file to one of the following directories:
  23. "
  24. " $HOME/.vim/plugin - Unix like systems
  25. " $HOME/vimfiles/plugin - MS-Windows
  26. " $VIM:vimfiles:plugin - Macintosh
  27. " $VIM/vimfiles/plugin - All
  28. "
  29. " Refer to the following Vim help topics for more information about Vim
  30. " plugins:
  31. "
  32. " :help add-plugin
  33. " :help add-global-plugin
  34. " :help runtimepath
  35. "
  36. " 2. Set the MRU_File Vim variable in the .vimrc file to the location of a
  37. " file to store the most recently edited file names. This step is needed
  38. " only if you want to change the default MRU filename.
  39. " 3. Restart Vim.
  40. " 4. You can use the ":MRU" command to list and edit the recently used files.
  41. " In GUI Vim, you can use the 'File->Recent Files' menu to access the
  42. " recently used files.
  43. "
  44. " To uninstall this plugin, remove this file (mru.vim) from the
  45. " $HOME/.vim/plugin or $HOME/vimfiles/plugin or the $VIM/vimfile/plugin
  46. " directory.
  47. "
  48. " Usage
  49. " -----
  50. " You can use the ":MRU" command to list all the most recently edited file
  51. " names. The file names will be listed in a temporary Vim window. If the MRU
  52. " window is already opened, then the MRU list displayed in the window will be
  53. " refreshed.
  54. "
  55. " If you are using GUI Vim, then the names of the recently edited files are
  56. " added to the "File->Recent Files" menu. You can select the name of a file
  57. " from this sub-menu to edit the file.
  58. "
  59. " You can use the normal Vim commands to move around in the MRU window. You
  60. " cannot make changes in the MRU window.
  61. "
  62. " You can select a file name to edit by pressing the <Enter> key or by double
  63. " clicking the left mouse button on a file name. The selected file will be
  64. " opened. If the file is already opened in a window, the cursor will be moved
  65. " to that window. Otherwise, the file is opened in the previous window. If the
  66. " previous window has a modified buffer or is the preview window or is used by
  67. " some other plugin, then the file is opened in a new window.
  68. "
  69. " You can press the 'o' key to open the file name under the cursor in the
  70. " MRU window in a new window.
  71. "
  72. " To open a file from the MRU window in a new tab, press the 't' key. If the
  73. " file is already opened in a window in the current or in another tab, then
  74. " the cursor is moved to that tab. Otherwise, a new tab is opened.
  75. "
  76. " You can press the 'u' key in the MRU window to update the file list. This is
  77. " useful if you keep the MRU window open always.
  78. "
  79. " You can close the MRU window by pressing the 'q' key or using one of the Vim
  80. " window commands.
  81. "
  82. " To display only files matching a pattern from the MRU list in the MRU
  83. " window, you can specify a pattern to the ":MRU" command. For example, to
  84. " display only file names containing "vim" in them, you can use the following
  85. " command ":MRU vim". When you specify a partial file name and only one
  86. " matching filename is found, then the ":MRU" command will edit that file.
  87. "
  88. " The ":MRU" command supports command-line completion of file names from
  89. " the MRU list. You can enter a partial file name and then press <Tab>
  90. " or <Ctrl-D> to complete or list all the matching file names.
  91. "
  92. " Whenever the MRU list changes, the MRU file is updated with the latest MRU
  93. " list. When you have multiple instances of Vim running at the same time, the
  94. " latest MRU list will show up in all the instances of Vim.
  95. "
  96. " Configuration
  97. " -------------
  98. " By changing the following variables you can configure the behavior of this
  99. " plugin. Set the following variables in your .vimrc file using the 'let'
  100. " command.
  101. "
  102. " The list of recently edit file names is stored in the file specified by the
  103. " MRU_File variable. The default setting for this variable is
  104. " $HOME/.vim_mru_files for Unix systems and $VIM/_vim_mru_files for non-Unix
  105. " systems. You can change this variable to point to a file by adding the
  106. " following line to the .vimrc file:
  107. "
  108. " let MRU_File = 'd:\myhome\_vim_mru_files'
  109. "
  110. " By default, the plugin will remember the names of the last 10 used files.
  111. " As you edit more files, old file names will be removed from the MRU list.
  112. " You can set the 'MRU_Max_Entries' variable to remember more file names. For
  113. " example, to remember 20 most recently used file names, you can use
  114. "
  115. " let MRU_Max_Entries = 20
  116. "
  117. " By default, all the edited file names will be added to the MRU list. If you
  118. " want to exclude file names matching a list of patterns, you can set the
  119. " MRU_Exclude_Files variable to a list of Vim regular expressions. By default,
  120. " this variable is set to an empty string. For example, to not include files
  121. " in the temporary (/tmp, /var/tmp and d:\temp) directories, you can set the
  122. " MRU_Exclude_Files variable to
  123. "
  124. " let MRU_Exclude_Files = '^/tmp/.*\|^/var/tmp/.*' " For Unix
  125. " let MRU_Exclude_Files = '^c:\\temp\\.*' " For MS-Windows
  126. "
  127. " The specified pattern should be a Vim regular expression pattern.
  128. "
  129. " The default height of the MRU window is 8. You can set the MRU_Window_Height
  130. " variable to change the window height.
  131. "
  132. " let MRU_Window_Height = 15
  133. "
  134. " By default, when the :MRU command is invoked, the MRU list will be displayed
  135. " in a new window. Instead, if you want the MRU plugin to reuse the current
  136. " window, then you can set the 'MRU_Use_Current_Window' variable to one.
  137. "
  138. " let MRU_Use_Current_Window = 1
  139. "
  140. " The MRU plugin will reuse the current window. When a file name is selected,
  141. " the file is also opened in the current window.
  142. "
  143. " When you select a file from the MRU window, the MRU window will be
  144. " automatically closed and the selected file will be opened in the previous
  145. " window. You can set the 'MRU_Auto_Close' variable to zero to keep the MRU
  146. " window open.
  147. "
  148. " let MRU_Auto_Close = 0
  149. "
  150. " If you don't use the "File->Recent Files" menu and want to disable it,
  151. " then you can set the 'MRU_Add_Menu' variable to zero. By default, the
  152. " menu is enabled.
  153. "
  154. " let MRU_Add_Menu = 0
  155. "
  156. " ****************** Do not modify after this line ************************
  157. if exists('loaded_mru')
  158. finish
  159. endif
  160. let loaded_mru=1
  161. if v:version < 700
  162. finish
  163. endif
  164. " Line continuation used here
  165. let s:cpo_save = &cpo
  166. set cpo&vim
  167. " Maximum number of entries allowed in the MRU list
  168. if !exists('MRU_Max_Entries')
  169. let MRU_Max_Entries = 10
  170. endif
  171. " Files to exclude from the MRU list
  172. if !exists('MRU_Exclude_Files')
  173. let MRU_Exclude_Files = ''
  174. endif
  175. " Height of the MRU window
  176. " Default height is 8
  177. if !exists('MRU_Window_Height')
  178. let MRU_Window_Height = 8
  179. endif
  180. if !exists('MRU_Use_Current_Window')
  181. let MRU_Use_Current_Window = 0
  182. endif
  183. if !exists('MRU_Auto_Close')
  184. let MRU_Auto_Close = 1
  185. endif
  186. if !exists('MRU_File')
  187. if has('unix')
  188. let MRU_File = $HOME . "/.vim_mru_files"
  189. else
  190. let MRU_File = $VIM . "/_vim_mru_files"
  191. endif
  192. endif
  193. " Option for enabling or disabling the MRU menu
  194. if !exists('MRU_Add_Menu')
  195. let MRU_Add_Menu = 1
  196. endif
  197. " MRU_LoadList
  198. " Load the latest MRU file list from the MRU file
  199. function! s:MRU_LoadList()
  200. " Read the list from the MRU file.
  201. if filereadable(g:MRU_File)
  202. let s:MRU_files = readfile(g:MRU_File)
  203. if s:MRU_files[0] =~# '^" Most recently edited files in Vim'
  204. " Generated by the previous version of the MRU plugin. Ignore the
  205. " list
  206. let s:MRU_files = []
  207. elseif s:MRU_files[0] =~# '^#'
  208. " Remove the comment line
  209. call remove(s:MRU_files, 0)
  210. endif
  211. else
  212. let s:MRU_files = []
  213. endif
  214. " Refresh the MRU menu
  215. call s:MRU_Refresh_Menu()
  216. endfunction
  217. " MRU_SaveList
  218. " Save the MRU list to the file
  219. function! s:MRU_SaveList()
  220. let l = []
  221. call add(l, '# Most recently edited files in Vim (version 3.0)')
  222. call extend(l, s:MRU_files)
  223. call writefile(l, g:MRU_File)
  224. endfunction
  225. " MRU_AddFile
  226. " Add a file to the MRU file list
  227. function! s:MRU_AddFile(acmd_bufnr)
  228. " Get the full path to the filename
  229. let fname = fnamemodify(bufname(a:acmd_bufnr + 0), ':p')
  230. if fname == ''
  231. return
  232. endif
  233. " Skip temporary buffer with buftype set
  234. if &buftype != ''
  235. return
  236. endif
  237. if g:MRU_Exclude_Files != ''
  238. " Do not add files matching the pattern specified in the
  239. " MRU_Exclude_Files to the MRU list
  240. if fname =~? g:MRU_Exclude_Files
  241. return
  242. endif
  243. endif
  244. " If the filename is already present in the MRU list, then move
  245. " it to the beginning of the list
  246. let idx = index(s:MRU_files, fname)
  247. if idx == -1
  248. if !filereadable(fname)
  249. " File is not readable and is not in the MRU list
  250. return
  251. endif
  252. endif
  253. " Load the latest MRU file list
  254. call s:MRU_LoadList()
  255. " Remove the new file name from the existing MRU list (if already present)
  256. call filter(s:MRU_files, 'v:val !=# fname')
  257. " Add the new file list to the beginning of the updated old file list
  258. call insert(s:MRU_files, fname, 0)
  259. " Return the trimmed list
  260. if len(s:MRU_files) > g:MRU_Max_Entries
  261. call remove(s:MRU_files, g:MRU_Max_Entries, -1)
  262. endif
  263. " Save the updated MRU list
  264. call s:MRU_SaveList()
  265. " Refresh the MRU menu
  266. call s:MRU_Refresh_Menu()
  267. " If the MRU window is open, update the displayed MRU list
  268. let bname = '__MRU_Files__'
  269. let winnum = bufwinnr(bname)
  270. if winnum != -1
  271. let cur_winnr = winnr()
  272. call s:MRU_Open_Window()
  273. if winnr() != cur_winnr
  274. exe cur_winnr . 'wincmd w'
  275. endif
  276. endif
  277. endfunction
  278. " MRU_Edit_File
  279. " Edit the specified file
  280. function! s:MRU_Edit_File(filename)
  281. let fname = escape(a:filename, ' %#"')
  282. " If the file is already open in one of the windows, jump to it
  283. let winnum = bufwinnr('^' . fname . '$')
  284. if winnum != -1
  285. if winnum != winnr()
  286. exe winnum . 'wincmd w'
  287. endif
  288. else
  289. if &modified || &buftype != '' || &previewwindow
  290. " Current buffer has unsaved changes or is a special buffer or is
  291. " the preview window. So open the file in a new window
  292. exe 'split ' . fname
  293. else
  294. exe 'edit ' . fname
  295. endif
  296. endif
  297. endfunction
  298. " MRU_Window_Edit_File
  299. " Open a file selected from the MRU window
  300. " win_opt == useopen, open file in previous window
  301. " win_opt == newwin, open file in new window
  302. " win_opt == newtab, open file in new tab
  303. function! s:MRU_Window_Edit_File(win_opt)
  304. let fname = getline('.')
  305. if fname == ''
  306. return
  307. endif
  308. let fname = escape(fname, ' %#"')
  309. if a:win_opt == 'newwin'
  310. " Edit the file in a new window
  311. exe 'leftabove new ' . fname
  312. if g:MRU_Auto_Close == 1 && g:MRU_Use_Current_Window == 0
  313. " Go back to the MRU window and close it
  314. let cur_winnr = winnr()
  315. wincmd p
  316. silent! close
  317. if winnr() != cur_winnr
  318. exe cur_winnr . 'wincmd w'
  319. endif
  320. endif
  321. elseif a:win_opt == 'newtab'
  322. if g:MRU_Auto_Close == 1 && g:MRU_Use_Current_Window == 0
  323. " Automatically close the window if the file window is
  324. " not used to display the MRU list.
  325. silent! close
  326. endif
  327. " If the selected file is already open in the current tab or in
  328. " another tab, jump to it. Otherwise open it in a new tab
  329. if bufwinnr('^' . fname . '$') == -1
  330. let tabnum = -1
  331. let i = 1
  332. let bnum = bufnr('^' . fname . '$')
  333. while i <= tabpagenr('$')
  334. if index(tabpagebuflist(i), bnum) != -1
  335. let tabnum = i
  336. break
  337. endif
  338. let i += 1
  339. endwhile
  340. if tabnum != -1
  341. " Goto the tab containing the file
  342. exe 'tabnext ' . i
  343. else
  344. " Open a new tab as the last tab page
  345. exe '999tabnew ' . fname
  346. endif
  347. endif
  348. " Jump to the window containing the file
  349. let winnum = bufwinnr('^' . fname . '$')
  350. if winnum != winnr()
  351. exe winnum . 'wincmd w'
  352. endif
  353. else
  354. " If the selected file is already open in one of the windows,
  355. " jump to it
  356. let winnum = bufwinnr('^' . fname . '$')
  357. if winnum != -1
  358. if g:MRU_Auto_Close == 1 && g:MRU_Use_Current_Window == 0
  359. " Automatically close the window if the file window is
  360. " not used to display the MRU list.
  361. silent! close
  362. endif
  363. " As the window numbers will change after closing a window,
  364. " get the window number again and jump to it, if the cursor
  365. " is not already in that window
  366. let winnum = bufwinnr('^' . fname . '$')
  367. if winnum != winnr()
  368. exe winnum . 'wincmd w'
  369. endif
  370. else
  371. if g:MRU_Auto_Close == 1 && g:MRU_Use_Current_Window == 0
  372. " Automatically close the window if the file window is
  373. " not used to display the MRU list.
  374. silent! close
  375. " Jump to the window from which the MRU window was opened
  376. if exists('s:MRU_last_buffer')
  377. let last_winnr = bufwinnr(s:MRU_last_buffer)
  378. if last_winnr != -1 && last_winnr != winnr()
  379. exe last_winnr . 'wincmd w'
  380. endif
  381. endif
  382. else
  383. if g:MRU_Use_Current_Window == 0
  384. " Goto the previous window
  385. " If MRU_Use_Current_Window is set to one, then the
  386. " current window is used to open the file
  387. wincmd p
  388. endif
  389. endif
  390. " Edit the file
  391. if &modified || &buftype != '' || &previewwindow
  392. " Current buffer has unsaved changes or is a special buffer or
  393. " is the preview window. So open the file in a new window
  394. exe 'split ' . fname
  395. else
  396. exe 'edit ' . fname
  397. endif
  398. endif
  399. endif
  400. endfunction
  401. " MRU_Warn_Msg
  402. " Display a warning message
  403. function! s:MRU_Warn_Msg(msg)
  404. echohl WarningMsg
  405. echo a:msg
  406. echohl None
  407. endfunction
  408. " MRU_Open_Window
  409. " Display the Most Recently Used file list in a temporary window.
  410. function! s:MRU_Open_Window(...)
  411. " Load the latest MRU file list
  412. call s:MRU_LoadList()
  413. " Empty MRU list
  414. if empty(s:MRU_files)
  415. call s:MRU_Warn_Msg('MRU file list is empty')
  416. return
  417. endif
  418. " Save the current buffer number. This is used later to open a file when a
  419. " entry is selected from the MRU window. The window number is not saved,
  420. " as the window number will change when new windows are opened.
  421. let s:MRU_last_buffer = bufnr('%')
  422. let bname = '__MRU_Files__'
  423. " If the window is already open, jump to it
  424. let winnum = bufwinnr(bname)
  425. if winnum != -1
  426. if winnr() != winnum
  427. " If not already in the window, jump to it
  428. exe winnum . 'wincmd w'
  429. endif
  430. setlocal modifiable
  431. " Delete the contents of the buffer to the black-hole register
  432. silent! %delete _
  433. else
  434. if g:MRU_Use_Current_Window
  435. " Reuse the current window
  436. "
  437. " If the __MRU_Files__ buffer exists, then reuse it. Otherwise open
  438. " a new buffer
  439. let bufnum = bufnr(bname)
  440. if bufnum == -1
  441. let cmd = 'edit ' . bname
  442. else
  443. let cmd = 'buffer ' . bufnum
  444. endif
  445. exe cmd
  446. if bufnr('%') != bufnr(bname)
  447. " Failed to edit the MRU buffer
  448. return
  449. endif
  450. else
  451. " Open a new window at the bottom
  452. " If the __MRU_Files__ buffer exists, then reuse it. Otherwise open
  453. " a new buffer
  454. let bufnum = bufnr(bname)
  455. if bufnum == -1
  456. let wcmd = bname
  457. else
  458. let wcmd = '+buffer' . bufnum
  459. endif
  460. exe 'silent! botright ' . g:MRU_Window_Height . 'split ' . wcmd
  461. endif
  462. endif
  463. " Mark the buffer as scratch
  464. setlocal buftype=nofile
  465. setlocal bufhidden=delete
  466. setlocal noswapfile
  467. setlocal nowrap
  468. setlocal nobuflisted
  469. " Use fixed height for the MRU window
  470. if v:version >= 602
  471. setlocal winfixheight
  472. endif
  473. " Setup the cpoptions properly for the maps to work
  474. let old_cpoptions = &cpoptions
  475. set cpoptions&vim
  476. " Create a mapping to jump to the file
  477. nnoremap <buffer> <silent> <CR>
  478. \ :call <SID>MRU_Window_Edit_File('useopen')<CR>
  479. nnoremap <buffer> <silent> o
  480. \ :call <SID>MRU_Window_Edit_File('newwin')<CR>
  481. nnoremap <buffer> <silent> t
  482. \ :call <SID>MRU_Window_Edit_File('newtab')<CR>
  483. nnoremap <buffer> <silent> u :MRU<CR>
  484. nnoremap <buffer> <silent> <2-LeftMouse>
  485. \ :call <SID>MRU_Window_Edit_File('useopen')<CR>
  486. nnoremap <buffer> <silent> q :close<CR>
  487. " Restore the previous cpoptions settings
  488. let &cpoptions = old_cpoptions
  489. " Display the MRU list
  490. if a:0 == 0
  491. " No search pattern specified. Display the complete list
  492. silent! 0put =s:MRU_files
  493. else
  494. " Display only the entries matching the specified pattern
  495. silent! 0put =filter(copy(s:MRU_files), 'v:val =~? a:1')
  496. endif
  497. " Move the cursor to the beginning of the file
  498. exe 1
  499. setlocal nomodifiable
  500. endfunction
  501. " MRU_Complete
  502. " Command-line completion function used by :MRU command
  503. function! s:MRU_Complete(ArgLead, CmdLine, CursorPos)
  504. if a:ArgLead == ''
  505. " Return the list of MRU files
  506. return s:MRU_files
  507. else
  508. return filter(copy(s:MRU_files), 'v:val =~? a:ArgLead')
  509. endif
  510. endfunction
  511. " MRU_Cmd
  512. " Function to handle the MRU command
  513. function! s:MRU_Cmd(pat)
  514. if a:pat == ''
  515. " No arguments specified. Open the MRU window
  516. call s:MRU_Open_Window()
  517. return
  518. endif
  519. " Load the latest MRU file
  520. call s:MRU_LoadList()
  521. " Empty MRU list
  522. if empty(s:MRU_files)
  523. call s:MRU_Warn_Msg('MRU file list is empty')
  524. return
  525. endif
  526. " First use the specified string as a literal string and search for
  527. " filenames containing the string. If only one filename is found,
  528. " then edit it.
  529. let m = filter(copy(s:MRU_files), 'stridx(v:val, a:pat) != -1')
  530. if len(m) == 1
  531. call s:MRU_Edit_File(m[0])
  532. return
  533. endif
  534. " Use the specified string as a regular expression pattern and search
  535. " for filenames matching the pattern
  536. let m = filter(copy(s:MRU_files), 'v:val =~? a:pat')
  537. if len(m) == 0
  538. " No filenames matching the specified pattern are found
  539. call s:MRU_Warn_Msg("MRU file list doesn't contain " .
  540. \ "files containing " . a:pat)
  541. return
  542. endif
  543. if len(m) == 1
  544. call s:MRU_Edit_File(m[0])
  545. return
  546. endif
  547. call s:MRU_Open_Window(a:pat)
  548. endfunction
  549. function! s:MRU_add_files_to_menu(prefix, file_list)
  550. for fname in a:file_list
  551. " Escape special characters in the filename
  552. let esc_fname = escape(fnamemodify(fname, ':t'), ". \\|\t%#")
  553. " Truncate the directory name if it is long
  554. let dir_name = fnamemodify(fname, ':h')
  555. let len = strlen(dir_name)
  556. " Shorten long file names by adding only few characters from
  557. " the beginning and end.
  558. if len > 30
  559. let dir_name = strpart(dir_name, 0, 10) .
  560. \ '...' .
  561. \ strpart(dir_name, len - 20)
  562. endif
  563. let esc_dir_name = escape(dir_name, ". \\|\t")
  564. exe 'anoremenu <silent> &File.Recent\ Files.' . a:prefix . esc_fname .
  565. \ '\ (' . esc_dir_name . ')' .
  566. \ " :call <SID>MRU_Edit_File('" . fname . "')<CR>"
  567. endfor
  568. endfunction
  569. " MRU_Refresh_Menu()
  570. " Refresh the MRU menu
  571. function! s:MRU_Refresh_Menu()
  572. if !has('menu') || !g:MRU_Add_Menu
  573. " No support for menus
  574. return
  575. endif
  576. " Setup the cpoptions properly for the maps to work
  577. let old_cpoptions = &cpoptions
  578. set cpoptions&vim
  579. " Remove the MRU menu
  580. " To retain the teared-off MRU menu, we need to add a dummy entry
  581. silent! unmenu &File.Recent\ Files
  582. " The menu priority of the File menu is 10. If the MRU plugin runs
  583. " first before menu.vim, the File menu order may not be correct.
  584. " So specify the priority of the File menu here.
  585. 10noremenu &File.Recent\ Files.Dummy <Nop>
  586. silent! unmenu! &File.Recent\ Files
  587. anoremenu <silent> &File.Recent\ Files.Refresh\ list
  588. \ :call <SID>MRU_LoadList()<CR>
  589. anoremenu File.Recent\ Files.-SEP1- :
  590. " Add the filenames in the MRU list to the menu
  591. let entry_cnt = len(s:MRU_files)
  592. if entry_cnt > 10
  593. for start_idx in range(0, entry_cnt, 10)
  594. let last_idx = start_idx + 9
  595. if last_idx >= entry_cnt
  596. let last_idx = entry_cnt - 1
  597. endif
  598. let prefix = 'Files\ (' . (start_idx + 1) . '\.\.\.' .
  599. \ (last_idx + 1) . ').'
  600. call s:MRU_add_files_to_menu(prefix,
  601. \ s:MRU_files[start_idx : last_idx])
  602. endfor
  603. else
  604. call s:MRU_add_files_to_menu('', s:MRU_files)
  605. endif
  606. " Remove the dummy menu entry
  607. unmenu &File.Recent\ Files.Dummy
  608. " Restore the previous cpoptions settings
  609. let &cpoptions = old_cpoptions
  610. endfunction
  611. " Load the MRU list on plugin startup
  612. call s:MRU_LoadList()
  613. " Autocommands to detect the most recently used files
  614. autocmd BufRead * call s:MRU_AddFile(expand('<abuf>'))
  615. autocmd BufNewFile * call s:MRU_AddFile(expand('<abuf>'))
  616. autocmd BufWritePost * call s:MRU_AddFile(expand('<abuf>'))
  617. " Command to open the MRU window
  618. command! -nargs=? -complete=customlist,s:MRU_Complete MRU
  619. \ call s:MRU_Cmd(<q-args>)
  620. " restore 'cpo'
  621. let &cpo = s:cpo_save
  622. unlet s:cpo_save