From dc0264aca176860f66b680d6e1f85abd8372dcb9 Mon Sep 17 00:00:00 2001 From: Johann Klähn Date: Sun, 22 Apr 2012 15:41:57 +0200 Subject: vim. set commentstring Fixes bug 528. --- contrib/vim/ftplugin/ledger.vim | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'contrib') 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 -- cgit v1.2.3 From 55256d7445a4429831c43478c7c90cb8d4fe267b Mon Sep 17 00:00:00 2001 From: Johann Klähn Date: Sun, 22 Apr 2012 15:42:28 +0200 Subject: vim. update syntax file --- contrib/vim/syntax/ledger.vim | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) (limited to 'contrib') diff --git a/contrib/vim/syntax/ledger.vim b/contrib/vim/syntax/ledger.vim index 73aaa0c3..c2962742 100644 --- a/contrib/vim/syntax/ledger.vim +++ b/contrib/vim/syntax/ledger.vim @@ -17,15 +17,23 @@ syntax clear " DATE[=EDATE] [*|!] [(CODE)] DESC <-- first line of transaction " ACCOUNT AMOUNT [; NOTE] <-- posting -syn region ledgerTransaction start=/^[[:digit:]~]/ skip=/^\s/ end=/^/ +syn region ledgerTransaction start=/^[[:digit:]~=]/ skip=/^\s/ end=/^/ \ fold keepend transparent contains=ledgerTransactionDate,ledgerMetadata,ledgerPosting 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=/^/ + \ fold 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 +42,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=ledgerApply 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 ledgerApply 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" -- cgit v1.2.3 From 5f85c72d082ac0fb482a7a9249c2d14300b73560 Mon Sep 17 00:00:00 2001 From: Johann Klähn Date: Sun, 22 Apr 2012 15:42:57 +0200 Subject: vim. add indent file Adresses Bug 529. --- contrib/vim/indent/ledger.vim | 46 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 contrib/vim/indent/ledger.vim (limited to 'contrib') 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 -- cgit v1.2.3 From 76ab0acaaa30b61b8482c4854f7f54eb92d0b6e8 Mon Sep 17 00:00:00 2001 From: Johann Klähn Date: Sun, 22 Apr 2012 16:02:27 +0200 Subject: vim. small fixes for syntax highlighting Also pre-declarations aren't folded anymore because the current 'foldexpr' does not make too much sense for them. --- contrib/vim/syntax/ledger.vim | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'contrib') diff --git a/contrib/vim/syntax/ledger.vim b/contrib/vim/syntax/ledger.vim index c2962742..c516bab0 100644 --- a/contrib/vim/syntax/ledger.vim +++ b/contrib/vim/syntax/ledger.vim @@ -18,7 +18,8 @@ syntax clear " ACCOUNT AMOUNT [; NOTE] <-- posting syn region ledgerTransaction start=/^[[:digit:]~=]/ skip=/^\s/ end=/^/ - \ fold keepend transparent contains=ledgerTransactionDate,ledgerMetadata,ledgerPosting + \ 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\%($\|;\)/ @@ -28,7 +29,7 @@ syn match ledgerPosting /^\s\+[^[:blank:];][^;]*\ze\%($\|;\)/ syn match ledgerAccount /^\s\+\zs\%(\S\@<= \S\|\S\)\+\ze\%( \|\t\|\s*$\)/ contained syn region ledgerPreDeclaration start=/^\(account\|payee\|commodity\|tag\)/ skip=/^\s/ end=/^/ - \ fold keepend transparent + \ keepend transparent \ contains=ledgerPreDeclarationType,ledgerPreDeclarationName,ledgerPreDeclarationDirective syn match ledgerPreDeclarationType /^\(account\|payee\|commodity\|tag\)/ contained syn match ledgerPreDeclarationName /^\S\+\s\+\zs.*/ contained @@ -43,7 +44,7 @@ syn match ledgerTag /\%(\%(;\|^tag\)[^:]\+\)\@<=[^:]\+:\ze[^:]\+$/ contained syn match ledgerTypedTag /\%(\%(;\|^tag\)[^:]\+\)\@<=[^:]\+::\ze[^:]\+$/ contained syn region ledgerApply - \ matchgroup=ledgerApply start=/^apply\>/ + \ matchgroup=ledgerStartApply start=/^apply\>/ \ matchgroup=ledgerEndApply end=/^end\s\+apply\>/ \ contains=ledgerApplyHead,ledgerApply,ledgerTransaction,ledgerComment syn match ledgerApplyHead /\%(^apply\s\+\)\@<=\S.*$/ contained @@ -53,7 +54,7 @@ highlight default link ledgerTransactionExpression Statement highlight default link ledgerMetadata Tag highlight default link ledgerTypedTag Keyword highlight default link ledgerTag Type -highlight default link ledgerApply Tag +highlight default link ledgerStartApply Tag highlight default link ledgerEndApply Tag highlight default link ledgerApplyHead Type highlight default link ledgerAccount Identifier -- cgit v1.2.3