irongit

has a title now

huncholanehuncholaneauthored
parent b396ec2commit 0426e2ed288c3236a5d651e7cb0d93e40488a8f0Browse files

3 files changed, +14 -13

+3-3lua/scratch/commands.lua
@@ -1,4 +1,4 @@
11 local scratch = require("scratch.scratch")
2-vim.api.nvim_create_user_command("Scratch", function()
3- scratch.relative_scratch()
4-end, {})
2+vim.api.nvim_create_user_command("Scratch", function(args)
3+ scratch.scratch(args.fargs[1])
4+end, { nargs = "?" })
+2-0lua/scratch/init.lua
@@ -5,4 +5,6 @@ M.setup = function()
55 require("scratch.scratch").load()
66 end
77
8+M.open = require("scratch.scratch").scratch
9+
810 return M
+9-10lua/scratch/scratch.lua
@@ -1,8 +1,7 @@
11 local M = {}
22
3-M.files = {}
4-
53 function M.load()
4+ M.files = {}
65 local cwd = vim.fn.getcwd()
76 M.hash = vim.fn.sha256(cwd)
87 M.scratchdir = vim.fn.stdpath("data") .. "/scratch"
@@ -20,11 +19,14 @@ function M.getfile(ext)
2019 end
2120
2221 ---Opens a buffer for the given file extension
23----@param ext string
22+---@param ext string?
2423 function M.scratch(ext)
24+ if not ext then
25+ ext = vim.fn.expand("%:e")
26+ end
2527 -- open scratch for the ext
2628 local filename = M.getfile(ext)
27- local buf = vim.api.nvim_create_buf(false, true)
29+ local buf = vim.api.nvim_create_buf(false, false)
2830
2931 -- immediately move into floating window
3032 local width = math.floor(vim.o.columns * 0.8)
@@ -39,6 +41,7 @@ function M.scratch(ext)
3941 col = col,
4042 style = "minimal",
4143 border = "rounded",
44+ title = ext .. " Scratchpad: " .. filename,
4245 })
4346 vim.cmd("edit " .. filename)
4447
@@ -47,8 +50,8 @@ function M.scratch(ext)
4750 vim.bo[buf].buflisted = false
4851
4952 -- easy close
50- vim.keymap.set("n", "q", ":q!<cr>", { buffer = buf, nowait = true })
51- vim.keymap.set("n", "<C-c>", ":q!<cr>", { buffer = buf, nowait = true })
53+ vim.keymap.set("n", "q", ":q<cr>", { buffer = buf, nowait = true })
54+ vim.keymap.set("n", "<C-c>", "<Esc>:q<cr>", { buffer = buf, nowait = true })
5255
5356 -- execute on save
5457 vim.api.nvim_create_autocmd("BufWritePost", {
@@ -59,8 +62,4 @@ function M.scratch(ext)
5962 })
6063 end
6164
62-function M.relative_scratch()
63- M.scratch(vim.fn.expand("%:e"))
64-end
65-
6665 return M