robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
d3068d34cc
master
1" Vim indent file 2" Language: Mathematica 3" Maintainer: Steve Layland <layland@wolfram.com> (Invalid email address) 4" Doug Kearns <dougkearns@gmail.com> 5" Last Change: Sat May 10 18:56:22 CDT 2005 6" 2022 April: b:undo_indent added by Doug Kearns 7" Source: http://vim.sourceforge.net/scripts/script.php?script_id=1274 8" http://members.wolfram.com/layland/vim/indent/mma.vim 9" 10" NOTE: 11" Empty .m files will automatically be presumed to be Matlab files 12" unless you have the following in your .vimrc: 13" 14" let filetype_m="mma" 15" 16" Credits: 17" o steve hacked this out of a random indent file in the Vim 6.1 18" distribution that he no longer remembers...sh.vim? Thanks! 19 20" Only load this indent file when no other was loaded. 21if exists ( "b:did_indent" ) 22finish 23endif 24let b: did_indent = 1 25 26setlocal indentexpr = GetMmaIndent () 27setlocal indentkeys += 0[,0],0(,0) 28setlocal nosi "turn off smart indent so we don't over analyze } blocks 29 30let b: undo_indent = "setl inde< indk< si<" 31 32if exists ( "*GetMmaIndent" ) 33finish 34endif 35 36function GetMmaIndent () 37 38" Hit the start of the file, use zero indent. 39if v: lnum == 0 40return 0 41endif 42 43" Find a non-blank line above the current line. 44let lnum = prevnonblank ( v: lnum - 1 ) 45 46" use indenting as a base 47let ind = indent ( v: lnum ) 48let lnum = v: lnum 49 50" if previous line has an unmatched bracket, or ( indent. 51" doesn't do multiple parens/blocks/etc... 52 53" also, indent only if this line if this line isn't starting a new 54" block... TODO - fix this with indentkeys? 55if getline ( v: lnum - 1 ) =~ '\\\@<!\%(\[[^\]]*\|([^)]*\|{[^}]*\)$' && getline ( v: lnum ) !~ '\s\+[\[({]' 56let ind = ind + shiftwidth () 57endif 58 59" if this line had unmatched closing block, 60" indent to the matching opening block 61if getline ( v: lnum ) =~ '[^[]*]\s*$' 62" move to the closing bracket 63call search ( ']' , 'bW' ) 64" and find its partner's indent 65let ind = indent ( searchpair ( '\[' , '' , ']' , 'bWn' )) 66" same for ( blocks 67elseif getline ( v: lnum ) =~ '[^(]*)$' 68call search ( ')' , 'bW' ) 69let ind = indent ( searchpair ( '(' , '' , ')' , 'bWn' )) 70 71" and finally, close { blocks if si ain't already set 72elseif getline ( v: lnum ) =~ '[^{]*}' 73call search ( '}' , 'bW' ) 74let ind = indent ( searchpair ( '{' , '' , '}' , 'bWn' )) 75endif 76 77return ind 78endfunction 79