" general per-language filetype file
if exists("did\_load\_filetypes")
  finish
endif

" Filetype mappingss
augroup markdown
  au! BufRead,BufNewFile *.mkd   setfiletype markdown
  au! BufRead,BufNewFile *.md   setfiletype markdown
augroup END
augroup mako
  au! BufRead,BufNewFile *.mak,*.mako  setfiletype mako
augroup END
augroup csv
  au! BufNewFile,BufRead *.csv setf csv
augroup END
augroup lilypond
  au! BufNewFile,BufRead *.ly,*.ily setf lilypond
augroup END
augroup java
  autocmd BufRead *.java set efm=%A\ %#[javac]\ %f:%l:\ %m,%-Z\ %#[javac]\ %p^,%-C%.%#
  autocmd BufRead *.java set makeprg=ant\ -find\ build.xml
  autocmd FileType java let b:auto_trim_whitespace=1
augroup END
augroup less
  autocmd BufNewFile,BufRead *.less set filetype=less
augroup END

augroup pcal
  au BufNewFile,BufRead *.pcal     setf tla
augroup END


au! BufNewFile,BufRead *.pde setf arduino

augroup org
  " leave these as is:
  au! BufRead,BufWrite,BufWritePost,BufNewFile *.org 
  au BufRead,BufNewFile *.org            call org#SetOrgFileType()
  au BufRead,BufNewFile *.org            :GitGutterDisable
  au BufRead *.org :PreLoadTags
  au BufWrite *.org :PreWriteTags
  au BufWritePost *.org :PostWriteTags
augroup END

au BufNewFile,BufRead motd.public,/tmp/motd.public.r.* setf motd

au Filetype html,xml,xsl source ~/.vim/closetag.vim

au BufRead,BufNewFile *.go set filetype=go

au FileType cpp let b:delimitMate_matchpairs = "(:),[:],{:}"

autocmd FileType vue syntax sync fromstart
au Filetype vue let b:AutoPairs = {'(':')', '[':']', '{':'}',"'":"'",'"':'"', '`':'`', '<':'>'}
au Filetype html let b:AutoPairs = {'(':')', '[':']', '{':'}',"'":"'",'"':'"', '`':'`', '<':'>'}

"Settings per filetype
augroup python
  ""autocmd FileType python set omnifunc=pythoncomplete#Complete
  ""autocmd FileType python call SuperTabSetCompletionType("<C-X><C-O>")
  ""autocmd FileType python set completeopt-=preview
  autocmd FileType python set ts=4
  autocmd FileType python set softtabstop=4
  autocmd FileType python set shiftwidth=4
  autocmd FileType python set expandtab
  autocmd FileType python set nosmartindent
  "autocmd FileType python let b:auto_trim_whitespace=1
augroup END
"augroup javascript
  "autocmd FileType javascript set ts=4
  "autocmd FileType javascript set softtabstop=4
  "autocmd FileType javascript set shiftwidth=4
  "autocmd FileType javascript set expandtab
  "autocmd FileType javascript let b:auto_trim_whitespace=1
"augroup END

augroup hs
  autocmd FileType hs nnoremap <Leader>ii :GhcModInfo!<CR>
augroup END

augroup mkd
  autocmd FileType mkd set ai formatoptions=tcroqn2 comments=n:&gt;
augroup END

augroup mediawiki
    autocmd BufRead,BufNewFile *.wiki setfiletype mediawiki
    autocmd BufRead,BufNewFile *.wikipedia.org* setfiletype mediawiki
augroup END

augroup go
  autocmd FileType go set ts=2
  autocmd FileType go set softtabstop=2
  autocmd FileType go set shiftwidth=2
  autocmd FileType go set noexpandtab
  autocmd FileType go nmap <Leader>gd <Plug>(go-doc)
  autocmd FileType go nmap gd <Plug>(go-def)
augroup END

augroup idris
  autocmd FileType idris nmap <LocalLeader>a a?hole<Esc><LocalLeader>t
augroup end

autocmd FileType go let b:auto_trim_whitespace=1
autocmd FileType cpp let b:auto_trim_whitespace=1
autocmd FileType perl let b:auto_trim_whitespace=1
autocmd FileType borg let b:auto_trim_whitespace=1
autocmd FileType javascript let b:auto_trim_whitespace=1
autocmd FileType python let b:auto_trim_whitespace=1
autocmd FileType proto let b:auto_trim_whitespace=1
autocmd FileType hy let b:auto_trim_whitespace=1
autocmd FileType idris let b:auto_trim_whitespace=1
autocmd FileType java let b:auto_trim_whitespace=1

augroup templates
  autocmd BufNewFile *.vue 0r ~/.vim/skeletons/skeleton.vue
augroup END
