diff options
| author | Adam Stankiewicz <sheerun@sher.pl> | 2020-09-16 15:50:39 +0200 | 
|---|---|---|
| committer | Adam Stankiewicz <sheerun@sher.pl> | 2020-09-16 15:50:39 +0200 | 
| commit | 17c2b630e1f0f0f02a24fcc664f0df91122e8e00 (patch) | |
| tree | 09a54c87c97be6d400291b79b89368fab37ce234 /autoload | |
| parent | 271679272c7bb1a281c7404408a2414068abf91c (diff) | |
| download | vim-polyglot-17c2b630e1f0f0f02a24fcc664f0df91122e8e00.tar.gz vim-polyglot-17c2b630e1f0f0f02a24fcc664f0df91122e8e00.zip | |
Write heuristics for perl, closes #550v4.10.2
Diffstat (limited to 'autoload')
| -rw-r--r-- | autoload/polyglot.vim | 103 | ||||
| -rw-r--r-- | autoload/sleuth.vim | 8 | 
2 files changed, 102 insertions, 9 deletions
| diff --git a/autoload/polyglot.vim b/autoload/polyglot.vim index 29287ece..5d4bfe9a 100644 --- a/autoload/polyglot.vim +++ b/autoload/polyglot.vim @@ -10,11 +10,11 @@ func! s:Setf(ft)    endif  endfunc -func! polyglot#Heuristics() +func! polyglot#Shebang()    " Try to detect filetype from shebang -  let l:filetype = polyglot#Shebang() -  if l:filetype != "" -    exec "setf " . l:filetype +  let ft = polyglot#ShebangFiletype() +  if ft != "" +    call s:Setf(ft)      return 1    endif @@ -52,6 +52,8 @@ let s:interpreters = {    \ 'cperl': 'perl',    \ 'perl': 'perl',    \ 'php': 'php', +  \ 'swipl': 'prolog', +  \ 'yap': 'prolog',    \ 'pwsh': 'ps1',    \ 'python': 'python',    \ 'python2': 'python', @@ -95,7 +97,7 @@ let s:r_hashbang = '^#!\s*\(\S\+\)\s*\(.*\)\s*'  let s:r_envflag = '%(\S\+=\S\+\|-[iS]\|--ignore-environment\|--split-string\)'  let s:r_env = '^\%(\' . s:r_envflag . '\s\+\)*\(\S\+\)' -func! polyglot#Shebang() +func! polyglot#ShebangFiletype()    let l:line1 = getline(1)    if l:line1 !~# "^#!" @@ -133,7 +135,7 @@ func! polyglot#Shebang()  endfunc  func! polyglot#DetectInpFiletype() -  let line = getline(1) +  let line = getline(nextnonblank(1))    if line =~# '^\*'      call s:Setf('abaqus') | return    endif @@ -269,10 +271,10 @@ func! polyglot#DetectIdrFiletype()      if line =~# '^%access .*'        call s:Setf('idris') | return      endif -    if exists("g:filetype_idr") -      call s:Setf(g:filetype_idr) | return -    endif    endfor +  if exists("g:filetype_idr") +    call s:Setf(g:filetype_idr) | return +  endif    call s:Setf('idris2') | return  endfunc @@ -296,6 +298,89 @@ func! polyglot#DetectBasFiletype()    call s:Setf('basic') | return  endfunc +func! polyglot#DetectPmFiletype() +  let line = getline(nextnonblank(1)) +  if line =~# 'XPM2' +    call s:Setf('xpm2') | return +  endif +  if line =~# 'XPM' +    call s:Setf('xpm') | return +  endif +  for lnum in range(1, min([line("$"), 50])) +    let line = getline(lnum) +    if line =~# '^\s*\%(use\s\+v6\(\<\|\>\)\|\(\<\|\>\)module\(\<\|\>\)\|\(\<\|\>\)\%(my\s\+\)\=class\(\<\|\>\)\)' +      call s:Setf('raku') | return +    endif +    if line =~# '\(\<\|\>\)use\s\+\%(strict\(\<\|\>\)\|v\=5\.\)' +      call s:Setf('perl') | return +    endif +  endfor +  if exists("g:filetype_pm") +    call s:Setf(g:filetype_pm) | return +  endif +  call s:Setf('perl') | return +endfunc + +func! polyglot#DetectPlFiletype() +  let line = getline(nextnonblank(1)) +  if line =~# '^[^#]*:-' || line =~# '^\s*\%(%\|/\*\)' || line =~# '\.\s*$' +    call s:Setf('prolog') | return +  endif +  for lnum in range(1, min([line("$"), 50])) +    let line = getline(lnum) +    if line =~# '^\s*\%(use\s\+v6\(\<\|\>\)\|\(\<\|\>\)module\(\<\|\>\)\|\(\<\|\>\)\%(my\s\+\)\=class\(\<\|\>\)\)' +      call s:Setf('raku') | return +    endif +    if line =~# '\(\<\|\>\)use\s\+\%(strict\(\<\|\>\)\|v\=5\.\)' +      call s:Setf('perl') | return +    endif +  endfor +  if exists("g:filetype_pl") +    call s:Setf(g:filetype_pl) | return +  endif +  call s:Setf('perl') | return +endfunc + +func! polyglot#DetectTFiletype() +  for lnum in range(1, min([line("$"), 5])) +    let line = getline(lnum) +    if line =~# '^\.' +      call s:Setf('nroff') | return +    endif +  endfor +  for lnum in range(1, min([line("$"), 50])) +    let line = getline(lnum) +    if line =~# '^\s*\%(use\s\+v6\(\<\|\>\)\|\(\<\|\>\)module\(\<\|\>\)\|\(\<\|\>\)\%(my\s\+\)\=class\(\<\|\>\)\)' +      call s:Setf('raku') | return +    endif +    if line =~# '\(\<\|\>\)use\s\+\%(strict\(\<\|\>\)\|v\=5\.\)' +      call s:Setf('perl') | return +    endif +  endfor +  if exists("g:filetype_t") +    call s:Setf(g:filetype_t) | return +  endif +  call s:Setf('perl') | return +endfunc + +func! polyglot#DetectTt2Filetype() +  for lnum in range(1, min([line("$"), 3])) +    let line = getline(lnum) +    if line =~? '<\%(!DOCTYPE HTML\|[%?]\|html\)' +      call s:Setf('tt2html') | return +    endif +  endfor +  call s:Setf('tt2') | return +endfunc + +func! polyglot#DetectHtmlFiletype() +  let line = getline(nextnonblank(1)) +  if line =~# '^\(%\|<[%&].*>\)' +    call s:Setf('mason') | return +  endif +  call s:Setf('html') | return +endfunc +  " Restore 'cpoptions'  let &cpo = s:cpo_save  unlet s:cpo_save diff --git a/autoload/sleuth.vim b/autoload/sleuth.vim index c1de82cd..ae101289 100644 --- a/autoload/sleuth.vim +++ b/autoload/sleuth.vim @@ -38,6 +38,7 @@ let s:globs = {    \ 'basic': '*.basic',    \ 'blade': '*.blade,*.blade.php',    \ 'brewfile': 'Brewfile', +  \ 'bzl': '*.bzl,BUCK,BUILD,BUILD.bazel,Tiltfile,WORKSPACE',    \ 'c': '*.c,*.cats,*.h,*.idc,*.qc',    \ 'caddyfile': 'Caddyfile',    \ 'carp': '*.carp', @@ -129,6 +130,7 @@ let s:globs = {    \ 'mako': '*.mako,*.mao',    \ 'markdown': '*.md,*.markdown,*.mdown,*.mdwn,*.mkd,*.mkdn,*.mkdown,*.ronn,*.workbook,contents.lr',    \ 'markdown.mdx': '*.mdx', +  \ 'mason': '*.mason,*.mhtml,*.comp',    \ 'meson': 'meson.build,meson_options.txt',    \ 'mma': '*.mathematica,*.cdf,*.m,*.ma,*.mt,*.nb,*.nbp,*.wl,*.wlt,*.wls,*.mma',    \ 'moon': '*.moon', @@ -151,7 +153,9 @@ let s:globs = {    \ 'perl': '*.pl,*.al,*.cgi,*.fcgi,*.perl,*.ph,*.plx,*.pm,*.psgi,*.t,Makefile.PL,Rexfile,ack,cpanfile',    \ 'php': '*.php,*.aw,*.ctp,*.fcgi,*.inc,*.php3,*.php4,*.php5,*.phps,*.phpt,Phakefile',    \ 'plantuml': '*.puml,*.iuml,*.plantuml,*.uml,*.pu', +  \ 'pod': '*.pod',    \ 'pony': '*.pony', +  \ 'prolog': '*.pl,*.pro,*.prolog,*.yap',    \ 'proto': '*.proto',    \ 'ps1': '*.ps1,*.psd1,*.psm1,*.pssc',    \ 'ps1xml': '*.ps1xml', @@ -190,6 +194,7 @@ let s:globs = {    \ 'sxhkdrc': '*.sxhkdrc,sxhkdrc',    \ 'systemd': '*.automount,*.mount,*.path,*.service,*.socket,*.swap,*.target,*.timer',    \ 'tablegen': '*.td', +  \ 'tads': '*.t',    \ 'terraform': '*.hcl,*.nomad,*.tf,*.tfvars,*.workflow',    \ 'textile': '*.textile',    \ 'thrift': '*.thrift', @@ -197,6 +202,8 @@ let s:globs = {    \ 'toml': '*.toml,Cargo.lock,Gopkg.lock,poetry.lock,Pipfile',    \ 'tptp': '*.p,*.tptp,*.ax',    \ 'trasys': '*.inp', +  \ 'tt2': '*.tt2', +  \ 'tt2html': '*.tt2',    \ 'typescript': '*.ts',    \ 'typescriptreact': '*.tsx',    \ 'unison': '*.u,*.uu', @@ -211,6 +218,7 @@ let s:globs = {    \ 'xdc': '*.xdc',    \ 'xml': '*.xml,*.adml,*.admx,*.ant,*.axml,*.builds,*.ccproj,*.ccxml,*.clixml,*.cproject,*.cscfg,*.csdef,*.csl,*.csproj,*.ct,*.depproj,*.dita,*.ditamap,*.ditaval,*.dll.config,*.dotsettings,*.filters,*.fsproj,*.fxml,*.glade,*.gml,*.gmx,*.grxml,*.gst,*.iml,*.ivy,*.jelly,*.jsproj,*.kml,*.launch,*.mdpolicy,*.mjml,*.mm,*.mod,*.mxml,*.natvis,*.ncl,*.ndproj,*.nproj,*.nuspec,*.odd,*.osm,*.pkgproj,*.pluginspec,*.proj,*.props,*.ps1xml,*.psc1,*.pt,*.rdf,*.resx,*.rss,*.sch,*.scxml,*.sfproj,*.shproj,*.srdf,*.storyboard,*.sublime-snippet,*.targets,*.tml,*.ui,*.urdf,*.ux,*.vbproj,*.vcxproj,*.vsixmanifest,*.vssettings,*.vstemplate,*.vxml,*.wixproj,*.workflow,*.wsdl,*.wsf,*.wxi,*.wxl,*.wxs,*.x3d,*.xacro,*.xaml,*.xib,*.xlf,*.xliff,*.xmi,*.xml.dist,*.xproj,*.xsd,*.xspec,*.xul,*.zcml,*.cdxml,App.config,NuGet.config,Settings.StyleCop,Web.Debug.config,Web.Release.config,Web.config,packages.config',    \ 'xml.twig': '*.xml.twig', +  \ 'xs': '*.xs',    \ 'xsl': '*.xslt,*.xsl',    \ 'yaml': '*.yml,*.mir,*.reek,*.rviz,*.sublime-syntax,*.syntax,*.yaml,*.yaml-tmlanguage,*.yaml.sed,*.yml.mysql,glide.lock,yarn.lock,fish_history,fish_read_history',    \ 'yaml.ansible': 'playbook.y{a,}ml,site.y{a,}ml,main.y{a,}ml,local.y{a,}ml,requirements.y{a,}ml,tasks.*.y{a,}ml,roles.*.y{a,}ml,handlers.*.y{a,}ml', | 
