Skip to content

Commit 17c2b63

Browse files
committed
Write heuristics for perl, closes #550
1 parent 2716792 commit 17c2b63

16 files changed

+1035
-42
lines changed

README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ A collection of language packs for Vim.
77
> One to rule them all, one to find them, one to bring them all and in the darkness bind them.
88
99
- It **won't affect your startup time**, as scripts are loaded only on demand\*.
10-
- It **installs and updates 120+ times faster** than the <!--Package Count-->196<!--/Package Count--> packages it consists of.
10+
- It **installs and updates 120+ times faster** than the <!--Package Count-->199<!--/Package Count--> packages it consists of.
1111
- It is more secure because scripts loaded for all extensions are generated by vim-polyglot (ftdetect).
1212
- Solid syntax and indentation support (other features skipped). Only the best language packs.
1313
- All unnecessary files are ignored (like enormous documentation from php support).
@@ -81,6 +81,7 @@ If you need full functionality of any plugin, please use it directly with your p
8181
- [basic](https://github.com/vim/vim/tree/master/runtime)
8282
- [blade](https://github.com/jwalton512/vim-blade)
8383
- [brewfile](https://github.com/bfontaine/Brewfile.vim)
84+
- [bzl](https://github.com/vim/vim/tree/master/runtime)
8485
- [c/c++](https://github.com/vim-jp/vim-cpp)
8586
- [caddyfile](https://github.com/isobit/vim-caddyfile)
8687
- [carp](https://github.com/hellerve/carp-vim)
@@ -177,6 +178,7 @@ If you need full functionality of any plugin, please use it directly with your p
177178
- [plantuml](https://github.com/aklt/plantuml-syntax)
178179
- [pony](https://github.com/jakwings/vim-pony)
179180
- [powershell](https://github.com/PProvost/vim-ps1)
181+
- [prolog](https://github.com/vim/vim/tree/master/runtime)
180182
- [protobuf](https://github.com/uarun/vim-protobuf)
181183
- [pug](https://github.com/digitaltoad/vim-pug)
182184
- [puppet](https://github.com/rodjek/vim-puppet)
@@ -213,6 +215,7 @@ If you need full functionality of any plugin, please use it directly with your p
213215
- [swift](https://github.com/keith/swift.vim)
214216
- [sxhkd](https://github.com/baskerville/vim-sxhkdrc)
215217
- [systemd](https://github.com/wgwoods/vim-systemd-syntax)
218+
- [tads](https://github.com/vim/vim/tree/master/runtime)
216219
- [terraform](https://github.com/hashivim/vim-terraform)
217220
- [textile](https://github.com/timcharper/textile.vim)
218221
- [thrift](https://github.com/solarnz/thrift.vim)

autoload/polyglot.vim

+94-9
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ func! s:Setf(ft)
1010
endif
1111
endfunc
1212

13-
func! polyglot#Heuristics()
13+
func! polyglot#Shebang()
1414
" Try to detect filetype from shebang
15-
let l:filetype = polyglot#Shebang()
16-
if l:filetype != ""
17-
exec "setf " . l:filetype
15+
let ft = polyglot#ShebangFiletype()
16+
if ft != ""
17+
call s:Setf(ft)
1818
return 1
1919
endif
2020

@@ -52,6 +52,8 @@ let s:interpreters = {
5252
\ 'cperl': 'perl',
5353
\ 'perl': 'perl',
5454
\ 'php': 'php',
55+
\ 'swipl': 'prolog',
56+
\ 'yap': 'prolog',
5557
\ 'pwsh': 'ps1',
5658
\ 'python': 'python',
5759
\ 'python2': 'python',
@@ -95,7 +97,7 @@ let s:r_hashbang = '^#!\s*\(\S\+\)\s*\(.*\)\s*'
9597
let s:r_envflag = '%(\S\+=\S\+\|-[iS]\|--ignore-environment\|--split-string\)'
9698
let s:r_env = '^\%(\' . s:r_envflag . '\s\+\)*\(\S\+\)'
9799

98-
func! polyglot#Shebang()
100+
func! polyglot#ShebangFiletype()
99101
let l:line1 = getline(1)
100102

101103
if l:line1 !~# "^#!"
@@ -133,7 +135,7 @@ func! polyglot#Shebang()
133135
endfunc
134136

135137
func! polyglot#DetectInpFiletype()
136-
let line = getline(1)
138+
let line = getline(nextnonblank(1))
137139
if line =~# '^\*'
138140
call s:Setf('abaqus') | return
139141
endif
@@ -269,10 +271,10 @@ func! polyglot#DetectIdrFiletype()
269271
if line =~# '^%access .*'
270272
call s:Setf('idris') | return
271273
endif
272-
if exists("g:filetype_idr")
273-
call s:Setf(g:filetype_idr) | return
274-
endif
275274
endfor
275+
if exists("g:filetype_idr")
276+
call s:Setf(g:filetype_idr) | return
277+
endif
276278
call s:Setf('idris2') | return
277279
endfunc
278280

@@ -296,6 +298,89 @@ func! polyglot#DetectBasFiletype()
296298
call s:Setf('basic') | return
297299
endfunc
298300

301+
func! polyglot#DetectPmFiletype()
302+
let line = getline(nextnonblank(1))
303+
if line =~# 'XPM2'
304+
call s:Setf('xpm2') | return
305+
endif
306+
if line =~# 'XPM'
307+
call s:Setf('xpm') | return
308+
endif
309+
for lnum in range(1, min([line("$"), 50]))
310+
let line = getline(lnum)
311+
if line =~# '^\s*\%(use\s\+v6\(\<\|\>\)\|\(\<\|\>\)module\(\<\|\>\)\|\(\<\|\>\)\%(my\s\+\)\=class\(\<\|\>\)\)'
312+
call s:Setf('raku') | return
313+
endif
314+
if line =~# '\(\<\|\>\)use\s\+\%(strict\(\<\|\>\)\|v\=5\.\)'
315+
call s:Setf('perl') | return
316+
endif
317+
endfor
318+
if exists("g:filetype_pm")
319+
call s:Setf(g:filetype_pm) | return
320+
endif
321+
call s:Setf('perl') | return
322+
endfunc
323+
324+
func! polyglot#DetectPlFiletype()
325+
let line = getline(nextnonblank(1))
326+
if line =~# '^[^#]*:-' || line =~# '^\s*\%(%\|/\*\)' || line =~# '\.\s*$'
327+
call s:Setf('prolog') | return
328+
endif
329+
for lnum in range(1, min([line("$"), 50]))
330+
let line = getline(lnum)
331+
if line =~# '^\s*\%(use\s\+v6\(\<\|\>\)\|\(\<\|\>\)module\(\<\|\>\)\|\(\<\|\>\)\%(my\s\+\)\=class\(\<\|\>\)\)'
332+
call s:Setf('raku') | return
333+
endif
334+
if line =~# '\(\<\|\>\)use\s\+\%(strict\(\<\|\>\)\|v\=5\.\)'
335+
call s:Setf('perl') | return
336+
endif
337+
endfor
338+
if exists("g:filetype_pl")
339+
call s:Setf(g:filetype_pl) | return
340+
endif
341+
call s:Setf('perl') | return
342+
endfunc
343+
344+
func! polyglot#DetectTFiletype()
345+
for lnum in range(1, min([line("$"), 5]))
346+
let line = getline(lnum)
347+
if line =~# '^\.'
348+
call s:Setf('nroff') | return
349+
endif
350+
endfor
351+
for lnum in range(1, min([line("$"), 50]))
352+
let line = getline(lnum)
353+
if line =~# '^\s*\%(use\s\+v6\(\<\|\>\)\|\(\<\|\>\)module\(\<\|\>\)\|\(\<\|\>\)\%(my\s\+\)\=class\(\<\|\>\)\)'
354+
call s:Setf('raku') | return
355+
endif
356+
if line =~# '\(\<\|\>\)use\s\+\%(strict\(\<\|\>\)\|v\=5\.\)'
357+
call s:Setf('perl') | return
358+
endif
359+
endfor
360+
if exists("g:filetype_t")
361+
call s:Setf(g:filetype_t) | return
362+
endif
363+
call s:Setf('perl') | return
364+
endfunc
365+
366+
func! polyglot#DetectTt2Filetype()
367+
for lnum in range(1, min([line("$"), 3]))
368+
let line = getline(lnum)
369+
if line =~? '<\%(!DOCTYPE HTML\|[%?]\|html\)'
370+
call s:Setf('tt2html') | return
371+
endif
372+
endfor
373+
call s:Setf('tt2') | return
374+
endfunc
375+
376+
func! polyglot#DetectHtmlFiletype()
377+
let line = getline(nextnonblank(1))
378+
if line =~# '^\(%\|<[%&].*>\)'
379+
call s:Setf('mason') | return
380+
endif
381+
call s:Setf('html') | return
382+
endfunc
383+
299384
" Restore 'cpoptions'
300385
let &cpo = s:cpo_save
301386
unlet s:cpo_save

autoload/sleuth.vim

+8
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ let s:globs = {
3838
\ 'basic': '*.basic',
3939
\ 'blade': '*.blade,*.blade.php',
4040
\ 'brewfile': 'Brewfile',
41+
\ 'bzl': '*.bzl,BUCK,BUILD,BUILD.bazel,Tiltfile,WORKSPACE',
4142
\ 'c': '*.c,*.cats,*.h,*.idc,*.qc',
4243
\ 'caddyfile': 'Caddyfile',
4344
\ 'carp': '*.carp',
@@ -129,6 +130,7 @@ let s:globs = {
129130
\ 'mako': '*.mako,*.mao',
130131
\ 'markdown': '*.md,*.markdown,*.mdown,*.mdwn,*.mkd,*.mkdn,*.mkdown,*.ronn,*.workbook,contents.lr',
131132
\ 'markdown.mdx': '*.mdx',
133+
\ 'mason': '*.mason,*.mhtml,*.comp',
132134
\ 'meson': 'meson.build,meson_options.txt',
133135
\ 'mma': '*.mathematica,*.cdf,*.m,*.ma,*.mt,*.nb,*.nbp,*.wl,*.wlt,*.wls,*.mma',
134136
\ 'moon': '*.moon',
@@ -151,7 +153,9 @@ let s:globs = {
151153
\ 'perl': '*.pl,*.al,*.cgi,*.fcgi,*.perl,*.ph,*.plx,*.pm,*.psgi,*.t,Makefile.PL,Rexfile,ack,cpanfile',
152154
\ 'php': '*.php,*.aw,*.ctp,*.fcgi,*.inc,*.php3,*.php4,*.php5,*.phps,*.phpt,Phakefile',
153155
\ 'plantuml': '*.puml,*.iuml,*.plantuml,*.uml,*.pu',
156+
\ 'pod': '*.pod',
154157
\ 'pony': '*.pony',
158+
\ 'prolog': '*.pl,*.pro,*.prolog,*.yap',
155159
\ 'proto': '*.proto',
156160
\ 'ps1': '*.ps1,*.psd1,*.psm1,*.pssc',
157161
\ 'ps1xml': '*.ps1xml',
@@ -190,13 +194,16 @@ let s:globs = {
190194
\ 'sxhkdrc': '*.sxhkdrc,sxhkdrc',
191195
\ 'systemd': '*.automount,*.mount,*.path,*.service,*.socket,*.swap,*.target,*.timer',
192196
\ 'tablegen': '*.td',
197+
\ 'tads': '*.t',
193198
\ 'terraform': '*.hcl,*.nomad,*.tf,*.tfvars,*.workflow',
194199
\ 'textile': '*.textile',
195200
\ 'thrift': '*.thrift',
196201
\ 'tmux': '',
197202
\ 'toml': '*.toml,Cargo.lock,Gopkg.lock,poetry.lock,Pipfile',
198203
\ 'tptp': '*.p,*.tptp,*.ax',
199204
\ 'trasys': '*.inp',
205+
\ 'tt2': '*.tt2',
206+
\ 'tt2html': '*.tt2',
200207
\ 'typescript': '*.ts',
201208
\ 'typescriptreact': '*.tsx',
202209
\ 'unison': '*.u,*.uu',
@@ -211,6 +218,7 @@ let s:globs = {
211218
\ 'xdc': '*.xdc',
212219
\ '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',
213220
\ 'xml.twig': '*.xml.twig',
221+
\ 'xs': '*.xs',
214222
\ 'xsl': '*.xslt,*.xsl',
215223
\ 'yaml': '*.yml,*.mir,*.reek,*.rviz,*.sublime-syntax,*.syntax,*.yaml,*.yaml-tmlanguage,*.yaml.sed,*.yml.mysql,glide.lock,yarn.lock,fish_history,fish_read_history',
216224
\ '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',

0 commit comments

Comments
 (0)