Skip to content

Commit 33b90c7

Browse files
committed
feat(nvim): add scratch files support
1 parent 2beb18c commit 33b90c7

File tree

2 files changed

+93
-10
lines changed

2 files changed

+93
-10
lines changed

home/dot_config/exact_nvim/exact_lua/exact_plugins/neotree.lua

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
local trash_not_installed = function(commmand_name)
2+
vim.api.nvim_echo({
3+
{ '- Trash utility not installed. Make sure to install it first\n', nil },
4+
{ '- In macOS run `brew install trash`\n', nil },
5+
{ '- Or delete the custom `' .. commmand_name .. '` command section in neo-tree', nil },
6+
}, false, {})
7+
end
8+
19
return {
210
{
311
'vhyrro/luarocks.nvim',
@@ -40,11 +48,7 @@ return {
4048
-- overwrite delete to use trash instead of rm
4149
delete = function(state)
4250
if vim.fn.executable('trash') == 0 then
43-
vim.api.nvim_echo({
44-
{ '- Trash utility not installed. Make sure to install it first\n', nil },
45-
{ '- In macOS run `brew install trash`\n', nil },
46-
{ '- Or delete the `custom delete command` section in neo-tree', nil },
47-
}, false, {})
51+
trash_not_installed('delete')
4852
return
4953
end
5054
local inputs = require('neo-tree.ui.inputs')
@@ -62,11 +66,7 @@ return {
6266
-- overwrite default 'delete_visual' command to 'trash' x n.
6367
delete_visual = function(state, selected_nodes)
6468
if vim.fn.executable('trash') == 0 then
65-
vim.api.nvim_echo({
66-
{ '- Trash utility not installed. Make sure to install it first\n', nil },
67-
{ '- In macOS run `brew install trash`\n', nil },
68-
{ '- Or delete the `custom delete command` section in neo-tree', nil },
69-
}, false, {})
69+
trash_not_installed('delete_visual')
7070
return
7171
end
7272
local inputs = require('neo-tree.ui.inputs')

home/dot_config/exact_nvim/exact_lua/exact_plugins/snacks.lua

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
---@diagnostic disable: missing-fields
12
---@class snacks.bigfile.Config
23
local bigfile = { enabled = true }
34

@@ -31,6 +32,82 @@ local indent = {
3132
only_scope = true,
3233
only_current = true,
3334
}
35+
36+
local scratch_delete_all = function()
37+
local items = Snacks.scratch.list()
38+
local count = #items
39+
40+
if count == 0 then
41+
vim.notify('No scratch buffers to delete', 'info')
42+
return
43+
end
44+
45+
for _, item in ipairs(items) do
46+
os.remove(item.file)
47+
end
48+
49+
vim.notify('Deleted ' .. count .. ' scratch buffer(s)', 'info')
50+
end
51+
52+
---@type snacks.win.Config
53+
local ts_win = {
54+
keys = {
55+
['source'] = {
56+
'<C-s>',
57+
'<cmd>Tsw rt=bun show_variables=true show_order=true<cr>',
58+
desc = 'Execute buffer',
59+
mode = { 'n', 'x' },
60+
},
61+
['delete'] = {
62+
'<C-d>',
63+
function(self)
64+
local buf_name = vim.api.nvim_buf_get_name(self.buf)
65+
os.remove(buf_name)
66+
vim.api.nvim_buf_delete(self.buf, { force = true })
67+
vim.notify('Deleted scratch buffer' .. buf_name, 'info')
68+
end,
69+
desc = 'Delete buffer',
70+
mode = { 'n', 'x' },
71+
},
72+
},
73+
}
74+
75+
---@class snacks.scratch.Config
76+
local scratch = {
77+
root = vim.fn.stdpath('data') .. '/scratch',
78+
name = 'Scratch',
79+
actions = {},
80+
win = {
81+
width = 0.5,
82+
height = 0.9,
83+
style = 'scratch',
84+
},
85+
ft = function()
86+
if vim.bo.buftype == '' and vim.bo.filetype ~= '' then
87+
return vim.bo.filetype
88+
end
89+
return 'typescript'
90+
end,
91+
---@type table<string, snacks.win.Config>
92+
win_by_ft = {
93+
lua = {
94+
keys = {
95+
['source'] = {
96+
'<C-s>',
97+
function(self)
98+
local name = 'scratch.' .. vim.fn.fnamemodify(vim.api.nvim_buf_get_name(self.buf), ':e')
99+
Snacks.debug.run({ buf = self.buf, name = name })
100+
end,
101+
desc = 'Source buffer',
102+
mode = { 'n', 'x' },
103+
},
104+
},
105+
},
106+
typescript = ts_win,
107+
javascript = ts_win,
108+
},
109+
}
110+
34111
---@class snacks.zen.Config
35112
local zen = {
36113
toggles = {
@@ -50,9 +127,15 @@ return {
50127
bigfile = bigfile,
51128
dashboard = dashboard,
52129
indent = indent,
130+
scratch = scratch,
53131
zen = zen,
54132
},
55133
keys = {
134+
{
135+
'<leader>bs',
136+
scratch_delete_all,
137+
desc = 'Delete all scratch buffers',
138+
},
56139
{
57140
'<leader>fN',
58141
function()

0 commit comments

Comments
 (0)