Skip to content

Commit

Permalink
Allow disabling heuristics on a per-filetype basis
Browse files Browse the repository at this point in the history
References: #29
  • Loading branch information
tpope committed Mar 18, 2022
1 parent f1df4ac commit fd73b75
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
17 changes: 13 additions & 4 deletions doc/sleuth.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,23 @@ CONFIGURATION *sleuth-configuration*
To override detection and force options for a particular file or directory,
use a |modeline| or EditorConfig (https://editorconfig.org/), respectively.

*g:sleuth_{filetype}_heuristics*
To disable the heuristic algorithm for a given 'filetype', assign a false
value to a variable named like g:sleuth_{filetype}_heuristics:
>
let g:sleuth_gitcommit_heuristics = 0
<
*g:sleuth_heuristics*
Alternatively, one can disable heuristics by default, and opt-in for
individual file types:
>
let g:sleuth_heuristics = 0
let g:sleuth_perl_heuristics = 1
<
*g:sleuth_automatic*
Automatic detection of buffer options can be disabled entirely with:
>
let g:sleuth_automatic = 0
<
or:
>
let b:sleuth_automatic = 0
<
*g:sleuth_no_filetype_indent_on*
Sleuth forces |:filetype-indent-on| by default, which enables file-type
Expand Down
6 changes: 3 additions & 3 deletions plugin/sleuth.vim
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ function! s:DetectHeuristics(into) abort
if has_key(detected, 'patterns')
call remove(detected, 'patterns')
endif
if empty(filetype)
if empty(filetype) || !get(b:, 'sleuth_automatic', 1) || empty(get(g:, 'sleuth_' . filetype . '_heuristics', get(g:, 'sleuth_heuristics', 1)))
return detected
endif
if s:Ready(detected)
Expand Down Expand Up @@ -589,10 +589,10 @@ endfunction
augroup sleuth
autocmd!
autocmd BufNewFile,BufReadPost * nested
\ if get(b:, 'sleuth_automatic', get(g:, 'sleuth_automatic', 1))
\ if get(g:, 'sleuth_automatic', 1)
\ | exe s:AutoInit() | endif
autocmd BufFilePost * nested
\ if (@% !~# '^!' || exists('b:sleuth')) && get(b:, 'sleuth_automatic', get(g:, 'sleuth_automatic', 1))
\ if (@% !~# '^!' || exists('b:sleuth')) && get(g:, 'sleuth_automatic', 1)
\ | exe s:AutoInit() | endif
autocmd FileType * nested
\ if exists('b:sleuth') | silent call s:Apply(s:DetectHeuristics(b:sleuth), s:safe_options) | endif
Expand Down

0 comments on commit fd73b75

Please sign in to comment.