Add PruneSession

Tue, 06 Jul 2021 13:34:06 -0500

author
Meredith Howard <mhoward@roomag.org>
date
Tue, 06 Jul 2021 13:34:06 -0500
changeset 920
c1cc35d18597
parent 919
79348384a55e
child 921
e6f397129333

Add PruneSession

.vim/autoload/vimrc.vim file | annotate | diff | comparison | revisions
.vimrc file | annotate | diff | comparison | revisions
--- a/.vim/autoload/vimrc.vim
+++ b/.vim/autoload/vimrc.vim
@@ -87,3 +87,20 @@ func! vimrc#SafeFilterFile(cmd)
     call delete(errors)
   endtry
 endfunc
+
+if has('perl')
+  func! vimrc#PruneSession() abort
+    perl <<END_PERL
+      my @bufs =
+        grep { !-e $_->Name || -d _ || (-M _ >= 30) }
+        grep { $_->Name } VIM::Buffers();
+
+      while (my $b = shift @bufs) {
+        VIM::Msg 'pruned: ' . $b->Name, 'Comment';
+        VIM::DoCommand 'bwipeout ' . $b->Number;
+      }
+      VIM::DoCommand 'bprev'
+        unless $curbuf->Name;
+END_PERL
+  endfunc
+endif
--- a/.vimrc
+++ b/.vimrc
@@ -141,6 +141,7 @@ command! Hgcd call vimrc#Hgcd()
 command! SyntaxCompleteOn setl omnifunc=syntaxcomplete#Complete
 
 command! Mksession execute "mksession! " . v:this_session
+command! PruneSession call vimrc#PruneSession()
 
 command! -nargs=* -complete=file Tig      call tig#Tig(<f-args>)
 command!                         TigBlame call tig#TigBlame()

mercurial