1 " Copyright 2015 The Chromium Authors. All rights reserved.
2 " Use of this source code is governed by a BSD-style license that can be
3 " found in the LICENSE file.
5 " We take care to preserve the user's fileencodings and fileformats,
6 " because those settings are global (not buffer local), yet we want
7 " to override them for loading mojom files, which should be UTF-8.
9 let s:current_fileformats = ''
10 let s:current_fileencodings = ''
12 " define fileencodings to open as utf-8 encoding even if it's ascii.
13 function! s:mojomfiletype_pre()
14 let s:current_fileformats = &g:fileformats
15 let s:current_fileencodings = &g:fileencodings
16 set fileencodings=utf-8 fileformats=unix
17 setlocal filetype=mojom
20 " restore fileencodings as others
21 function! s:mojomfiletype_post()
22 let &g:fileformats = s:current_fileformats
23 let &g:fileencodings = s:current_fileencodings
26 au BufNewFile *.mojom setlocal filetype=mojom fileencoding=utf-8 fileformat=unix
27 au BufRead *.mojom call s:mojomfiletype_pre()
28 au BufReadPost *.mojom call s:mojomfiletype_post()