Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github: tpope
custom: ["https://www.paypal.me/vimpope"]
2 changes: 1 addition & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ installing [pathogen.vim](https://github.com/tpope/vim-pathogen), and
then simply copy and paste:

cd ~/.vim/bundle
git clone git://github.com/tpope/vim-obsession.git
git clone https://github.com/tpope/vim-obsession.git
vim -u NONE -c "helptags vim-obsession/doc" -c q

## Self-Promotion
Expand Down
9 changes: 7 additions & 2 deletions doc/obsession.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ USAGE *obsession* *:Obsession*
it will be overwritten if and only if it looks like a
session file.

Set `g:obsession_no_bufenter` to disable saving the
session on |BufEnter|, improving performance at the
expense of safety.

:Obsession {dir} Invoke |:Obsession| on {dir}/Session.vim. Use "." to
write to a session file in the current directory.

Expand All @@ -29,7 +33,8 @@ STATUS INDICATOR *obsession-status*
*ObsessionStatus()*
Add %{ObsessionStatus()} to 'statusline', 'tabline', or 'titlestring' to get
an indicator when Obsession is active or paused. Pass an argument to override
the text of the indicator and a second argument to override the text of the
paused indictor.
the text of the active indicator and a second argument to override the text of
the paused indictor. By default, the active indicator is `[$]`, and the
paused indicator is `[S]`.

vim:tw=78:et:ft=help:norl:
37 changes: 31 additions & 6 deletions plugin/obsession.vim
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
" obsession.vim - Continuously updated session files
" Maintainer: Tim Pope <http://tpo.pe/>
" Version: 1.0
" GetLatestVimScripts: 4472 1 :AutoInstall: obsession.vim

if exists("g:loaded_obsession") || v:version < 700 || &cp
if exists("g:loaded_obsession") || v:version < 704 || &cp
finish
endif
let g:loaded_obsession = 1
Expand Down Expand Up @@ -53,27 +54,47 @@ function! s:dispatch(bang, file) abort
endtry
endfunction

function! s:doautocmd_user(arg) abort
if !exists('#User#' . a:arg)
return ''
else
return 'doautocmd <nomodeline> User ' . fnameescape(a:arg)
endif
endfunction

function! s:persist() abort
if exists('g:SessionLoad')
return ''
endif
let sessionoptions = &sessionoptions
if exists('g:this_obsession')
let tmp = g:this_obsession . '.' . getpid() . '.obsession~'
try
set sessionoptions-=blank sessionoptions-=options sessionoptions+=tabpages
execute 'mksession! '.fnameescape(g:this_obsession)
let body = readfile(g:this_obsession)
exe s:doautocmd_user('ObsessionPre')
execute 'mksession!' fnameescape(tmp)
let v:this_session = g:this_obsession
let body = readfile(tmp)
call insert(body, 'let g:this_session = v:this_session', -3)
call insert(body, 'let g:this_obsession = v:this_session', -3)
call insert(body, 'let g:this_obsession_status = 2', -3)
call writefile(body, g:this_obsession)
if type(get(g:, 'obsession_append')) == type([])
for line in g:obsession_append
call insert(body, line, -3)
endfor
endif
call writefile(body, tmp)
call rename(tmp, g:this_obsession)
let g:this_session = g:this_obsession
exe s:doautocmd_user('Obsession')
catch /^Vim(mksession):E11:/
return ''
catch
unlet g:this_obsession
let &l:readonly = &l:readonly
return 'echoerr '.string(v:exception)
finally
let &sessionoptions = sessionoptions
call delete(tmp)
endtry
endif
return ''
Expand All @@ -100,7 +121,11 @@ endfunction

augroup obsession
autocmd!
autocmd BufEnter,VimLeavePre * exe s:persist()
autocmd VimLeavePre * exe s:persist()
autocmd BufEnter *
\ if !get(g:, 'obsession_no_bufenter') |
\ exe s:persist() |
\ endif
autocmd User Flags call Hoist('global', 'ObsessionStatus')
augroup END

Expand Down