Skip to content

Commit f05dea8

Browse files
committed
Disable languages also from heuristics, fixes #673
1 parent e3ad29c commit f05dea8

File tree

3 files changed

+31
-20
lines changed

3 files changed

+31
-20
lines changed

autoload/polyglot/detect.vim

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,16 @@ func! polyglot#detect#H(...)
5353
for lnum in range(1, min([line("$"), 200]))
5454
let line = getline(lnum)
5555
if line =~# '^\s*\(@\(interface\|class\|protocol\|property\|end\|synchronised\|selector\|implementation\)\(\<\|\>\)\|#import\s\+.\+\.h[">]\)'
56-
if exists("g:c_syntax_for_h")
56+
if exists('g:c_syntax_for_h')
5757
set ft=objc | return
5858
endif
5959
set ft=objcpp | return
6060
endif
6161
endfor
62-
if exists("g:c_syntax_for_h")
62+
if exists('g:c_syntax_for_h')
6363
set ft=c | return
6464
endif
65-
if exists("g:ch_syntax_for_h")
65+
if exists('g:ch_syntax_for_h')
6666
set ft=ch | return
6767
endif
6868
set ft=cpp | return
@@ -82,7 +82,14 @@ func! polyglot#detect#M(...)
8282
set ft=objc | return
8383
endif
8484
if line =~# '^\s*%'
85-
set ft=octave | return
85+
if !has_key(g:polyglot_is_disabled, 'octave')
86+
set ft=octave | return
87+
endif
88+
endif
89+
if line =~# '^\s*%'
90+
if has_key(g:polyglot_is_disabled, 'octave')
91+
set ft=matlab | return
92+
endif
8693
endif
8794
if line =~# '^\s*(\*'
8895
set ft=mma | return
@@ -97,7 +104,12 @@ func! polyglot#detect#M(...)
97104
if exists("g:filetype_m")
98105
let &ft = g:filetype_m | return
99106
endif
100-
set ft=octave | return
107+
if !has_key(g:polyglot_is_disabled, 'octave')
108+
set ft=octave | return
109+
endif
110+
if has_key(g:polyglot_is_disabled, 'octave')
111+
set ft=matlab | return
112+
endif
101113
endfunc
102114

103115
func! polyglot#detect#Fs(...)

heuristics.yaml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ rules:
2828
- lines: 200
2929
pattern: '^\s*(@(interface|class|protocol|property|end|synchronised|selector|implementation)\b|#import\s+.+\.h[">])'
3030
rules:
31-
- if_exists: "g:c_syntax_for_h"
31+
- if: "exists('g:c_syntax_for_h')"
3232
filetype: objc
3333
- filetype: objcpp
34-
- if_exists: "g:c_syntax_for_h"
34+
- if: "exists('g:c_syntax_for_h')"
3535
filetype: c
36-
- if_exists: "g:ch_syntax_for_h"
36+
- if: "exists('g:ch_syntax_for_h')"
3737
filetype: ch
3838
- filetype: cpp
3939
---
@@ -46,16 +46,23 @@ rules:
4646
- pattern: '^\s*(@(interface|class|protocol|property|end|synchronised|selector|implementation)\b|#import\s+.+\.h[">])'
4747
filetype: objc
4848
- pattern: '^\s*%'
49+
if: "!has_key(g:polyglot_is_disabled, 'octave')"
4950
filetype: octave
51+
- pattern: '^\s*%'
52+
if: "has_key(g:polyglot_is_disabled, 'octave')"
53+
filetype: matlab
5054
- pattern: '^\s*\(\*'
5155
filetype: mma
5256
- pattern: '^\s*((type|var)\b|--)'
5357
ignore_case: true
5458
filetype: murphi
55-
- if_set: "saw_comment"
59+
- if: "saw_comment"
5660
filetype: objc
5761
- override: true
5862
- filetype: octave
63+
if: "!has_key(g:polyglot_is_disabled, 'octave')"
64+
- filetype: matlab
65+
if: "has_key(g:polyglot_is_disabled, 'octave')"
5966
---
6067
extensions: [fs]
6168
rules:

scripts/build

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -427,18 +427,10 @@ def rule_to_code(rule)
427427
end.join("\n")
428428
end
429429

430-
if rule.has_key?("if_set")
430+
if rule.has_key?("if")
431431
return <<~EOS
432-
if #{rule["negative"] ? "!" : ""}#{rule["if_set"]}
433-
#{indent(rule_to_code(except(rule, "if_set", "negative")), 2)}
434-
endif
435-
EOS
436-
end
437-
438-
if rule.has_key?("if_exists")
439-
return <<~EOS
440-
if #{rule["negative"] ? "!" : ""}exists("#{rule["if_exists"]}")
441-
#{indent(rule_to_code(except(rule, "if_exists", "negative")), 2)}
432+
if #{rule["if"]}
433+
#{indent(rule_to_code(except(rule, "if")), 2)}
442434
endif
443435
EOS
444436
end

0 commit comments

Comments
 (0)