Skip to content

Commit

Permalink
editorconfig support (#11)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
mehalter committed Apr 3, 2023
1 parent c37467b commit b8ae749
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 6 additions & 0 deletions doc/guess_indent.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lua/guess-indent/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ local M = {}

local default_config = {
auto_cmd = true,
override_editorconfig = false,
filetype_exclude = {
"netrw",
"tutor",
Expand Down
9 changes: 9 additions & 0 deletions lua/guess-indent/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b8ae749

Please sign in to comment.