Skip to content

Commit

Permalink
Disable ftdetect parts of some plugins, fixes #254
Browse files Browse the repository at this point in the history
vim-polyglot discourages use of commands like:

autocmd BufRead *
autocmd BufNewFile *

And others that execute for every file / buffer opened.
  • Loading branch information
sheerun committed Dec 30, 2017
1 parent 17ad302 commit cef5e2d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 169 deletions.
8 changes: 7 additions & 1 deletion build
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ extract() {
fi
done

output "${subdirs##, })\n"

if (echo "julia coffee-script elixir fish git plantuml scala swift" | fgrep -q "$name"); then
echo "Skipping ftdetect installation of $name"
continue
fi

for f in ${dir}/ftdetect/*; do
(
echo "augroup filetypedetect";
Expand All @@ -62,7 +69,6 @@ extract() {
) >> tmp/polyglot.vim;
done

output "${subdirs##, })\n"
done

mv tmp/polyglot.vim ftdetect/
Expand Down
11 changes: 11 additions & 0 deletions config.vim
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,14 @@ augroup filetypedetect
augroup END

let g:python_highlight_all = 1

augroup filetypedetect
if v:version < 704
" NOTE: this line fixes an issue with the default system-wide lisp ftplugin
" which didn't define b:undo_ftplugin on older Vim versions
" (*.jl files are recognized as lisp)
autocmd BufRead,BufNewFile *.jl let b:undo_ftplugin = "setlocal comments< define< formatoptions< iskeyword< lisp<"
endif

autocmd BufRead,BufNewFile *.jl set filetype=julia
augroup END
179 changes: 11 additions & 168 deletions ftdetect/polyglot.vim
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ augroup filetypedetect
augroup END

let g:python_highlight_all = 1

augroup filetypedetect
if v:version < 704
" NOTE: this line fixes an issue with the default system-wide lisp ftplugin
" which didn't define b:undo_ftplugin on older Vim versions
" (*.jl files are recognized as lisp)
autocmd BufRead,BufNewFile *.jl let b:undo_ftplugin = "setlocal comments< define< formatoptions< iskeyword< lisp<"
endif

autocmd BufRead,BufNewFile *.jl set filetype=julia
augroup END
augroup filetypedetect
" apiblueprint:sheerun/apiblueprint.vim
autocmd BufReadPost,BufNewFile *.apib set filetype=apiblueprint
Expand Down Expand Up @@ -106,39 +117,6 @@ augroup filetypedetect
" cmake:pboettch/vim-cmake-syntax
augroup END

augroup filetypedetect
" coffee-script:kchmck/vim-coffee-script
" Language: CoffeeScript
" Maintainer: Mick Koch <mick@kochm.co>
" URL: http://github.com/kchmck/vim-coffee-script
" License: WTFPL

autocmd BufNewFile,BufRead *.coffee set filetype=coffee
autocmd BufNewFile,BufRead *Cakefile set filetype=coffee
autocmd BufNewFile,BufRead *.coffeekup,*.ck set filetype=coffee
autocmd BufNewFile,BufRead *._coffee set filetype=coffee

function! s:DetectCoffee()
if getline(1) =~ '^#!.*\<coffee\>'
set filetype=coffee
endif
endfunction

autocmd BufNewFile,BufRead * call s:DetectCoffee()
augroup END

augroup filetypedetect
" coffee-script:kchmck/vim-coffee-script
" Language: Literate CoffeeScript
" Maintainer: Michael Smith <michael@diglumi.com>
" URL: https://github.com/mintplant/vim-literate-coffeescript
" License: MIT

autocmd BufNewFile,BufRead *.litcoffee set filetype=litcoffee
autocmd BufNewFile,BufRead *.coffee.md set filetype=litcoffee

augroup END

augroup filetypedetect
" cryptol:victoredwardocallaghan/cryptol.vim
" Copyright © 2013 Edward O'Callaghan. All Rights Reserved.
Expand Down Expand Up @@ -180,23 +158,6 @@ augroup filetypedetect
" dockerfile:docker/docker::/contrib/syntax/vim/
augroup END

augroup filetypedetect
" elixir:elixir-lang/vim-elixir
au BufRead,BufNewFile *.ex,*.exs call s:setf('elixir')
au BufRead,BufNewFile *.eex call s:setf('eelixir')
au BufRead,BufNewFile * call s:DetectElixir()

function! s:setf(filetype) abort
let &filetype = a:filetype
endfunction

function! s:DetectElixir()
if getline(1) =~ '^#!.*\<elixir\>'
call s:setf('elixir')
endif
endfunction
augroup END

augroup filetypedetect
" elm:ElmCast/elm-vim
" detection for Elm (http://elm-lang.org/)
Expand Down Expand Up @@ -247,64 +208,12 @@ augroup filetypedetect
au BufNewFile,BufRead *.erl,*.hrl,rebar.config,*.app,*.app.src,*.yaws,*.xrl,*.escript set ft=erlang
augroup END

augroup filetypedetect
" fish:dag/vim-fish
autocmd BufRead,BufNewFile *.fish setfiletype fish

" Detect fish scripts by the shebang line.
autocmd BufRead *
\ if getline(1) =~# '\v^#!%(\f*/|/usr/bin/env\s*<)fish>' |
\ setlocal filetype=fish |
\ endif

" Move cursor to first empty line when using funced.
autocmd BufRead fish_funced_*_*.fish call search('^$')

" Fish histories are YAML documents.
autocmd BufRead,BufNewFile ~/.config/fish/fish_{read_,}history setfiletype yaml

" Universal variable storages should not be hand edited.
autocmd BufRead,BufNewFile ~/.config/fish/fishd.* setlocal readonly

" Mimic `funced` when manually creating functions.
autocmd BufNewFile ~/.config/fish/functions/*.fish
\ call append(0, ['function '.expand('%:t:r'),
\'',
\'end']) |
\ 2
augroup END

augroup filetypedetect
" fsharp:fsharp/vim-fsharp:_BASIC
" F#, fsharp
autocmd BufNewFile,BufRead *.fs,*.fsi,*.fsx set filetype=fsharp
augroup END

augroup filetypedetect
" git:tpope/vim-git
" Git
autocmd BufNewFile,BufRead *.git/{,modules/**/,worktrees/*/}{COMMIT_EDIT,TAG_EDIT,MERGE_,}MSG set ft=gitcommit
autocmd BufNewFile,BufRead *.git/config,.gitconfig,gitconfig,.gitmodules set ft=gitconfig
autocmd BufNewFile,BufRead */.config/git/config set ft=gitconfig
autocmd BufNewFile,BufRead *.git/modules/**/config set ft=gitconfig
autocmd BufNewFile,BufRead git-rebase-todo set ft=gitrebase
autocmd BufNewFile,BufRead .gitsendemail.* set ft=gitsendemail
autocmd BufNewFile,BufRead *.git/**
\ if getline(1) =~ '^\x\{40\}\>\|^ref: ' |
\ set ft=git |
\ endif

" This logic really belongs in scripts.vim
autocmd BufNewFile,BufRead,StdinReadPost *
\ if getline(1) =~ '^\(commit\|tree\|object\) \x\{40\}\>\|^tag \S\+$' |
\ set ft=git |
\ endif
autocmd BufNewFile,BufRead *
\ if getline(1) =~ '^From \x\{40\} Mon Sep 17 00:00:00 2001$' |
\ set filetype=gitsendemail |
\ endif
augroup END

augroup filetypedetect
" gmpl:maelvalais/gmpl.vim
au BufRead,BufNewFile *.mod set filetype=gmpl
Expand Down Expand Up @@ -504,31 +413,6 @@ autocmd BufNewFile,BufRead *.js
\ if <SID>EnableJSX() | set filetype=javascript.jsx | endif
augroup END

augroup filetypedetect
" julia:JuliaEditorSupport/julia-vim
if v:version < 704
" NOTE: this line fixes an issue with the default system-wide lisp ftplugin
" which didn't define b:undo_ftplugin on older Vim versions
" (*.jl files are recognized as lisp)
autocmd BufRead,BufNewFile *.jl let b:undo_ftplugin = "setlocal comments< define< formatoptions< iskeyword< lisp<"
endif

autocmd BufRead,BufNewFile *.jl set filetype=julia

autocmd FileType * call LaTeXtoUnicode#Refresh()
autocmd BufEnter * call LaTeXtoUnicode#Refresh()

" This autocommand is used to postpone the first initialization of LaTeXtoUnicode as much as possible,
" by calling LaTeXtoUnicode#SetTab amd LaTeXtoUnicode#SetAutoSub only at InsertEnter or later
function! s:L2UTrigger()
augroup L2UInit
autocmd!
autocmd InsertEnter * let g:did_insert_enter = 1 | call LaTeXtoUnicode#Init(0)
augroup END
endfunction
autocmd BufEnter * call s:L2UTrigger()
augroup END

augroup filetypedetect
" kotlin:udalov/kotlin-vim
autocmd BufNewFile,BufRead *.kt setfiletype kotlin
Expand Down Expand Up @@ -705,16 +589,6 @@ augroup filetypedetect
" php:StanAngeloff/php.vim
augroup END

augroup filetypedetect
" plantuml:aklt/plantuml-syntax
if did_filetype()
finish
endif

autocmd BufRead,BufNewFile * :if getline(1) =~ '^.*startuml.*$'| setfiletype plantuml | set filetype=plantuml | endif
autocmd BufRead,BufNewFile *.pu,*.uml,*.plantuml setfiletype plantuml | set filetype=plantuml
augroup END

augroup filetypedetect
" powershell:PProvost/vim-ps1
" Vim ftdetect plugin file
Expand Down Expand Up @@ -954,21 +828,6 @@ augroup filetypedetect
au BufRead,BufNewFile *.sbt set filetype=sbt.scala
augroup END

augroup filetypedetect
" scala:derekwyatt/vim-scala
fun! s:DetectScala()
if getline(1) =~# '^#!\(/usr\)\?/bin/env\s\+scalas\?'
set filetype=scala
endif
endfun

au BufRead,BufNewFile *.scala,*.sc set filetype=scala
au BufRead,BufNewFile * call s:DetectScala()

" Install vim-sbt for additional syntax highlighting.
au BufRead,BufNewFile *.sbt setfiletype sbt.scala
augroup END

augroup filetypedetect
" scss:cakebaker/scss-syntax.vim
au BufRead,BufNewFile *.scss setfiletype scss
Expand Down Expand Up @@ -997,22 +856,6 @@ autocmd BufNewFile,BufReadPost *.styl set filetype=stylus
autocmd BufNewFile,BufReadPost *.stylus set filetype=stylus
augroup END

augroup filetypedetect
" swift:keith/swift.vim
autocmd BufNewFile,BufRead *.swift set filetype=swift
autocmd BufRead * call s:Swift()
function! s:Swift()
if !empty(&filetype)
return
endif

let line = getline(1)
if line =~ "^#!.*swift"
setfiletype swift
endif
endfunction
augroup END

augroup filetypedetect
" sxhkd:baskerville/vim-sxhkdrc
if &compatible || v:version < 603
Expand Down

2 comments on commit cef5e2d

@rainerborene
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sheerun so, what's the alternative to autodetect these filetypes then?

@sheerun
Copy link
Owner Author

@sheerun sheerun commented on cef5e2d Jan 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could accept a PR that does just one getline(1) and matches all filetypes on it

Please sign in to comment.