From b8ae749fce17aa4c267eec80a6984130b94f80b2 Mon Sep 17 00:00:00 2001 From: Micah Halter Date: Mon, 3 Apr 2023 12:31:05 -0400 Subject: [PATCH] editorconfig support (#11) * Ignore buffers that have editorconfig values set * Update stylua github workflow * Add configuration option to control editorconfig overriding * Allow manual guess indentation to override editorconfig settings --- .github/workflows/lint.yml | 10 +++++----- README.md | 1 + doc/guess_indent.txt | 6 ++++++ lua/guess-indent/config.lua | 1 + lua/guess-indent/init.lua | 9 +++++++++ 5 files changed, 22 insertions(+), 5 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index ce0731f..e150ffd 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -2,21 +2,21 @@ name: Style checking on: push: - branches: [ main ] + branches: [main] pull_request: - branches: [ main ] + branches: [main] workflow_dispatch: - jobs: stylua: name: StyLua runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Lint with stylua - uses: JohnnyMorganz/stylua-action@1.0.0 + uses: JohnnyMorganz/stylua-action@v2 with: token: ${{ secrets.GITHUB_TOKEN }} + version: latest args: --color always --check lua/ diff --git a/README.md b/README.md index b32c2df..7777412 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,7 @@ The plugin provides the following configuration options: -- This is the default configuration require('guess-indent').setup { auto_cmd = true, -- Set to false to disable automatic execution + override_editorconfig = false, -- Set to true to override settings set by .editorconfig filetype_exclude = { -- A list of filetypes for which the auto command gets disabled "netrw", "tutor", diff --git a/doc/guess_indent.txt b/doc/guess_indent.txt index 8e1131b..39b6249 100644 --- a/doc/guess_indent.txt +++ b/doc/guess_indent.txt @@ -51,6 +51,12 @@ instead. created that guesses the indentation style for each buffer that gets opened. +`override_editorconfig` If this option is set to true, guessed indentation + will take precedence over settings set by + .editorconfig. Note this only changes the behavior if + `auto_cmd` is set to true or if `:GuessIndent` is run + with argument `autocmd`. + `filetype_exclude` A list of file types. If you open a buffer and its 'filetype' is contained in this list, then guess-indent won't run automatically. Note this only diff --git a/lua/guess-indent/config.lua b/lua/guess-indent/config.lua index 017c0a1..d53004a 100644 --- a/lua/guess-indent/config.lua +++ b/lua/guess-indent/config.lua @@ -2,6 +2,7 @@ local M = {} local default_config = { auto_cmd = true, + override_editorconfig = false, filetype_exclude = { "netrw", "tutor", diff --git a/lua/guess-indent/init.lua b/lua/guess-indent/init.lua index 31ef811..9708e46 100644 --- a/lua/guess-indent/init.lua +++ b/lua/guess-indent/init.lua @@ -267,6 +267,15 @@ end -- called by an auto command. function M.set_from_buffer(context) if context == "auto_cmd" then + -- editorconfig interoperability + if not config.override_editorconfig then + local editorconfig = vim.b.editorconfig + if editorconfig and (editorconfig.indent_style or editorconfig.indent_size or editorconfig.tab_width) then + utils.v_print(1, "Excluded because of editorconfig settings.") + return + end + end + -- Filter local filetype = vim.bo.filetype local buftype = vim.bo.buftype