Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Re-introduced :TRecentlyUsedFilesSessions command.

  • Loading branch information...
commit b2648d0d96c6d1851289c84290213c2aa6d76604 1 parent e0aa4bc
@tomtom authored
Showing with 70 additions and 16 deletions.
  1. +27 −13 autoload/tmru.vim
  2. +43 −3 plugin/tmru.vim
View
40 autoload/tmru.vim
@@ -3,21 +3,35 @@
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Created: 2011-04-10.
" @Last Change: 2011-08-24.
-" @Revision: 10
+" @Revision: 25
-function! tmru#Session(defs, session_no) "{{{3
+function! tmru#Session(session_no, mru) "{{{3
" TLogVAR a:session_no
- let [mru, metadata] = a:defs
- for idx in range(len(mru))
- let metaitem = metadata[idx]
- let session_no = get(metaitem, 'sessions', -1)
- " TLogVAR idx, session_no
- if session_no == a:session_no
- let filename = mru[idx]
- call TmruEdit(filename)
- endif
- endfor
+ let session_no = empty(a:session_no) ? 1 : str2nr(a:session_no)
+ if session_no > 0
+ for [filename, props] in a:mru
+ " TLogVAR filename, props
+ if get(props, 'session', 0) == session_no
+ call TmruEdit(filename)
+ endif
+ endfor
+ endif
+endf
+
+
+function! tmru#SetSessions(def) "{{{3
+ let [filename, props] = a:def
+ let session = get(props, 'session', 0)
+ if buflisted(filename)
+ let session += 1
+ endif
+ if session > 0 && session <= g:tmru_sessions
+ let a:def[1].session = session
+ elseif has_key(props, 'session')
+ call remove(a:def[1], 'session')
+ endif
+ return a:def
endf
@@ -26,7 +40,7 @@ function! tmru#DisplayUnreadableFiles(mru) "{{{3
for file in a:mru
if !filereadable(file)
echohl WarningMsg
- echom "DBG TMRU: unreadable file:" file
+ " echom "DBG TMRU: unreadable file:" file
echohl NONE
endif
endfor
View
46 plugin/tmru.vim
@@ -4,7 +4,7 @@
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Created: 2007-04-13.
" @Last Change: 2012-11-27.
-" @Revision: 712
+" @Revision: 740
" GetLatestVimScripts: 1864 1 tmru.vim
if &cp || exists("loaded_tmru")
@@ -30,6 +30,15 @@ if !exists("g:tmruMenuSize")
endif
+if !exists('g:tmru_sessions')
+ " If greater than zero, make tmru to save the file list opened when
+ " closing vim. Save at most information for N sessions.
+ "
+ " Setting this variable to 0, disables this feature.
+ let g:tmru_sessions = 10 "{{{2
+endif
+
+
if !exists('g:tmru_drop')
" If true, use |:drop| to edit loaded buffers.
let g:tmru_drop = 1 "{{{2
@@ -159,6 +168,10 @@ if !exists('g:tmru_world') "{{{2
\ }
" \ 'filter_format': 'fnamemodify(%s, ":t")',
if !empty(g:tmru_file)
+ if g:tmru_sessions > 0
+ call add(g:tmru_world.key_handlers,
+ \ {'key': 12, 'agent': s:SNR() .'PreviousSession', 'key_name': '<c-l>', 'help': 'Open files from a previous session'})
+ endif
call add(g:tmru_world.key_handlers,
\ {'key': 16, 'agent': s:SNR() .'TogglePersistent', 'key_name': '<c-p>', 'help': 'Toggle a file''s persistent mark'})
call add(g:tmru_world.key_handlers,
@@ -392,9 +405,16 @@ function! s:SetFilenameIndicators(world, mru) "{{{3
let a:world.filename_indicators = {}
for item in a:mru
let [filename, props] = item
+ let indicators = []
if get(props, 'sticky', 0)
- let a:world.filename_indicators[filename] = "s"
- " TLogVAR item, props
+ call add(indicators, "s")
+ endif
+ let session = get(props, 'session', 0)
+ if session > 0
+ call add(indicators, '-'. session)
+ endif
+ if !empty(indicators)
+ let a:world.filename_indicators[filename] = join(indicators, '')
endif
endfor
endf
@@ -650,3 +670,23 @@ command! TMRU TRecentlyUsedFiles
" Edit the MRU list.
command! TRecentlyUsedFilesEdit call s:EditMRU()
+if g:tmru_sessions > 0
+ " Open files from a previous session (see |g:tmru_sessions|).
+ " This command is only available if g:tmru_sessions > 0.
+ command! -nargs=? TRecentlyUsedFilesSessions call tmru#Session(<q-args>, s:MruRetrieve())
+
+ autocmd tmru VimLeave * call s:MruStore(map(s:MruRetrieve(), 'tmru#SetSessions(v:val)'), {'save': 2})
+
+ function! s:PreviousSession(world, selected) "{{{3
+ let session = input('Session number: ', 1)
+ if session > 0
+ call a:world.CloseScratch()
+ exec 'TRecentlyUsedFilesSessions' session
+ let a:world.state = 'exit'
+ else
+ let a:world.state = 'redisplay'
+ endif
+ return a:world
+ endf
+endif
+
Please sign in to comment.
Something went wrong with that request. Please try again.