summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2010-03-04 13:41:35 -0500
committerJohn Wiegley <johnw@newartisans.com>2010-03-04 13:41:35 -0500
commit9143fbcdf13eb1d3601b37e8d8a3cdccacb90df1 (patch)
tree82c264de1672c7a3fa27d6934f869096817e78ee
parente5f4d54f14d8198a6eacddf38cc6ebdf5985bb06 (diff)
parent020c3fb2b64b8b59e509925e184d874b76b874de (diff)
downloadfork-ledger-9143fbcdf13eb1d3601b37e8d8a3cdccacb90df1.tar.gz
fork-ledger-9143fbcdf13eb1d3601b37e8d8a3cdccacb90df1.tar.bz2
fork-ledger-9143fbcdf13eb1d3601b37e8d8a3cdccacb90df1.zip
Merge remote branch 'kljohann/master' into next
-rw-r--r--contrib/vim/README2
-rw-r--r--contrib/vim/compiler/ledger.vim31
-rw-r--r--contrib/vim/syntax/ledger.vim25
3 files changed, 50 insertions, 8 deletions
diff --git a/contrib/vim/README b/contrib/vim/README
index 4da73ea6..368c9c71 100644
--- a/contrib/vim/README
+++ b/contrib/vim/README
@@ -2,7 +2,7 @@
This is the ledger filetype for vim.
Copy each file to the corresponding directory in your ~/.vim directory.
Then include the following line in your .vimrc or in ~/.vim/filetype.vim
- au BufNewFile,BufRead *.ldg,*.ledger setf ledger
+ au BufNewFile,BufRead *.ldg,*.ledger setf ledger | comp ledger
You can also use a modeline like this in every ledger file
vim:filetype=ledger
diff --git a/contrib/vim/compiler/ledger.vim b/contrib/vim/compiler/ledger.vim
new file mode 100644
index 00000000..33b019cb
--- /dev/null
+++ b/contrib/vim/compiler/ledger.vim
@@ -0,0 +1,31 @@
+" Vim Compiler File
+" Compiler: 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("current_compiler")
+ finish
+endif
+let current_compiler = "ledger"
+
+if exists(":CompilerSet") != 2
+ command -nargs=* CompilerSet setlocal <args>
+endif
+
+if ! exists("g:ledger_bin") || ! executable(g:ledger_bin)
+ if executable('ledger')
+ let g:ledger_bin = 'ledger'
+ else
+ echoerr "ledger command not found. Set g:ledger_bin or extend $PATH."
+ finish
+ endif
+endif
+
+" %-G throws away blank lines, everything else is assumed to be part of a
+" multi-line error message.
+CompilerSet errorformat=%-G,%EWhile\ parsing\ file\ \"%f\"\\,\ line\ %l:%.%#,%ZError:\ %m,%C%.%#
+
+" unfortunately there is no 'check file' command,
+" so we will just use a query that returns no results. ever.
+exe 'CompilerSet makeprg='.g:ledger_bin.'\ -f\ %\ reg\ not\ ''.*''\ \>\ /dev/null'
+
diff --git a/contrib/vim/syntax/ledger.vim b/contrib/vim/syntax/ledger.vim
index 8914cf2a..c96e4c3c 100644
--- a/contrib/vim/syntax/ledger.vim
+++ b/contrib/vim/syntax/ledger.vim
@@ -24,26 +24,37 @@ endif
" for debugging
syntax clear
-
+
+" DATE[=EDATE] [*|!] [(CODE)] DESC <-- first line of transaction
+" ACCOUNT AMOUNT [; NOTE] <-- posting
+
" region: a transaction containing postings
syn region transNorm start=/^[[:digit:]~]/ skip=/^\s/ end=/^/
- \ fold keepend transparent contains=transDate, Metadata, Posting
+ \ fold keepend transparent contains=transDate,Metadata,Posting
syn match transDate /^\d\S\+/ contained
-syn match Metadata /^\s\+;.*/ contained
+syn match Metadata /^\s\+;.*/ contained contains=MetadataTag
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
+syn match Posting /^\s\+[^[:blank:];].*$/ contained transparent contains=Account,Amount
+" FIXME: add other symbols?
+let s:currency = '\([$€£¢]\|\w\+\)'
+let s:figures = '\d\+\([.,]\d\+\)*'
+let s:amount = '-\?\('.s:figures.'\s*'.s:currency.'\|'.s:currency.'\s*'.s:figures.'\)'
+exe 'syn match Amount /'.s:amount.'/ contained'
+syn match MetadataTag /:\zs[^:]\+\ze:\|;\s*\zs[^:]\+\ze:[^:]\+$/ contained
-highlight default link transDate Question
-highlight default link Metadata PreProc
+highlight default link transDate Constant
+highlight default link Metadata Tag
+highlight default link MetadataTag Type
+highlight default link Amount Number
highlight default link Comment Comment
highlight default link Account Identifier
" syncinc is easy: search for the first transaction.
syn sync clear
-syn sync match ledgerSync grouphere transNorm "^\d"
+syn sync match ledgerSync grouphere transNorm "^[[:digit:]~]"
let b:current_syntax = "ledger"