Lua-based snippets from mutt configurations #1763
shuber2
started this conversation in
Show and tell
Replies: 1 comment 1 reply
-
Thanks for sharing! I am glad that a bit advanced loading capabilities of 'mini.snippets' is put to good use. I'd personally rewrite the 'snippets/mail/mutt.lua' file to reduce the nesting. Something like this, maybe: Rewrite of 'snippets/mail/mutt.lua'local config = require("mini-snippets-mutt").config
local snippets = {}
-- Signature snippets
local read_signature_file = function(file)
local filename = vim.fn.fnamemodify(file, ":t:r")
local body = vim.fn.readfile(file)
snippets[filename] = {
prefix = "sig-" .. filename,
body = config.signature_prefix .. table.concat(body, "\n"),
}
end
for _, pattern in ipairs(config.signature_files) do
for _, file in ipairs(vim.fn.glob(pattern, false, true)) do
read_signature_file(file)
end
end
-- From address snippets
local read_address_line = function(line)
if not line:match("^set from") then return end
local from = line:match('^set from%s*=%s*"(.*)"')
if not from then return end
local domain = from:match("@(.*)>")
if not domain then return end
snippets["from-" .. domain] = { prefix = "from-" .. domain, body = from }
end
for _, pattern in ipairs(config.muttrc_files) do
for _, file in ipairs(vim.fn.glob(pattern, false, true)) do
for _, line in ipairs(vim.fn.readfile(file)) do
read_address_line(line)
end
end
end
return snippets |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I have published the package mini-snippets-mutt.nvim, which are Lua-based snippets from mutt configurations for signatures and from-addresses.
Beta Was this translation helpful? Give feedback.
All reactions