mattn.jp | 2 Mar 2012 03:54
Picon
Gravatar

code review 5718045: misc/vim: restore fileencodings. (issue 5718045)

Reviewers: golang-dev_googlecode.com,

Message:
Hello golang-dev@... (cc: golang-dev@...),

I'd like you to review this change to
http://go.googlecode.com/hg/

Description:
misc/vim: restore fileencodings.
Currently, ftdetect/gofiletype.vim set fileencodings to open the file as
utf-8 encoding event if the file deos not contain multibyte characters.
But fileencodings is global option.

$ vim foo.txt
:set fileencodings
utf-8,ucs-bom,cp932

$ vim foo.go
:set fileencodings
utf-8

This change restore fileencodings before opening the file.
Also added specify fileformats=unix.

Please review this at http://codereview.appspot.com/5718045/

Affected files:
   M misc/vim/ftdetect/gofiletype.vim

Index: misc/vim/ftdetect/gofiletype.vim
===================================================================
--- a/misc/vim/ftdetect/gofiletype.vim
+++ b/misc/vim/ftdetect/gofiletype.vim
 <at>  <at>  -1,1 +1,20  <at>  <at> 
-au BufRead,BufNewFile *.go set filetype=go fileencoding=utf-8  
fileencodings=utf-8
+let s:current_fileformats = ''
+let s:current_fileencodings = ''
+
+" define fileencodings to open as utf-8 encoding even if it's ascii.
+function! s:gofiletype_pre()
+  let s:current_fileformats = &g:fileformats
+  let s:current_fileencodings = &g:fileencodings
+  set fileencodings=utf-8 fileformats=unix
+  setlocal filetype=go
+endfunction
+
+" restore fileencodings as others
+function! s:gofiletype_post()
+  let &g:fileformats = s:current_fileformats
+  let &g:fileencodings = s:current_fileencodings
+endfunction
+
+au BufNewFile *.go setlocal filetype=go fileencoding=utf-8 fileformat=unix
+au BufRead *.go call s:gofiletype_pre()
+au BufReadPost *.go call s:gofiletype_post()


Gmane