Thu, 11 Apr 2024 13:19:32 -0400
Add catlee/pull_diags.nvim
1022 | 1 | func! vimrc#AutoFmtToggle() abort |
2 | if &formatoptions =~# 'a' | |
3 | setl formatoptions-=a | echo '-a' | |
4 | else | |
5 | setl formatoptions+=a | echo '+a' | |
6 | endif | |
7 | endfunc | |
8 | ||
9 | func! vimrc#SafeFilterFile(cmd) | |
10 | let errors = tempname() | |
11 | try | |
12 | exec 'silent %!' . a:cmd . ' 2>' . shellescape(errors) | |
13 | if v:shell_error | |
14 | for line in readfile(errors) | |
15 | echomsg line | |
16 | endfor | |
17 | endif | |
18 | finally | |
19 | call delete(errors) | |
20 | endtry | |
21 | endfunc | |
22 | ||
23 | if has('perl') | |
24 | func! vimrc#PruneSession() abort | |
25 | perl <<END_PERL | |
26 | my @bufs = | |
27 | grep { !-e $_->Name || -d _ || (-M _ >= 30) } | |
28 | grep { $_->Name } VIM::Buffers(); | |
29 | ||
30 | while (my $b = shift @bufs) { | |
31 | VIM::Msg 'pruned: ' . $b->Name, 'Comment'; | |
32 | VIM::DoCommand 'bwipeout ' . $b->Number; | |
33 | } | |
34 | VIM::DoCommand 'bprev' | |
35 | unless $curbuf->Name; | |
36 | END_PERL | |
37 | endfunc | |
38 | endif | |
39 | ||
40 | if has('ruby') | |
41 | func! s:PruneFiles(path, days) abort | |
42 | ruby <<END_RUBY | |
43 | require 'pathname' | |
44 | ||
45 | (path, days) = VIM.evaluate('[a:path, a:days]') | |
46 | sunset = Time.now - (days * 86400) | |
47 | ||
48 | Pathname(path).realpath.each_child do |file| | |
49 | file.delete if file.mtime < sunset | |
50 | end | |
51 | END_RUBY | |
52 | endfunc | |
53 | else | |
54 | func! s:PruneFiles(path, days) abort | |
55 | endfunc | |
56 | endif | |
57 | ||
58 | func! vimrc#PruneFiles(path, days) abort | |
59 | call s:PruneFiles(a:path, a:days) | |
60 | endfunc | |
61 |