Skip to content

Commit

Permalink
feat(nvim): add scratch files support
Browse files Browse the repository at this point in the history
  • Loading branch information
miszo committed Dec 19, 2024
1 parent 2beb18c commit 33b90c7
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 10 deletions.
20 changes: 10 additions & 10 deletions home/dot_config/exact_nvim/exact_lua/exact_plugins/neotree.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
local trash_not_installed = function(commmand_name)
vim.api.nvim_echo({
{ '- Trash utility not installed. Make sure to install it first\n', nil },
{ '- In macOS run `brew install trash`\n', nil },
{ '- Or delete the custom `' .. commmand_name .. '` command section in neo-tree', nil },
}, false, {})
end

return {
{
'vhyrro/luarocks.nvim',
Expand Down Expand Up @@ -40,11 +48,7 @@ return {
-- overwrite delete to use trash instead of rm
delete = function(state)
if vim.fn.executable('trash') == 0 then
vim.api.nvim_echo({
{ '- Trash utility not installed. Make sure to install it first\n', nil },
{ '- In macOS run `brew install trash`\n', nil },
{ '- Or delete the `custom delete command` section in neo-tree', nil },
}, false, {})
trash_not_installed('delete')
return
end
local inputs = require('neo-tree.ui.inputs')
Expand All @@ -62,11 +66,7 @@ return {
-- overwrite default 'delete_visual' command to 'trash' x n.
delete_visual = function(state, selected_nodes)
if vim.fn.executable('trash') == 0 then
vim.api.nvim_echo({
{ '- Trash utility not installed. Make sure to install it first\n', nil },
{ '- In macOS run `brew install trash`\n', nil },
{ '- Or delete the `custom delete command` section in neo-tree', nil },
}, false, {})
trash_not_installed('delete_visual')
return
end
local inputs = require('neo-tree.ui.inputs')
Expand Down
83 changes: 83 additions & 0 deletions home/dot_config/exact_nvim/exact_lua/exact_plugins/snacks.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---@diagnostic disable: missing-fields
---@class snacks.bigfile.Config
local bigfile = { enabled = true }

Expand Down Expand Up @@ -31,6 +32,82 @@ local indent = {
only_scope = true,
only_current = true,
}

local scratch_delete_all = function()
local items = Snacks.scratch.list()
local count = #items

if count == 0 then
vim.notify('No scratch buffers to delete', 'info')
return
end

for _, item in ipairs(items) do
os.remove(item.file)
end

vim.notify('Deleted ' .. count .. ' scratch buffer(s)', 'info')
end

---@type snacks.win.Config
local ts_win = {
keys = {
['source'] = {
'<C-s>',
'<cmd>Tsw rt=bun show_variables=true show_order=true<cr>',
desc = 'Execute buffer',
mode = { 'n', 'x' },
},
['delete'] = {
'<C-d>',
function(self)
local buf_name = vim.api.nvim_buf_get_name(self.buf)
os.remove(buf_name)
vim.api.nvim_buf_delete(self.buf, { force = true })
vim.notify('Deleted scratch buffer' .. buf_name, 'info')
end,
desc = 'Delete buffer',
mode = { 'n', 'x' },
},
},
}

---@class snacks.scratch.Config
local scratch = {
root = vim.fn.stdpath('data') .. '/scratch',
name = 'Scratch',
actions = {},
win = {
width = 0.5,
height = 0.9,
style = 'scratch',
},
ft = function()
if vim.bo.buftype == '' and vim.bo.filetype ~= '' then
return vim.bo.filetype
end
return 'typescript'
end,
---@type table<string, snacks.win.Config>
win_by_ft = {
lua = {
keys = {
['source'] = {
'<C-s>',
function(self)
local name = 'scratch.' .. vim.fn.fnamemodify(vim.api.nvim_buf_get_name(self.buf), ':e')
Snacks.debug.run({ buf = self.buf, name = name })
end,
desc = 'Source buffer',
mode = { 'n', 'x' },
},
},
},
typescript = ts_win,
javascript = ts_win,
},
}

---@class snacks.zen.Config
local zen = {
toggles = {
Expand All @@ -50,9 +127,15 @@ return {
bigfile = bigfile,
dashboard = dashboard,
indent = indent,
scratch = scratch,
zen = zen,
},
keys = {
{
'<leader>bs',
scratch_delete_all,
desc = 'Delete all scratch buffers',
},
{
'<leader>fN',
function()
Expand Down

0 comments on commit 33b90c7

Please sign in to comment.