From b96df34d75e9c0afde5b1706c00a6c8a58b2fff4 Mon Sep 17 00:00:00 2001 From: Johann Klähn Date: Mon, 15 Jun 2009 23:37:57 +0200 Subject: ledger.vim: split into multiple files for better extendability --- contrib/vim/syntax/ledger.vim | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 contrib/vim/syntax/ledger.vim (limited to 'contrib/vim/syntax/ledger.vim') diff --git a/contrib/vim/syntax/ledger.vim b/contrib/vim/syntax/ledger.vim new file mode 100644 index 00000000..aac6c2fa --- /dev/null +++ b/contrib/vim/syntax/ledger.vim @@ -0,0 +1,43 @@ +" Vim syntax file +" filetype: ledger +" Version: 0.1.0 +" by Johann Klähn; Use according to the terms of the GPL>=2. +" by Stefan Karrmann; Use according to the terms of the GPL>=2. +" by Wolfgang Oertl; Use according to the terms of the GPL>=2. +" Revision history +" 2009-06-12 J. Klähn: Use all available columns for foldtext +" 2009-03-25 J. Klähn: Allow Metadata +" in transactions and postings (Ledger 3.0) +" Also fixed alignment for multi-byte-characters +" 2009-01-28 S.Karrmann: minor fixes +" 2009-01-27 third version by S.Karrmann. +" better extraction of the amount of the posting +" decimal separator can be one of '.' and ','. +" 2005-02-05 first version (partly copied from ledger.vim 0.0.1) +" vim:ts=2:sw=2:sts=2:foldmethod=marker + +if version < 600 + syntax clear +elseif exists("b:current_sytax") + finish +endif + +" for debugging +syntax clear + +" region: a transaction containing postings +syn region transNorm start=/^\d/ skip=/^\s/ end=/^/ + \ fold keepend transparent contains=transDate, Metadata +syn match transDate /^\d\S\+/ contained +syn match Metadata /^\s\+;.*/ contained +syn match Comment /^;.*$/ + +highlight default link Comment SpecialKey +highlight default link Metadata SpecialKey +highlight default link transDate Question + +" syncinc is easy: search for the first transaction. +syn sync clear +syn sync match ledgerSync grouphere transNorm "^\d" + +let b:current_syntax = "ledger" -- cgit v1.2.3 From 9701548f7e634f9a19295e34f624264343b78f0b Mon Sep 17 00:00:00 2001 From: Johann Klähn Date: Wed, 17 Jun 2009 12:40:50 +0200 Subject: vim: highlight account names This helps to avoid confusion when an account is not seperated from the amount by two spaces or a tab but only by one space. In these cases the amount will now be highlighted as if it belongs to the account name. Thanks to user 'plaindocs' for reporting this. --- contrib/vim/ftplugin/ledger.vim | 2 +- contrib/vim/syntax/ledger.vim | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) (limited to 'contrib/vim/syntax/ledger.vim') diff --git a/contrib/vim/ftplugin/ledger.vim b/contrib/vim/ftplugin/ledger.vim index 4e8bfcf1..cef0d81e 100644 --- a/contrib/vim/ftplugin/ledger.vim +++ b/contrib/vim/ftplugin/ledger.vim @@ -85,7 +85,7 @@ function! s:multibyte_strlen(text) "{{{2 return strlen(substitute(a:text, ".", "x", "g")) endfunction "}}} -function s:get_columns(win) "{{{2 +function! s:get_columns(win) "{{{2 " As long as vim doesn't provide a command natively, " we have to compute the available columns. " see :help todo.txt -> /Add argument to winwidth()/ diff --git a/contrib/vim/syntax/ledger.vim b/contrib/vim/syntax/ledger.vim index aac6c2fa..1c1968e4 100644 --- a/contrib/vim/syntax/ledger.vim +++ b/contrib/vim/syntax/ledger.vim @@ -26,15 +26,21 @@ endif syntax clear " region: a transaction containing postings -syn region transNorm start=/^\d/ skip=/^\s/ end=/^/ - \ fold keepend transparent contains=transDate, Metadata +syn region transNorm start=/^[[:digit:]~]/ skip=/^\s/ end=/^/ + \ fold keepend transparent contains=transDate, Metadata, Posting syn match transDate /^\d\S\+/ contained syn match Metadata /^\s\+;.*/ contained syn match Comment /^;.*$/ +" 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 Account /^\s\+\zs\%(\S\|\S \S\)\+\ze\%([ ]\{2,}\|\t\s*\|\s*$\)/ contained +syn match Posting /^\s\+[^[:blank:];].*$/ contained transparent contains=Account + -highlight default link Comment SpecialKey -highlight default link Metadata SpecialKey highlight default link transDate Question +highlight default link Metadata PreProc +highlight default link Comment Comment +highlight default link Account Identifier " syncinc is easy: search for the first transaction. syn sync clear -- cgit v1.2.3