summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Stankiewicz <sheerun@sher.pl>2020-09-06 23:37:24 +0200
committerAdam Stankiewicz <sheerun@sher.pl>2020-09-06 23:37:24 +0200
commit46040f3ffd35c4a981ca1f3713934f55b58bb525 (patch)
treea562dbf2edce5657e648f6c6a69856ea30985d27
parent48254ec7adc9cbbc2ff15c606faf062d23d7f200 (diff)
downloadvim-polyglot-46040f3ffd35c4a981ca1f3713934f55b58bb525.tar.gz
vim-polyglot-46040f3ffd35c4a981ca1f3713934f55b58bb525.zip
Add heuristics for .h extension
-rw-r--r--autoload/polyglot.vim19
-rw-r--r--autoload/sleuth.vim10
-rw-r--r--ftdetect/polyglot.vim19
-rw-r--r--heuristics.yaml14
-rw-r--r--packages.yaml24
-rwxr-xr-xscripts/build18
-rw-r--r--scripts/test_extensions.vim26
-rw-r--r--scripts/test_filetypes.vim2
8 files changed, 107 insertions, 25 deletions
diff --git a/autoload/polyglot.vim b/autoload/polyglot.vim
index ffb3c43f..1ed71826 100644
--- a/autoload/polyglot.vim
+++ b/autoload/polyglot.vim
@@ -154,6 +154,25 @@ func! polyglot#DetectAspFiletype()
setf aspvbs | return
endfunc
+func! polyglot#DetectHFiletype()
+ for lnum in range(1, min([line("$"), 200]))
+ let line = getline(lnum)
+ if line =~# '^\s*\(@\(interface\|class\|protocol\|property\|end\|synchronised\|selector\|implementation\)\(\<\|\>\)\|#import\s\+.\+\.h[">]\)'
+ if exists("g:c_syntax_for_h")
+ setf objc | return
+ endif
+ setf objcpp | return
+ endif
+ endfor
+ if exists("g:c_syntax_for_h")
+ setf c | return
+ endif
+ if exists("g:ch_syntax_for_h")
+ setf ch | return
+ endif
+ setf cpp | return
+endfunc
+
func! polyglot#DetectMFiletype()
let saw_comment = 0
for lnum in range(1, min([line("$"), 100]))
diff --git a/autoload/sleuth.vim b/autoload/sleuth.vim
index 0460a46e..2eb95a63 100644
--- a/autoload/sleuth.vim
+++ b/autoload/sleuth.vim
@@ -10,7 +10,7 @@ let s:globs = {
\ 'abc': '*.abc',
\ 'abel': '*.abl',
\ 'acedb': '*.wrm',
- \ 'ada': '*.adb,*.ads,*.ada,*.gpr',
+ \ 'ada': '*.adb,*.ads,*.ada,*.adc,*.gpr,*.ada_m',
\ 'ahdl': '*.tdf',
\ 'aidl': '*.aidl',
\ 'alsaconf': '',
@@ -34,17 +34,17 @@ let s:globs = {
\ 'autoit': '*.au3',
\ 'automake': '[Mm]akefile.am,GNUmakefile.am',
\ 'ave': '*.ave',
- \ 'awk': '*.awk',
+ \ 'awk': '*.awk,*.gawk',
\ 'basic': '*.basic',
\ 'blade': '*.blade,*.blade.php',
\ 'brewfile': 'Brewfile',
- \ 'c': '*.c,*.cats,*.h,*.idc',
+ \ 'c': '*.c,*.cats,*.h,*.idc,*.qc',
\ 'caddyfile': 'Caddyfile',
\ 'carp': '*.carp',
\ 'clojure': '*.clj,*.boot,*.cl2,*.cljc,*.cljs,*.cljs.hl,*.cljscm,*.cljx,*.hic,*.edn,riemann.config,build.boot,profile.boot',
\ 'cmake': '*.cmake,*.cmake.in,CMakeLists.txt',
\ 'coffee': '*.coffee,*._coffee,*.cake,*.cjsx,*.iced,*.coffeekup,Cakefile',
- \ 'cpp': '*.cpp,*.c++,*.cc,*.cp,*.cxx,*.h,*.h++,*.hh,*.hpp,*.hxx,*.inc,*.inl,*.ipp,*.tcc,*.tpp',
+ \ 'cpp': '*.cpp,*.c++,*.cc,*.cp,*.cxx,*.h,*.h++,*.hh,*.hpp,*.hxx,*.inc,*.inl,*.ipp,*.tcc,*.tpp,*.moc',
\ 'cql': '*.cql',
\ 'cryptol': '*.cry,*.cyl,*.lcry,*.lcyl',
\ 'crystal': '*.cr,Projectfile',
@@ -52,7 +52,7 @@ let s:globs = {
\ 'cucumber': '*.feature,*.story',
\ 'cuesheet': '*.cue',
\ 'd': '*.d,*.di',
- \ 'dart': '*.dart',
+ \ 'dart': '*.dart,*.drt',
\ 'dcov': '*.lst',
\ 'dd': '*.dd',
\ 'ddoc': '*.ddoc',
diff --git a/ftdetect/polyglot.vim b/ftdetect/polyglot.vim
index 6d080cf3..19d164c5 100644
--- a/ftdetect/polyglot.vim
+++ b/ftdetect/polyglot.vim
@@ -134,7 +134,7 @@ if !has_key(s:disabled_packages, 'awk')
endif
if !has_key(s:disabled_packages, 'c/c++')
- au! BufRead,BufNewFile *.c,*.cpp,*.tpp
+ au! BufRead,BufNewFile *.cpp,*.tpp,*.c
endif
if !has_key(s:disabled_packages, 'cmake')
@@ -343,7 +343,9 @@ endif
if !has_key(s:disabled_packages, 'ada')
au BufNewFile,BufRead *.ada setf ada
+ au BufNewFile,BufRead *.ada_m setf ada
au BufNewFile,BufRead *.adb setf ada
+ au BufNewFile,BufRead *.adc setf ada
au BufNewFile,BufRead *.ads setf ada
au BufNewFile,BufRead *.gpr setf ada
endif
@@ -465,6 +467,7 @@ endif
if !has_key(s:disabled_packages, 'awk')
au BufNewFile,BufRead *.awk setf awk
+ au BufNewFile,BufRead *.gawk setf awk
endif
if !has_key(s:disabled_packages, 'reason')
@@ -473,16 +476,11 @@ if !has_key(s:disabled_packages, 'reason')
endif
if !has_key(s:disabled_packages, 'c/c++')
- au BufNewFile,BufRead *.c setf c
- au BufNewFile,BufRead *.cats setf c
- au BufNewFile,BufRead *.h setf c
- au BufNewFile,BufRead *.idc setf c
au BufNewFile,BufRead *.c++ setf cpp
au BufNewFile,BufRead *.cc setf cpp
au BufNewFile,BufRead *.cp setf cpp
au BufNewFile,BufRead *.cpp setf cpp
au BufNewFile,BufRead *.cxx setf cpp
- au BufNewFile,BufRead *.h setf cpp
au BufNewFile,BufRead *.h++ setf cpp
au BufNewFile,BufRead *.hh setf cpp
au BufNewFile,BufRead *.hpp setf cpp
@@ -490,8 +488,14 @@ if !has_key(s:disabled_packages, 'c/c++')
au BufNewFile,BufRead *.inc setf cpp
au BufNewFile,BufRead *.inl setf cpp
au BufNewFile,BufRead *.ipp setf cpp
+ au BufNewFile,BufRead *.moc setf cpp
au BufNewFile,BufRead *.tcc setf cpp
au BufNewFile,BufRead *.tpp setf cpp
+ au BufNewFile,BufRead *.c setf c
+ au BufNewFile,BufRead *.cats setf c
+ au BufNewFile,BufRead *.idc setf c
+ au BufNewFile,BufRead *.qc setf c
+ au! BufNewFile,BufRead *.h call polyglot#DetectHFiletype()
endif
if !has_key(s:disabled_packages, 'caddyfile')
@@ -566,6 +570,7 @@ endif
if !has_key(s:disabled_packages, 'dart')
au BufNewFile,BufRead *.dart setf dart
+ au BufNewFile,BufRead *.drt setf dart
endif
if !has_key(s:disabled_packages, 'dhall')
@@ -1065,7 +1070,7 @@ if !has_key(s:disabled_packages, 'nix')
endif
if !has_key(s:disabled_packages, 'objc')
- au BufNewFile,BufRead *.h setf objc
+ au! BufNewFile,BufRead *.h call polyglot#DetectHFiletype()
au! BufNewFile,BufRead *.m call polyglot#DetectMFiletype()
endif
diff --git a/heuristics.yaml b/heuristics.yaml
index 8c0c1663..901241cb 100644
--- a/heuristics.yaml
+++ b/heuristics.yaml
@@ -23,6 +23,20 @@ rules:
filetype: aspperl
- filetype: aspvbs
---
+extensions: [h]
+rules:
+- lines: 200
+ pattern: '^\s*(@(interface|class|protocol|property|end|synchronised|selector|implementation)\b|#import\s+.+\.h[">])'
+ rules:
+ - if_exists: "g:c_syntax_for_h"
+ filetype: objc
+ - filetype: objcpp
+- if_exists: "g:c_syntax_for_h"
+ filetype: c
+- if_exists: "g:ch_syntax_for_h"
+ filetype: ch
+- filetype: cpp
+---
extensions: [m]
rules:
- lines: 100
diff --git a/packages.yaml b/packages.yaml
index fb67e676..e1406101 100644
--- a/packages.yaml
+++ b/packages.yaml
@@ -93,7 +93,9 @@ filetypes:
- adb
- ads
- ada
+ - adc
- gpr
+ - ada_m
---
name: ahdl
remote: vim/vim:runtime
@@ -191,6 +193,11 @@ filetypes:
- '*/.aptitude/config'
- '*/etc/apt/apt.conf.d/[^.]*'
- '*/etc/apt/apt.conf.d/*.conf'
+ ignored_warnings:
+ # some kind of bugs in filetype detection algorithm
+ - '*/etc/apt/apt.conf.d/{[-_[:alnum:]]\+,[-_.[:alnum:]]\+.conf}'
+ - '*/etc/apt/apt.conf.d/]\+'
+ - '*/etc/apt/apt.conf.d/]\+.conf'
---
name: arch
remote: vim/vim:runtime
@@ -302,19 +309,25 @@ filetypes:
- name: awk
extensions:
- awk
+ - gawk
---
name: c/c++
remote: vim-jp/vim-cpp
filetypes:
-- name: c
- linguist: C
- name: cpp
linguist: C++
+ extra_extensions:
+ - moc
ignored_extensions:
# conflicts with more popular reason, remove after heuristics work
- re
# implemented by arduino
- ino
+- name: c
+ linguist: C
+ extra_extensions:
+ # Quake C
+ - qc
---
name: caddyfile
remote: isobit/vim-caddyfile
@@ -358,10 +371,9 @@ filetypes:
extra_extensions:
# 17 results: https://github.com/search?q=extension%3Acoffeekup+html&type=Code
- coffeekup
- ignored_filenames:
+ ignored_warnings:
# Probably mistake
- '*Cakefile'
- ignored_warnings:
# Used by C#
- csx
# Used by Chuck
@@ -430,6 +442,8 @@ remote: dart-lang/dart-vim-plugin
filetypes:
- name: dart
linguist: Dart
+ extra_extensions:
+ - drt
---
name: dhall
remote: vmchale/dhall-vim
@@ -470,7 +484,7 @@ filetypes:
filenames:
- 'docker-compose*.yaml'
- 'docker-compose*.yml'
- ignored_filenames:
+ ignored_warnings:
# Probably mistakes?
- 'docker-compose*.yaml*'
- 'docker-compose*.yml*'
diff --git a/scripts/build b/scripts/build
index f688c28f..67f01ca3 100755
--- a/scripts/build
+++ b/scripts/build
@@ -268,10 +268,6 @@ def rule_to_code(rule)
end
end
- if rule.has_key?("rules")
- return rule["rules"].map { |r| indent(rule_to_code(r), 0) }.join("\n")
- end
-
if rule.has_key?("pattern") || rule.has_key?("or") || rule.has_key?("and")
return <<~EOS
if #{pattern_to_condition(rule)}
@@ -280,6 +276,10 @@ def rule_to_code(rule)
EOS
end
+ if rule.has_key?("rules")
+ return rule["rules"].map { |r| indent(rule_to_code(r), 0) }.join("\n")
+ end
+
if rule.has_key?("if_set")
return <<~EOS
if #{rule["negative"] ? "!" : ""}#{rule["if_set"]}
@@ -288,6 +288,14 @@ def rule_to_code(rule)
EOS
end
+ if rule.has_key?("if_exists")
+ return <<~EOS
+ if #{rule["negative"] ? "!" : ""}exists("#{rule["if_exists"]}")
+ #{indent(rule_to_code(except(rule, "if_exists", "negative")), 2)}
+ endif
+ EOS
+ end
+
if rule.has_key?("set")
return <<~EOS
let #{rule["set"]} = 1
@@ -455,7 +463,7 @@ def generate_ftdetect(packages, heuristics)
extensions = filetype["extensions"]
filenames = filetype["filenames"]
- expected_extensions = all_filetypes.has_key?(name) ? all_filetypes.fetch(name)[:extensions] : []
+ expected_extensions = (all_filetypes.has_key?(name) ? all_filetypes.fetch(name)[:extensions] : []).map(&:downcase)
ignored_extensions = expand_all(filetype.fetch("ignored_extensions", []))
ignored_warnings = expand_all(filetype.fetch("ignored_warnings", []))
diff --git a/scripts/test_extensions.vim b/scripts/test_extensions.vim
index 9cac0b21..f2aaf66c 100644
--- a/scripts/test_extensions.vim
+++ b/scripts/test_extensions.vim
@@ -181,6 +181,18 @@ call TestExtension("ave", "foobar.ave", "")
" Awk
call TestExtension("awk", "foobar.awk", "")
+" C++
+call TestExtension("c", "foobar.c", "")
+call TestExtension("cpp", "foobar.cxx", "")
+call TestExtension("cpp", "foobar.c++", "")
+call TestExtension("cpp", "foobar.hh", "")
+call TestExtension("cpp", "foobar.hxx", "")
+call TestExtension("cpp", "foobar.hpp", "")
+call TestExtension("cpp", "foobar.ipp", "")
+call TestExtension("cpp", "foobar.moc", "")
+call TestExtension("cpp", "foobar.tcc", "")
+call TestExtension("cpp", "foobar.inl", "")
+
" vim-polyglot only
call TestExtension("blade", "test.blade.php", "")
call TestExtension("yaml.ansible", "playbook.yml", "")
@@ -233,7 +245,7 @@ call TestExtension("vb", "vb.dsm", "")
call TestExtension("vb", "vb.dsm", "")
call TestExtension("vb", "vb.ctl", "")
-" Idris
+" .idr extension
call TestExtension("idris", "lowercase.idr", "--idris1")
call TestExtension("idris", "uppercase.idr", "--Idris1")
call TestExtension("idris", "start-space-l.idr", "-- idris1")
@@ -253,7 +265,17 @@ call TestExtension("idris2", "two-spaces-u.idr", "-- Idris 2")
call TestExtension("idris2", "mypkg.ipkg", "package mypkg\n\ndepends = effects")
call TestExtension("idris2", "use-post-proj.idr", "%language PostfixProjections")
-" Literate Idris
+" .lidr extension
call TestExtension("lidris", "lidris-1.lidr", "Some test plaintext\n\n> --idris1\n> myfact : Nat -> Nat\n> myfact Z = 1\n> myfact (S k) = (S k) * myfact k\n\nMore plaintext")
call TestExtension("lidris2", "lidris-2.lidr", "Some test plaintext\n\n> --idris2\n> myfact : Nat -> Nat\n> myfact Z = 1\n> myfact (S k) = (S k) * myfact k\n\nMore plaintext")
+
+" .h extension
+call TestExtension("objcpp", "foo.h", "@interface MTNavigationController : UINavigationController")
+call TestExtension("cpp", "foo.h", "")
+let g:c_syntax_for_h = 1
+call TestExtension("objc", "foo.h", "@interface MTNavigationController : UINavigationController")
+call TestExtension("c", "foo.h", "")
+unlet g:c_syntax_for_h
+let g:ch_syntax_for_h = 1
+call TestExtension("ch", "foo.h", "")
diff --git a/scripts/test_filetypes.vim b/scripts/test_filetypes.vim
index e157889d..42e683d1 100644
--- a/scripts/test_filetypes.vim
+++ b/scripts/test_filetypes.vim
@@ -45,8 +45,8 @@ call TestFiletype('autoit')
call TestFiletype('ave')
call TestFiletype('awk')
call TestFiletype('reason')
-call TestFiletype('c')
call TestFiletype('cpp')
+call TestFiletype('c')
call TestFiletype('caddyfile')
call TestFiletype('carp')
call TestFiletype('clojure')