Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 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. |
| 6 | if exists("b:did_indent") |
| 7 | finish |
| 8 | endif |
| 9 | let b:did_indent = 1 |
| 10 | |
| 11 | setlocal indentexpr=GetIshdIndent(v:lnum) |
| 12 | setlocal indentkeys& |
| 13 | setlocal indentkeys+==else,=elseif,=endif,=end,=begin,<:> |
| 14 | " setlocal indentkeys-=0# |
| 15 | |
| 16 | " Only define the function once. |
| 17 | if exists("*GetIshdIndent") |
| 18 | finish |
| 19 | endif |
| 20 | |
| 21 | fun! GetIshdIndent(lnum) |
| 22 | " labels and preprocessor get zero indent immediately |
| 23 | let this_line = getline(a:lnum) |
| 24 | let LABELS_OR_PREPROC = '^\s*\(\<\k\+\>:\s*$\|#.*\)' |
| 25 | let LABELS_OR_PREPROC_EXCEPT = '^\s*\<default\+\>:' |
| 26 | if this_line =~ LABELS_OR_PREPROC && this_line !~ LABELS_OR_PREPROC_EXCEPT |
| 27 | return 0 |
| 28 | endif |
| 29 | |
| 30 | " Find a non-blank line above the current line. |
| 31 | " Skip over labels and preprocessor directives. |
| 32 | let lnum = a:lnum |
| 33 | while lnum > 0 |
| 34 | let lnum = prevnonblank(lnum - 1) |
| 35 | let previous_line = getline(lnum) |
| 36 | if previous_line !~ LABELS_OR_PREPROC || previous_line =~ LABELS_OR_PREPROC_EXCEPT |
| 37 | break |
| 38 | endif |
| 39 | endwhile |
| 40 | |
| 41 | " Hit the start of the file, use zero indent. |
| 42 | if lnum == 0 |
| 43 | return 0 |
| 44 | endif |
| 45 | |
| 46 | let ind = indent(lnum) |
| 47 | |
| 48 | " Add |
| 49 | if previous_line =~ '^\s*\<\(function\|begin\|switch\|case\|default\|if.\{-}then\|else\|elseif\|while\|repeat\)\>' |
| 50 | let ind = ind + &sw |
| 51 | endif |
| 52 | |
| 53 | " Subtract |
| 54 | if this_line =~ '^\s*\<endswitch\>' |
| 55 | let ind = ind - 2 * &sw |
| 56 | elseif this_line =~ '^\s*\<\(begin\|end\|endif\|endwhile\|else\|elseif\|until\)\>' |
| 57 | let ind = ind - &sw |
| 58 | elseif this_line =~ '^\s*\<\(case\|default\)\>' |
| 59 | if previous_line !~ '^\s*\<switch\>' |
| 60 | let ind = ind - &sw |
| 61 | endif |
| 62 | endif |
| 63 | |
| 64 | return ind |
| 65 | endfun |