]> git.donarmstrong.com Git - lilypond.git/blob - vim/lilypond-indent.vim
Add '-dcrop' option to ps and svg backends
[lilypond.git] / vim / lilypond-indent.vim
1 " LilyPond indent file
2 " Language:     LilyPond
3 " Maintainer:   Heikki Junes <hjunes@cc.hut.fi>
4 " Last Change:  2010 Jul 26
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=o,O,},>>,!^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   if getline(v:lnum) =~ '^\s*\(}\|>>\)'
38     let ind = ind - &sw
39   endif
40
41   " Check if the first character from the previous line is within
42   " a `lilyScheme' region, and if so, use lisp-style indentation
43   " for the current line.
44   "
45   " TODO:
46   "   - Only works in version 7.1.215 or later, though it should
47   "     silently fail in older versions.
48   "   - We should support `lilyScheme' regions that begin in the
49   "     middle of the line, too.
50   for id in synstack(lnum, 1)
51     if synIDattr(id, "name") == "lilyScheme"
52       let ind = lispindent(v:lnum)
53     endif
54   endfor
55
56   return ind
57 endfunction
58 "
59 "
60 "