Sun, 05 May 2024 20:43:54 -0500
Fix VimEnter/vim_did_enter behavior
1078
aa4c1aa529a5
Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
1 | local command = vim.api.nvim_create_user_command |
1095
226221dc1d6b
Simplify command aliases
Meredith Howard <mhoward@roomag.org>
parents:
1080
diff
changeset
|
2 | local cmd, fn = vim.cmd, vim.fn |
1156
0a7162df160d
pull out last_modified_days
Meredith Howard <mhoward@roomag.org>
parents:
1155
diff
changeset
|
3 | local util = require("config.util") |
1078
aa4c1aa529a5
Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
4 | |
1156
0a7162df160d
pull out last_modified_days
Meredith Howard <mhoward@roomag.org>
parents:
1155
diff
changeset
|
5 | util.calias({ |
1155 | 6 | -- replace default: |
7 | grep = "Grep", | |
8 | ||
9 | -- typos: | |
10 | Q = "q", | |
11 | Qa = "qa", | |
12 | W = "w", | |
13 | gcd = "Gcd", | |
14 | hgcd = "Hgcd", | |
15 | ||
16 | -- Make the ! versions default to stay in one window + buffer: | |
17 | doc = "ViewDoc!", | |
18 | help = "ViewDocHelp!", | |
19 | man = "ViewDocMan!", | |
20 | perldoc = "ViewDocPerl!", | |
21 | }) | |
22 | ||
1078
aa4c1aa529a5
Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
23 | command("Hgcd", function() |
aa4c1aa529a5
Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
24 | local root = fn.systemlist("hg root 2>/dev/null")[1] |
aa4c1aa529a5
Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
25 | if vim.v.shell_error == 0 then |
aa4c1aa529a5
Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
26 | cmd.cd(root) |
aa4c1aa529a5
Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
27 | end |
aa4c1aa529a5
Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
28 | end, {}) |
aa4c1aa529a5
Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
29 | |
aa4c1aa529a5
Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
30 | command("Gcd", function() |
aa4c1aa529a5
Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
31 | local root = fn.systemlist("git rev-parse --show-toplevel 2>/dev/null")[1] |
aa4c1aa529a5
Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
32 | if vim.v.shell_error == 0 then |
aa4c1aa529a5
Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
33 | cmd.cd(root) |
aa4c1aa529a5
Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
34 | end |
aa4c1aa529a5
Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
35 | end, {}) |
aa4c1aa529a5
Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
36 | |
1079 | 37 | command("Grep", function(ctx) |
38 | local pattern = ctx.fargs[1] or fn.expand("<cword>") | |
39 | local grepcmd = table.concat({ | |
40 | vim.o.grepprg, | |
41 | fn.shellescape(pattern), | |
42 | table.concat(vim.list_slice(ctx.fargs, 2, #ctx.fargs), " "), | |
43 | }, " ") | |
44 | ||
45 | fn.setqflist({}, " ", { title = grepcmd, lines = fn.systemlist(grepcmd) }) | |
1080
83c9f8460bde
continue to confuse the verymagic options
Meredith Howard <mhoward@roomag.org>
parents:
1079
diff
changeset
|
46 | fn.setreg("/", [[\v]] .. pattern) |
1079 | 47 | cmd.copen() |
48 | cmd.cfirst() | |
49 | end, { nargs = "*", complete = "file" }) | |
50 | ||
1155 | 51 | -- Remove buffers for files that are gone, old, or netrw dirs |
52 | command("PruneSession", function() | |
53 | local bufs = vim.api.nvim_list_bufs() | |
54 | for _, bufnr in ipairs(bufs) do | |
55 | local name = vim.api.nvim_buf_get_name(bufnr) | |
56 | if name then | |
1157
a237720efee9
Convert backup/undofile pruning to lua
Meredith Howard <mhoward@roomag.org>
parents:
1156
diff
changeset
|
57 | local type = fn.getftype(name) |
1155 | 58 | if type == "" or type == "dir" |
1156
0a7162df160d
pull out last_modified_days
Meredith Howard <mhoward@roomag.org>
parents:
1155
diff
changeset
|
59 | or util.last_modified_days(name) > 30 |
1155 | 60 | then |
61 | vim.print("pruned: " .. name) | |
1157
a237720efee9
Convert backup/undofile pruning to lua
Meredith Howard <mhoward@roomag.org>
parents:
1156
diff
changeset
|
62 | cmd.bwipeout(bufnr) |
1155 | 63 | end |
64 | end | |
65 | end | |
66 | if not vim.api.nvim_buf_get_name(0) then | |
1157
a237720efee9
Convert backup/undofile pruning to lua
Meredith Howard <mhoward@roomag.org>
parents:
1156
diff
changeset
|
67 | cmd.bprev() |
1155 | 68 | end |
69 | end, {}) |