commit d7f55f06c398d154e5b27bd0d56a89034e24ffd3
parent 8bf003ea5261fb345e74af42db3a758982209123
Author: Tomas Nemec <nemi@skaut.cz>
Date: Fri, 16 Dec 2022 23:47:07 +0100
update
Diffstat:
26 files changed, 101 insertions(+), 88 deletions(-)
diff --git a/after/plugin/actions.lua b/after/plugin/actions.lua
@@ -1,15 +1,23 @@
-if not pcall(require, 'actions') then return end
+if not pcall(require, 'actions') then
+ return
+end
local utils = require 'actions.utils'
local actions = {}
local mappings = { ['n <space>ar'] = 'run', ['n <space>at'] = 'test', ['n <space>ab'] = 'build' }
-local function make(_) vim.cmd [[make]] end
+local function make(_)
+ vim.cmd.make()
+end
-local add = function(action) table.insert(actions, action) end
+local add = function(action)
+ table.insert(actions, action)
+end
-local add_lang = function(lang, a) add { predicate = utils.make_language_predicate(lang), actions = a } end
+local add_lang = function(lang, a)
+ add { predicate = utils.make_language_predicate(lang), actions = a }
+end
add_lang('dart', {
run = make,
@@ -22,30 +30,35 @@ add_lang('lua', { run = make })
add_lang('go', {
run = function(_)
- vim.cmd [[set makeprg=go\ run\ %]]
- vim.cmd [[make]]
- vim.cmd [[comp go]]
+ vim.bo.makeprg = 'go run %'
+ vim.cmd.make()
+ vim.cmd.compiler('go')
end,
test = function(_)
- vim.cmd [[set makeprg=go\ test]]
- vim.cmd [[make]]
- vim.cmd [[comp go]]
+ vim.bo.makeprg = 'go test'
+ vim.cmd.make()
+ vim.cmd.compiler('go')
end,
build = make,
})
add_lang('zsh', {
run = function(_)
- vim.cmd [[set makeprg=./%]]
- vim.cmd [[set efm=%f:%.%#:%l:\ %m,%f:%l:\ %m,%-G%.%#]]
- vim.cmd [[make]]
- vim.cmd [[comp zsh]]
+ vim.bo.makeprg = [[./%]]
+ vim.bo.efm = [[%f:%.%#:%l:\ %m,%f:%l:\ %m,%-G%.%#]]
+ vim.cmd.make()
+ vim.cmd.compiler('zsh')
end,
build = make,
})
add_lang('gdscript', {
- run = function(_) vim.cmd [[GodotRun]] end, build = function(_) vim.api.nvim_input(':GodotRun ') end
+ run = function(_)
+ vim.api.nvim_command('GodotRun')
+ end,
+ build = function(_)
+ vim.api.nvim_input(':GodotRun ')
+ end,
})
add_lang('sh', { run = make })
diff --git a/after/plugin/animate.lua b/after/plugin/animate.lua
@@ -1,10 +1,11 @@
- if not vim.g['animate#loaded'] then return end
- vim.cmd('let g:animate#duration = 100.0')
- vim.keymap.set('n', '<c-up>', ':call animate#window_delta_height(10)<cr>', { silent = true })
- vim.keymap.set('n', '<c-down>', ':call animate#window_delta_height(-10)<cr>', { silent = true })
- vim.keymap.set('n', '<c-left>', ':call animate#window_delta_width(-10)<cr>', { silent = true })
- vim.keymap.set('n', '<c-right>', ':call animate#window_delta_width(10)<cr>', { silent = true })
- vim.keymap.set('n', '<s-up>', ':call animate#window_delta_height(1)<cr>', { silent = true })
- vim.keymap.set('n', '<s-down>', ':call animate#window_delta_height(-1)<cr>', { silent = true })
- vim.keymap.set('n', '<s-left>', ':call animate#window_delta_width(-1)<cr>', { silent = true })
- vim.keymap.set('n', '<s-right>', ':call animate#window_delta_width(1)<cr>', { silent = true })
+if not vim.g['animate#loaded'] then
+ return
+end
+vim.keymap.set('n', '<c-up>', ':call animate#window_delta_height(10)<cr>', { silent = true })
+vim.keymap.set('n', '<c-down>', ':call animate#window_delta_height(-10)<cr>', { silent = true })
+vim.keymap.set('n', '<c-left>', ':call animate#window_delta_width(-10)<cr>', { silent = true })
+vim.keymap.set('n', '<c-right>', ':call animate#window_delta_width(10)<cr>', { silent = true })
+vim.keymap.set('n', '<s-up>', ':call animate#window_delta_height(1)<cr>', { silent = true })
+vim.keymap.set('n', '<s-down>', ':call animate#window_delta_height(-1)<cr>', { silent = true })
+vim.keymap.set('n', '<s-left>', ':call animate#window_delta_width(-1)<cr>', { silent = true })
+vim.keymap.set('n', '<s-right>', ':call animate#window_delta_width(1)<cr>', { silent = true })
diff --git a/after/plugin/format.lua b/after/plugin/format.lua
@@ -13,7 +13,7 @@ vim.api.nvim_create_autocmd('LspAttach', {
vim.lsp.buf.format()
if vim.api.nvim_buf_get_option(buf, 'ft') == 'dart' then
- vim.api.nvim_cmd({ cmd = 'NgHtmlFormat' }, {})
+ vim.api.nvim_command('NgHtmlFormat')
end
end, { buffer = buf, desc = 'LSP Format' })
diff --git a/after/plugin/ng_html.lua b/after/plugin/ng_html.lua
@@ -1,5 +1,4 @@
-- TODO(tms) 06.09.22: Handle single line template string
-
local template_query = vim.treesitter.parse_query('dart', [[
(annotation
(arguments
@@ -13,16 +12,16 @@ local template_query = vim.treesitter.parse_query('dart', [[
)
]])
-local get_root = function(bufnr)
+local function get_root(bufnr)
local parser = vim.treesitter.get_parser(bufnr, 'dart', {})
local tree = parser:parse()[1]
return tree:root();
end
-local prettier_html = function(text)
+local function prettier_html(text)
local split = vim.split(text, '\n')
local result = table.concat(vim.list_slice(split, 2, #split - 1), '\n')
- local job = require('plenary.job'):new {
+ local job = require('plenary.job'):new{
command = 'prettier',
args = { '--parser=html', '--tab-width=4' },
writer = { result },
@@ -31,7 +30,7 @@ local prettier_html = function(text)
return job:sync()
end
-local format_ng_html = function()
+local function format_ng_html()
local bufnr = vim.api.nvim_get_current_buf()
if vim.bo[bufnr].filetype ~= 'dart' then
@@ -60,15 +59,7 @@ local format_ng_html = function()
end
end
-vim.api.nvim_create_user_command('NgHtmlFormat', function()
- format_ng_html()
-end, {})
+vim.api.nvim_create_user_command('NgHtmlFormat', format_ng_html, {})
-local group = vim.api.nvim_create_augroup('ng-html-format', { clear = true })
-vim.api.nvim_create_autocmd('BufWritePre', {
- group = group,
- pattern = '*.dart',
- callback = function()
- format_ng_html()
- end,
-})
+local group = vim.api.nvim_create_augroup('ng-html-format', {})
+vim.api.nvim_create_autocmd('BufWritePre', { group = group, pattern = '*.dart', callback = format_ng_html })
diff --git a/after/plugin/telescope.lua b/after/plugin/telescope.lua
@@ -24,9 +24,9 @@ pcall(telescope.load_extension, 'dap')
pcall(telescope.load_extension, 'zk')
pcall(telescope.load_extension, 'git_worktree')
-vim.cmd [[packadd packer.nvim]]
+vim.cmd.packadd('packer.nvim')
require('packer').init()
-_ = telescope.load_extension('packer')
+_ = pcall(telescope.load_extension, 'packer')
local layout = require('tms.p.telescope').layout
diff --git a/colors/base16.lua b/colors/base16.lua
@@ -39,10 +39,8 @@ local cterm06 = 13
local cterm09 = 9
local cterm0F = 14
-vim.cmd [[
- highlight clear
- syntax reset
-]]
+vim.cmd.highlight('clear')
+vim.cmd.syntax('reset')
vim.g.colors_name = 'base16-gruvbox-dark-hard'
-- Vim editor colors fg bg ctermfg ctermbg attr guisp
diff --git a/ftplugin/dart.lua b/ftplugin/dart.lua
@@ -11,9 +11,9 @@ if string.find(full_path, '%.pub%-cache') then
end
if vim.fn.getline(1):match('^#!.*dcli') then
- vim.cmd [[comp dcli]]
+ vim.cmd.compiler('dcli')
else
- vim.cmd [[comp dart]]
+ vim.cmd.compiler('dart')
end
vim.lsp.start(require'tms.lsp'.make_opts('dartls'))
diff --git a/ftplugin/gitcommit.lua b/ftplugin/gitcommit.lua
@@ -7,4 +7,4 @@ require('cmp').setup.buffer {
},
}
-vim.cmd([[startinsert]])
+vim.cmd.startinsert()
diff --git a/ftplugin/go.lua b/ftplugin/go.lua
@@ -1,4 +1,4 @@
-vim.cmd [[comp go]]
+vim.cmd.compiler('go')
-- vim.cmd [[command! -buffer -nargs=? Godoc lua require('tms.ft.go.doc').godoc(vim.fn.expand('<args>'), vim.fn.expand('<cword>'))]]
vim.api.nvim_create_autocmd('BufWritePre', {
diff --git a/ftplugin/json.lua b/ftplugin/json.lua
@@ -1,5 +1,3 @@
-vim.cmd('match Comment +\\/\\/.\\+$+')
-
vim.keymap.set('n', 'gO', '<cmd>Json<cr>')
if vim.fn.exists('+winbar') then
diff --git a/ftplugin/lua.lua b/ftplugin/lua.lua
@@ -1,3 +1,3 @@
-vim.cmd [[comp lua]]
+vim.cmd.compiler('lua')
vim.treesitter.start()
diff --git a/ftplugin/sh.lua b/ftplugin/sh.lua
@@ -1,4 +1,4 @@
-vim.cmd [[comp bash]]
+vim.cmd.compiler('bash')
local cmp = require('cmp')
cmp.setup.buffer {sources = {{name = 'nvim_lsp'}, {name = 'exe'}, {name = 'path'}}}
diff --git a/ftplugin/vim.lua b/ftplugin/vim.lua
@@ -1,2 +1,2 @@
-vim.cmd[[syntax off]]
+vim.cmd.syntax('off')
vim.treesitter.start()
diff --git a/ftplugin/zsh.lua b/ftplugin/zsh.lua
@@ -1,4 +1,4 @@
-vim.cmd [[comp zsh]]
+vim.cmd.compiler('zsh')
require('cmp').setup.buffer {
--
diff --git a/init.lua b/init.lua
@@ -2,7 +2,7 @@ vim.g.mapleader = ','
vim.g.loaded_matchparen = 1
require('tms.first_load')
require('impatient')
-vim.cmd('colorscheme base16')
+vim.cmd.colorscheme('base16')
require('tms.options')
require('tms.keymap')
require('tms.autocmd')
diff --git a/lua/plugins.lua b/lua/plugins.lua
@@ -1,4 +1,4 @@
-vim.cmd [[packadd packer.nvim]]
+vim.cmd.packadd('packer.nvim')
local packer = require('packer')
return packer.startup({
function()
diff --git a/lua/tms/ft/dart/analyze.lua b/lua/tms/ft/dart/analyze.lua
@@ -25,7 +25,7 @@ M.qf = function(make_entry)
vim.fn.setqflist(list)
if #list > 0 then
- vim.cmd [[copen]]
+ vim.cmd.copen()
else
print('Analyzer finished.')
end
diff --git a/lua/tms/p/leap/ast.lua b/lua/tms/p/leap/ast.lua
@@ -7,7 +7,9 @@ local get_nodes = function()
local wininfo = vim.fn.getwininfo(api.nvim_get_current_win())[1]
-- Get current TS node.
local cur_node = ts_utils.get_node_at_cursor(0)
- if not cur_node then return end
+ if not cur_node then
+ return
+ end
-- Get parent nodes recursively.
local nodes = { cur_node }
local parent = cur_node:parent()
@@ -24,14 +26,16 @@ local get_nodes = function()
table.insert(targets, target)
end
end
- if #targets >= 1 then return targets end
+ if #targets >= 1 then
+ return targets
+ end
end
local select_range = function(target)
local mode = api.nvim_get_mode().mode
if not mode:match('n?o') then
-- Force going back to Normal (implies mode = v | V | ).
- vim.cmd('normal! ' .. mode)
+ vim.cmd.normal { mode, bang = true }
end
local vmode = 'charwise'
if mode:match('V') then
diff --git a/lua/tms/p/terminal.lua b/lua/tms/p/terminal.lua
@@ -4,10 +4,14 @@ local chan = nil
local last_command = nil
-- Returns a bool to show if the terminal window exists
-local function win_is_open() return winh ~= nil and vim.api.nvim_win_is_valid(winh) end
+local function win_is_open()
+ return winh ~= nil and vim.api.nvim_win_is_valid(winh)
+end
-- returns a bool to show if the buf exists
-local function buf_is_valid() return bufh ~= nil and vim.api.nvim_buf_is_valid(bufh) end
+local function buf_is_valid()
+ return bufh ~= nil and vim.api.nvim_buf_is_valid(bufh)
+end
-- Creates the terminal window and return the user to the window where the call was made
local function create_window()
@@ -23,8 +27,8 @@ local function create_buffer()
bufh = vim.api.nvim_create_buf(false, true)
vim.api.nvim_win_set_buf(winh, bufh)
vim.api.nvim_set_current_win(winh)
- vim.cmd('term')
- vim.cmd('norm G')
+ vim.cmd.term()
+ vim.cmd.normal('G')
vim.api.nvim_buf_set_name(bufh, 'terminal')
chan = vim.b.terminal_job_id
vim.api.nvim_set_current_win(curr)
@@ -63,7 +67,7 @@ M.exit = function()
winh = nil
end
if buf_is_valid() then
- vim.api.nvim_buf_delete(bufh, {force = true})
+ vim.api.nvim_buf_delete(bufh, { force = true })
bufh = nil
end
chan = nil
@@ -103,10 +107,10 @@ M.interactive = function()
end
if vim.api.nvim_get_current_win() == winh then
- vim.cmd('wincmd w')
+ vim.cmd.wincmd('w')
else
vim.api.nvim_set_current_win(winh)
- vim.cmd('startinsert')
+ vim.cmd.startinsert()
end
end
@@ -116,7 +120,9 @@ M.catchup = function()
M.toggle()
end
if buf_is_valid() then
- vim.api.nvim_buf_call(bufh, function() vim.cmd [[normal G]] end)
+ vim.api.nvim_buf_call(bufh, function()
+ vim.cmd.normal('G')
+ end)
end
end
diff --git a/lua/tms/p/trans.lua b/lua/tms/p/trans.lua
@@ -27,7 +27,7 @@ end
local function replace(text)
text = text:gsub('\n', '')
vim.fn.setreg('t', text)
- vim.cmd [[norm gv"tp]]
+ vim.cmd.norm('gv"tp')
end
function M.translate(to, from)
diff --git a/plugin/bufremove.lua b/plugin/bufremove.lua
@@ -73,7 +73,7 @@ function BufRemove.unshow_in_window(win_id)
end
-- Try using previous buffer
- vim.cmd([[bprevious]])
+ vim.cmd.bprevious()
if cur_buf ~= vim.api.nvim_win_get_buf(win_id) then return end
-- Create new listed scratch buffer
diff --git a/plugin/builtin.lua b/plugin/builtin.lua
@@ -1 +1 @@
-vim.cmd [[packadd cfilter]]
+vim.cmd.packadd('cfilter')
diff --git a/plugin/json_qf.lua b/plugin/json_qf.lua
@@ -41,10 +41,10 @@ local function populate_qf(type, sort, use_quickfix)
if use_quickfix then
vim.fn.setqflist(qf_list, ' ')
- vim.cmd('copen')
+ vim.cmd.copen()
else
vim.fn.setloclist(0, qf_list, ' ')
- vim.cmd('lopen')
+ vim.cmd.lopen()
end
end
diff --git a/plugin/scratch.lua b/plugin/scratch.lua
@@ -1,6 +1,6 @@
local open = function()
- vim.cmd('topleft split')
- vim.cmd('resize 12')
+ vim.cmd.topleft('split')
+ vim.cmd.resize('12')
local win = vim.api.nvim_get_current_win()
local buf = vim.api.nvim_create_buf(false, true)
vim.api.nvim_win_set_buf(win, buf)
diff --git a/plugin/trun.lua b/plugin/trun.lua
@@ -76,7 +76,7 @@ local function trun_to_qf(name)
efm = [[%EErrors in %.%#,%Zline %l\, column %c of %f %m,%f:%l:%c: %t%*[^:]: %m.,%-G%.%#]],
})
if #vim.fn.getqflist() > 0 then
- vim.cmd [[ copen ]]
+ vim.cmd.copen()
else
vim.notify('no errors found', vim.log.levels.INFO)
end
diff --git a/test/dart.lua b/test/dart.lua
@@ -27,15 +27,13 @@ end
local make_code_action_params = function()
local params = vim.lsp.util.make_range_params()
- params.context = {
- diagnostics = vim.lsp.diagnostic.get_line_diagnostics()
- }
+ params.context = { diagnostics = vim.lsp.diagnostic.get_line_diagnostics() }
return params
end
local list_code_action_kinds = function()
local params = make_code_action_params()
- local result = vim.lsp.buf_request_sync(0, "textDocument/codeAction", params)
+ local result = vim.lsp.buf_request_sync(0, 'textDocument/codeAction', params)
for _, res in pairs(result or {}) do
print('---', 'CODE ACTIONS')
for _, r in pairs(res.result or {}) do
@@ -47,10 +45,12 @@ local list_code_action_kinds = function()
end
local execute_code_action = function(kind)
- if not kind then return end
+ if not kind then
+ return
+ end
local params = make_code_action_params()
params.context.only = { kind }
- local result = vim.lsp.buf_request_sync(0, "textDocument/codeAction", params)
+ local result = vim.lsp.buf_request_sync(0, 'textDocument/codeAction', params)
for _, res in pairs(result or {}) do
for _, r in pairs(res.result or {}) do
if r.edit then
@@ -62,8 +62,10 @@ local execute_code_action = function(kind)
end
end
-vim.keymap.set('n', ',e', function() execute_code_action('refactor.remove.typeAnnotation') end)
+vim.keymap.set('n', ',e', function()
+ execute_code_action('refactor.remove.typeAnnotation')
+end)
vim.keymap.set('n', ',l', list_code_action_kinds)
print('loaded')
-vim.cmd [[messages clear]]
+vim.cmd.messages('clear')