" Vim syntax file " Language: Mathematica " Maintainer: steve layland " Last Change: Tue May 10 18:31:00 CDT 2005 " Source: http://vim.sourceforge.net/scripts/script.php?script_id=1273 " http://members.wri.com/layland/vim/syntax/mma.vim " " NOTE: " Empty .m files will automatically be presumed as Matlab files " unless you have the following in your .vimrc: " " let filetype_m="mma" " " I also recommend setting the default 'Comment' hilighting to something " other than the color used for 'Function', since both are plentiful in " most mathematica files, and they are often the same color (when using " background=dark). I use " " hi Comment ctermfg=darkcyan " " darkgreen also looks good on my terminal. " " Credits: " o Original Mathematica syntax version written by " Wolfgang Waltenberger " o Some ideas like the CommentStar,CommentTitle were adapted " from the Java vim syntax file by Claudio Fleiner. Thanks! " o Everything else written by steve " " TODO: " folding " fix nesting " finish populating popular symbols if version < 600 syntax clear elseif exists("b:current_syntax") finish endif " Group Definitions: syntax cluster mmaNotes contains=mmaTodo,mmaFixme syntax cluster mmaComments contains=mmaComment,mmaFunctionComment,mmaItem,mmaFunctionTitle,mmaCommentStar syntax cluster mmaCommentStrings contains=mmaLooseQuote,mmaCommentString,mmaUnicode syntax cluster mmaStrings contains=@mmaCommentStrings,mmaString syntax cluster mmaTop contains=mmaOperator,mmaGenericFunction,mmaPureFunction,mmaVariable " Variables: " Dollar sign variables syntax match mmaVariable "$\a\+\d*" " Preceding contexts syntax match mmaVariable "`\=\a\+\d*`" " Numbers: syntax match mmaNumber "\<\%(\d\+\.\=\d*\|\d*\.\=\d\+\)\>" syntax match mmaNumber "`\d\+\>" " Predefined Constants: " to list all predefined Symbols would be too insane... " it's probably smarter to define a select few, and get the rest from " context if absolutely necessary. " TODO - populate this with other often used Symbols " standard fixed symbols: syntax keyword mmaVariable True False None Automatic All Null C General " mathematical constants: syntax keyword mmaVariable Pi I E Infinity ComplexInfinity Indeterminate GoldenRatio EulerGamma Degree Catalan Khinchin Glaisher " stream data / atomic heads: syntax keyword mmaVariable Byte Character Expression Number Real String Word EndOfFile Integer Symbol " sets: syntax keyword mmaVariable Integers Complexes Reals Booleans Rationals " character classes: syntax keyword mmaPattern DigitCharacter LetterCharacter WhitespaceCharacter WordCharacter EndOfString StartOfString EndOfLine StartOfLine WordBoundary " SelectionMove directions/units: syntax keyword mmaVariable Next Previous After Before Character Word Expression TextLine CellContents Cell CellGroup EvaluationCell ButtonCell GeneratedCell Notebook syntax keyword mmaVariable CellTags CellStyle CellLabel " TableForm positions: syntax keyword mmaVariable Above Below Left Right " colors: syntax keyword mmaVariable Black Blue Brown Cyan Gray Green Magenta Orange Pink Purple Red White Yellow " function attributes syntax keyword mmaVariable Protected Listable OneIdentity Orderless Flat Constant NumericFunction Locked ReadProtected HoldFirst HoldRest HoldAll HoldAllComplete SequenceHold NHoldFirst NHoldRest NHoldAll Temporary Stub " Strings: " "string" " 'string' is not accepted (until literal strings are supported!) syntax region mmaString start=+\\\@]\@!" contains=mmaOperator "pattern default: syntax match mmaPattern ": *[^ ,]\+[\], ]\@=" contains=@mmaCommentStrings,@mmaTop,mmaOperator "pattern head/test: syntax match mmaPattern "[A-Za-z0-9`]*_\+\%(\a\+\)\=\%(?([^)]\+)\|?[^\]},]\+\)\=" contains=@mmaTop,@mmaCommentStrings,mmaPatternError " Operators: " /: ^= ^:= UpValue " /; Conditional " := = DownValue " == === || " != =!= && Logic " >= <= < > " += -= *= " /= ++ -- Math " ^* " -> :> Rules " @@ @@@ Apply " /@ //@ Map " /. //. Replace " // @ Function application " <> ~~ String/Pattern join " ~ infix operator " . : Pattern operators syntax match mmaOperator "\%(@\{1,3}\|//[.@]\=\)" syntax match mmaOperator "\%(/[;:@.]\=\|\^\=:\==\)" syntax match mmaOperator "\%([-:=]\=>\|<=\=\)" "syntax match mmaOperator "\%(++\=\|--\=\|[/+-*]=\|[^*]\)" syntax match mmaOperator "[*+=^.:?-]" syntax match mmaOperator "\%(\~\~\=\)" syntax match mmaOperator "\%(=\{2,3}\|=\=!=\|||\=\|&&\|!\)" contains=ALLBUT,mmaPureFunction " Special Characters: " \[Name] named character " \ooo octal " \.xx 2 digit hex " \:xxxx 4 digit hex (multibyte unicode) syntax match mmaUnicode "\\\[\w\+\d*\]" syntax match mmaUnicode "\\\%(\x\{3}\|\.\x\{2}\|:\x\{4}\)" " Syntax Errors: syntax match mmaError "\*)" containedin=ALLBUT,@mmaComments,@mmaStrings syntax match mmaError "\%([&:|+*/?~-]\{3,}\|[.=]\{4,}\|_\@<=\.\{2,}\|`\{2,}\)" containedin=ALLBUT,@mmaComments,@mmaStrings " Punctuation: " things that shouldn't really be highlighted, or highlighted " in they're own group if you _really_ want. :) " ( ) { } " TODO - use Delimiter group? syntax match mmaBoring "[(){}]" contained " Function Arguments: " anything between brackets [] " TODO - make good folds for this. "syntax region mmaArgument start="\[" end="]" containedin=ALLBUT,@mmaComments,@mmaCommentStrings transparent fold "syntax sync fromstart "set foldmethod=syntax "set foldminlines=10 if version >= 508 || !exists("did_mma_syn_inits") if version < 508 let did_mma_syn_inits = 1 command -nargs=+ HiLink hi link else command -nargs=+ HiLink hi def link endif " NOTE - the following links are not guaranteed to " look good under all colorschemes. You might need to " :so $VIMRUNTIME/syntax/hitest.vim and tweak these to " look good in yours HiLink mmaComment Comment HiLink mmaCommentStar Comment HiLink mmaFunctionComment Comment HiLink mmaLooseQuote Comment HiLink mmaGenericFunction Function HiLink mmaOperator Operator HiLink mmaPatternOp Operator HiLink mmaPureFunction Operator HiLink mmaVariable Identifier HiLink mmaString String HiLink mmaCommentString String HiLink mmaUnicode String HiLink mmaMessage Type HiLink mmaNumber Type HiLink mmaPattern Type HiLink mmaError Error HiLink mmaFixme Error HiLink mmaPatternError Error HiLink mmaTodo Todo HiLink mmaemPHAsis Special HiLink mmaFunctionTitle Special HiLink mmaItem Preproc delcommand HiLink endif let b:current_syntax = "mma"