Sun, 05 May 2024 01:56:33 -0500
luafy PruneSession
--- a/.config/nvim/autoload/vimrc.vim +++ b/.config/nvim/autoload/vimrc.vim @@ -20,23 +20,6 @@ func! vimrc#SafeFilterFile(cmd) 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 - if has('ruby') func! s:PruneFiles(path, days) abort ruby <<END_RUBY
--- a/.config/nvim/lua/config/commands.lua +++ b/.config/nvim/lua/config/commands.lua @@ -1,6 +1,24 @@ local command = vim.api.nvim_create_user_command local cmd, fn = vim.cmd, vim.fn +require("config.util").calias({ + -- replace default: + grep = "Grep", + + -- typos: + Q = "q", + Qa = "qa", + W = "w", + gcd = "Gcd", + hgcd = "Hgcd", + + -- Make the ! versions default to stay in one window + buffer: + doc = "ViewDoc!", + help = "ViewDocHelp!", + man = "ViewDocMan!", + perldoc = "ViewDocPerl!", +}) + command("Hgcd", function() local root = fn.systemlist("hg root 2>/dev/null")[1] if vim.v.shell_error == 0 then @@ -29,20 +47,22 @@ command("Grep", function(ctx) cmd.cfirst() end, { nargs = "*", complete = "file" }) -require("config.util").calias({ - -- replace default: - grep = "Grep", - - -- typos: - Q = "q", - Qa = "qa", - W = "w", - gcd = "Gcd", - hgcd = "Hgcd", - - -- Make the ! versions default to stay in one window + buffer: - doc = "ViewDoc!", - help = "ViewDocHelp!", - man = "ViewDocMan!", - perldoc = "ViewDocPerl!", -}) +-- Remove buffers for files that are gone, old, or netrw dirs +command("PruneSession", function() + local bufs = vim.api.nvim_list_bufs() + for _, bufnr in ipairs(bufs) do + local name = vim.api.nvim_buf_get_name(bufnr) + if name then + local type = vim.fn.getftype(name) + if type == "" or type == "dir" + or (os.time() - vim.fn.getftime(name)) > 2592000 + then + vim.print("pruned: " .. name) + vim.cmd.bwipeout(bufnr) + end + end + end + if not vim.api.nvim_buf_get_name(0) then + vim.cmd.bprev() + end +end, {})
--- a/.config/nvim/plugin/vimrc/commands.vim +++ b/.config/nvim/plugin/vimrc/commands.vim @@ -1,7 +1,6 @@ command! SyntaxCompleteOn setl omnifunc=syntaxcomplete#Complete command! Mksession execute "mksession! " . v:this_session -command! PruneSession call vimrc#PruneSession() " Preview markdown mail -- I edit with headers so I box them in a code block. command! MailPreview enew | set bt=nofile | 0r # | exe 'norm! 0O```<Esc>}O```' | silent exe '%!mutt-md2html | mutt-html2txt' | 0