New metadata/note syntax

113 views
Skip to first unread message

John Wiegley

unread,
Feb 1, 2009, 9:50:44 PM2/1/09
to ledge...@googlegroups.com
Ledger 3.0 now supports entry and transaction "notes", which may
contain new metadata and tag markers. Here's an example:

2004/05/27 (100) Credit card company
; This is an entry note!
; Sample: Value
Liabilities:MasterCard $20.00
; This is a transaction note!
; Sample: Another Value
; :MyTag:
Assets:Bank:Checking
; :AnotherTag:

An indented paragraph starting with ';' is parsed as a persistent note
for its preceding category. These notes will get printed back to you
with the "print" command. They are accessible to value expressions
using the "note" variable.

Further, any occurrence of ":foo:" in a note will cause a metadata tag
for "foo" to be registered for that entry. You can then search for
such transactions using:

ledger reg %foo
ldeger reg tag foo

Also, if any word in the note ends (but does not start) with a colon,
the remainder of that line will be taken to be the metadata value for
that tag. That is:

; :foo:bar:baz: <-- These are three tags
; name: value <-- this is a tag with a value

Tags with value can be searched for just like tags. In addition, you
can further limit your tag search by looking for only those tags that
have specific values:

ledger reg %name=value
ledger reg tag name=value

Comments that are occur before an entry, or which starts at column
zero, are always ignored and are neither searched nor printed back.

John

Vinod Kurup

unread,
Feb 2, 2009, 8:51:04 AM2/2/09
to Ledger
This is cool! Now I can add

; :taxable

to any entry that I think might have implications at income-tax time,
without dirtying up my account hierarchy.

I'm going to have to start trying out 3.0.

John Wiegley

unread,
Feb 2, 2009, 2:09:39 PM2/2/09
to ledge...@googlegroups.com
On Feb 2, 2009, at 9:51 AM, Vinod Kurup wrote:

> This is cool! Now I can add
>
> ; :taxable

It needs to be ":taxable:" to be considered a tag.

> I'm going to have to start trying out 3.0.

It's still a touch rough, but it's all I use nowadays. Please let me
know of any problems you find, so I can get it up to basic usage
standards asap!

Thanks, John

Manish

unread,
Feb 2, 2009, 2:16:48 PM2/2/09
to ledge...@googlegroups.com

How do I get 3.0? Latest pull from git://github.com/jwiegley/ledger.git
does not seem to show it.

--
Manish

John Wiegley

unread,
Feb 2, 2009, 2:21:58 PM2/2/09
to ledge...@googlegroups.com
On Feb 2, 2009, at 3:16 PM, Manish wrote:

> How do I get 3.0? Latest pull from git://github.com/jwiegley/
> ledger.git
> does not seem to show it.

Just follow the master branch, that's 3.0pre.

John

Johann Klähn

unread,
Mar 24, 2009, 5:41:31 PM3/24/09
to Ledger
I've updated the vim syntax file to allow those metadata-comments and
align properly for multi-byte-characters:

if version < 600
syntax clear
elseif exists("b:current_sytax")
finish
endif

" for debugging
syntax clear

" region: a normal posting
syn region postNorm start=/^\d/ skip=/^\s/ end=/^/ fold keepend
transparent contains=postDate,Metadata
syn match postDate /^\d\S\+/ contained
syn match Metadata /^\s\+;.*$/ contained
syn match Comment /^;.*$/

highlight default link Comment SpecialKey
highlight default link Metadata SpecialKey
highlight default link postDate Question

" folding: how to represent a posting in one line.
function! LedgerFoldText()
let line = strpart(getline(v:foldstart), 0, 99)
let amount = ""

let delta = 1
while (delta >= 1 && delta < (v:foldend-v:foldstart+1))
let other_line = getline(v:foldstart+delta)

if len(matchstr(other_line, '^\s\+;')) != 0
" Skip metadata/leading comment
let delta = delta + 1
else
" No comment, look for amount...
let delta = -1
let lst = matchlist(other_line,'\(\%([0-9]\+[,.]\)\=[0-9]\+\%
([,.][0-9]\+\)\=\|[,.][0-9]\+\)\s*\%([A-Za-z$€¢]\+\s*\)\=\%(\s*;.*\)\=
$')
if (len(lst) != 0)
let amount = lst[1]
endif
endif
endwhile

" Replace each char with x prior to counting
" this fixes problems with multi byte characters
let pad_len = 80 - strlen(substitute(line, ".", "x", "g")) - strlen
(substitute(amount, ".", "x", "g"))

if (pad_len < 0)
pad_len = 0
endif
let pad = strpart
("
", 0, pad_len)
return line . pad . amount
endfunction
set foldtext=LedgerFoldText()
set foldmethod=syntax

" syncinc is easy: search for the first posting.
syn sync clear
syn sync match ledgerSync grouphere postNorm "^\d"

let b:current_syntax = "ledger"

Johann Klähn

unread,
Mar 25, 2009, 7:16:15 AM3/25/09
to Ledger
Sorry, this came in totally delayed. I tried to post it, but it didn't
show up, so I sent you the mail.
Reply all
Reply to author
Forward
0 new messages