robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
cbf54ec2a5
master
1" Vim indent file 2" Language: Zimbu 3" Maintainer: The Vim Project <https://github.com/vim/vim> 4" Last Change: 2023 Aug 10 5" Former Maintainer: Bram Moolenaar <Bram@vim.org> 6 7" Only load this indent file when no other was loaded. 8if exists ( "b:did_indent" ) 9finish 10endif 11let b: did_indent = 1 12 13setlocal ai nolisp nocin 14setlocal indentexpr = GetZimbuIndent (v:lnum) 15setlocal indentkeys = 0{,0},!^F,o,O,0=ELSE,0=ELSEIF,0=CASE,0=DEFAULT,0=FINALLY 16 17" We impose recommended defaults: no Tabs, 'shiftwidth' = 2 18setlocal sw = 2 et 19 20let b: undo_indent = "setl ai< cin< et< indentkeys< indentexpr< lisp< sw<" 21 22" Only define the function once. 23if exists ( "*GetZimbuIndent" ) 24finish 25endif 26 27let s: cpo_save = & cpo 28set cpo & vim 29 30" Come here when loading the script the first time. 31 32let s: maxoff = 50 " maximum number of lines to look backwards for () 33 34func GetZimbuIndent ( lnum ) 35let prevLnum = prevnonblank ( a: lnum - 1 ) 36if prevLnum == 0 37" This is the first non-empty line, use zero indent. 38return 0 39endif 40 41" Taken from Python indenting: 42" If the previous line is inside parenthesis, use the indent of the starting 43" line. 44" Trick: use the non-existing "dummy" variable to break out of the loop when 45" going too far back. 46call cursor ( prevLnum , 1 ) 47let parlnum = searchpair ( '(\|{\|\[' , '' , ')\|}\|\]' , 'nbW' , 48 \"line('.') < " . ( prevLnum - s: maxoff ) . " ? dummy :" 49 \. " synIDattr(synID(line('.'), col('.'), 1), 'name')" 50 \. " =~ '\\(Comment\\|String\\|Char\\)$'" ) 51if parlnum > 0 52let plindent = indent ( parlnum ) 53let plnumstart = parlnum 54else 55let plindent = indent ( prevLnum ) 56let plnumstart = prevLnum 57endif 58 59 60" When inside parenthesis: If at the first line below the parenthesis add 61" two 'shiftwidth', otherwise same as previous line. 62" i = (a 63" + b 64" + c) 65call cursor ( a: lnum , 1 ) 66let p = searchpair ( '(\|{\|\[' , '' , ')\|}\|\]' , 'bW' , 67 \"line('.') < " . ( a: lnum - s: maxoff ) . " ? dummy :" 68 \. " synIDattr(synID(line('.'), col('.'), 1), 'name')" 69 \. " =~ '\\(Comment\\|String\\|Char\\)$'" ) 70if p > 0 71if p == prevLnum 72" When the start is inside parenthesis, only indent one 'shiftwidth'. 73let pp = searchpair ( '(\|{\|\[' , '' , ')\|}\|\]' , 'bW' , 74 \"line('.') < " . ( a: lnum - s: maxoff ) . " ? dummy :" 75 \. " synIDattr(synID(line('.'), col('.'), 1), 'name')" 76 \. " =~ '\\(Comment\\|String\\|Char\\)$'" ) 77if pp > 0 78return indent ( prevLnum ) + shiftwidth () 79endif 80return indent ( prevLnum ) + shiftwidth () * 2 81endif 82if plnumstart == p 83return indent ( prevLnum ) 84endif 85return plindent 86endif 87 88let prevline = getline ( prevLnum ) 89let thisline = getline ( a: lnum ) 90 91" If this line is not a comment and the previous one is then move the 92" previous line further back. 93if thisline !~ '^\s*#' 94while prevline =~ '^\s*#' 95let prevLnum = prevnonblank ( prevLnum - 1 ) 96if prevLnum == 0 97" Only comment lines before this, no indent 98return 0 99endif 100let prevline = getline ( prevLnum ) 101let plindent = indent ( prevLnum ) 102endwhile 103endif 104 105if prevline =~ '^\s*\(IF\|\|ELSEIF\|ELSE\|GENERATE_IF\|\|GENERATE_ELSEIF\|GENERATE_ELSE\|WHILE\|REPEAT\|TRY\|CATCH\|FINALLY\|FOR\|DO\|SWITCH\|CASE\|DEFAULT\|FUNC\|VIRTUAL\|ABSTRACT\|DEFINE\|REPLACE\|FINAL\|PROC\|MAIN\|NEW\|ENUM\|CLASS\|INTERFACE\|BITS\|MODULE\|SHARED\)\>' 106let plindent += shiftwidth () 107endif 108if thisline =~ '^\s*\(}\|ELSEIF\>\|ELSE\>\|CATCH\|FINALLY\|GENERATE_ELSEIF\>\|GENERATE_ELSE\>\|UNTIL\>\)' 109let plindent -= shiftwidth () 110endif 111if thisline =~ '^\s*\(CASE\>\|DEFAULT\>\)' && prevline !~ '^\s*SWITCH\>' 112let plindent -= shiftwidth () 113endif 114 115" line up continued comment that started after some code 116" String something # comment comment 117" # comment 118if a: lnum == prevLnum + 1 && thisline =~ '^\s*#' && prevline !~ '^\s*#' 119let n = match ( prevline , '#' ) 120if n > 1 121let plindent = n 122endif 123endif 124 125return plindent 126endfunc 127 128let & cpo = s: cpo_save 129unlet s: cpo_save