robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
ab20681c52
master
1" PostScript indent file 2" Language: PostScript 3" Maintainer: Mike Williams <mrw@eandem.co.uk> 4" Last Change: 2022 Apr 06 5 6" Only load this indent file when no other was loaded. 7if exists ( "b:did_indent" ) 8finish 9endif 10let b: did_indent = 1 11 12setlocal indentexpr = PostscrIndentGet (v:lnum) 13setlocal indentkeys += 0],0=>>,0=%%,0=end,0=restore,0=grestoreindentkeys -= :,0#,e 14 15let b: undo_indent = "setl inde< indk<" 16 17" Catch multiple instantiations 18if exists ( "*PostscrIndentGet" ) 19finish 20endif 21 22function ! PostscrIndentGet ( lnum ) 23" Find a non-empty non-comment line above the current line. 24" Note: ignores DSC comments as well! 25let lnum = a: lnum - 1 26while lnum != 0 27let lnum = prevnonblank ( lnum ) 28if getline ( lnum ) !~ '^\s*%.*$' 29break 30endif 31let lnum = lnum - 1 32endwhile 33 34" Hit the start of the file, use user indent. 35if lnum == 0 36return -1 37endif 38 39" Start with the indent of the previous line 40let ind = indent ( lnum ) 41let pline = getline ( lnum ) 42 43" Indent for dicts, arrays, and saves with possible trailing comment 44if pline =~ '\(begin\|<<\|g\=save\|{\|[\)\s*\(%.*\)\=$' 45let ind = ind + shiftwidth () 46endif 47 48" Remove indent for popped dicts, and restores. 49if pline =~ '\(end\|g\=restore\)\s*$' 50let ind = ind - shiftwidth () 51 52" Else handle immediate dedents of dicts, restores, and arrays. 53elseif getline ( a: lnum ) =~ '\(end\|>>\|g\=restore\|}\|]\)' 54let ind = ind - shiftwidth () 55 56" Else handle DSC comments - always start of line. 57elseif getline ( a: lnum ) =~ '^\s*%%' 58let ind = 0 59endif 60 61" For now catch excessive left indents if they occur. 62if ind < 0 63let ind = -1 64endif 65 66return ind 67endfunction 68 69" vim:sw=2