# HG changeset patch # User Meredith Howard # Date 1714892193 18000 # Node ID fcec334dfe7a3e33b3ae905b4cb97c4e670f6d65 # Parent dc04a7db1e830755b07547a5086cd6c97de53ab8 luafy PruneSession diff --git a/.config/nvim/autoload/vimrc.vim b/.config/nvim/autoload/vimrc.vim --- 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 <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 </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, {}) diff --git a/.config/nvim/plugin/vimrc/commands.vim b/.config/nvim/plugin/vimrc/commands.vim --- 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```}O```' | silent exe '%!mutt-md2html | mutt-html2txt' | 0