refactor(git): promote set_buf_name_and_filetype to diff.M
This commit is contained in:
+6
-2
@@ -145,9 +145,13 @@ function M.load_file_buf(abs_path)
|
||||
return buf
|
||||
end
|
||||
|
||||
---Name a scratch buffer with a `git://...` URI and apply the filetype
|
||||
---inferred from the inner path segment. The `nvim_buf_set_name` call is
|
||||
---wrapped in pcall because a buffer with that name may already exist
|
||||
---(E95).
|
||||
---@param buf integer
|
||||
---@param name string
|
||||
local function set_buf_name_and_filetype(buf, name)
|
||||
function M.set_buf_name_and_filetype(buf, name)
|
||||
pcall(vim.api.nvim_buf_set_name, buf, name)
|
||||
local ft = vim.filetype.match({ buf = buf })
|
||||
if ft then
|
||||
@@ -181,7 +185,7 @@ function M.split(opts)
|
||||
local is_index = opts.ref == ""
|
||||
local other = M.git_show_buf(worktree, opts.ref, rel, is_index)
|
||||
local label = is_index and "index" or opts.ref
|
||||
set_buf_name_and_filetype(other, "git://" .. label .. "/" .. rel)
|
||||
M.set_buf_name_and_filetype(other, "git://" .. label .. "/" .. rel)
|
||||
|
||||
local split_cmd = opts.vertical and "leftabove vertical sbuffer "
|
||||
or "leftabove sbuffer "
|
||||
|
||||
Reference in New Issue
Block a user