.config/nvim/autoload/vimrc.vim

Sun, 19 Feb 2023 13:48:14 -0600

author
Meredith Howard <mhoward@roomag.org>
date
Sun, 19 Feb 2023 13:48:14 -0600
changeset 1032
b0497894f69b
parent 1022
d509e282ae10
child 1076
15007f695dfb
permissions
-rw-r--r--

Customize LSP float diags further

1022
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
1 func! vimrc#CommandAlias(abbrev, expand) abort
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
2 execute printf('cnoreabbrev <expr> %s (getcmdtype()==":" && getcmdline()=="%s") ? "%s" : "%s"', a:abbrev, a:abbrev, a:expand, a:abbrev)
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
3 endfunc
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
4
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
5 func! vimrc#AutoFmtToggle() abort
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
6 if &formatoptions =~# 'a'
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
7 setl formatoptions-=a | echo '-a'
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
8 else
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
9 setl formatoptions+=a | echo '+a'
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
10 endif
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
11 endfunc
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
12
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
13 " Make paths when writing, as necessary
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
14 func! vimrc#MkNonExDir(file, buf) abort
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
15 if empty(getbufvar(a:buf, '&buftype')) && a:file!~#'\v^\w+\:\/'
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
16 let dir=fnamemodify(a:file, ':h')
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
17 if !isdirectory(dir)
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
18 call mkdir(dir, 'p')
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
19 endif
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
20 endif
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
21 endfunc
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
22
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
23 func! vimrc#AutoSessionCheck() abort
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
24 if strlen(v:servername) > 0 && match(v:servername, 'VIM') == -1
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
25 let sessionfile = g:vimcache . "/session/" . tolower(v:servername) . ".vim"
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
26
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
27 if filereadable(sessionfile)
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
28 execute "source " . sessionfile
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
29 endif
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
30 endif
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
31 endfunc
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
32
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
33 func! vimrc#Grep(...) abort
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
34 let pattern = get(a:000, 0, expand('<cword>'))
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
35 let cmd = join([&grepprg, shellescape(pattern)] + a:000[1:], ' ')
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
36
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
37 echo cmd
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
38 cgetexpr system(cmd)
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
39 call setqflist([], 'a', {"title": cmd})
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
40 let @/ = '\v' . pattern
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
41 copen
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
42 cfirst
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
43 endfunc
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
44
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
45 func! vimrc#Gcd() abort
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
46 let root = system('git rev-parse --show-toplevel 2>/dev/null')[:-2]
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
47 if ! v:shell_error
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
48 exec 'cd ' . root
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
49 endif
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
50 pwd
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
51 endfunc
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
52
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
53 func! vimrc#Hgcd() abort
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
54 let root = system('hg root 2>/dev/null')[:-2]
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
55 if ! v:shell_error
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
56 exec 'cd ' . root
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
57 endif
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
58 pwd
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
59 endfunc
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
60
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
61 func! vimrc#SafeFilterFile(cmd)
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
62 let errors = tempname()
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
63 try
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
64 exec 'silent %!' . a:cmd . ' 2>' . shellescape(errors)
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
65 if v:shell_error
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
66 for line in readfile(errors)
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
67 echomsg line
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
68 endfor
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
69 endif
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
70 finally
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
71 call delete(errors)
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
72 endtry
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
73 endfunc
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
74
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
75 if has('perl')
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
76 func! vimrc#PruneSession() abort
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
77 perl <<END_PERL
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
78 my @bufs =
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
79 grep { !-e $_->Name || -d _ || (-M _ >= 30) }
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
80 grep { $_->Name } VIM::Buffers();
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
81
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
82 while (my $b = shift @bufs) {
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
83 VIM::Msg 'pruned: ' . $b->Name, 'Comment';
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
84 VIM::DoCommand 'bwipeout ' . $b->Number;
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
85 }
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
86 VIM::DoCommand 'bprev'
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
87 unless $curbuf->Name;
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
88 END_PERL
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
89 endfunc
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
90 endif
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
91
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
92 func! vimrc#PrepDir(path) abort
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
93 if !filewritable(a:path)
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
94 call mkdir(a:path, 'p', 0700)
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
95 endif
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
96 endfunc
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
97
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
98 if has('ruby')
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
99 func! s:PruneFiles(path, days) abort
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
100 ruby <<END_RUBY
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
101 require 'pathname'
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
102
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
103 (path, days) = VIM.evaluate('[a:path, a:days]')
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
104 sunset = Time.now - (days * 86400)
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
105
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
106 Pathname(path).realpath.each_child do |file|
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
107 file.delete if file.mtime < sunset
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
108 end
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
109 END_RUBY
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
110 endfunc
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
111 else
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
112 func! s:PruneFiles(path, days) abort
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
113 endfunc
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
114 endif
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
115
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
116 func! vimrc#PruneFiles(path, days) abort
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
117 call s:PruneFiles(a:path, a:days)
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
118 endfunc
d509e282ae10 More nvim config
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
119

mercurial