Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the ability to disable individual rules per-buffer #155

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,15 @@ let g:EditorConfig_disable_rules = ['trim_trailing_whitespace']

You are able to disable any supported EditorConfig properties.

Additionally, you can also disable rules for a single buffer, which you can then
use to disable rules for all buffers of a specific filetype. This can be used to
prevent EditorConfig from producing broken Makefiles by replacing tabs with
spaces.

```viml
au FileType make let b:EditorConfig_disable_rules = ['indent_style']
```

## Bugs and Feature Requests

Feel free to submit bugs, feature requests, and other issues to the
Expand Down
23 changes: 23 additions & 0 deletions doc/editorconfig.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,29 @@ Example: Avoid loading EditorConfig for any remote files over ssh
let g:EditorConfig_exclude_patterns = ['scp://.*']
<

*g:EditorConfig_disable_rules*
This is a list that contains EditorConfig properties that should be ignored by
the plugin. This setting only applies when |g:EditorConfig_core_mode| is set
to "vim_core". The default is an empty list.

Example: Prevent EditorConfig from trimming trailing whitespaces
>
let g:EditorConfig_disable_rules = ['trim_trailing_whitespace']
<

*b:EditorConfig_disable_rules*
This is a buffer-local version of |g:EditorConfig_disable_rules|. The
default is an empty list.

Example: Prevent EditorConfig from replacing tabs with spaces for a single
buffer
>
let b:EditorConfig_disable_rules = ['indent_style']
<
Example: Prevent EditorConfig from replacing tabs with spaces within Makefiles
>
au FileType make let b:EditorConfig_disable_rules = ['indent_style']
<
*g:EditorConfig_exec_path*
The file path to the EditorConfig core executable. You can set this value in
your |vimrc| like this:
Expand Down
7 changes: 5 additions & 2 deletions plugin/editorconfig.vim
Original file line number Diff line number Diff line change
Expand Up @@ -504,8 +504,11 @@ function! s:TrimTrailingWhitespace() " {{{1
endfunction " }}}1

function! s:IsRuleActive(name, config) " {{{1
return index(g:EditorConfig_disable_rules, a:name) < 0 &&
\ has_key(a:config, a:name)
let l:globally_active = index(g:EditorConfig_disable_rules, a:name) < 0
let l:locally_active = exists("b:EditorConfig_disable_rules") &&
\ index(b:EditorConfig_disable_rules, a:name) < 0
let l:has_rule = has_key(a:config, a:name)
return l:has_rule && (l:globally_active || l:locally_active)
endfunction "}}}1

let &cpo = s:saved_cpo
Expand Down