misc: add vim syntax and indent files
authorJean Privat <jean@pryen.org>
Fri, 26 Jun 2009 17:26:46 +0000 (13:26 -0400)
committerJean Privat <jean@pryen.org>
Fri, 26 Jun 2009 17:26:46 +0000 (13:26 -0400)
misc/vim/filetype.vim [new file with mode: 0644]
misc/vim/indent/nit.vim [new file with mode: 0644]
misc/vim/syntax/nit.vim [new file with mode: 0644]

diff --git a/misc/vim/filetype.vim b/misc/vim/filetype.vim
new file mode 100644 (file)
index 0000000..700fb94
--- /dev/null
@@ -0,0 +1,2 @@
+" Nit syntax and indent  
+au BufNewFile,BufRead *.nit                     setf nit
diff --git a/misc/vim/indent/nit.vim b/misc/vim/indent/nit.vim
new file mode 100644 (file)
index 0000000..784e552
--- /dev/null
@@ -0,0 +1,82 @@
+" Vim indent file
+" Language:    Nit
+" Maintainer:  Jean Privat <jean@pryen.org>
+
+" This file is part of NIT ( http://www.nitlanguage.org ).
+"
+" Copyright 2009 Jean Privat <jean@pryen.org>
+"
+" Licensed under the Apache License, Version 2.0 (the "License");
+" you may not use this file except in compliance with the License.
+" You may obtain a copy of the License at
+"
+"     http://www.apache.org/licenses/LICENSE-2.0
+"
+" Unless required by applicable law or agreed to in writing, software
+" distributed under the License is distributed on an "AS IS" BASIS,
+" WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+" See the License for the specific language governing permissions and
+" limitations under the License.
+
+" Only load this indent file when no other was loaded.
+if exists("b:did_indent")
+       finish
+endif
+let b:did_indent = 1
+
+setlocal indentexpr=GetNITIndent()
+setlocal nolisp
+setlocal nosmartindent
+setlocal nocindent
+setlocal autoindent
+setlocal comments=:#
+setlocal indentkeys+==end,=else,=do,=var,=with,=then,=special,=class,=interface,=universal
+setlocal sw=8
+
+" Indent after
+let s:relative_indent = '\<\(do\|then\|else\|if\)\s*$\|^\s*\(\<\(redef\|private\)\>\s*\)\?\(\<abstract\>\s*\)\?\<\(class\|interface\|universal\|special\)\>'
+" Unindent on them
+let s:outdent = '^\s*\(else\|then\|with\|end\)\>'
+" At 0
+let s:no_indent = '^\s*\(class\|import\|special\)\>'
+
+" Only define the function once.
+if exists("*GetNITIndent")
+       finish
+endif
+
+function GetNITIndent()
+       " Find a non-blank line above the current line.
+       let lnum = prevnonblank(v:lnum - 1)
+
+       " At the start of the file use zero indent.
+       if lnum == 0
+               return 0
+       endif
+
+       let cline = getline(v:lnum) " The line to indent
+       let prevline=getline(lnum) " The previous nonempty line
+       let ind = indent(lnum) " The previous nonempty indent level
+
+       " Add a 'shiftwidth' after lines that start with an indent word
+       if prevline =~ s:relative_indent
+               let ind = ind + &sw
+       endif
+
+       " Subtract a 'shiftwidth', for lines that start with an outdent word
+       if cline =~ s:outdent
+               let ind = ind - &sw
+       endif
+
+       " The following should always be at the start of a line, no indenting
+       if cline =~ s:no_indent
+               let ind = 0
+       endif
+
+       " Subtract a shiftwidth for end statements
+       if prevline =~ '$\s*end\s*\(#|$\)'
+               let ind = ind - &sw
+       endif
+
+       return ind
+endfunction
diff --git a/misc/vim/syntax/nit.vim b/misc/vim/syntax/nit.vim
new file mode 100644 (file)
index 0000000..4a1f269
--- /dev/null
@@ -0,0 +1,101 @@
+" Vim syntax file
+" Language:    Nit
+" Maintainer:  Jean Privat <jean@pryen.org>
+
+" This file is part of NIT ( http://www.nitlanguage.org ).
+"
+" Copyright 2009 Jean Privat <jean@pryen.org>
+"
+" Licensed under the Apache License, Version 2.0 (the "License");
+" you may not use this file except in compliance with the License.
+" You may obtain a copy of the License at
+"
+"     http://www.apache.org/licenses/LICENSE-2.0
+"
+" Unless required by applicable law or agreed to in writing, software
+" distributed under the License is distributed on an "AS IS" BASIS,
+" WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+" See the License for the specific language governing permissions and
+" limitations under the License.
+
+if exists("b:current_syntax")
+       finish
+endif
+
+" Expression Substitution and Backslash Notation
+syn match NITExprSubst "\\." contained
+syn match NITExprSubst "{[^}]*}" contained
+
+" Numbers and ASCII Codes
+syn match NITNumber "\<\(\d\+\.\d\+\|\d\+\)\>"
+
+" Identifiers
+syn match NITClass             "\u\w*"
+syn match NITAttribute         "\<_\h\w*"
+
+" Literal strings
+syn region NITString matchgroup=NITStringDelimit start="\"" end="\"" skip="\\\\\|\\\"" contains=NITExprSubst
+syn region NITString matchgroup=NITStringDelimit start="'"  end="'"  skip="\\\\\|\\'"
+
+
+" Fallback highlight keywords
+syn match NITBoolean "\<\(null\)\>"
+syn match NITControl "\<\(init\|end\|not null\|not\|var\|do\|then\|else\|with\)\>"
+" Unmatchning error
+syn match Error "\<end\>"
+
+" Declarations, definitions and blocks
+syn region NITPackageDecl matchgroup=NITDefine start="\<\(import\|package\)\>\s*" matchgroup=NONE end="\ze\(\s\|:\|(\|$\)"  oneline
+syn region NITClassBlock matchgroup=NITDefine start="\<\(class\|universal\|interface\)\>" matchgroup=NITDefine end="\<end\>" contains=ALL fold
+syn region NITFunctionDecl matchgroup=NITDefine start="\<\(meth\|fun\)\>\s*" matchgroup=NONE end="\ze\(\<do\>\|\s\|:\|(\|$\)"  oneline
+syn region NITTypeDecl matchgroup=NITDefine start="\<type\>\s*" matchgroup=NONE end="\ze\(\<do\>\|\s\|:\|(\|$\)"  oneline contained containedin=NITClassBlock
+syn region NITAttrDecl matchgroup=NITDefine start="\<\(var\|attr\)\>\s*\ze_" matchgroup=NONE end="\ze\(\<do\>\|\s\|:\|(\|$\)"  oneline contained containedin=NITClassBlock
+syn region NITInitDecl matchgroup=NITDefine start="\<init\>\s*" matchgroup=NONE end="\ze\(\<do\>\|\s\|:\|(\|$\)"  oneline contained containedin=NITClassBlock
+
+syn region NITStmtBlock matchgroup=NITControl start="\<\(do\|then\|else\)\>\ze\s*\(#\|$\)" matchgroup=NITControl end="^\s*\<\(end\|\zeelse\|with\)\>" contains=ALLBUT,NITTypeDecl,NITAttrDecl,NITInitDecl
+syn region NITStmtBlock matchgroup=NITControl start="\<\(do\|then\|else\)\>" matchgroup=NITControl end="\<end\>" oneline
+
+if !exists("NIT_minlines")
+       let NIT_minlines = 50
+endif
+exec "syn sync minlines=" . NIT_minlines
+
+" Comments and Documentation
+syn match  NITSharpBang        "\%^#!.*"
+syn match  NITComment  "#.*" contains=NITTodo
+
+" Keywords
+syn keyword NITKeyword  is abstract intern extern
+syn keyword NITDefine   private public protected intrude readable writable redef
+syn keyword NITControl   if while for assert
+syn keyword NITControl   and or in as isa
+syn keyword NITControl   break continue return label abort
+syn keyword NITKeyword   super new nullable
+syn keyword NITInclude   special
+syn keyword NITTodo      FIXME NOTE TODO XXX contained
+syn keyword NITBoolean   true false self
+
+" Define the default highlighting.
+hi def link NITDefine                  Define
+hi def link NITPackageDecl             Identifier
+hi def link NITFunctionDecl            Function
+hi def link NITTypeDecl                        Function
+hi def link NITAttrDecl                        Function
+hi def link NITInitDecl                        Function
+hi def link NITControl                 Statement
+hi def link NITInclude                 Include
+hi def link NITNumber                  Number
+hi def link NITBoolean                 Boolean
+hi def link NITClass                   Type
+hi def link NITAttribute               Identifier
+hi def link NITSharpBang               PreProc
+hi def link NITKeyword                 Keyword
+
+hi def link NITString                  String
+hi def link NITStringDelimit           Delimiter
+hi def link NITExprSubst               Special
+
+hi def link NITComment                 Comment
+hi def link NITTodo                    Todo
+
+let b:current_syntax = "Nit"