From 12f18a076f79470941f7ed54ac2de7effcbff740 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sat, 4 Dec 2021 13:07:20 +0900 Subject: neovim: refactor after/ftplugin/* --- .config/nvim/lua/vimrc.lua | 61 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 48 insertions(+), 13 deletions(-) (limited to '.config/nvim/lua/vimrc.lua') diff --git a/.config/nvim/lua/vimrc.lua b/.config/nvim/lua/vimrc.lua index 80a02bc..0a2b9d9 100644 --- a/.config/nvim/lua/vimrc.lua +++ b/.config/nvim/lua/vimrc.lua @@ -15,19 +15,6 @@ function vimrc.autocmd(event, filter, callback) end -local conf = {} -conf.SPACE = true -conf.TAB = false -function conf.indent(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 vimrc.after_ftplugin(ft, callback) local var_name = 'did_ftplugin_' .. ft .. '_after' @@ -42,4 +29,52 @@ end +local SPACE = true +local TAB = false + +local indentation_settings = { + c = { style = SPACE, width = 4 }, + cmake = { style = SPACE, width = 2 }, + cpp = { style = SPACE, width = 4 }, + css = { style = SPACE, width = 2 }, + go = { style = TAB, width = 4 }, + haskell = { style = SPACE, width = 4 }, + html = { style = SPACE, width = 2 }, + javascript = { style = SPACE, width = 2 }, + json = { style = SPACE, width = 2 }, + lisp = { style = SPACE, width = 2 }, + lua = { style = SPACE, width = 3 }, + markdown = { style = SPACE, width = 4 }, + php = { style = SPACE, width = 2 }, + python = { style = SPACE, width = 4 }, + ruby = { style = SPACE, width = 2 }, + toml = { style = SPACE, width = 2 }, + typescript = { style = SPACE, width = 2 }, + vim = { style = SPACE, width = 4 }, + yaml = { style = SPACE, width = 2 }, +} + +function vimrc.register_filetype_autocmds_for_indentation() + for ft, setting in pairs(indentation_settings) do + vim.cmd(([[autocmd Vimrc FileType %s call v:lua.vimrc._set_indentation(%s, %d)]]):format( + ft, + setting.style and 'v:true' or 'v:false', + setting.width + )) + end +end + +function vimrc._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 + + + return vimrc -- cgit v1.2.3-70-g09d2