summaryrefslogtreecommitdiff
path: root/runtime/indent/readline.vim
blob: b2640f1f2f97f13f2e91778c13fa5a356a354535 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
" Vim indent file
" Language:	    readline configuration file
" Maintainer:	    Nikolai Weibull <source@pcppopper.org>
" URL:		    http://www.pcppopper.org/vim/indent/pcp/readline/
" Latest Revision:  2004-04-25
" arch-tag:	    ee681235-3abf-4a42-8587-edabd409a980

" Only load this indent file when no other was loaded.
if exists("b:did_indent")
  finish
endif

let b:did_indent = 1

setlocal indentexpr=GetReadlineIndent()
setlocal indentkeys=!^F,o,O,=$else,=$endif

" Only define the function once.
if exists("*GetReadlineIndent")
  finish
endif

function GetReadlineIndent()
  let lnum = prevnonblank(v:lnum - 1)

  if lnum == 0
    return 0
  endif

  let line = getline(lnum)
  let ind = indent(lnum)

  " increase indent if previous line started with $if or $else
  if  line =~ '^\s*$\(if\|else\)\>'
    let ind = ind + &sw
  endif

  let line = getline(v:lnum)

  " decrease indent if this line starts with $else or $endif
  if line =~ '^\s*$\(else\|endif\)\>'
    let ind = ind - &sw
  endif

  return ind
endfunction

" vim: set sts=2 sw=2: