diff options
| author | Thomas Vanbesien <tvanbesi@proton.me> | 2026-06-11 19:53:59 +0200 |
|---|---|---|
| committer | Thomas Vanbesien <tvanbesi@proton.me> | 2026-06-11 20:08:37 +0200 |
| commit | b62430bb2610198bffb076a59755ad74b4a3d50a (patch) | |
| tree | 1fd55be01a1e31b35440b56bb5c6176dc59c0eb4 /.config/nvim/after/ftplugin/markdown.lua | |
| parent | 796b523aa141dd6aff2d100ddcc46f2895859ecd (diff) | |
| download | dotfiles-b62430bb2610198bffb076a59755ad74b4a3d50a.tar.gz dotfiles-b62430bb2610198bffb076a59755ad74b4a3d50a.zip | |
refactor(nvim): rewrite the buffer formatting flow
Diffstat (limited to '.config/nvim/after/ftplugin/markdown.lua')
| -rw-r--r-- | .config/nvim/after/ftplugin/markdown.lua | 56 |
1 files changed, 1 insertions, 55 deletions
diff --git a/.config/nvim/after/ftplugin/markdown.lua b/.config/nvim/after/ftplugin/markdown.lua index d492855..f0f9691 100644 --- a/.config/nvim/after/ftplugin/markdown.lua +++ b/.config/nvim/after/ftplugin/markdown.lua @@ -1,56 +1,3 @@ -local function format() - local view = vim.fn.winsaveview() - local buf_str = table.concat(vim.api.nvim_buf_get_lines(0, 0, -1, false), "\n") .. "\n" - local tempname = vim.fn.tempname() - local tempfile = assert(io.open(tempname, "w"), "Could not open temporary file") - tempfile:write(buf_str) - tempfile:close() - - local r_check = vim.system({ - "mdformat", - "--number", - "--extensions", - "tables", - "--extensions", - "frontmatter", - "--extensions", - "wikilink", - "--wrap", - tostring(vim.bo.textwidth), - "--check", - tempname, - }):wait() - if r_check.code == 0 then - return - elseif r_check.code ~= 1 then - vim.notify("mdformat failed (" .. r_check.code .. "):\n" .. r_check.stderr) - end - local r_format = vim.system({ - "mdformat", - "--number", - "--extensions", - "tables", - "--extensions", - "frontmatter", - "--extensions", - "wikilink", - "--wrap", - tostring(vim.bo.textwidth), - tempname, - }):wait() - if r_format.code ~= 0 then - vim.notify("mdformat failed (" .. r_format.code .. "):\n" .. r_format.stderr) - end - local formatted_lines = {} - for line in io.lines(tempname) do - formatted_lines[#formatted_lines + 1] = line - end - os.remove(tempname) - vim.api.nvim_buf_set_lines(0, 0, -1, false, formatted_lines) - - vim.fn.winrestview(view) -end - vim.opt_local.tabstop = 2 -- CommonMark expects two spaces for indentation vim.opt_local.shiftwidth = 0 vim.opt_local.softtabstop = -1 @@ -74,8 +21,7 @@ vim.opt_local.complete = { -- Visible link labels vim.api.nvim_set_hl(0, "@markup.link.label.markdown_inline", { underline = true, update = true }) -vim.b.autoformat = true -vim.b.format_func = format +vim.b.format = true -- See plugin/50-format.lua local function item_range() local cursor_row = vim.api.nvim_win_get_cursor(0)[1] |
