Source

dotfiles / vim / syntax / lecnote.vim

Full commit
" Vim syntax file
" Language:     Lecture notes
" Maintainer:   Jonas Höglund <firefly@firefly.nu>
" Filenames:    *.lecnote
" Last Change:  2012-01-17

if exists("b:current_syntax")
  finish
endif

"runtime! syntax/markdown.vim
"unlet! b:current_syntax

syn sync minlines=4


"""" Borrow stuff from markdown... """"""""""""""""""""""""""""""""""
syn match   markdownLineStart      "^[<@]\@!" nextgroup=@markdownBlock

syn cluster markdownBlock contains=markdownHeading

" Altered: allow leading whitespace.
syn match   markdownHeading        ".\+\n\s*=\+$"  contained contains=markdownHeadingRule
syn match   markdownHeading        ".\+\n\s*-\+$"  contained contains=markdownHeadingRule
syn match   markdownHeadingRule    "^\s*[=-]\+$"   contained

syn region  markdownHeading  start="^\s*#\+" end="#*\s*$"  oneline contained

" Altered: +oneline, concealends
syn region  markdownItalic         matchgroup=Conceal concealends oneline
\           start="\S\@<=\*\|\*\S\@="      end="\S\@<=\*\|\*\S\@="
syn region  markdownBold           matchgroup=Conceal concealends oneline
\           start="\S\@<=\*\*\|\*\*\S\@="  end="\S\@<=\*\*\|\*\*\S\@="


"""" Other general-purpose formatting """""""""""""""""""""""""""""""
syn match   lectureProperty        "^\s*[A-ZÅÄÖa-zåäö0-9_*]\+: "
\           contains=markdownItalic,markdownBold

syn region  lectureUnderline       matchgroup=Conceal concealends oneline
\           start="\S\@<=_\|_\S\@="        end="\S\@<=_\|_\S\@="

syn match   lectureListMarker      "^\s*[-+*]\+ \@="
syn match   lectureListMarker      "^\s*\%([a-z]\|[0-9.]\+\)\+[).:] \@="

syn match   lectureMathMode        ".*"  contained
\           contains=@lectureMathMode

syn region  lectureMathMode        matchgroup=Conceal concealends oneline
\           start="\$" end="\$"    contains=@lectureMathMode

syn cluster lectureMathMode        contains=@lectureMathOperator
syn cluster lectureMathOperator
\           contains=lectureMathMacroOperator,lectureMathMatrixTranspose

syn match   lectureMathVectorSubsts "_u" conceal cchar=a
"syn match   lectureMathVectorSubsts "_u" conceal cchar=u̅
"syn match   lectureMathVectorSubsts "_v" conceal cchar=v̅
"syn match   lectureMathVectorSubsts "_w" conceal cchar=w̅

syn match   lectureMathMatrixTranspose "\^T" contained conceal cchar=
syn match   lectureMathVector      "_[A-Za-z0]"
\           contains=lectureMathVectorSubsts contained

syn match   lectureMathMacroOperator  "<=\+>\|<=\+\|=\+>"  contains=lectureMathArrowPart
syn match   lectureMathMacroOperator  "<-\+>\|<-\+\|-\+>"  contains=lectureMathArrowPart

syn match   lectureMathArrowPart   "-"  contained conceal cchar=syn match   lectureMathArrowPart   "="  contained conceal cchar=syn match   lectureMathArrowPart   ">"  contained conceal cchar=syn match   lectureMathArrowPart   "<"  contained conceal cchar=
"syn match   lectureHorizontalBrace   "`-\+ [-+*/^A-Za-z0-9.]\+ -\+´"
"syn match   lectureHorizontalBrace   "`- [-+*/^A-Za-z0-9.] -´"

syn match   lectureHorizontalBrace   "`-"
\           contains=lectureHoriontalBracePart
syn match   lectureHorizontalBracePart  "`"  contained conceal cchar=syn match   lectureHorizontalBracePart  "´"  contained conceal cchar=syn match   lectureHorizontalBracePart  "-"  contained conceal cchar=

"""" Matrices """""""""""""""""""""""""""""""""""""""""""""""""""""""
syn match   lectureParenTopLeft    "/"  contained conceal cchar=⎛"⎡
syn match   lectureParenTopRight   "\\" contained conceal cchar=⎞"⎤
syn match   lectureParenBtmLeft    "\\" contained conceal cchar=⎝"⎣
syn match   lectureParenBtmRight   "/"  contained conceal cchar=⎠"⎦

syn match   lectureParenBar        "|"  contained conceal cchar=syn match   lectureParenEdgeLeft   "\%(| \+[-().a-z0-9]\+ [-() .a-z0-9]*\)\@<!|"
\           contained conceal cchar=syn match   lectureParenEdgeRight  "\%(| \+[-().a-z0-9]\+ [-() .a-z0-9]*\)\@!|"
\           contained conceal cchar=
syn match   lectureParenTop        "/ [-+*/() .a-z0-9]\+ \%(| \+[-+*/() .a-z0-9]\+ \+\)*\\"
\           contains=lectureParenTopLeft,lectureParenTopRight,lectureParenBar

"syn match   lectureParenMiddle    "| [-+*/() .a-z0-9]\+ \%(| \+[-+*/().a-z0-9]\+ \+\)*|"
syn match   lectureParenMiddle     "\%(|\%( \+[-().a-z0-9]\+\)\+ \+\)\+|"
\           contains=lectureParenEdgeLeft,lectureParenEdgeRight,lectureParenBar

syn match   lectureParenBtm        "\\ [-+*/() .a-z0-9]\+ \%(| \+[-+*/() .a-z0-9]\+ \+\)*/"
\           contains=lectureParenBtmLeft,lectureParenBtmRight,lectureParenBar


"""" Equation systems """""""""""""""""""""""""""""""""""""""""""""""
syn match  lectureEqSysTopChar    "/"  contained conceal cchar=syn match  lectureEqSysBtmChar    "\\" contained conceal cchar=syn match  lectureEqSysMiddleChar "{"  contained conceal cchar=syn match  lectureEqSysBarChar    "|"  contained conceal cchar=
syn match  lectureEqSysTop        "/ \+\%([-+*/() a-z0-9]\+ = \+[-a-z0-9]\+\|--\)"
\          contains=lectureEqSysTopChar
syn match  lectureEqSysBtm        "\\ \+\%([-+*/() a-z0-9]\+ = \+[-a-z0-9]\+\|--\)"
\          contains=lectureEqSysBtmChar
syn match  lectureEqSysMiddle     "{ \+\%([-+*/() a-z0-9]\+ = \+[-a-z0-9]\+\|--\)"
\          contains=lectureEqSysMiddleChar
syn match  lectureEqSysBar        "| \+\%([-+*/() a-z0-9]\+ = \+[-a-z0-9]\+\|--\)"
\          contains=lectureEqSysBarChar


"""" Highlighting """""""""""""""""""""""""""""""""""""""""""""""""""
"hi lectureProperty    ctermfg=red
"hi lectureListMarker  ctermfg=yellow  cterm=bold

hi           markdownHeading           cterm=bold
hi           markdownItalic            cterm=italic
hi           markdownBold              cterm=bold
hi           lectureListMarker         cterm=bold    ctermfg=yellow

hi def link  markdownHeadingRule       PreProc
hi def link  lectureUnderline          Underlined
hi def link  lectureListMarker         Character
hi def link  lectureProperty           Statement

hi def link  lectureMathMode           Identifier
hi def link  lectureMathMacroOperator  Operator

let b:current_syntax = "lecnote"