Address BufWritePost error, fixes #573

This commit is contained in:
Adam Stankiewicz
2020-10-04 19:00:16 +02:00
parent 073e4d44be
commit d221139bd7
3 changed files with 36 additions and 63 deletions

View File

@@ -2,10 +2,6 @@
let s:cpo_save = &cpo let s:cpo_save = &cpo
set cpo&vim set cpo&vim
func! s:WritePostOnce(fn)
exe 'au! filetypedetect BufWritePost <buffer> au! filetypedetect BufWritePost <buffer> | ' . a:fn
endfunc
" DO NOT EDIT CODE BELOW, IT IS GENERATED WITH MAKEFILE " DO NOT EDIT CODE BELOW, IT IS GENERATED WITH MAKEFILE
func! polyglot#detect#Inp() func! polyglot#detect#Inp()
@@ -193,9 +189,7 @@ func! polyglot#detect#Pm()
let &ft = g:filetype_pm | return let &ft = g:filetype_pm | return
endif endif
if polyglot#shebang#Detect() | return | endif if polyglot#shebang#Detect() | return | endif
setf perl set ft=perl | return
call s:WritePostOnce('call polyglot#detect#Pm()')
return
endfunc endfunc
func! polyglot#detect#Pl() func! polyglot#detect#Pl()
@@ -216,9 +210,7 @@ func! polyglot#detect#Pl()
let &ft = g:filetype_pl | return let &ft = g:filetype_pl | return
endif endif
if polyglot#shebang#Detect() | return | endif if polyglot#shebang#Detect() | return | endif
setf perl set ft=perl | return
call s:WritePostOnce('call polyglot#detect#Pl()')
return
endfunc endfunc
func! polyglot#detect#T() func! polyglot#detect#T()
@@ -241,9 +233,7 @@ func! polyglot#detect#T()
let &ft = g:filetype_t | return let &ft = g:filetype_t | return
endif endif
if polyglot#shebang#Detect() | return | endif if polyglot#shebang#Detect() | return | endif
setf perl set ft=perl | return
call s:WritePostOnce('call polyglot#detect#T()')
return
endfunc endfunc
func! polyglot#detect#Tt2() func! polyglot#detect#Tt2()
@@ -270,9 +260,7 @@ func! polyglot#detect#Html()
set ft=xhtml | return set ft=xhtml | return
endif endif
endfor endfor
setf html set ft=html | return
call s:WritePostOnce('call polyglot#detect#Html()')
return
endfunc endfunc
" DO NOT EDIT CODE ABOVE, IT IS GENERATED WITH MAKEFILE " DO NOT EDIT CODE ABOVE, IT IS GENERATED WITH MAKEFILE

View File

@@ -126,11 +126,11 @@ if !has_key(s:disabled_packages, 'gitignore')
endif endif
if !has_key(s:disabled_packages, 'tads') if !has_key(s:disabled_packages, 'tads')
au! BufNewFile,BufRead *.t call polyglot#detect#T() au! BufNewFile,BufRead,BufWritePost *.t call polyglot#detect#T()
endif endif
if !has_key(s:disabled_packages, 'prolog') if !has_key(s:disabled_packages, 'prolog')
au! BufNewFile,BufRead *.pl call polyglot#detect#Pl() au! BufNewFile,BufRead,BufWritePost *.pl call polyglot#detect#Pl()
au BufNewFile,BufRead *.pdb,*.pro,*.prolog,*.yap setf prolog au BufNewFile,BufRead *.pdb,*.pro,*.prolog,*.yap setf prolog
endif endif
@@ -149,7 +149,7 @@ if !has_key(s:disabled_packages, 'dosini')
endif endif
if !has_key(s:disabled_packages, 'visual-basic') if !has_key(s:disabled_packages, 'visual-basic')
au! BufNewFile,BufRead *.bas call polyglot#detect#Bas() au! BufNewFile,BufRead,BufWritePost *.bas call polyglot#detect#Bas()
au BufNewFile,BufRead *.cls,*.ctl,*.dsm,*.frm,*.frx,*.sba,*.vba,*.vbs setf vb au BufNewFile,BufRead *.cls,*.ctl,*.dsm,*.frm,*.frx,*.sba,*.vba,*.vbs setf vb
endif endif
@@ -158,7 +158,7 @@ if !has_key(s:disabled_packages, 'basic')
endif endif
if !has_key(s:disabled_packages, 'trasys') if !has_key(s:disabled_packages, 'trasys')
au! BufNewFile,BufRead *.inp call polyglot#detect#Inp() au! BufNewFile,BufRead,BufWritePost *.inp call polyglot#detect#Inp()
endif endif
if !has_key(s:disabled_packages, 'zig') if !has_key(s:disabled_packages, 'zig')
@@ -351,7 +351,7 @@ if !has_key(s:disabled_packages, 'rst')
endif endif
if !has_key(s:disabled_packages, 'reason') if !has_key(s:disabled_packages, 'reason')
au! BufNewFile,BufRead *.re call polyglot#detect#Re() au! BufNewFile,BufRead,BufWritePost *.re call polyglot#detect#Re()
au BufNewFile,BufRead *.rei setf reason au BufNewFile,BufRead *.rei setf reason
endif endif
@@ -364,9 +364,9 @@ if !has_key(s:disabled_packages, 'raml')
endif endif
if !has_key(s:disabled_packages, 'raku') if !has_key(s:disabled_packages, 'raku')
au! BufNewFile,BufRead *.t call polyglot#detect#T() au! BufNewFile,BufRead,BufWritePost *.t call polyglot#detect#T()
au! BufNewFile,BufRead *.pm call polyglot#detect#Pm() au! BufNewFile,BufRead,BufWritePost *.pm call polyglot#detect#Pm()
au! BufNewFile,BufRead *.pl call polyglot#detect#Pl() au! BufNewFile,BufRead,BufWritePost *.pl call polyglot#detect#Pl()
au BufNewFile,BufRead *.6pl,*.6pm,*.nqp,*.p6,*.p6l,*.p6m,*.pl6,*.pm6,*.pod6,*.raku,*.rakudoc,*.rakumod,*.rakutest,*.t6 setf raku au BufNewFile,BufRead *.6pl,*.6pm,*.nqp,*.p6,*.p6l,*.p6m,*.pl6,*.pm6,*.pod6,*.raku,*.rakudoc,*.rakumod,*.rakutest,*.t6 setf raku
endif endif
@@ -452,10 +452,10 @@ if !has_key(s:disabled_packages, 'pgsql')
endif endif
if !has_key(s:disabled_packages, 'perl') if !has_key(s:disabled_packages, 'perl')
au! BufNewFile,BufRead *.tt2 call polyglot#detect#Tt2() au! BufNewFile,BufRead,BufWritePost *.tt2 call polyglot#detect#Tt2()
au! BufNewFile,BufRead *.t call polyglot#detect#T() au! BufNewFile,BufRead,BufWritePost *.t call polyglot#detect#T()
au! BufNewFile,BufRead *.pm call polyglot#detect#Pm() au! BufNewFile,BufRead,BufWritePost *.pm call polyglot#detect#Pm()
au! BufNewFile,BufRead *.pl call polyglot#detect#Pl() au! BufNewFile,BufRead,BufWritePost *.pl call polyglot#detect#Pl()
au BufNewFile,BufRead *.xs setf xs au BufNewFile,BufRead *.xs setf xs
au BufNewFile,BufRead *.comp,*.mason,*.mhtml setf mason au BufNewFile,BufRead *.comp,*.mason,*.mhtml setf mason
au BufNewFile,BufRead *.pod setf pod au BufNewFile,BufRead *.pod setf pod
@@ -467,7 +467,7 @@ if !has_key(s:disabled_packages, 'opencl')
endif endif
if !has_key(s:disabled_packages, 'octave') if !has_key(s:disabled_packages, 'octave')
au! BufNewFile,BufRead *.m call polyglot#detect#M() au! BufNewFile,BufRead,BufWritePost *.m call polyglot#detect#M()
au BufNewFile,BufRead *.oct setf octave au BufNewFile,BufRead *.oct setf octave
endif endif
@@ -484,8 +484,8 @@ if !has_key(s:disabled_packages, 'ocaml')
endif endif
if !has_key(s:disabled_packages, 'objc') if !has_key(s:disabled_packages, 'objc')
au! BufNewFile,BufRead *.m call polyglot#detect#M() au! BufNewFile,BufRead,BufWritePost *.m call polyglot#detect#M()
au! BufNewFile,BufRead *.h call polyglot#detect#H() au! BufNewFile,BufRead,BufWritePost *.h call polyglot#detect#H()
endif endif
if !has_key(s:disabled_packages, 'nix') if !has_key(s:disabled_packages, 'nix')
@@ -503,7 +503,7 @@ if !has_key(s:disabled_packages, 'nginx')
endif endif
if !has_key(s:disabled_packages, 'murphi') if !has_key(s:disabled_packages, 'murphi')
au! BufNewFile,BufRead *.m call polyglot#detect#M() au! BufNewFile,BufRead,BufWritePost *.m call polyglot#detect#M()
endif endif
if !has_key(s:disabled_packages, 'moonscript') if !has_key(s:disabled_packages, 'moonscript')
@@ -524,7 +524,7 @@ if !has_key(s:disabled_packages, 'markdown')
endif endif
if !has_key(s:disabled_packages, 'mathematica') if !has_key(s:disabled_packages, 'mathematica')
au! BufNewFile,BufRead *.m call polyglot#detect#M() au! BufNewFile,BufRead,BufWritePost *.m call polyglot#detect#M()
au BufNewFile,BufRead *.cdf,*.ma,*.mathematica,*.mma,*.mt,*.nb,*.nbp,*.wl,*.wls,*.wlt setf mma au BufNewFile,BufRead *.cdf,*.ma,*.mathematica,*.mma,*.mt,*.nb,*.nbp,*.wl,*.wls,*.wlt setf mma
endif endif
@@ -615,14 +615,14 @@ if !has_key(s:disabled_packages, 'ion')
endif endif
if !has_key(s:disabled_packages, 'idris2') if !has_key(s:disabled_packages, 'idris2')
au! BufNewFile,BufRead *.lidr call polyglot#detect#Lidr() au! BufNewFile,BufRead,BufWritePost *.lidr call polyglot#detect#Lidr()
au! BufNewFile,BufRead *.idr call polyglot#detect#Idr() au! BufNewFile,BufRead,BufWritePost *.idr call polyglot#detect#Idr()
au BufNewFile,BufRead *.ipkg,idris-response setf idris2 au BufNewFile,BufRead *.ipkg,idris-response setf idris2
endif endif
if !has_key(s:disabled_packages, 'idris') if !has_key(s:disabled_packages, 'idris')
au! BufNewFile,BufRead *.lidr call polyglot#detect#Lidr() au! BufNewFile,BufRead,BufWritePost *.lidr call polyglot#detect#Lidr()
au! BufNewFile,BufRead *.idr call polyglot#detect#Idr() au! BufNewFile,BufRead,BufWritePost *.idr call polyglot#detect#Idr()
au BufNewFile,BufRead idris-response setf idris au BufNewFile,BufRead idris-response setf idris
endif endif
@@ -635,7 +635,7 @@ if !has_key(s:disabled_packages, 'i3')
endif endif
if !has_key(s:disabled_packages, 'html5') if !has_key(s:disabled_packages, 'html5')
au! BufNewFile,BufRead *.html call polyglot#detect#Html() au! BufNewFile,BufRead,BufWritePost *.html call polyglot#detect#Html()
au BufNewFile,BufRead *.htm,*.html.hl,*.inc,*.st,*.xht,*.xhtml setf html au BufNewFile,BufRead *.htm,*.html.hl,*.inc,*.st,*.xht,*.xhtml setf html
endif endif
@@ -703,7 +703,7 @@ if !has_key(s:disabled_packages, 'gmpl')
endif endif
if !has_key(s:disabled_packages, 'glsl') if !has_key(s:disabled_packages, 'glsl')
au! BufNewFile,BufRead *.fs call polyglot#detect#Fs() au! BufNewFile,BufRead,BufWritePost *.fs call polyglot#detect#Fs()
au BufNewFile,BufRead *.comp,*.fp,*.frag,*.frg,*.fsh,*.fshader,*.geo,*.geom,*.glsl,*.glslf,*.glslv,*.gs,*.gshader,*.shader,*.tesc,*.tese,*.vert,*.vrx,*.vsh,*.vshader setf glsl au BufNewFile,BufRead *.comp,*.fp,*.frag,*.frg,*.fsh,*.fshader,*.geo,*.geom,*.glsl,*.glslf,*.glslv,*.gs,*.gshader,*.shader,*.tesc,*.tese,*.vert,*.vrx,*.vsh,*.vshader setf glsl
endif endif
@@ -720,12 +720,12 @@ if !has_key(s:disabled_packages, 'gdscript')
endif endif
if !has_key(s:disabled_packages, 'fsharp') if !has_key(s:disabled_packages, 'fsharp')
au! BufNewFile,BufRead *.fs call polyglot#detect#Fs() au! BufNewFile,BufRead,BufWritePost *.fs call polyglot#detect#Fs()
au BufNewFile,BufRead *.fsi,*.fsx setf fsharp au BufNewFile,BufRead *.fsi,*.fsx setf fsharp
endif endif
if !has_key(s:disabled_packages, 'forth') if !has_key(s:disabled_packages, 'forth')
au! BufNewFile,BufRead *.fs call polyglot#detect#Fs() au! BufNewFile,BufRead,BufWritePost *.fs call polyglot#detect#Fs()
au BufNewFile,BufRead *.ft,*.fth setf forth au BufNewFile,BufRead *.ft,*.fth setf forth
endif endif
@@ -853,12 +853,12 @@ if !has_key(s:disabled_packages, 'atlas')
endif endif
if !has_key(s:disabled_packages, 'aspperl') if !has_key(s:disabled_packages, 'aspperl')
au! BufNewFile,BufRead *.asp call polyglot#detect#Asp() au! BufNewFile,BufRead,BufWritePost *.asp call polyglot#detect#Asp()
endif endif
if !has_key(s:disabled_packages, 'aspvbs') if !has_key(s:disabled_packages, 'aspvbs')
au! BufNewFile,BufRead *.asp call polyglot#detect#Asp() au! BufNewFile,BufRead,BufWritePost *.asp call polyglot#detect#Asp()
au! BufNewFile,BufRead *.asa call polyglot#detect#Asa() au! BufNewFile,BufRead,BufWritePost *.asa call polyglot#detect#Asa()
endif endif
if !has_key(s:disabled_packages, 'asn') if !has_key(s:disabled_packages, 'asn')
@@ -890,7 +890,7 @@ if !has_key(s:disabled_packages, 'arduino')
endif endif
if !has_key(s:disabled_packages, 'c/c++') if !has_key(s:disabled_packages, 'c/c++')
au! BufNewFile,BufRead *.h call polyglot#detect#H() au! BufNewFile,BufRead,BufWritePost *.h call polyglot#detect#H()
au BufNewFile,BufRead *.c,*.cats,*.idc,*.qc,*enlightenment/*.cfg setf c au BufNewFile,BufRead *.c,*.cats,*.idc,*.qc,*enlightenment/*.cfg setf c
au BufNewFile,BufRead *.c++,*.cc,*.cp,*.cpp,*.cxx,*.h++,*.hh,*.hpp,*.hxx,*.inc,*.inl,*.ipp,*.moc,*.tcc,*.tlh,*.tpp setf cpp au BufNewFile,BufRead *.c++,*.cc,*.cp,*.cpp,*.cxx,*.h++,*.hh,*.hpp,*.hxx,*.inc,*.inl,*.ipp,*.moc,*.tcc,*.tlh,*.tpp setf cpp
endif endif
@@ -979,7 +979,7 @@ if !has_key(s:disabled_packages, 'abc')
endif endif
if !has_key(s:disabled_packages, 'abaqus') if !has_key(s:disabled_packages, 'abaqus')
au! BufNewFile,BufRead *.inp call polyglot#detect#Inp() au! BufNewFile,BufRead,BufWritePost *.inp call polyglot#detect#Inp()
endif endif
if !has_key(s:disabled_packages, 'abap') if !has_key(s:disabled_packages, 'abap')
@@ -3427,13 +3427,6 @@ au BufNewFile,BufRead *.txt
" state. " state.
augroup END augroup END
" Generic configuration file. Use FALLBACK, it's just guessing!
au filetypedetect BufNewFile,BufRead,StdinReadPost *
\ if !did_filetype() && expand("<amatch>") !~ g:ft_ignore_pat
\ && (getline(1) =~ '^#' || getline(2) =~ '^#' || getline(3) =~ '^#'
\ || getline(4) =~ '^#' || getline(5) =~ '^#') |
\ setf FALLBACK conf |
\ endif
" Restore 'cpoptions' " Restore 'cpoptions'
let &cpo = s:cpo_save let &cpo = s:cpo_save

View File

@@ -390,17 +390,9 @@ def rule_to_code(rule)
end end
if rule.has_key?("filetype") if rule.has_key?("filetype")
if rule.has_key?("fallback")
return <<~EOS
setf #{rule["filetype"]}
call s:WritePostOnce('call polyglot#detect##{camelize(rule["extensions"].first)}()')
return
EOS
end
return <<~EOS return <<~EOS
set ft=#{rule["filetype"]} | return set ft=#{rule["filetype"]} | return
#{indent(rule_to_code(except(rule, "filetype")), 0)} #{indent(rule_to_code(except(rule, "filetype", "fallback")), 0)}
EOS EOS
end end
@@ -570,7 +562,7 @@ def generate_ftdetect(packages, heuristics)
for heuristic in package_heuristics.uniq for heuristic in package_heuristics.uniq
extensions = heuristic["extensions"].map { |e| "*.#{e}" } extensions = heuristic["extensions"].map { |e| "*.#{e}" }
autocommands << " au! BufNewFile,BufRead #{extensions.join(",")} call polyglot#detect##{camelize(heuristic["extensions"].first)}()\n" autocommands << " au! BufNewFile,BufRead,BufWritePost #{extensions.join(",")} call polyglot#detect##{camelize(heuristic["extensions"].first)}()\n"
end end
if autocommands != "" if autocommands != ""