Bunch of changes inspired by r00k

This commit is contained in:
2013-07-07 17:25:47 -04:00
parent c5a1ed1258
commit cf3eea13fb
141 changed files with 22472 additions and 519 deletions

1
vim/bundle/vim-obsession/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/doc/tags

View File

@@ -0,0 +1 @@
See the [contribution guidelines for pathogen.vim](https://github.com/tpope/vim-pathogen/blob/master/CONTRIBUTING.markdown).

View File

@@ -0,0 +1,47 @@
# obsession.vim
Vim features a `:mksession` command to write a file containing the current
state of Vim: window positions, open folds, stuff like that. For most of my
existence, I found the interface way too awkward and manual to be useful, but
I've recently discovered that the only thing standing between me and simple,
no-hassle Vim sessions is a few tweaks:
* Instead of making me remember to capture the session immediately before
exiting Vim, allow me to do it at any time, and automatically re-invoke
`:mksession` immediately before exit.
* Also invoke `:mksession` whenever the layout changes (in particular, on
`BufEnter`), so that even if Vim exits abnormally, I'm good to go.
* If I load an existing session, automatically keep it updated as above.
* If I try to create a new session on top of an existing session, don't refuse
to overwrite it. Just do what I mean.
* If I pass in a directory rather than a file name, just create a
`Session.vim` inside of it.
* Don't capture options and maps. Options are sometimes mutilated and maps
just interfere with updating plugins.
Use `:Obsess` (with optional file/directory name) to start recording to a
session file and `:Obsess!` to stop and throw it away. That's it. Load a
session in the usual manner: `vim -S`, or `:source` it.
## Installation
If you don't have a preferred installation method, I recommend
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
## Self-Promotion
Like obsession.vim? Follow the repository on
[GitHub](https://github.com/tpope/vim-obsession) and vote for it on
[vim.org](http://www.vim.org/scripts/script.php?script_id=4472). And if
you're feeling especially charitable, follow [tpope](http://tpo.pe/) on
[Twitter](http://twitter.com/tpope) and
[GitHub](https://github.com/tpope).
## License
Copyright © Tim Pope. Distributed under the same terms as Vim itself.
See `:help license`.

View File

@@ -0,0 +1,27 @@
*obsession.txt* Continuously updated session files
Author: Tim Pope <http://tpo.pe/>
Repo: https://github.com/tpope/vim-obsession
License: Same terms as Vim itself (see |license|)
USAGE *obsession* *:Obsession*
:Obsession {file} Invoke |:mksession| on {file} and continue to keep it
updated until Vim exits, triggering on the |BufEnter|
and |VimLeavePre| autocommands. If the file exists,
it will be overwritten if and only if it looks like a
session file.
:Obsession {dir} Invoke |:Obsession| on {dir}/Session.vim. Use "." to
write to a session file in the current directory.
:Obsession If session tracking is already in progress, pause it.
Otherwise, resume tracking or create a new session in
the current directory.
:Obsession! Stop obsession and delete the underlying session file.
Loading a session created with |:Obsession| automatically resumes updates to
that file.
vim:tw=78:et:ft=help:norl:

View File

@@ -0,0 +1,71 @@
" obsession.vim - Continuously updated session files
" Maintainer: Tim Pope <http://tpo.pe/>
" Version: 1.0
if exists("g:loaded_obsession") || v:version < 700 || &cp
finish
endif
let g:loaded_obsession = 1
command! -bar -bang -complete=file -nargs=? Obsession execute s:dispatch(<bang>0, <q-args>)
function! s:dispatch(bang, file) abort
if a:bang && empty(a:file) && filereadable(get(g:, 'this_obsession', v:this_session))
echo 'Deleting session in '.fnamemodify(get(g:, 'this_obsession', v:this_session), ':~:.')
call delete(get(g:, 'this_obsession', v:this_session))
unlet! g:this_obsession
return ''
elseif empty(a:file) && exists('g:this_obsession')
echo 'Pausing session in '.fnamemodify(g:this_obsession, ':~:.')
unlet g:this_obsession
return ''
elseif empty(a:file) && !empty(v:this_session)
let file = v:this_session
elseif empty(a:file)
let file = getcwd() . '/Session.vim'
elseif isdirectory(a:file)
let file = fnamemodify(expand(a:file), ':p') . '/Session.vim'
else
let file = fnamemodify(expand(a:file), ':p')
endif
if !a:bang
\ && file !~# 'Session\.vim$'
\ && filereadable(file)
\ && getfsize(file) > 0
\ && readfile(file, '', 1)[0] !=# 'let SessionLoad = 1'
return 'mksession '.fnameescape(file)
endif
let g:this_obsession = file
let error = s:persist()
if empty(error)
echo 'Tracking session in '.fnamemodify(file, ':~:.')
let v:this_session = file
return ''
else
return error
endif
endfunction
function! s:persist()
if exists('g:this_obsession')
let sessionoptions = &sessionoptions
try
set sessionoptions-=options
execute 'mksession! '.fnameescape(g:this_obsession)
call writefile(insert(readfile(g:this_obsession), 'let g:this_obsession = v:this_session', -2), g:this_obsession)
catch
unlet g:this_obsession
return 'echoerr '.string(v:exception)
finally
let &sessionoptions = sessionoptions
endtry
endif
return ''
endfunction
augroup obsession
autocmd!
autocmd BufEnter,VimLeavePre * exe s:persist()
augroup END
" vim:set et sw=2: