Auto sync: 2025-08-18 15:51:48 (1 files changed)

M  lua/custom/language_specific_commands/markdown_and_tex.lua
This commit is contained in:
Dane Sabo 2025-08-18 15:51:48 -04:00
parent 4028ceade0
commit 3723b055f7

View File

@ -1,24 +1,30 @@
-- Efficient Markdown/TeX + Nabla integration
local grp = vim.api.nvim_create_augroup("MarkdownTexWithNabla", { clear = true })
-- ~/.config/nvim/lua/custom/language_specific_commands/markdown_and_tex.lua
-- 1) Set buffer-local stuff ONCE (spell, textwidth, formatoptions, keymaps) on FileType
local GRP = vim.api.nvim_create_augroup("MarkdownTexWithNabla", { clear = true })
-- 1) Buffer-local settings: set ONCE per buffer
vim.api.nvim_create_autocmd("FileType", {
group = grp,
group = GRP,
pattern = { "markdown", "tex" },
callback = function(args)
local ft = vim.bo[args.buf].filetype
-- Buffer-local basics (only once per buffer)
-- Buffer-local basics
vim.opt_local.spell = true
vim.opt_local.spelllang = "en_us"
vim.opt_local.formatoptions:append "t"
if ft == "markdown" then
vim.opt_local.textwidth = 60
else -- tex
else
vim.opt_local.textwidth = 80
end
-- Buffer-local Nabla keymaps (define once)
-- Buffer-local conceal (instead of window-local)
vim.opt_local.conceallevel = 2
vim.opt_local.concealcursor = "ic" -- reveal on hover in normal mode
-- Buffer-local Nabla keymaps (define once per buffer)
if not vim.b[args.buf].nabla_keys then
local ok_nabla, nabla = pcall(require, "nabla")
if ok_nabla then
@ -32,7 +38,8 @@ vim.api.nvim_create_autocmd("FileType", {
vim.keymap.set("n", "<leader>mnp", function()
nabla.popup()
end, vim.tbl_extend("force", bufopts, { desc = "Nabla: popup under cursor" }))
-- Enable once initially and mark as active
-- initial enable
nabla.enable_virt()
vim.b[args.buf].nabla_enabled = true
end
@ -41,26 +48,13 @@ vim.api.nvim_create_autocmd("FileType", {
end,
})
-- 2) Window-local conceal settings (apply per window that views the buffer)
vim.api.nvim_create_autocmd("BufWinEnter", {
group = grp,
callback = function(args)
local ft = vim.bo[args.buf].filetype
if ft ~= "markdown" and ft ~= "tex" then
return
end
-- Window-local: set each time the buffer is shown in a window
vim.wo[args.win].conceallevel = 2
vim.wo[args.win].concealcursor = "ic" -- reveal on hover in normal mode
end,
})
-- 3) Re-enable Nabla only after writes (some tools clear virt text on save)
-- 2) Re-enable Nabla virtual text after writes (if cleared)
vim.api.nvim_create_autocmd("BufWritePost", {
group = grp,
group = GRP,
pattern = { "*.md", "*.mdx", "*.markdown", "*.tex", "*.ltx" },
callback = function(args)
if not vim.b[args.buf].nabla_enabled then
local ft = vim.bo[args.buf].filetype
if (ft ~= "markdown" and ft ~= "tex") or not vim.b[args.buf].nabla_enabled then
return
end
local ok_nabla, nabla = pcall(require, "nabla")