refactor: use vim._with where possible

This mostly means replacing `nvim_buf_call` and `nvim_win_call` with
`vim._with`.
This commit is contained in:
dundargoc
2024-06-08 21:40:18 +02:00
committed by dundargoc
parent 496091b632
commit aa6b9c677d
17 changed files with 46 additions and 45 deletions

View File

@@ -640,7 +640,7 @@ function M.rename(old_fname, new_fname, opts)
-- Rename with :saveas. This does two things:
-- * Unset BF_WRITE_MASK, so that users don't get E13 when they do :write.
-- * Send didClose and didOpen via textDocument/didSave handler.
api.nvim_buf_call(b, function()
vim._with({ buf = b }, function()
vim.cmd('keepalt saveas! ' .. vim.fn.fnameescape(rename.to))
end)
-- Delete the new buffer with the old name created by :saveas. nvim_buf_delete and
@@ -1014,7 +1014,7 @@ function M.show_document(location, offset_encoding, opts)
local row = range.start.line
local col = get_line_byte_from_position(bufnr, range.start, offset_encoding)
api.nvim_win_set_cursor(win, { row + 1, col })
api.nvim_win_call(win, function()
vim._with({ win = win }, function()
-- Open folds under the cursor
vim.cmd('normal! zv')
end)
@@ -1334,7 +1334,7 @@ function M.stylize_markdown(bufnr, contents, opts)
end
-- needs to run in the buffer for the regions to work
api.nvim_buf_call(bufnr, function()
vim._with({ buf = bufnr }, function()
-- we need to apply lsp_markdown regions speperately, since otherwise
-- markdown regions can "bleed" through the other syntax regions
-- and mess up the formatting