refactor(nvim): register autolist mappings with an autocmd

This permits buffer-only mappings
This commit is contained in:
Price Hiller 2023-06-30 17:15:29 -05:00
parent f410a1a34e
commit 27ca7913d2
Signed by: Price
SSH Key Fingerprint: SHA256:Y4S9ZzYphRn1W1kbJerJFO6GGsfu9O70VaBSxJO7dF8
2 changed files with 79 additions and 12 deletions

View File

@ -248,16 +248,82 @@ vim.keymap.set("n", "<leader>xq", "<cmd>TroubleToggle quickfix<cr>", { silent =
vim.keymap.set("n", "<leader>xt", "<cmd>TodoTrouble<cr>", { silent = true, desc = "Trouble: Todo Items" })
-- Autolist mappings
vim.keymap.set("i", "<tab>", "<cmd>AutolistTab<cr>", { silent = true, desc = "Trouble: Todo Items" })
vim.keymap.set("i", "<s-tab>", "<cmd>AutolistShiftTab<cr>", { silent = true, desc = "Trouble: Todo Items" })
vim.keymap.set("i", "<CR>", "<CR><cmd>AutolistNewBullet<cr>", { silent = true, desc = "Trouble: Todo Items" })
vim.keymap.set("n", "o", "o<cmd>AutolistNewBullet<cr>", { silent = true, desc = "Trouble: Todo Items" })
vim.keymap.set("n", "O", "O<cmd>AutolistNewBulletBefore<cr>", { silent = true, desc = "Trouble: Todo Items" })
vim.keymap.set("n", "<S-CR>", "<cmd>AutolistToggleCheckbox<cr><CR>", { silent = true, desc = "Trouble: Todo Items" })
vim.keymap.set("n", "<C-r>", "<cmd>AutolistRecalculate<cr>", { silent = true, desc = "Trouble: Todo Items" })
local autolist_group = vim.api.nvim_create_augroup("Autolist", {})
-- NOTE: Why is this wrapped in an autocmd you ask? Because we want to bind these for buffer local *only*. We do not
-- want to pollute the global keymaps with autolist as autolist only supports certain filetypes.
vim.api.nvim_create_autocmd("filetype", {
group = autolist_group,
pattern = {
"markdown",
"text",
"tex",
"plaintex",
"norg"
},
callback = function()
if pcall(require, "autolist") then
vim.keymap.set(
"i",
"<tab>",
"<cmd>AutolistTab<cr>",
{ silent = true, desc = "Autolist: Tab", buffer = true }
)
vim.keymap.set(
"i",
"<s-tab>",
"<cmd>AutolistShiftTab<cr>",
{ silent = true, desc = "Autolist: Shift Tab", buffer = true }
)
vim.keymap.set(
"i",
"<CR>",
"<CR><cmd>AutolistNewBullet<cr>",
{ silent = true, desc = "Autolist: New Bullet", buffer = true }
)
vim.keymap.set(
"n",
"o",
"o<cmd>AutolistNewBullet<cr>",
{ silent = true, desc = "Autolist: New Bullet", buffer = true }
)
vim.keymap.set(
"n",
"O",
"O<cmd>AutolistNewBulletBefore<cr>",
{ silent = true, desc = "Autolist: New Bullet Before", buffer = true }
)
vim.keymap.set(
"n",
"<C-CR>",
"<cmd>AutolistToggleCheckbox<cr>",
{ silent = true, desc = "Autolist: Toggle Checkbox", buffer = true }
)
-- functions to recalculate list on edit
vim.keymap.set("n", ">>", ">><cmd>AutolistRecalculate<cr>", { silent = true, desc = "Trouble: Todo Items" })
vim.keymap.set("n", "<<", "<<<cmd>AutolistRecalculate<cr>", { silent = true, desc = "Trouble: Todo Items" })
vim.keymap.set("n", "dd", "dd<cmd>AutolistRecalculate<cr>", { silent = true, desc = "Trouble: Todo Items" })
vim.keymap.set("v", "d", "d<cmd>AutolistRecalculate<cr>", { silent = true, desc = "Trouble: Todo Items" })
-- functions to recalculate list on edit
vim.keymap.set(
"n",
">>",
">><cmd>AutolistRecalculate<cr>",
{ silent = true, desc = "Autolist: Indent", buffer = true }
)
vim.keymap.set(
"n",
"<<",
"<<<cmd>AutolistRecalculate<cr>",
{ silent = true, desc = "Autolist: Dedent", buffer = true }
)
vim.keymap.set(
"n",
"dd",
"dd<cmd>AutolistRecalculate<cr>",
{ silent = true, desc = "Autolist: Delete", buffer = true }
)
vim.keymap.set(
"v",
"d",
"d<cmd>AutolistRecalculate<cr>",
{ silent = true, desc = "Autolist: Delete", buffer = true }
)
end
end,
})

View File

@ -572,6 +572,7 @@ lazy.setup({
"text",
"tex",
"plaintex",
"norg"
},
opts = {},
},