Skip to content

Commit

Permalink
Remove dirty session tracking (it's too fragile)
Browse files Browse the repository at this point in the history
I never liked this code and the additional complexity it introduced, so
lets try without for a while and see if anyone complains. If I really want
to I can always get the code back from version control.

Pull request #37: #37
Issue #38: #38
  • Loading branch information
xolox committed Apr 20, 2013
1 parent e365e75 commit 5d79e44
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 69 deletions.
71 changes: 4 additions & 67 deletions autoload/xolox/session.vim
@@ -1,9 +1,9 @@
" Vim script
" Author: Peter Odding
" Last Change: April 18, 2013
" Last Change: April 20, 2013
" URL: http://peterodding.com/code/vim/session/

let g:xolox#session#version = '1.5.2'
let g:xolox#session#version = '1.5.3'

" Public API for session persistence. {{{1

Expand Down Expand Up @@ -263,7 +263,7 @@ endfunction
function! xolox#session#auto_save() " {{{2
if !v:dying && g:session_autosave != 'no'
let name = s:get_name('', 0)
if name != '' && exists('s:session_is_dirty')
if name != ''
let msg = "Do you want to save your editing session before quitting Vim?"
if s:prompt(msg, 'g:session_autosave')
execute 'SaveSession' fnameescape(name)
Expand All @@ -284,66 +284,6 @@ function! xolox#session#auto_unlock() " {{{2
endwhile
endfunction

function! xolox#session#auto_dirty_check() " {{{2
" TODO Why execute this on every buffer change?! Instead execute it only when we want to know whether the session is dirty!
" This function is called each time a BufEnter event fires to detect when
" the current tab page (or the buffer list) is changed in some way. This
" enables the plug-in to not bother with the auto-save dialog when the
" session hasn't changed.
if v:this_session == ''
" Don't waste CPU time when no session is loaded.
return
elseif !exists('s:cached_layouts')
let s:cached_layouts = {}
else
" Clear non-existing tab pages from s:cached_layouts.
let last_tabpage = tabpagenr('$')
call filter(s:cached_layouts, 'v:key <= last_tabpage')
endif
" Check the buffer list.
let all_buffers = s:serialize_buffer_list()
if all_buffers != get(s:cached_layouts, 0, '')
let s:session_is_dirty = 1
endif
let s:cached_layouts[0] = all_buffers
" Check the layout of the current tab page.
let tabpagenr = tabpagenr()
let keys = ['tabpage:' . tabpagenr]
let buflist = tabpagebuflist()
for winnr in range(1, winnr('$'))
" Create a string that describes the state of the window {winnr}.
call add(keys, printf('width:%i,height:%i,buffer:%i',
\ winwidth(winnr), winheight(winnr), buflist[winnr - 1]))
endfor
let layout = join(keys, "\n")
if layout != get(s:cached_layouts, tabpagenr, '')
let s:session_is_dirty = 1
endif
let s:cached_layouts[tabpagenr] = layout
endfunction

function! s:serialize_buffer_list()
if &sessionoptions =~ '\<buffers\>'
return join(map(range(1, bufnr('$')), 's:serialize_buffer_state(v:val)'), "\n")
endif
return ''
endfunction

function! s:serialize_buffer_state(bufnr)
" TODO ssop =~ '\<blank\>' ?
let bufname = bufname(a:bufnr)
if bufname =~ '^NERD_tree_\d\+$'
" TODO I thought this would work, but somehow it doesn't?!
let root = getbufvar(a:bufnr, 'b:NERDTreeRoot')
if !empty(root)
let bufname = root.path.str() . '/' . bufname
endif
elseif bufname != ''
let bufname = fnamemodify(bufname, ':p')
endif
return a:bufnr . ':' . bufname
endfunction

" Commands that enable users to manage multiple sessions. {{{1

function! s:prompt(msg, var)
Expand Down Expand Up @@ -372,7 +312,6 @@ function! xolox#session#open_cmd(name, bang) abort " {{{2
let s:oldcwd = oldcwd
call s:lock_session(path)
execute 'source' fnameescape(path)
unlet! s:session_is_dirty
call s:last_session_persist(name)
call xolox#misc#timer#stop("session.vim %s: Opened %s session in %s.", g:xolox#session#version, string(name), starttime)
call xolox#misc#msg#info("session.vim %s: Opened %s session from %s.", g:xolox#session#version, string(name), fnamemodify(path, ':~'))
Expand Down Expand Up @@ -414,7 +353,6 @@ function! xolox#session#save_cmd(name, bang) abort " {{{2
call xolox#misc#msg#info("session.vim %s: Saved %s session to %s.", g:xolox#session#version, string(name), friendly_path)
let v:this_session = path
call s:lock_session(path)
unlet! s:session_is_dirty
endif
endif
endfunction
Expand All @@ -441,7 +379,7 @@ endfunction

function! xolox#session#close_cmd(bang, silent) abort " {{{2
let name = s:get_name('', 0)
if name != '' && exists('s:session_is_dirty')
if name != ''
let msg = "Do you want to save your current editing session before closing it?"
if s:prompt(msg, 'g:session_autosave')
SaveSession
Expand Down Expand Up @@ -470,7 +408,6 @@ function! xolox#session#close_cmd(bang, silent) abort " {{{2
execute s:oldcwd
unlet s:oldcwd
endif
unlet! s:session_is_dirty
if v:this_session == ''
if !a:silent
let msg = "session.vim %s: Closed session."
Expand Down
3 changes: 1 addition & 2 deletions plugin/session.vim
@@ -1,6 +1,6 @@
" Vim script
" Author: Peter Odding
" Last Change: December 11, 2011
" Last Change: April 20, 2013
" URL: http://peterodding.com/code/vim/session/

" Support for automatic update using the GLVS plug-in.
Expand Down Expand Up @@ -79,7 +79,6 @@ augroup PluginSession
au VimEnter * nested call xolox#session#auto_load()
au VimLeavePre * call xolox#session#auto_save()
au VimLeavePre * call xolox#session#auto_unlock()
au BufEnter * call xolox#session#auto_dirty_check()
augroup END

" Define commands that enable users to manage multiple named sessions.
Expand Down

0 comments on commit 5d79e44

Please sign in to comment.