]> git.donarmstrong.com Git - lilypond.git/blob - vim/lilypond-indent.vim
* vim/lilypond-indent.vim: use <TAB> is indent character in
[lilypond.git] / vim / lilypond-indent.vim
1 " LilyPond indent file
2 " Language:     LilyPond
3 " Maintainer:   Heikki Junes <hjunes@cc.hut.fi>
4 " Last Change:  2004 Mar 01
5
6 " Only load this indent file when no other was loaded.
7 if exists("b:did_indent")
8   finish
9 endif
10 let b:did_indent = 1
11
12 setlocal indentexpr=GetLilyPondIndent()
13 setlocal indentkeys+==},>>,!<TAB>
14
15 " Only define the function once.
16 if exists("*GetLilyPondIndent")
17   finish
18 endif
19
20 function GetLilyPondIndent()
21   if v:lnum == 1
22     return 0
23   endif
24
25   "Find a non-blank line above the current line.
26   let lnum = prevnonblank(v:lnum - 1)
27   "Check if a block was started: '{' or '<<' is the last non-blank character of the line.
28   if getline(lnum) =~ '^.*\({\|<<\)\s*$'
29     let ind = indent(lnum) + &sw
30   else
31     let ind = indent(lnum)
32   endif
33
34   "Check if a block was ended: '}' or '>>' is the first non-blank character of the line.
35   if getline(v:lnum) =~ '^\s*\(}\|>>\)'
36     let ind = ind - &sw
37   endif
38
39   return ind
40 endfunction
41 "
42 "
43 "