diff --git a/README.md b/README.md index 7777412..0caa1a0 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,15 @@ require('guess-indent').setup { "terminal", "prompt", }, + on_tab_options = { -- A table of vim options when tabs are detected + ["expandtab"] = false, + }, + on_space_options = { -- A table of vim options when spaces are detected + ["expandtab"] = true, + ["tabstop"] = "detected", -- If the option value is 'detected', The value is set to the automatically detected indent size. + ["softtabstop"] = "detected", + ["shiftwidth"] = "detected", + }, } ``` diff --git a/doc/guess_indent.txt b/doc/guess_indent.txt index 39b6249..d109294 100644 --- a/doc/guess_indent.txt +++ b/doc/guess_indent.txt @@ -65,6 +65,12 @@ instead. `buftype_exclude` Same as `filetype_exclude` but for 'buftype' instead. +`on_tab_options` A table of vim options when tabs are detected. + +`on_space_options` A table of vim options when spaces are detected. + If the option value is `'detected'`, The value is set + to the automatically detected indent size. + ============================================================================== COMMANDS *GuessIndent-commands* diff --git a/lua/guess-indent/config.lua b/lua/guess-indent/config.lua index d53004a..e21c113 100644 --- a/lua/guess-indent/config.lua +++ b/lua/guess-indent/config.lua @@ -13,6 +13,15 @@ local default_config = { "terminal", "prompt", }, + on_tab_options = { + ["expandtab"] = false, + }, + on_space_options = { + ["expandtab"] = true, + ["tabstop"] = "detected", + ["softtabstop"] = "detected", + ["shiftwidth"] = "detected", + }, } -- The current active config diff --git a/lua/guess-indent/init.lua b/lua/guess-indent/init.lua index 9708e46..14abda2 100644 --- a/lua/guess-indent/init.lua +++ b/lua/guess-indent/init.lua @@ -65,13 +65,17 @@ local function set_indentation(indentation) end if indentation == "tabs" then - set_buffer_opt(0, "expandtab", false) + for opt, value in pairs(config.on_tab_options) do + set_buffer_opt(0, opt, value) + end print("Did set indentation to tabs.") elseif type(indentation) == "number" and indentation > 0 then - set_buffer_opt(0, "expandtab", true) - set_buffer_opt(0, "tabstop", indentation) - set_buffer_opt(0, "softtabstop", indentation) - set_buffer_opt(0, "shiftwidth", indentation) + for opt, value in pairs(config.on_space_options) do + if value == "detected" then + value = indentation + end + set_buffer_opt(0, opt, value) + end print("Did set indentation to", indentation, "spaces.") else print("Failed to detect indentation style.")