diff options
author | John Wiegley <johnw@newartisans.com> | 2012-04-26 16:39:25 -0500 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2012-04-26 16:39:25 -0500 |
commit | 64a9b42381c26baf24e58b40f50f0b253e551811 (patch) | |
tree | 5447a29dff64c3a8b7be8100a01bcb4a2d73b0bb /contrib | |
parent | 7cc550fc22357e2ded194d3e65287c6b3317f5ae (diff) | |
parent | b4407c10c0071365322b2963747bf42a57fd7304 (diff) | |
download | fork-ledger-64a9b42381c26baf24e58b40f50f0b253e551811.tar.gz fork-ledger-64a9b42381c26baf24e58b40f50f0b253e551811.tar.bz2 fork-ledger-64a9b42381c26baf24e58b40f50f0b253e551811.zip |
Merge branch 'release/v3.0.0-20120426'
Diffstat (limited to 'contrib')
-rw-r--r-- | contrib/vim/ftplugin/ledger.vim | 3 | ||||
-rw-r--r-- | contrib/vim/indent/ledger.vim | 46 | ||||
-rw-r--r-- | contrib/vim/syntax/ledger.vim | 34 |
3 files changed, 72 insertions, 11 deletions
diff --git a/contrib/vim/ftplugin/ledger.vim b/contrib/vim/ftplugin/ledger.vim index 63de88b5..0067f9f8 100644 --- a/contrib/vim/ftplugin/ledger.vim +++ b/contrib/vim/ftplugin/ledger.vim @@ -11,7 +11,7 @@ let b:did_ftplugin = 1 let b:undo_ftplugin = "setlocal ". \ "foldmethod< foldtext< ". - \ "include< comments< omnifunc< formatprg<" + \ "include< comments< commentstring< omnifunc< formatprg<" " don't fill fold lines --> cleaner look setl fillchars="fold: " @@ -19,6 +19,7 @@ setl foldtext=LedgerFoldText() setl foldmethod=syntax setl include=^!include setl comments=b:; +setl commentstring=;%s setl omnifunc=LedgerComplete " set location of ledger binary for checking and auto-formatting diff --git a/contrib/vim/indent/ledger.vim b/contrib/vim/indent/ledger.vim new file mode 100644 index 00000000..ce5d508d --- /dev/null +++ b/contrib/vim/indent/ledger.vim @@ -0,0 +1,46 @@ +" Vim filetype indent file +" filetype: ledger +" by Johann Klähn; Use according to the terms of the GPL>=2. +" vim:ts=2:sw=2:sts=2:foldmethod=marker + +if exists("b:did_indent") + finish +endif +let b:did_indent = 1 + +setl autoindent +setl indentexpr=GetLedgerIndent() + +if exists("*GetLedgerIndent") + finish +endif + +function GetLedgerIndent(...) + " You can pass in a line number when calling this function manually. + let lnum = a:0 > 0 ? a:1 : v:lnum + " If this line is empty look at (the indentation of) the last line. + " Note that inside of a transaction no blank lines are allowed. + let line = getline(lnum) + let prev = getline(lnum - 1) + + if line =~ '^\s\+\S' + " Lines that already are indented (→postings, sub-directives) keep their indentation. + return &sw + elseif line =~ '^\s*$' + " Current line is empty, try to guess its type based on the previous line. + if prev =~ '^\([[:digit:]~=]\|\s\+\S\)' + " This is very likely a posting or a sub-directive. + " While lines following the start of a transaction are automatically + " indented you will have to indent the first line following a + " pre-declaration manually. This makes it easier to type long lists of + " 'account' pre-declarations without sub-directives, for example. + return &sw + else + return 0 + endif + else + " Everything else is not indented: + " start of transactions, pre-declarations, apply/end-lines + return 0 + endif +endf diff --git a/contrib/vim/syntax/ledger.vim b/contrib/vim/syntax/ledger.vim index 73aaa0c3..c516bab0 100644 --- a/contrib/vim/syntax/ledger.vim +++ b/contrib/vim/syntax/ledger.vim @@ -17,15 +17,24 @@ syntax clear " DATE[=EDATE] [*|!] [(CODE)] DESC <-- first line of transaction " ACCOUNT AMOUNT [; NOTE] <-- posting -syn region ledgerTransaction start=/^[[:digit:]~]/ skip=/^\s/ end=/^/ - \ fold keepend transparent contains=ledgerTransactionDate,ledgerMetadata,ledgerPosting +syn region ledgerTransaction start=/^[[:digit:]~=]/ skip=/^\s/ end=/^/ + \ fold keepend transparent + \ contains=ledgerTransactionDate,ledgerMetadata,ledgerPosting,ledgerTransactionExpression syn match ledgerTransactionDate /^\d\S\+/ contained +syn match ledgerTransactionExpression /^[=~]\s\+\zs.*/ contained syn match ledgerPosting /^\s\+[^[:blank:];][^;]*\ze\%($\|;\)/ \ contained transparent contains=ledgerAccount,ledgerMetadata " every space in an account name shall be surrounded by two non-spaces " every account name ends with a tab, two spaces or the end of the line syn match ledgerAccount /^\s\+\zs\%(\S\@<= \S\|\S\)\+\ze\%( \|\t\|\s*$\)/ contained +syn region ledgerPreDeclaration start=/^\(account\|payee\|commodity\|tag\)/ skip=/^\s/ end=/^/ + \ keepend transparent + \ contains=ledgerPreDeclarationType,ledgerPreDeclarationName,ledgerPreDeclarationDirective +syn match ledgerPreDeclarationType /^\(account\|payee\|commodity\|tag\)/ contained +syn match ledgerPreDeclarationName /^\S\+\s\+\zs.*/ contained +syn match ledgerPreDeclarationDirective /^\s\+\zs\S\+/ contained + syn match ledgerComment /^;.*$/ " comments at eol must be preceeded by at least 2 spaces / 1 tab syn region ledgerMetadata start=/\%( \|\t\|^\s\+\);/ skip=/^\s\+;/ end=/^/ @@ -34,22 +43,27 @@ syn match ledgerTag /:[^:]\+:/hs=s+1,he=e-1 contained syn match ledgerTag /\%(\%(;\|^tag\)[^:]\+\)\@<=[^:]\+:\ze[^:]\+$/ contained syn match ledgerTypedTag /\%(\%(;\|^tag\)[^:]\+\)\@<=[^:]\+::\ze[^:]\+$/ contained -syn region ledgerTagStack - \ matchgroup=ledgerTagPush start=/^tag\>/ - \ matchgroup=ledgerTagPop end=/^pop\>/ - \ contains=ledgerTagHead,ledgerTagStack,ledgerTransaction,ledgerComment -syn match ledgerTagHead /\%(^tag\s\+\)\@<=\S.*$/ contained contains=ledgerTag transparent +syn region ledgerApply + \ matchgroup=ledgerStartApply start=/^apply\>/ + \ matchgroup=ledgerEndApply end=/^end\s\+apply\>/ + \ contains=ledgerApplyHead,ledgerApply,ledgerTransaction,ledgerComment +syn match ledgerApplyHead /\%(^apply\s\+\)\@<=\S.*$/ contained highlight default link ledgerTransactionDate Constant +highlight default link ledgerTransactionExpression Statement highlight default link ledgerMetadata Tag highlight default link ledgerTypedTag Keyword highlight default link ledgerTag Type -highlight default link ledgerTagPop Tag -highlight default link ledgerTagPush Tag +highlight default link ledgerStartApply Tag +highlight default link ledgerEndApply Tag +highlight default link ledgerApplyHead Type highlight default link ledgerAccount Identifier +highlight default link ledgerPreDeclarationType Type +highlight default link ledgerPreDeclarationName Identifier +highlight default link ledgerPreDeclarationDirective Type " syncinc is easy: search for the first transaction. syn sync clear -syn sync match ledgerSync grouphere ledgerTransaction "^[[:digit:]~]" +syn sync match ledgerSync grouphere ledgerTransaction "^[[:digit:]~=]" let b:current_syntax = "ledger" |