ref: 8b5f4cf211ff980f796058bef0ec1696e894b033
parent: bc529a54b673dfe0769f6f139dc85e440b8051cf
author: Ori Bernstein <[email protected]>
date: Fri Apr 17 10:59:49 EDT 2015
Add vim support files.
--- /dev/null
+++ b/support/vim/ftdetect/mbld.vim
@@ -1,0 +1,8 @@
+au BufRead,BufNewFile bld.proj
+ \ setlocal ft=mbld |
+ \ setlocal noet |
+ \ setlocal sw=8
+au BufRead,BufNewFile bld.sub
+ \ setlocal ft=mbld |
+ \ setlocal noet |
+ \ setlocal sw=8
--- /dev/null
+++ b/support/vim/ftdetect/myr.vim
@@ -1,0 +1,1 @@
+au BufRead,BufNewFile *.myr set ft=myr
--- /dev/null
+++ b/support/vim/indent/mbld.vim
@@ -1,0 +1,54 @@
+" Vim Indentation file
+" Language: Myrddin
+" Maintainer: Ori Bernstein
+
+if exists("b:did_indent")
+ finish
+endif
+
+function! s:CheckMatch(line, pats)
+ for p in a:pats
+ let idx = match(a:line, p)
+ if idx >= 0
+ return 1
+ endif
+ endfor
+ return 0
+endfunction
+
+
+function! GetMbldIndent(ln)
+ let ln = a:ln
+
+ if ln == 1
+ let ind = 0
+ else
+ let i = 1
+ let prevln = ''
+ while prevln =~ '^\s*$'
+ let prevln = getline(ln - i)
+ let ind = indent(ln - i)
+ let i = i + 1
+ endwhile
+ echo "IND IS " ind
+ let curln = getline(ln)
+ let inpat = ['^\s*\<bin\>', '^\s*\<lib\>',
+ \'^\s*\<gen\>', '^\s*\<test\>',
+ \'^\s*\<man\>', '^\s*\<sub\>']
+ let level = 0
+ if s:CheckMatch(prevln, inpat)
+ let level = level + 1
+ endif
+
+ if match(curln, ';;\s*$') > 0
+ let level = level - 1
+ endif
+ echo "TABSTOP IS " &tabstop
+ let ind = ind + (level * &tabstop)
+ endif
+ return ind
+endfunction
+
+setlocal indentkeys+=,;
+setlocal indentexpr=GetMbldIndent(v:lnum)
+let b:did_indent = 1
--- /dev/null
+++ b/support/vim/indent/myr.vim
@@ -1,0 +1,74 @@
+" Vim Indentation file
+" Language: Myrddin
+" Maintainer: Ori Bernstein
+
+if exists("b:did_indent")
+ finish
+endif
+
+function! s:CountMatches(line, pats)
+ let matches = 0
+ for p in a:pats
+ let idx = 0
+ while idx >= 0
+ let idx = match(a:line, p, idx)
+ if idx >= 0
+ let matches = matches + 1
+ let idx = idx + strlen(p)
+ endif
+ endwhile
+ endfor
+ return matches
+endfunction
+
+function! s:LineMatch(line, pats)
+ for p in a:pats
+ let pat = '^\s*'.p.'\s*$'
+ if match(a:line, pat, 0) >= 0
+ return 1
+ endif
+ endfor
+ return 0
+endfunction
+
+function! GetMyrIndent(ln)
+ let ln = a:ln
+
+ if ln == 1
+ let ind = 0
+ else
+ let i = 1
+ let prevln = ''
+ while prevln =~ '^\s*$'
+ let prevln = getline(ln - i)
+ let ind = indent(ln - i)
+
+ let i = i + 1
+ endwhile
+
+ let curln = getline(ln)
+
+ let inpat = ['\<if\>', '\<elif\>', '\<else\>',
+ \ '\<while\>','\<for\>', '\<match\>',
+ \ '\<struct\>', '\<union\>',
+ \ '{', '^\s*|', '=\s*$']
+ let outpat = ['}', ';;']
+ let outalone = ['\<else\>', '\<elif\>', '}', ';;', '|.*']
+ let width = &tabstop
+
+ let n_in = s:CountMatches(prevln, inpat)
+ let n_out = s:CountMatches(prevln, outpat)
+ if s:LineMatch(curln, outalone) != 0
+ let ind = n_in * &tabstop + ind - &tabstop
+ " avoid double-counting outdents from outalones.
+ elseif s:LineMatch(prevln, outpat) == 0
+ let ind = ind + (n_in - n_out) * &tabstop
+ endif
+ endif
+ return ind
+endfunction
+
+setlocal indentkeys+=,;\|,=elif
+setlocal indentexpr=GetMyrIndent(v:lnum)
+
+let b:did_indent = 1
--- /dev/null
+++ b/support/vim/syntax/mbld.vim
@@ -1,0 +1,21 @@
+" Vim Syntax file
+" Language: Myrddin Build
+" Maintainer: Ori Bernstein
+
+if exists("b:current_syntax")
+ finish
+endif
+
+syn region mbldComment start=+#+ end=+$+
+syn region mbldString start=+"+ skip=+\\"+ end=+"+ extend
+syn keyword mbldKeyword
+ \ bin
+ \ lib
+ \ gen
+ \ test
+ \ man
+ \ sub
+
+hi def link mbldComment Comment
+hi def link mbldString String
+
--- /dev/null
+++ b/support/vim/syntax/myr.vim
@@ -1,0 +1,48 @@
+" Vim Syntax file
+" Language: Myrddin
+" Maintainer: Ori Bernstein
+
+if exists("b:current_syntax")
+ finish
+endif
+
+syn region myrComment start=+/\*+ end=+\*/+
+syn match myrSpecial display contained "\\\(x\x\+\|\o\{1,3}\|u{.*}\|.\|$\)"
+syn match myrFormat display "%[sbwilpc]"
+syn region myrString start=+"+ skip=+\\"+ end=+"+ contains=myrSpecial,myrFormat extend
+syn region myrChar start=+'+ skip=+\\'+ end=+'+ contains=myrSpecial,myrFormat extend
+syn keyword myrKeyword castto
+ \ const
+ \ default
+ \ elif
+ \ else
+ \ export
+ \ extern
+ \ false
+ \ for
+ \ generic
+ \ goto
+ \ if
+ \ match
+ \ pkg
+ \ protect
+ \ sizeof
+ \ struct
+ \ trait
+ \ true
+ \ type
+ \ union
+ \ use
+ \ var
+ \ while
+
+hi def link myrComment Comment
+hi def link myrString String
+hi def link myrChar String
+hi def link myrSpecial Special
+hi def link myrFormat Special
+" Too much color makes my eyes hurt. Just highlight
+" the most important and uncommon stuff.
+"hi def link myrKeyword Keyword
+
+let b:current_syntax = "myr"