1
+ --- @diagnostic disable : missing-fields
1
2
--- @class snacks.bigfile.Config
2
3
local bigfile = { enabled = true }
3
4
@@ -31,6 +32,82 @@ local indent = {
31
32
only_scope = true ,
32
33
only_current = true ,
33
34
}
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
+
34
111
--- @class snacks.zen.Config
35
112
local zen = {
36
113
toggles = {
@@ -50,9 +127,15 @@ return {
50
127
bigfile = bigfile ,
51
128
dashboard = dashboard ,
52
129
indent = indent ,
130
+ scratch = scratch ,
53
131
zen = zen ,
54
132
},
55
133
keys = {
134
+ {
135
+ ' <leader>bs' ,
136
+ scratch_delete_all ,
137
+ desc = ' Delete all scratch buffers' ,
138
+ },
56
139
{
57
140
' <leader>fN' ,
58
141
function ()
0 commit comments