aboutsummaryrefslogtreecommitdiffhomepage
path: root/.config/nvim/lua/vimrc.lua
diff options
context:
space:
mode:
Diffstat (limited to '.config/nvim/lua/vimrc.lua')
-rw-r--r--.config/nvim/lua/vimrc.lua54
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