Skip to content

Commit

Permalink
Address BufWritePost error, fixes #573
Browse files Browse the repository at this point in the history
  • Loading branch information
sheerun committed Oct 4, 2020
1 parent 073e4d4 commit d221139
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 63 deletions.
20 changes: 4 additions & 16 deletions autoload/polyglot/detect.vim
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
let s:cpo_save = &cpo
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

func! polyglot#detect#Inp()
Expand Down Expand Up @@ -193,9 +189,7 @@ func! polyglot#detect#Pm()
let &ft = g:filetype_pm | return
endif
if polyglot#shebang#Detect() | return | endif
setf perl
call s:WritePostOnce('call polyglot#detect#Pm()')
return
set ft=perl | return
endfunc

func! polyglot#detect#Pl()
Expand All @@ -216,9 +210,7 @@ func! polyglot#detect#Pl()
let &ft = g:filetype_pl | return
endif
if polyglot#shebang#Detect() | return | endif
setf perl
call s:WritePostOnce('call polyglot#detect#Pl()')
return
set ft=perl | return
endfunc

func! polyglot#detect#T()
Expand All @@ -241,9 +233,7 @@ func! polyglot#detect#T()
let &ft = g:filetype_t | return
endif
if polyglot#shebang#Detect() | return | endif
setf perl
call s:WritePostOnce('call polyglot#detect#T()')
return
set ft=perl | return
endfunc

func! polyglot#detect#Tt2()
Expand All @@ -270,9 +260,7 @@ func! polyglot#detect#Html()
set ft=xhtml | return
endif
endfor
setf html
call s:WritePostOnce('call polyglot#detect#Html()')
return
set ft=html | return
endfunc

" DO NOT EDIT CODE ABOVE, IT IS GENERATED WITH MAKEFILE
Expand Down
67 changes: 30 additions & 37 deletions ftdetect/polyglot.vim
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ if !has_key(s:disabled_packages, 'gitignore')
endif

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

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
endif

Expand All @@ -149,7 +149,7 @@ if !has_key(s:disabled_packages, 'dosini')
endif

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
endif

Expand All @@ -158,7 +158,7 @@ if !has_key(s:disabled_packages, 'basic')
endif

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

if !has_key(s:disabled_packages, 'zig')
Expand Down Expand Up @@ -351,7 +351,7 @@ if !has_key(s:disabled_packages, 'rst')
endif

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
endif

Expand All @@ -364,9 +364,9 @@ if !has_key(s:disabled_packages, 'raml')
endif

if !has_key(s:disabled_packages, 'raku')
au! BufNewFile,BufRead *.t call polyglot#detect#T()
au! BufNewFile,BufRead *.pm call polyglot#detect#Pm()
au! BufNewFile,BufRead *.pl call polyglot#detect#Pl()
au! BufNewFile,BufRead,BufWritePost *.t call polyglot#detect#T()
au! BufNewFile,BufRead,BufWritePost *.pm call polyglot#detect#Pm()
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
endif

Expand Down Expand Up @@ -452,10 +452,10 @@ if !has_key(s:disabled_packages, 'pgsql')
endif

if !has_key(s:disabled_packages, 'perl')
au! BufNewFile,BufRead *.tt2 call polyglot#detect#Tt2()
au! BufNewFile,BufRead *.t call polyglot#detect#T()
au! BufNewFile,BufRead *.pm call polyglot#detect#Pm()
au! BufNewFile,BufRead *.pl call polyglot#detect#Pl()
au! BufNewFile,BufRead,BufWritePost *.tt2 call polyglot#detect#Tt2()
au! BufNewFile,BufRead,BufWritePost *.t call polyglot#detect#T()
au! BufNewFile,BufRead,BufWritePost *.pm call polyglot#detect#Pm()
au! BufNewFile,BufRead,BufWritePost *.pl call polyglot#detect#Pl()
au BufNewFile,BufRead *.xs setf xs
au BufNewFile,BufRead *.comp,*.mason,*.mhtml setf mason
au BufNewFile,BufRead *.pod setf pod
Expand All @@ -467,7 +467,7 @@ if !has_key(s:disabled_packages, 'opencl')
endif

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
endif

Expand All @@ -484,8 +484,8 @@ if !has_key(s:disabled_packages, 'ocaml')
endif

if !has_key(s:disabled_packages, 'objc')
au! BufNewFile,BufRead *.m call polyglot#detect#M()
au! BufNewFile,BufRead *.h call polyglot#detect#H()
au! BufNewFile,BufRead,BufWritePost *.m call polyglot#detect#M()
au! BufNewFile,BufRead,BufWritePost *.h call polyglot#detect#H()
endif

if !has_key(s:disabled_packages, 'nix')
Expand All @@ -503,7 +503,7 @@ if !has_key(s:disabled_packages, 'nginx')
endif

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

if !has_key(s:disabled_packages, 'moonscript')
Expand All @@ -524,7 +524,7 @@ if !has_key(s:disabled_packages, 'markdown')
endif

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
endif

Expand Down Expand Up @@ -615,14 +615,14 @@ if !has_key(s:disabled_packages, 'ion')
endif

if !has_key(s:disabled_packages, 'idris2')
au! BufNewFile,BufRead *.lidr call polyglot#detect#Lidr()
au! BufNewFile,BufRead *.idr call polyglot#detect#Idr()
au! BufNewFile,BufRead,BufWritePost *.lidr call polyglot#detect#Lidr()
au! BufNewFile,BufRead,BufWritePost *.idr call polyglot#detect#Idr()
au BufNewFile,BufRead *.ipkg,idris-response setf idris2
endif

if !has_key(s:disabled_packages, 'idris')
au! BufNewFile,BufRead *.lidr call polyglot#detect#Lidr()
au! BufNewFile,BufRead *.idr call polyglot#detect#Idr()
au! BufNewFile,BufRead,BufWritePost *.lidr call polyglot#detect#Lidr()
au! BufNewFile,BufRead,BufWritePost *.idr call polyglot#detect#Idr()
au BufNewFile,BufRead idris-response setf idris
endif

Expand All @@ -635,7 +635,7 @@ if !has_key(s:disabled_packages, 'i3')
endif

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
endif

Expand Down Expand Up @@ -703,7 +703,7 @@ if !has_key(s:disabled_packages, 'gmpl')
endif

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
endif

Expand All @@ -720,12 +720,12 @@ if !has_key(s:disabled_packages, 'gdscript')
endif

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
endif

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
endif

Expand Down Expand Up @@ -853,12 +853,12 @@ if !has_key(s:disabled_packages, 'atlas')
endif

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

if !has_key(s:disabled_packages, 'aspvbs')
au! BufNewFile,BufRead *.asp call polyglot#detect#Asp()
au! BufNewFile,BufRead *.asa call polyglot#detect#Asa()
au! BufNewFile,BufRead,BufWritePost *.asp call polyglot#detect#Asp()
au! BufNewFile,BufRead,BufWritePost *.asa call polyglot#detect#Asa()
endif

if !has_key(s:disabled_packages, 'asn')
Expand Down Expand Up @@ -890,7 +890,7 @@ if !has_key(s:disabled_packages, 'arduino')
endif

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++,*.cc,*.cp,*.cpp,*.cxx,*.h++,*.hh,*.hpp,*.hxx,*.inc,*.inl,*.ipp,*.moc,*.tcc,*.tlh,*.tpp setf cpp
endif
Expand Down Expand Up @@ -979,7 +979,7 @@ if !has_key(s:disabled_packages, 'abc')
endif

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

if !has_key(s:disabled_packages, 'abap')
Expand Down Expand Up @@ -3427,13 +3427,6 @@ au BufNewFile,BufRead *.txt
" state.
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'
let &cpo = s:cpo_save
Expand Down
12 changes: 2 additions & 10 deletions scripts/build
Original file line number Diff line number Diff line change
Expand Up @@ -390,17 +390,9 @@ def rule_to_code(rule)
end

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
set ft=#{rule["filetype"]} | return
#{indent(rule_to_code(except(rule, "filetype")), 0)}
#{indent(rule_to_code(except(rule, "filetype", "fallback")), 0)}
EOS
end

Expand Down Expand Up @@ -570,7 +562,7 @@ def generate_ftdetect(packages, heuristics)

for heuristic in package_heuristics.uniq
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

if autocommands != ""
Expand Down

0 comments on commit d221139

Please sign in to comment.