From b82f48bbcc950ad25db7e9ddd938d9d9f911bb56 Mon Sep 17 00:00:00 2001 From: Chris Weyl Date: Mon, 2 Oct 2017 21:16:50 -0500 Subject: [PATCH 01/18] Call user autocommand `Obsession` on session save This call will allow people to hook in after a session has been saved -- e.g. for updating a `Sessionx.vim`. (This code cribbed from `fugitive.vim`) --- plugin/obsession.vim | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/plugin/obsession.vim b/plugin/obsession.vim index 2517430..2674254 100644 --- a/plugin/obsession.vim +++ b/plugin/obsession.vim @@ -68,6 +68,14 @@ function! s:persist() abort call insert(body, 'let g:this_obsession_status = 2', -3) call writefile(body, g:this_obsession) let g:this_session = g:this_obsession + if exists('#User#Obsession') + try + let [save_mls, &modelines] = [&mls, 0] + doautocmd User Obsession + finally + let &mls = save_mls + endtry + endif catch unlet g:this_obsession let &l:readonly = &l:readonly From 7cc3d2b89562034e4c02249307e97b6a87df3bf1 Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Wed, 21 Feb 2018 11:30:40 -0500 Subject: [PATCH 02/18] Allow disabling BufEnter autocommand Closes https://github.com/tpope/vim-obsession/issues/40 --- plugin/obsession.vim | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/plugin/obsession.vim b/plugin/obsession.vim index 2674254..a5e5a8e 100644 --- a/plugin/obsession.vim +++ b/plugin/obsession.vim @@ -1,6 +1,7 @@ " obsession.vim - Continuously updated session files " Maintainer: Tim Pope " Version: 1.0 +" GetLatestVimScripts: 4472 1 :AutoInstall: obsession.vim if exists("g:loaded_obsession") || v:version < 700 || &cp finish @@ -66,6 +67,11 @@ function! s:persist() abort 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) + if exists('g:obsession_append') + for line in type(g:obsession_append) == type('') ? split(g:obsession_append, "\n") : g:obsession_append + call insert(body, line, -3) + endfor + endif call writefile(body, g:this_obsession) let g:this_session = g:this_obsession if exists('#User#Obsession') @@ -108,7 +114,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 From d2f78ce466186839b1838c7e85115f96d051c7a5 Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Thu, 1 Mar 2018 19:46:59 -0500 Subject: [PATCH 03/18] Don't support strings in g:obsession_append Closes https://github.com/tpope/vim-obsession/issues/41 --- plugin/obsession.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin/obsession.vim b/plugin/obsession.vim index a5e5a8e..c7eb35f 100644 --- a/plugin/obsession.vim +++ b/plugin/obsession.vim @@ -67,8 +67,8 @@ function! s:persist() abort 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) - if exists('g:obsession_append') - for line in type(g:obsession_append) == type('') ? split(g:obsession_append, "\n") : g:obsession_append + if type(get(g:, 'obsession_append')) == type([]) + for line in g:obsession_append call insert(body, line, -3) endfor endif From 523b2c60eb956aba6014e18be75aa7bde5280c33 Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Sun, 26 Aug 2018 20:46:45 -0400 Subject: [PATCH 04/18] Use doautocmd when available --- plugin/obsession.vim | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/plugin/obsession.vim b/plugin/obsession.vim index c7eb35f..2950063 100644 --- a/plugin/obsession.vim +++ b/plugin/obsession.vim @@ -54,6 +54,18 @@ function! s:dispatch(bang, file) abort endtry endfunction +function! s:doautocmd_user(arg) abort + if !exists('#User#' . a:arg) + return '' + elseif v:version >= 704 && 0 + return 'doautocmd User ' . fnameescape(a:arg) + else + return 'try | let [save_mls, &mls] = [&mls, 0] | ' . + \ 'doautocmd User ' . fnameescape(a:arg) . ' | ' . + \ 'finally | let &mls = save_mls | endtry' + endif +endfunction + function! s:persist() abort if exists('g:SessionLoad') return '' @@ -74,14 +86,7 @@ function! s:persist() abort endif call writefile(body, g:this_obsession) let g:this_session = g:this_obsession - if exists('#User#Obsession') - try - let [save_mls, &modelines] = [&mls, 0] - doautocmd User Obsession - finally - let &mls = save_mls - endtry - endif + exe s:doautocmd_user('Obsession') catch unlet g:this_obsession let &l:readonly = &l:readonly From 95a576210dc4408a4804a0a62a9eae90d701026b Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Mon, 17 Sep 2018 12:02:17 -0400 Subject: [PATCH 05/18] Fix conditional broken for debugging --- plugin/obsession.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/obsession.vim b/plugin/obsession.vim index 2950063..4cb79f9 100644 --- a/plugin/obsession.vim +++ b/plugin/obsession.vim @@ -57,7 +57,7 @@ endfunction function! s:doautocmd_user(arg) abort if !exists('#User#' . a:arg) return '' - elseif v:version >= 704 && 0 + elseif v:version >= 704 return 'doautocmd User ' . fnameescape(a:arg) else return 'try | let [save_mls, &mls] = [&mls, 0] | ' . From 60f0ef80fd74b8c58fd0cc7a55b81846e06c04f3 Mon Sep 17 00:00:00 2001 From: Matan Nassau Date: Wed, 29 May 2019 14:43:10 -0400 Subject: [PATCH 06/18] Remove unused variable this_obsession_status The status is never read from the hard-coded this_obsession_status, but computed in ObsessionStatus() from this_obsession. --- plugin/obsession.vim | 1 - 1 file changed, 1 deletion(-) diff --git a/plugin/obsession.vim b/plugin/obsession.vim index 4cb79f9..3963695 100644 --- a/plugin/obsession.vim +++ b/plugin/obsession.vim @@ -78,7 +78,6 @@ function! s:persist() abort let body = readfile(g:this_obsession) 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) if type(get(g:, 'obsession_append')) == type([]) for line in g:obsession_append call insert(body, line, -3) From a794bba99644b959c47fe46f82d0b9e676386b2f Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Tue, 24 Sep 2019 18:09:00 -0400 Subject: [PATCH 07/18] Add sponsor button --- .github/FUNDING.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .github/FUNDING.yml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..e2a49d1 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,2 @@ +github: tpope +custom: ["https://www.paypal.me/vimpope"] From c44d3c432243d39469046f4e25d38a690e49c755 Mon Sep 17 00:00:00 2001 From: Pratyush Yadav Date: Thu, 24 Oct 2019 03:25:49 +0530 Subject: [PATCH 08/18] Document 'g:obsession_no_bufenter' Unless someone dives into the source code, there is no way of knowing the option to disable saving session on BufEnter exists. --- doc/obsession.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doc/obsession.txt b/doc/obsession.txt index 5d302dd..b798c73 100644 --- a/doc/obsession.txt +++ b/doc/obsession.txt @@ -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. From 366364019c7daec898e579da5ea76c11bb58d73d Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Sun, 19 Jan 2020 04:19:31 -0500 Subject: [PATCH 09/18] Avoid E11 in command line window This targets unnamed buftype=nofile buffers, which includes some false positives, but such false positives aren't particularly useful to store in a session file anyways. Closes https://github.com/tpope/vim-obsession/issues/59 --- plugin/obsession.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/obsession.vim b/plugin/obsession.vim index 3963695..ad9401c 100644 --- a/plugin/obsession.vim +++ b/plugin/obsession.vim @@ -120,7 +120,7 @@ augroup obsession autocmd! autocmd VimLeavePre * exe s:persist() autocmd BufEnter * - \ if !get(g:, 'obsession_no_bufenter') | + \ if !get(g:, 'obsession_no_bufenter') && (&buftype !=# 'nofile' || len(expand(''))) | \ exe s:persist() | \ endif autocmd User Flags call Hoist('global', 'ObsessionStatus') From 96a3f837c112cb64e0a9857b69f6d6a71041155e Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Sun, 19 Jan 2020 08:19:30 -0500 Subject: [PATCH 10/18] Really avoid E11 in command line window Closes https://github.com/tpope/vim-obsession/issues/59 --- plugin/obsession.vim | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugin/obsession.vim b/plugin/obsession.vim index ad9401c..59b88eb 100644 --- a/plugin/obsession.vim +++ b/plugin/obsession.vim @@ -86,6 +86,8 @@ function! s:persist() abort call writefile(body, 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 @@ -120,7 +122,7 @@ augroup obsession autocmd! autocmd VimLeavePre * exe s:persist() autocmd BufEnter * - \ if !get(g:, 'obsession_no_bufenter') && (&buftype !=# 'nofile' || len(expand(''))) | + \ if !get(g:, 'obsession_no_bufenter') | \ exe s:persist() | \ endif autocmd User Flags call Hoist('global', 'ObsessionStatus') From 82c9ac5e130c92a46e043dd9cd9e5b48d15e286d Mon Sep 17 00:00:00 2001 From: Rob Pilling Date: Sun, 19 Apr 2020 18:30:25 +0100 Subject: [PATCH 11/18] Add `ObsessionPre` autocmd This complements the `Obsession` autocmd, allowing users to add hooks which might affect what obsession stores, for example, populating `g:obsession_append` to restore tab- or window-local variables. --- plugin/obsession.vim | 1 + 1 file changed, 1 insertion(+) diff --git a/plugin/obsession.vim b/plugin/obsession.vim index 59b88eb..faefd6d 100644 --- a/plugin/obsession.vim +++ b/plugin/obsession.vim @@ -74,6 +74,7 @@ function! s:persist() abort if exists('g:this_obsession') try set sessionoptions-=blank sessionoptions-=options sessionoptions+=tabpages + exe s:doautocmd_user('ObsessionPre') execute 'mksession! '.fnameescape(g:this_obsession) let body = readfile(g:this_obsession) call insert(body, 'let g:this_session = v:this_session', -3) From a56dcd6101b01f0eaad250db977f0d5dcaf98e21 Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Fri, 25 Mar 2022 15:58:51 -0400 Subject: [PATCH 12/18] Bump minimum Vim version to 7.4 --- plugin/obsession.vim | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/plugin/obsession.vim b/plugin/obsession.vim index faefd6d..c257f80 100644 --- a/plugin/obsession.vim +++ b/plugin/obsession.vim @@ -3,7 +3,7 @@ " 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 @@ -57,12 +57,8 @@ endfunction function! s:doautocmd_user(arg) abort if !exists('#User#' . a:arg) return '' - elseif v:version >= 704 - return 'doautocmd User ' . fnameescape(a:arg) else - return 'try | let [save_mls, &mls] = [&mls, 0] | ' . - \ 'doautocmd User ' . fnameescape(a:arg) . ' | ' . - \ 'finally | let &mls = save_mls | endtry' + return 'doautocmd User ' . fnameescape(a:arg) endif endfunction From d2818a614ec3a5d174c6bb19e87e2eeb207f4900 Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Fri, 25 Mar 2022 16:03:14 -0400 Subject: [PATCH 13/18] Use temp file to reduce risk of session file corruption Resolves: https://github.com/tpope/vim-obsession/issues/71 --- plugin/obsession.vim | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/plugin/obsession.vim b/plugin/obsession.vim index c257f80..0d26a06 100644 --- a/plugin/obsession.vim +++ b/plugin/obsession.vim @@ -70,9 +70,10 @@ function! s:persist() abort if exists('g:this_obsession') try set sessionoptions-=blank sessionoptions-=options sessionoptions+=tabpages + let tmp = g:this_obsession . '.obsession.' . getpid() exe s:doautocmd_user('ObsessionPre') - execute 'mksession! '.fnameescape(g:this_obsession) - let body = readfile(g:this_obsession) + execute 'mksession!' fnameescape(tmp) + 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) if type(get(g:, 'obsession_append')) == type([]) @@ -80,7 +81,8 @@ function! s:persist() abort call insert(body, line, -3) endfor endif - call writefile(body, g:this_obsession) + 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:/ From a905aa8b82f7ad771c044f7a1a74e27165afd3c2 Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Tue, 5 Apr 2022 11:25:48 -0400 Subject: [PATCH 14/18] Give temp file a "*~" name for easy SCM ignore --- plugin/obsession.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/obsession.vim b/plugin/obsession.vim index 0d26a06..c5711b5 100644 --- a/plugin/obsession.vim +++ b/plugin/obsession.vim @@ -68,9 +68,9 @@ function! s:persist() abort endif let sessionoptions = &sessionoptions if exists('g:this_obsession') + let tmp = g:this_obsession . '.' . getpid() . '.obsession~' try set sessionoptions-=blank sessionoptions-=options sessionoptions+=tabpages - let tmp = g:this_obsession . '.obsession.' . getpid() exe s:doautocmd_user('ObsessionPre') execute 'mksession!' fnameescape(tmp) let body = readfile(tmp) From 7d39576149d17bde3c096fd57e3a2cdae65deaf5 Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Tue, 5 Apr 2022 11:27:15 -0400 Subject: [PATCH 15/18] Delete temp file if error occurs Resolves: https://github.com/tpope/vim-obsession/issues/72 --- plugin/obsession.vim | 1 + 1 file changed, 1 insertion(+) diff --git a/plugin/obsession.vim b/plugin/obsession.vim index c5711b5..c13a7c1 100644 --- a/plugin/obsession.vim +++ b/plugin/obsession.vim @@ -93,6 +93,7 @@ function! s:persist() abort return 'echoerr '.string(v:exception) finally let &sessionoptions = sessionoptions + call delete(tmp) endtry endif return '' From fe9d3e1a9a50171e7d316a52e1e56d868e4c1fe5 Mon Sep 17 00:00:00 2001 From: Adrian Kocis Date: Thu, 1 Dec 2022 17:28:48 -0800 Subject: [PATCH 16/18] Restore previous v:this_session value after writing tmp session file (#78) --- plugin/obsession.vim | 1 + 1 file changed, 1 insertion(+) diff --git a/plugin/obsession.vim b/plugin/obsession.vim index c13a7c1..e36729d 100644 --- a/plugin/obsession.vim +++ b/plugin/obsession.vim @@ -73,6 +73,7 @@ function! s:persist() abort set sessionoptions-=blank sessionoptions-=options sessionoptions+=tabpages 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) From f50baec758c4bf2702fa8f051652789a90c5bfa9 Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Fri, 25 Oct 2024 15:53:04 -0400 Subject: [PATCH 17/18] Document default ObsessionStatus() indicators Resolves: https://github.com/tpope/vim-obsession/issues/82 --- doc/obsession.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/doc/obsession.txt b/doc/obsession.txt index b798c73..f53525e 100644 --- a/doc/obsession.txt +++ b/doc/obsession.txt @@ -33,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: From ed9dfc7c2cc917ace8b24f4f9f80a91e05614b63 Mon Sep 17 00:00:00 2001 From: Kayce Serafin Date: Sun, 27 Oct 2024 09:53:53 -0600 Subject: [PATCH 18/18] Update link to clone repo Correct the link to clone the repo in the README. --- README.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.markdown b/README.markdown index aa05b2b..68eb584 100644 --- a/README.markdown +++ b/README.markdown @@ -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