]> git.donarmstrong.com Git - lilypond.git/blob - vim/lilypond-indent.vim
* Documentation/topdocs/INSTALL.texi: give even more detailed orders.
[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 " Installed As: vim/indent/lilypond.vim
7 "
8 " Only load this indent file when no other was loaded.
9 if exists("b:did_indent")
10   finish
11 endif
12 let b:did_indent = 1
13
14 setlocal indentexpr=GetLilyPondIndent()
15 setlocal indentkeys+==},>>,!^F
16
17 " Only define the function once.
18 if exists("*GetLilyPondIndent")
19   finish
20 endif
21
22 function GetLilyPondIndent()
23   if v:lnum == 1
24     return 0
25   endif
26
27   "Find a non-blank line above the current line.
28   let lnum = prevnonblank(v:lnum - 1)
29   "Check if a block was started: '{' or '<<' is the last non-blank character of the previous line.
30   if getline(lnum) =~ '^.*\({\|<<\)\s*$'
31     let ind = indent(lnum) + &sw
32   else
33     let ind = indent(lnum)
34   endif
35
36   "Check if a block was ended: '}' or '>>' is the first non-blank character of the current line.
37   elseif getline(v:lnum) =~ '^\s*\(}\|>>\)'
38     let ind = ind - &sw
39   endif
40
41   return ind
42 endfunction
43 "
44 "
45 "