refactor(git): older-on-left placement, drop empty placeholders
This commit is contained in:
+10
-16
@@ -62,22 +62,16 @@ local function setup_scratch(buf, opts)
|
||||
end
|
||||
end
|
||||
|
||||
---Build a read-only scratch buffer, optionally naming it. When `opts.name`
|
||||
---is set and a loaded buffer with that name already exists, returns it
|
||||
---instead of creating a duplicate.
|
||||
---@param opts ow.Git.ScratchOpts?
|
||||
---@return integer
|
||||
function M.empty_buf(opts)
|
||||
opts = opts or {}
|
||||
if opts.name then
|
||||
local existing = vim.fn.bufnr(opts.name)
|
||||
if existing ~= -1 and vim.api.nvim_buf_is_loaded(existing) then
|
||||
return existing
|
||||
end
|
||||
---Set a buffer's name and re-run filetype detection from it. Wrapped
|
||||
---in `pcall` because a buffer with that name may already exist (E95).
|
||||
---@param buf integer
|
||||
---@param name string
|
||||
function M.set_buf_name(buf, name)
|
||||
pcall(vim.api.nvim_buf_set_name, buf, name)
|
||||
local ft = vim.filetype.match({ buf = buf })
|
||||
if ft then
|
||||
vim.bo[buf].filetype = ft
|
||||
end
|
||||
local buf = vim.api.nvim_create_buf(false, true)
|
||||
setup_scratch(buf, opts)
|
||||
return buf
|
||||
end
|
||||
|
||||
---Place a buffer in the current window or a new split per `split`.
|
||||
@@ -96,7 +90,7 @@ function M.place_buf(buf, split)
|
||||
local win = vim.api.nvim_open_win(buf, true, {
|
||||
split = split or (vim.o.splitbelow and "below" or "above"),
|
||||
})
|
||||
vim.cmd("clearjumps")
|
||||
vim.cmd.clearjumps()
|
||||
return win
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user