diff options
| author | nsfisis <nsfisis@gmail.com> | 2022-04-30 20:46:42 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2022-04-30 20:46:42 +0900 |
| commit | f291e62f4d8aeda4f9fb5b3eece7a6223121526b (patch) | |
| tree | a52ff9e053c73dee15d6d174b06a820c9bafc7c5 /.config/nvim/lua | |
| parent | 1a32b613a4e794f387c8f642ed67a5a3b2f35a43 (diff) | |
| download | dotfiles-f291e62f4d8aeda4f9fb5b3eece7a6223121526b.tar.gz dotfiles-f291e62f4d8aeda4f9fb5b3eece7a6223121526b.tar.zst dotfiles-f291e62f4d8aeda4f9fb5b3eece7a6223121526b.zip | |
neovim: replace :autocmd with Lua API
Diffstat (limited to '.config/nvim/lua')
| -rw-r--r-- | .config/nvim/lua/vimrc.lua | 54 |
1 files changed, 29 insertions, 25 deletions
diff --git a/.config/nvim/lua/vimrc.lua b/.config/nvim/lua/vimrc.lua index 5f7475b..7de36d5 100644 --- a/.config/nvim/lua/vimrc.lua +++ b/.config/nvim/lua/vimrc.lua @@ -1,16 +1,18 @@ local M = {} -local autocmd_callbacks = {} -M.autocmd_callbacks = autocmd_callbacks -function M.autocmd(event, filter, callback) - local callback_id = #autocmd_callbacks + 1 - autocmd_callbacks[callback_id] = callback - vim.cmd(('autocmd Vimrc %s %s lua vimrc.autocmd_callbacks[%d]()'):format( - event, - filter, - callback_id)) +local vimrc_augroup + +function M.create_augroup_for_vimrc() + vimrc_augroup = vim.api.nvim_create_augroup('Vimrc', {}) +end + +function M.autocmd(event, opts) + if not opts.group then + opts.group = vimrc_augroup + end + vim.api.nvim_create_autocmd(event, opts) end @@ -28,6 +30,18 @@ end +local function set_indentation(style, width) + vim.bo.expandtab = style + vim.bo.tabstop = width + vim.bo.shiftwidth = width + vim.bo.softtabstop = width + + if vim.fn.exists(':IndentLinesReset') == 2 then + vim.cmd('IndentLinesReset') + end +end + + function M.register_filetype_autocmds_for_indentation() local SPACE = true local TAB = false @@ -56,22 +70,12 @@ function M.register_filetype_autocmds_for_indentation() } for ft, setting in pairs(indentation_settings) do - vim.cmd(([[autocmd Vimrc FileType %s lua vimrc._set_indentation(%s, %d)]]):format( - ft, - setting.style, - setting.width - )) - end -end - -function M._set_indentation(style, width) - vim.bo.expandtab = style - vim.bo.tabstop = width - vim.bo.shiftwidth = width - vim.bo.softtabstop = width - - if vim.fn.exists(':IndentLinesReset') == 2 then - vim.cmd('IndentLinesReset') + vimrc.autocmd('FileType', { + pattern = ft, + callback = function() + set_indentation(setting.style, setting.width) + end, + }) end end |
