Single Line Ledger Entries

27 views
Skip to first unread message

Alex Simma

unread,
May 6, 2023, 10:30:33 AM5/6/23
to hledger
Hi, I thought I posted this before but it didn't show up so maybe it got spam filtered?

Has there been any consideration to adding support for allowing entries on a single line, where for example a delimiter character acts as a newline would in a normal entry?

For example,

2023/05/06   Dinner
    Asset:Bank   -$15.30
    Expense:Food  

could be written as

2023/05/06 Dinner   |   Asset:Bank   -$15.30   | Expense:Food

which has the advantage of allowing easy columnar entries with numbers aligned

2023/05/04 Dinner   |   Asset:Bank   -$12.10   | Expense:Food
2023/05/05 Dinner   |   Asset:Bank   -$18.22   | Expense:Food
2023/05/06 Dinner   |   Asset:Bank   -$15.30   | Expense:Food

Obviously, this can be done w/ a pre-processor (just regex replace the delimiter with newlines + indentation) but doing it within hledger would preserve line numbers in error messages, etc.  This whole thing started w/ me thinking about u sing a pre-processor for ledger like m4 and realizing that 90% of my needs would be met by these single-line entries + good use of vim.  The real value is all about keeping columns of numbers in like-entries aligned.

Henning Thielemann

unread,
May 6, 2023, 11:31:58 AM5/6/23
to hledger

On Sat, 6 May 2023, Alex Simma wrote:

> Hi, I thought I posted this before but it didn't show up so maybe it got spam filtered?
> Has there been any consideration to adding support for allowing entries on a single line, where for
> example a delimiter character acts as a newline would in a normal entry?
>
> For example,
>
> 2023/05/06   Dinner
>     Asset:Bank   -$15.30
>     Expense:Food  
>
> could be written as
>
> 2023/05/06 Dinner   |   Asset:Bank   -$15.30   | Expense:Food
>
> which has the advantage of allowing easy columnar entries with numbers aligned
>
> 2023/05/04 Dinner   |   Asset:Bank   -$12.10   | Expense:Food
> 2023/05/05 Dinner   |   Asset:Bank   -$18.22   | Expense:Food
> 2023/05/06 Dinner   |   Asset:Bank   -$15.30   | Expense:Food
>
> Obviously, this can be done w/ a pre-processor (just regex replace the delimiter with newlines +
> indentation) but doing it within hledger would preserve line numbers in error messages, etc.


What about CSV format and CSV import?

Alex Simma

unread,
May 6, 2023, 12:48:28 PM5/6/23
to hledger
Yeah, that's an option and the converter is very flexible so it can probably do almost everything that's needed.  However, it just feels weird to manually write CSVs w/ an editor... maybe that's in my head.  The other issue is that w/ the suggestion above, it's easy to have a bunch of types of entry in one file.  W/ CSVs, they all have to follow the same tabular format and while if statements in the rules file can turn different types of records into different types of ledger entries, that seems particularly awkward.

Nevertheless, it's definitely workable.  I still think my suggestion would be a valuable addition but maybe I'll try the CSV direction and see how that goes for my needs.


Simon Michael

unread,
May 6, 2023, 1:06:32 PM5/6/23
to hle...@googlegroups.com
Yes indeed - in between multi line journal format and tabular csv/tsv/data format there's an interesting format to try: just replacing the intra-entry newlines with something else as you say. I think double space or tab would work well.


Alex Simma

unread,
May 6, 2023, 1:47:59 PM5/6/23
to hledger
We may need a more explicit separator than whitespace, since whitespace also delimits between accounts and amounts for example, so the parsing could be ambiguous.  A tab could work though requiring hard tabs may be confusing for some users.  For clarity, I think a visible, explicit separator like |, ^, %, etc would be less surprising for most users.

One thing to keep in mind is that account names or descriptions can vary in length by quite a bit, more than the length of a tab, so space padding may still be needed.  EG (read in fixed width)
2023/05/05 Quick Dinner                       <Tab>Asset:Bank  -$15.20<Tab>Expense:Food
2023/05/06 Birthday Dinner at Fancy Restaurant<Tab>Asset:Bank  -$15.20<Tab>Expense:Food

Reply all
Reply to author
Forward
0 new messages