fix(git): set filetype on URI buffers from the inner path
This commit is contained in:
@@ -35,13 +35,6 @@ function M.setup()
|
|||||||
for name, link in pairs(HIGHLIGHTS) do
|
for name, link in pairs(HIGHLIGHTS) do
|
||||||
vim.api.nvim_set_hl(0, name, { link = link, default = true })
|
vim.api.nvim_set_hl(0, name, { link = link, default = true })
|
||||||
end
|
end
|
||||||
vim.filetype.add({
|
|
||||||
pattern = {
|
|
||||||
["git://.*:([^:]+)$"] = function(_, bufnr, inner)
|
|
||||||
return vim.filetype.match({ filename = inner, buf = bufnr })
|
|
||||||
end,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
local group = vim.api.nvim_create_augroup("ow.git", { clear = true })
|
local group = vim.api.nvim_create_augroup("ow.git", { clear = true })
|
||||||
vim.api.nvim_create_autocmd("BufReadCmd", {
|
vim.api.nvim_create_autocmd("BufReadCmd", {
|
||||||
pattern = "git://*",
|
pattern = "git://*",
|
||||||
|
|||||||
+19
-5
@@ -198,14 +198,13 @@ function M.read_uri(buf)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local parsed = util.parse_revspec(revspec)
|
local parsed = util.parse_revspec(revspec)
|
||||||
local index_path = parsed.stage == 0 and parsed.path or nil
|
if parsed.stage == 0 and parsed.path then
|
||||||
if index_path then
|
|
||||||
vim.bo[buf].buftype = "acwrite"
|
vim.bo[buf].buftype = "acwrite"
|
||||||
-- Re-running BufReadCmd (e.g. on `:edit`) would otherwise stack
|
-- Re-running BufReadCmd (e.g. on `:edit`) would otherwise stack
|
||||||
-- another BufWriteCmd on the same buffer, so each `:w` runs
|
-- another BufWriteCmd on the same buffer, so each `:w` runs
|
||||||
-- hash-object + update-index N times.
|
-- hash-object + update-index N times.
|
||||||
if not vim.b[buf].git_index_writer then
|
if not vim.b[buf].git_index_writer then
|
||||||
attach_index_writer(buf, worktree, index_path)
|
attach_index_writer(buf, worktree, parsed.path)
|
||||||
vim.b[buf].git_index_writer = true
|
vim.b[buf].git_index_writer = true
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@@ -214,8 +213,23 @@ function M.read_uri(buf)
|
|||||||
end
|
end
|
||||||
vim.bo[buf].modified = false
|
vim.bo[buf].modified = false
|
||||||
|
|
||||||
-- BufReadCmd suppresses the normal BufReadPost dispatch, so filetype
|
-- Filetype from the inner path. We can't lean on `vim.filetype.add`
|
||||||
-- detection and modeline parsing don't run unless we fire it ourselves.
|
-- because Vim normalises `git://` filenames (cwd-prefix + collapses
|
||||||
|
-- `://` to `:/`) before matching, breaking any pattern keyed on the
|
||||||
|
-- raw scheme as well as any built-in pattern that doesn't catch a
|
||||||
|
-- recognisable extension on the mangled form (.Xresources is the
|
||||||
|
-- canonical example).
|
||||||
|
if parsed.path then
|
||||||
|
local ft = vim.filetype.match({ filename = parsed.path, buf = buf })
|
||||||
|
if ft then
|
||||||
|
vim.bo[buf].filetype = ft
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- BufReadCmd suppresses the normal BufReadPost dispatch, so
|
||||||
|
-- modeline parsing doesn't run unless we fire it ourselves. The
|
||||||
|
-- modeline can still override the filetype set above; standard Vim
|
||||||
|
-- precedence.
|
||||||
vim.api.nvim_exec_autocmds("BufReadPost", { buffer = buf })
|
vim.api.nvim_exec_autocmds("BufReadPost", { buffer = buf })
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user