diff options
author | dundargoc <gocdundar@gmail.com> | 2024-06-08 21:40:18 +0200 |
---|---|---|
committer | dundargoc <33953936+dundargoc@users.noreply.github.com> | 2024-06-28 19:58:31 +0200 |
commit | aa6b9c677d83d76d448c3bb0973bf8d14bfdf922 (patch) | |
tree | 11b53f3dfac47faa94b375280d392959c754f4bd /runtime | |
parent | 496091b63241f33dffc15411e35e89d8018e6fa2 (diff) | |
download | rneovim-aa6b9c677d83d76d448c3bb0973bf8d14bfdf922.tar.gz rneovim-aa6b9c677d83d76d448c3bb0973bf8d14bfdf922.tar.bz2 rneovim-aa6b9c677d83d76d448c3bb0973bf8d14bfdf922.zip |
refactor: use `vim._with` where possible
This mostly means replacing `nvim_buf_call` and `nvim_win_call` with
`vim._with`.
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/filetype.lua | 4 | ||||
-rw-r--r-- | runtime/lua/tohtml.lua | 6 | ||||
-rw-r--r-- | runtime/lua/vim/_inspector.lua | 2 | ||||
-rw-r--r-- | runtime/lua/vim/diagnostic.lua | 2 | ||||
-rw-r--r-- | runtime/lua/vim/filetype/detect.lua | 2 | ||||
-rw-r--r-- | runtime/lua/vim/highlight.lua | 2 | ||||
-rw-r--r-- | runtime/lua/vim/lsp.lua | 4 | ||||
-rw-r--r-- | runtime/lua/vim/lsp/util.lua | 6 | ||||
-rw-r--r-- | runtime/lua/vim/shared.lua | 2 | ||||
-rw-r--r-- | runtime/lua/vim/snippet.lua | 2 | ||||
-rw-r--r-- | runtime/lua/vim/treesitter/highlighter.lua | 2 | ||||
-rw-r--r-- | runtime/lua/vim/ui.lua | 7 |
12 files changed, 21 insertions, 20 deletions
diff --git a/runtime/filetype.lua b/runtime/filetype.lua index be76af787d..797033da06 100644 --- a/runtime/filetype.lua +++ b/runtime/filetype.lua @@ -21,7 +21,7 @@ vim.api.nvim_create_autocmd({ 'BufRead', 'BufNewFile', 'StdinReadPost' }, { -- Generic configuration file used as fallback ft = require('vim.filetype.detect').conf(args.file, args.buf) if ft then - vim.api.nvim_buf_call(args.buf, function() + vim._with({ buf = args.buf }, function() vim.api.nvim_cmd({ cmd = 'setf', args = { 'FALLBACK', ft } }, {}) end) end @@ -32,7 +32,7 @@ vim.api.nvim_create_autocmd({ 'BufRead', 'BufNewFile', 'StdinReadPost' }, { on_detect(args.buf) end - vim.api.nvim_buf_call(args.buf, function() + vim._with({ buf = args.buf }, function() vim.api.nvim_cmd({ cmd = 'setf', args = { ft } }, {}) end) end diff --git a/runtime/lua/tohtml.lua b/runtime/lua/tohtml.lua index a67e1c69e2..37ad60b436 100644 --- a/runtime/lua/tohtml.lua +++ b/runtime/lua/tohtml.lua @@ -646,7 +646,7 @@ end --- @param state vim.tohtml.state local function styletable_conceal(state) local bufnr = state.bufnr - vim.api.nvim_buf_call(bufnr, function() + vim._with({ buf = bufnr }, function() for row = 1, state.buflen do --- @type table<integer,[integer,integer,string]> local conceals = {} @@ -764,7 +764,7 @@ local function styletable_statuscolumn(state) if foldcolumn:match('^auto') then local max = tonumber(foldcolumn:match('^%w-:(%d)')) or 1 local maxfold = 0 - vim.api.nvim_buf_call(state.bufnr, function() + vim._with({ buf = state.bufnr }, function() for row = 1, vim.api.nvim_buf_line_count(state.bufnr) do local foldlevel = vim.fn.foldlevel(row) if foldlevel > maxfold then @@ -1291,7 +1291,7 @@ local styletable_funcs = { --- @param state vim.tohtml.state local function state_generate_style(state) - vim.api.nvim_win_call(state.winid, function() + vim._with({ win = state.winid }, function() for _, fn in ipairs(styletable_funcs) do --- @type string? local cond diff --git a/runtime/lua/vim/_inspector.lua b/runtime/lua/vim/_inspector.lua index f5d1640c82..21dacbe41d 100644 --- a/runtime/lua/vim/_inspector.lua +++ b/runtime/lua/vim/_inspector.lua @@ -84,7 +84,7 @@ function vim.inspect_pos(bufnr, row, col, filter) -- syntax if filter.syntax and vim.api.nvim_buf_is_valid(bufnr) then - vim.api.nvim_buf_call(bufnr, function() + vim._with({ buf = bufnr }, function() for _, i1 in ipairs(vim.fn.synstack(row + 1, col + 1)) do results.syntax[#results.syntax + 1] = resolve_hl({ hl_group = vim.fn.synIDattr(i1, 'name') }) diff --git a/runtime/lua/vim/diagnostic.lua b/runtime/lua/vim/diagnostic.lua index 3be22556ab..43954358a3 100644 --- a/runtime/lua/vim/diagnostic.lua +++ b/runtime/lua/vim/diagnostic.lua @@ -964,7 +964,7 @@ local function goto_diagnostic(diagnostic, opts) local winid = opts.winid or api.nvim_get_current_win() - api.nvim_win_call(winid, function() + vim._with({ win = winid }, function() -- Save position in the window's jumplist vim.cmd("normal! m'") api.nvim_win_set_cursor(winid, { diagnostic.lnum + 1, diagnostic.col }) diff --git a/runtime/lua/vim/filetype/detect.lua b/runtime/lua/vim/filetype/detect.lua index b52dba7388..e1891e299e 100644 --- a/runtime/lua/vim/filetype/detect.lua +++ b/runtime/lua/vim/filetype/detect.lua @@ -450,7 +450,7 @@ local function modula2(bufnr) return 'modula2', function(b) - vim.api.nvim_buf_call(b, function() + vim._with({ buf = b }, function() fn['modula2#SetDialect'](dialect, extension) end) end diff --git a/runtime/lua/vim/highlight.lua b/runtime/lua/vim/highlight.lua index 233bc50237..a8d88db372 100644 --- a/runtime/lua/vim/highlight.lua +++ b/runtime/lua/vim/highlight.lua @@ -71,7 +71,7 @@ function M.range(bufnr, ns, higroup, start, finish, opts) return end - vim.api.nvim_buf_call(bufnr, function() + vim._with({ buf = bufnr }, function() if pos1[3] ~= v_maxcol then local max_col1 = vim.fn.col({ pos1[2], '$' }) pos1[3] = math.min(pos1[3], max_col1) diff --git a/runtime/lua/vim/lsp.lua b/runtime/lua/vim/lsp.lua index 39222cb8bc..382ec58156 100644 --- a/runtime/lua/vim/lsp.lua +++ b/runtime/lua/vim/lsp.lua @@ -352,7 +352,7 @@ function lsp._set_defaults(client, bufnr) then vim.bo[bufnr].formatexpr = 'v:lua.vim.lsp.formatexpr()' end - api.nvim_buf_call(bufnr, function() + vim._with({ buf = bufnr }, function() if client.supports_method(ms.textDocument_hover) and is_empty_or_default(bufnr, 'keywordprg') @@ -378,7 +378,7 @@ local function reset_defaults(bufnr) if vim.bo[bufnr].formatexpr == 'v:lua.vim.lsp.formatexpr()' then vim.bo[bufnr].formatexpr = nil end - api.nvim_buf_call(bufnr, function() + vim._with({ buf = bufnr }, function() local keymap = vim.fn.maparg('K', 'n', false, true) if keymap and keymap.callback == vim.lsp.buf.hover and keymap.buffer == 1 then vim.keymap.del('n', 'K', { buffer = bufnr }) diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua index a5cf13ed0f..b0fd25af3a 100644 --- a/runtime/lua/vim/lsp/util.lua +++ b/runtime/lua/vim/lsp/util.lua @@ -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 diff --git a/runtime/lua/vim/shared.lua b/runtime/lua/vim/shared.lua index 6de1ce9d0c..621de2b1c2 100644 --- a/runtime/lua/vim/shared.lua +++ b/runtime/lua/vim/shared.lua @@ -1218,6 +1218,8 @@ end --- only moving context save and restore to lower level might resolve this. --- --- @param context vim.context.mods +--- @param f function +--- @return any function vim._with(context, f) vim.validate('context', context, 'table') vim.validate('f', f, 'function') diff --git a/runtime/lua/vim/snippet.lua b/runtime/lua/vim/snippet.lua index 98a7a79ce0..a880bf0197 100644 --- a/runtime/lua/vim/snippet.lua +++ b/runtime/lua/vim/snippet.lua @@ -257,7 +257,7 @@ end function Session:restore_keymaps() local function restore(keymap, lhs, mode) if keymap then - vim.api.nvim_buf_call(self.bufnr, function() + vim._with({ buf = self.bufnr }, function() vim.fn.mapset(keymap) end) else diff --git a/runtime/lua/vim/treesitter/highlighter.lua b/runtime/lua/vim/treesitter/highlighter.lua index cd5c67d816..052b839609 100644 --- a/runtime/lua/vim/treesitter/highlighter.lua +++ b/runtime/lua/vim/treesitter/highlighter.lua @@ -143,7 +143,7 @@ function TSHighlighter.new(tree, opts) vim.cmd.runtime({ 'syntax/synload.vim', bang = true }) end - api.nvim_buf_call(self.bufnr, function() + vim._with({ buf = self.bufnr }, function() vim.opt_local.spelloptions:append('noplainbuffer') end) diff --git a/runtime/lua/vim/ui.lua b/runtime/lua/vim/ui.lua index f168da4955..ec5c5c5ba0 100644 --- a/runtime/lua/vim/ui.lua +++ b/runtime/lua/vim/ui.lua @@ -180,10 +180,9 @@ function M._get_url() end end - local old_isfname = vim.o.isfname - vim.cmd [[set isfname+=@-@]] - local url = vim.fn.expand('<cfile>') - vim.o.isfname = old_isfname + local url = vim._with({ go = { isfname = vim.o.isfname .. ',@-@' } }, function() + return vim.fn.expand('<cfile>') + end) return url end |