Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1 | " Vim indent file |
| 2 | " Language: readline configuration file |
| 3 | " Maintainer: Nikolai Weibull <source@pcppopper.org> |
| 4 | " URL: http://www.pcppopper.org/vim/indent/pcp/readline/ |
| 5 | " Latest Revision: 2004-04-25 |
| 6 | " arch-tag: ee681235-3abf-4a42-8587-edabd409a980 |
| 7 | |
| 8 | " Only load this indent file when no other was loaded. |
| 9 | if exists("b:did_indent") |
| 10 | finish |
| 11 | endif |
| 12 | |
| 13 | let b:did_indent = 1 |
| 14 | |
| 15 | setlocal indentexpr=GetReadlineIndent() |
| 16 | setlocal indentkeys=!^F,o,O,=$else,=$endif |
| 17 | |
| 18 | " Only define the function once. |
| 19 | if exists("*GetReadlineIndent") |
| 20 | finish |
| 21 | endif |
| 22 | |
| 23 | function GetReadlineIndent() |
| 24 | let lnum = prevnonblank(v:lnum - 1) |
| 25 | |
| 26 | if lnum == 0 |
| 27 | return 0 |
| 28 | endif |
| 29 | |
| 30 | let line = getline(lnum) |
| 31 | let ind = indent(lnum) |
| 32 | |
| 33 | " increase indent if previous line started with $if or $else |
| 34 | if line =~ '^\s*$\(if\|else\)\>' |
| 35 | let ind = ind + &sw |
| 36 | endif |
| 37 | |
| 38 | let line = getline(v:lnum) |
| 39 | |
| 40 | " decrease indent if this line starts with $else or $endif |
| 41 | if line =~ '^\s*$\(else\|endif\)\>' |
| 42 | let ind = ind - &sw |
| 43 | endif |
| 44 | |
| 45 | return ind |
| 46 | endfunction |
| 47 | |
| 48 | " vim: set sts=2 sw=2: |