robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
ad527392ab
master
1" Description: InstallShield indenter 2" Author: Johannes Zellner <johannes@zellner.org> 3" Last Change: Tue, 27 Apr 2004 14:54:59 CEST 4 5" Only load this indent file when no other was loaded. 6if exists ( "b:did_indent" ) 7finish 8endif 9let b: did_indent = 1 10 11setlocal autoindent 12setlocal indentexpr = GetIshdIndent (v:lnum) 13setlocal indentkeys & 14setlocal indentkeys += =else,=elseif,=endif,=end,=begin,<:> 15" setlocal indentkeys-=0# 16 17let b: undo_indent = "setl ai< indentexpr< indentkeys<" 18 19" Only define the function once. 20if exists ( "*GetIshdIndent" ) 21finish 22endif 23 24fun ! GetIshdIndent ( lnum ) 25" labels and preprocessor get zero indent immediately 26let this_line = getline ( a: lnum ) 27let LABELS_OR_PREPROC = '^\s*\(\<\k\+\>:\s*$\|#.*\)' 28let LABELS_OR_PREPROC_EXCEPT = '^\s*\<default\+\>:' 29if this_line =~ LABELS_OR_PREPROC && this_line !~ LABELS_OR_PREPROC_EXCEPT 30return 0 31endif 32 33" Find a non-blank line above the current line. 34" Skip over labels and preprocessor directives. 35let lnum = a: lnum 36while lnum > 0 37let lnum = prevnonblank ( lnum - 1 ) 38let previous_line = getline ( lnum ) 39if previous_line !~ LABELS_OR_PREPROC || previous_line =~ LABELS_OR_PREPROC_EXCEPT 40break 41endif 42endwhile 43 44" Hit the start of the file, use zero indent. 45if lnum == 0 46return 0 47endif 48 49let ind = indent ( lnum ) 50 51" Add 52if previous_line =~ '^\s*\<\(function\|begin\|switch\|case\|default\|if.\{-}then\|else\|elseif\|while\|repeat\)\>' 53let ind = ind + shiftwidth () 54endif 55 56" Subtract 57if this_line =~ '^\s*\<endswitch\>' 58let ind = ind - 2 * shiftwidth () 59elseif this_line =~ '^\s*\<\(begin\|end\|endif\|endwhile\|else\|elseif\|until\)\>' 60let ind = ind - shiftwidth () 61elseif this_line =~ '^\s*\<\(case\|default\)\>' 62if previous_line !~ '^\s*\<switch\>' 63let ind = ind - shiftwidth () 64endif 65endif 66 67return ind 68endfun