Skip to content

Commit 91add37

Browse files
committed
feat: delayed .md ft handling (cause obsidian)
1 parent 1d4ab80 commit 91add37

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

lua/gp/init.lua

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -241,20 +241,22 @@ M.setup = function(opts)
241241
end
242242
end
243243

244-
vim.filetype.add({
245-
extension = {
246-
md = function(path, buf)
247-
M.logger.debug("filetype markdown: " .. path .. " buf: " .. buf)
248-
if not M.not_chat(buf, path) then
249-
return "markdown.gpchat"
244+
vim.api.nvim_create_autocmd("BufEnter", {
245+
pattern = "*.md",
246+
callback = function(ev)
247+
vim.defer_fn(function()
248+
M.logger.debug("Markdown BufEnter: " .. ev.file)
249+
local path = ev.file
250+
local buf = ev.buf
251+
local current_ft = vim.bo[buf].filetype
252+
if not M.not_chat(buf, path) and current_ft ~= "markdown.gpchat" then
253+
vim.bo[buf].filetype = "markdown.gpchat"
254+
elseif M.helpers.ends_with(path, ".gp.md") and current_ft ~= "markdown.gpmd" then
255+
vim.bo[buf].filetype = "markdown.gpmd"
250256
end
251-
252-
if M.helpers.ends_with(path, ".gp.md") then
253-
return "markdown.gpmd"
254-
end
255-
return "markdown"
256-
end,
257-
},
257+
vim.cmd("doautocmd User GpRefresh")
258+
end, 100)
259+
end,
258260
})
259261

260262
if vim.fn.executable("curl") == 0 then

0 commit comments

Comments
 (0)