github.com/varialus/godfly@v0.0.0-20130904042352-1934f9f095ab/misc/vim/ftdetect/gofiletype.vim (about)

     1  " We take care to preserve the user's fileencodings and fileformats,
     2  " because those settings are global (not buffer local), yet we want
     3  " to override them for loading Go files, which are defined to be UTF-8.
     4  let s:current_fileformats = ''
     5  let s:current_fileencodings = ''
     6  
     7  " define fileencodings to open as utf-8 encoding even if it's ascii.
     8  function! s:gofiletype_pre()
     9    let s:current_fileformats = &g:fileformats
    10    let s:current_fileencodings = &g:fileencodings
    11    set fileencodings=utf-8 fileformats=unix
    12    setlocal filetype=go
    13  endfunction
    14  
    15  " restore fileencodings as others
    16  function! s:gofiletype_post()
    17    let &g:fileformats = s:current_fileformats
    18    let &g:fileencodings = s:current_fileencodings
    19  endfunction
    20  
    21  au BufNewFile *.go setlocal filetype=go fileencoding=utf-8 fileformat=unix
    22  au BufRead *.go call s:gofiletype_pre()
    23  au BufReadPost *.go call s:gofiletype_post()