X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=vim%2Flilypond-indent.vim;h=224f5de4cdfd511946b9173767f7b36220868460;hb=aafcc4147ae2fea2ba1d95c7a54963c61f21b963;hp=e2426d6d89c2e66633bfd32b94279c0ef79cd671;hpb=6c08722ad9d26f016832a2d6851d8c9addf62de7;p=lilypond.git diff --git a/vim/lilypond-indent.vim b/vim/lilypond-indent.vim index e2426d6d89..224f5de4cd 100644 --- a/vim/lilypond-indent.vim +++ b/vim/lilypond-indent.vim @@ -1,8 +1,10 @@ " LilyPond indent file " Language: LilyPond " Maintainer: Heikki Junes -" Last Change: 2004 Mar 01 - +" Last Change: 2010 Jul 26 +" +" Installed As: vim/indent/lilypond.vim +" " Only load this indent file when no other was loaded. if exists("b:did_indent") finish @@ -10,6 +12,7 @@ endif let b:did_indent = 1 setlocal indentexpr=GetLilyPondIndent() +setlocal indentkeys=o,O,},>>,!^F " Only define the function once. if exists("*GetLilyPondIndent") @@ -23,7 +26,32 @@ function GetLilyPondIndent() "Find a non-blank line above the current line. let lnum = prevnonblank(v:lnum - 1) - let ind = indent(lnum) + "Check if a block was started: '{' or '<<' is the last non-blank character of the previous line. + if getline(lnum) =~ '^.*\({\|<<\)\s*$' + let ind = indent(lnum) + &sw + else + let ind = indent(lnum) + endif + + "Check if a block was ended: '}' or '>>' is the first non-blank character of the current line. + if getline(v:lnum) =~ '^\s*\(}\|>>\)' + let ind = ind - &sw + endif + + " Check if the first character from the previous line is within + " a `lilyScheme' region, and if so, use lisp-style indentation + " for the current line. + " + " TODO: + " - Only works in version 7.1.215 or later, though it should + " silently fail in older versions. + " - We should support `lilyScheme' regions that begin in the + " middle of the line, too. + for id in synstack(lnum, 1) + if synIDattr(id, "name") == "lilyScheme" + let ind = lispindent(v:lnum) + endif + endfor return ind endfunction