summaryrefslogtreecommitdiffstats
path: root/tools/vim
diff options
context:
space:
mode:
authorscottmg <scottmg@chromium.org>2015-06-04 18:40:23 -0700
committerCommit bot <commit-bot@chromium.org>2015-06-05 01:40:49 +0000
commitb3518a5fb8cf9c82cd1fb62e1f178db561c066dc (patch)
tree9cb925e956751261d8d56179d819d85922a5b8cf /tools/vim
parent2182e2d0109df09086eee803e34a9759cf101b16 (diff)
downloadchromium_src-b3518a5fb8cf9c82cd1fb62e1f178db561c066dc.zip
chromium_src-b3518a5fb8cf9c82cd1fb62e1f178db561c066dc.tar.gz
chromium_src-b3518a5fb8cf9c82cd1fb62e1f178db561c066dc.tar.bz2
Update vim mojom syntax file and add ftdetect to set type
Adds some missing keywords (const, module, array), highlights punctuation (=>, ?), highlights strings, sets filetype appropriately. TBR=viettrungluu@chromium.org Review URL: https://codereview.chromium.org/1165943006 Cr-Commit-Position: refs/heads/master@{#332987}
Diffstat (limited to 'tools/vim')
-rw-r--r--tools/vim/mojom/ftdetect/mojomfiletype.vim28
-rw-r--r--tools/vim/mojom/syntax/mojom.vim (renamed from tools/vim/mojom.vim)38
2 files changed, 49 insertions, 17 deletions
diff --git a/tools/vim/mojom/ftdetect/mojomfiletype.vim b/tools/vim/mojom/ftdetect/mojomfiletype.vim
new file mode 100644
index 0000000..cff7ce6
--- /dev/null
+++ b/tools/vim/mojom/ftdetect/mojomfiletype.vim
@@ -0,0 +1,28 @@
+" Copyright 2015 The Chromium Authors. All rights reserved.
+" Use of this source code is governed by a BSD-style license that can be
+" found in the LICENSE file.
+
+" We take care to preserve the user's fileencodings and fileformats,
+" because those settings are global (not buffer local), yet we want
+" to override them for loading mojom files, which should be 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:mojomfiletype_pre()
+ let s:current_fileformats = &g:fileformats
+ let s:current_fileencodings = &g:fileencodings
+ set fileencodings=utf-8 fileformats=unix
+ setlocal filetype=mojom
+endfunction
+
+" restore fileencodings as others
+function! s:mojomfiletype_post()
+ let &g:fileformats = s:current_fileformats
+ let &g:fileencodings = s:current_fileencodings
+endfunction
+
+au BufNewFile *.mojom setlocal filetype=mojom fileencoding=utf-8 fileformat=unix
+au BufRead *.mojom call s:mojomfiletype_pre()
+au BufReadPost *.mojom call s:mojomfiletype_post()
diff --git a/tools/vim/mojom.vim b/tools/vim/mojom/syntax/mojom.vim
index 76a0ee3..cdd3f7e 100644
--- a/tools/vim/mojom.vim
+++ b/tools/vim/mojom/syntax/mojom.vim
@@ -1,23 +1,22 @@
+" Copyright 2015 The Chromium Authors. All rights reserved.
+" Use of this source code is governed by a BSD-style license that can be
+" found in the LICENSE file.
+
" Vim syntax file " Language: Mojom
" To get syntax highlighting for .mojom files, add the following to your .vimrc
" file:
-" source /path/to/src/tools/vim/mojom.vim
-
-if !exists("g:main_syntax")
- if version < 600
- syntax clear
- elseif exists("b:current_syntax")
- finish
- endif
- let g:main_syntax = 'mojom'
- syntax region mojomFold start="{" end="}" transparent fold
-endif
+" set runtimepath^=/path/to/src/tools/vim/mojom
+
+syn case match
+
+syntax region mojomFold start="{" end="}" transparent fold
" keyword definitions
-syntax keyword mojomType bool int8 int16 int32 int64 uint8 uint16 uint32 uint64 float double
+syntax keyword mojomType bool int8 int16 int32 int64 uint8 uint16 uint32 uint64 float double array
syntax match mojomImport "^\(import\)\s"
-syntax keyword mojomModule module
-syntax keyword mojomKeyword interface enum struct union
+syntax keyword mojomKeyword const module interface enum struct union
+syntax match mojomOperator /=>/
+syntax match mojomOperator /?/
" Comments
syntax keyword mojomTodo contained TODO FIXME XXX
@@ -26,6 +25,10 @@ syntax match mojomLineComment "//.*" contains=mojomTodo,@Spell
syntax match mojomLineDocComment "///.*" contains=mojomTodo,mojomDocLink,@Spell
syntax region mojomDocLink contained start=+\[+ end=+\]+
+" Strings
+syn region mojomString start=+L\="+ skip=+\\\\\|\\"+ end=+"+ contains=@Spell
+hi def link mojomString String
+
" The default highlighting.
highlight default link mojomTodo Todo
highlight default link mojomComment Comment
@@ -35,10 +38,11 @@ highlight default link mojomDocLink SpecialComment
highlight default link mojomType Type
highlight default link mojomImport Include
highlight default link mojomKeyword Keyword
+highlight default link mojomOperator Operator
let b:current_syntax = "mojom"
let b:spell_options = "contained"
-if g:main_syntax is# 'mojom'
- unlet g:main_syntax
-endif
+syn sync minlines=500
+
+let b:current_syntax = "mojom"