Browse files

Don't simply record a file's latest session but every session it was in

  • Loading branch information...
1 parent e1671f8 commit f68c5e84f39301519b155a8db5642a3f2c53dc64 @tomtom committed Nov 30, 2012
Showing with 47 additions and 28 deletions.
  1. +27 −17 autoload/tmru.vim
  2. +20 −11 plugin/tmru.vim
View
44 autoload/tmru.vim
@@ -3,7 +3,7 @@
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Created: 2011-04-10.
" @Last Change: 2012-11-29.
-" @Revision: 52
+" @Revision: 68
if !exists('g:tmru#world') "{{{2
@@ -152,7 +152,7 @@ function! tmru#Session(session_no, mru) "{{{3
if session_no > 0
for [filename, props] in a:mru
" TLogVAR filename, props
- if get(props, 'session', 0) == session_no
+ if index(get(props, 'sessions', []), session_no) != -1
call tmru#Edit(filename)
endif
endfor
@@ -162,16 +162,18 @@ endf
function! tmru#SetSessions(def) "{{{3
let [filename, props] = a:def
- let session = get(props, 'session', 0)
+ let sessions = get(props, 'sessions', [])
+ if !empty(sessions)
+ let sessions = map(sessions, 'v:val + 1')
+ let sessions = filter(sessions, 'v:val <= g:tmru_sessions')
+ endif
if buflisted(filename)
- let session = 1
- elseif session > 0
- let session += 1
+ let sessions = insert(sessions, 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')
+ if !empty(sessions)
+ let a:def[1].sessions = sessions
+ elseif has_key(props, 'sessions')
+ call remove(a:def[1], 'sessions')
endif
return a:def
endf
@@ -318,26 +320,34 @@ endf
function! tmru#PreviousSession(world, selected) "{{{3
- let sessions = []
+ let sessions_done = []
let tmruobj = TmruObj()
let filenames = tmruobj.GetFilenames()
for filename in a:selected
let fidx = tmruobj.FilenameIndex(filenames, filename)
if fidx >= 0
let props = tmruobj.mru[fidx][1]
- if has_key(props, 'session')
- let session = props['session']
- if session > 0 && index(sessions, session) == -1
- if empty(sessions)
+ if has_key(props, 'sessions')
+ let sessions = copy(props.sessions)
+ let sessions = filter(sessions, 'index(sessions_done, v:val) == -1')
+ if empty(sessions)
+ let session = 0
+ elseif len(sessions) == 1
+ let session = sessions[0]
+ else
+ let session = tlib#input#List('s', 'Select session:', sessions)
+ endif
+ if session > 0
+ if empty(sessions_done)
call a:world.CloseScratch()
endif
- call add(sessions, session)
+ call add(sessions_done, session)
exec 'TRecentlyUsedFilesSessions' session
endif
endif
endif
endfor
- if empty(sessions)
+ if empty(sessions_done)
let a:world.state = 'redisplay'
else
let a:world.state = 'exit'
View
31 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-30.
-" @Revision: 822
+" @Revision: 845
" GetLatestVimScripts: 1864 1 tmru.vim
if &cp || exists("loaded_tmru")
@@ -86,7 +86,7 @@ if !exists("g:tmru_events")
unlet g:tmruEvents
else
let g:tmru_events = {
- \ 'VimLeave': {'load': 0, 'register': 0, 'save': g:tmru_single_instance_mode},
+ \ 'VimLeave': {'load': 0, 'register': 0, 'save': g:tmru_single_instance_mode, 'exit': 1},
\ 'FocusGained': {'load': 1, 'register': 0, 'save': !g:tmru_single_instance_mode},
\ 'FocusLost': {'load': 0, 'register': 0, 'save': !g:tmru_single_instance_mode},
\ 'BufWritePost': {'load': 0, 'register': 1, 'save': !g:tmru_single_instance_mode},
@@ -230,12 +230,13 @@ function! s:SetFilenameIndicators(world, mru) "{{{3
if get(props, 'sticky', 0)
call add(indicators, "s")
endif
- let session = get(props, 'session', 0)
- if session > 0
- call add(indicators, '-'. session)
+ let sessions = get(props, 'sessions', [])
+ if !empty(sessions)
+ call add(indicators, '-'. join(sessions, '-'))
endif
if !empty(indicators)
let fname = g:tmru#display_relative_filename ? a:world.base[idx] : filename
+ " TLogVAR fname, indicators
let a:world.filename_indicators[fname] = join(indicators, '')
endif
let idx += 1
@@ -275,14 +276,22 @@ function! s:NormalizeFilename(filename) "{{{3
endf
-function! s:MruStore(mru, props)
- " TLogVAR g:tmru_file, a:props
+function! s:MruStore(mru, ...)
+ " TLogVAR g:tmru_file
+ let props = a:0 >= 1 ? a:1 : {}
let tmru_list = s:MruSort(a:mru)[0 : g:tmruSize]
+ if get(props, 'exit', 0)
+ " echom "DBG tmru_list != s:tmru_list" (tmru_list != s:tmru_list)
+ " echom "DBG tmru_list != s:tmru_list" (string(tmru_list) != string(s:tmru_list))
+ " echom "DBG tmru_list" string(filter(copy(tmru_list), 'has_key(v:val[1], "sessions")'))
+ endif
if tmru_list != s:tmru_list
- let s:tmru_list = copy(tmru_list)
+ let s:tmru_list = deepcopy(tmru_list)
" TLogVAR g:TMRU
" TLogVAR g:tmru_file
- call s:BuildMenu(0)
+ if !get(props, 'exit', 0)
+ call s:BuildMenu(0)
+ endif
if empty(g:tmru_file)
if g:tmru_update_viminfo
let g:TMRU = join(map(s:tmru_list, 'v:val[0]'), "\n")
@@ -403,8 +412,8 @@ if g:tmru_sessions > 0
autocmd tmru VimLeave *
\ let s:tmruobj = TmruObj() |
- \ let s:tmruobj.mru = map(s:tmruobj.mru, 'tmru#SetSessions(v:val)') |
- \ call s:tmruobj.Save() |
+ \ let s:tmruobj.mru = map(deepcopy(s:tmruobj.mru), 'tmru#SetSessions(v:val)') |
+ \ call s:tmruobj.Save({'exit': 1}) |
\ unlet s:tmruobj
endif

0 comments on commit f68c5e8

Please sign in to comment.