···11+-- ── neomd: attach file from within the email editor ───────────────────────
22+-- Usage: <leader>a in normal mode while writing a neomd-*.md email buffer.
33+-- Opens yazi in a floating window. Selected file path(s) are inserted as
44+-- <!-- Attach: /absolute/path/to/file.pdf -->
55+-- neomd strips these lines before sending and adds them as MIME attachments.
66+local function neomd_attach()
77+ local target_buf = vim.api.nvim_get_current_buf()
88+ local target_win = vim.api.nvim_get_current_win()
99+ local cursor_row = vim.api.nvim_win_get_cursor(target_win)[1]
1010+ local chooser = vim.fn.tempname()
1111+1212+ -- Floating terminal sized to 85 % of the screen
1313+ local W = math.floor(vim.o.columns * 0.85)
1414+ local H = math.floor(vim.o.lines * 0.85)
1515+ local float_buf = vim.api.nvim_create_buf(false, true)
1616+ local float_win = vim.api.nvim_open_win(float_buf, true, {
1717+ relative = "editor",
1818+ width = W, height = H,
1919+ col = math.floor((vim.o.columns - W) / 2),
2020+ row = math.floor((vim.o.lines - H) / 2),
2121+ style = "minimal",
2222+ border = "rounded",
2323+ title = " attach file — <Enter> select, q quit ",
2424+ title_pos = "center",
2525+ })
2626+2727+ vim.fn.termopen({ "yazi", "--chooser-file", chooser }, {
2828+ on_exit = function()
2929+ if vim.api.nvim_win_is_valid(float_win) then
3030+ vim.api.nvim_win_close(float_win, true)
3131+ end
3232+ vim.schedule(function()
3333+ local ok, lines = pcall(vim.fn.readfile, chooser)
3434+ vim.fn.delete(chooser)
3535+ if not ok or not lines or #lines == 0 then return end
3636+3737+ local inserts = {}
3838+ for _, path in ipairs(lines) do
3939+ path = vim.trim(path)
4040+ if path ~= "" then
4141+ table.insert(inserts, "[attach] " .. path)
4242+ end
4343+ end
4444+ if #inserts == 0 then return end
4545+4646+ -- Insert after the current cursor row, then move cursor past them
4747+ vim.api.nvim_buf_set_lines(target_buf, cursor_row, cursor_row, false, inserts)
4848+ if vim.api.nvim_win_is_valid(target_win) then
4949+ vim.api.nvim_win_set_cursor(target_win, { cursor_row + #inserts, 0 })
5050+ end
5151+ end)
5252+ end,
5353+ })
5454+ vim.cmd("startinsert")
5555+end
5656+5757+-- Only map <leader>a when editing a neomd compose buffer (neomd-*.md)
5858+vim.api.nvim_create_autocmd("BufEnter", {
5959+ pattern = "neomd-*.md",
6060+ callback = function()
6161+ vim.keymap.set("n", "<leader>a", neomd_attach, {
6262+ buffer = true,
6363+ desc = "neomd: attach file via yazi",
6464+ })
6565+ end,
6666+})
6767+-- ── end neomd ──────────────────────────────────────────────────────────────
6868+169--custom function to set colortheme based on session session_name
270--please make sure that the theme isn't loaded lazy when set as initial theme
371function SetThemeBasedOnTmuxSession(sessionThemes)