bradyt / cone

A ledger.
https://cone.tangential.info
20 stars 5 forks source link

Match formatting of ledger-mode fill-paragraph function #33

Closed bradyt closed 4 years ago

bradyt commented 4 years ago

Issue raised by a user on IRC.

Right now, posting indent is two spaces, and amounts are right aligned just far enough to ensure there are two spaces of separation between account names and amounts.

This is done to make sure transactions have minimum visual wrapping on small mobile device screens.

We will revisit this once the file is being parsed (using ad-hoc regex, most likely) sufficiently to present transactions as cards. At that point, the formatting in the file will not effect the view in home page.

At that time, we might set the defaults to whatever emacs -Q and ledger-mode.el give us, for indent and column. (four and eighty? seventy-two?) Potentially, we could look for a first parsed transaction to get different indent and column settings. But that might be broken out into a separate issue if someone feels strongly enough.

bradyt commented 4 years ago

Ah, I think ledger-mode right aligns the numerical part to column fifty-two, and indents posting four spaces.

bradyt commented 4 years ago

At v0.2.14+22, the transaction view uses a parsed transaction, so the home page view no longer blocks whether we should write to disk at column 52 or similar.

bradyt commented 4 years ago

This issue was raised by another IRC user, and more discussion, on #plaintextaccounting. We can probably detect from the ledger file some defaults. Indentation should be easier. For alignment column, I think hledger in some places uses a heuristic, searching for the last period or comma in a number. We should use that idea for setting column. Otherwise, we just use position of last number.

ghost commented 4 years ago

(continuation of https://github.com/bradyt/cone/issues/48#issuecomment-549188416)

I think a nice system could be set up by having the user optionally provide format strings, since it would allow for a very flexible format.

Here's an example in python:

>>> "    {acc:<36}{amt:>20}".format(acc="test", amt="RSD200")
'    test                                              RSD200'
>>> "    {acc:<36}{amt:>20}".format(acc="asdasdtest", amt="RSDdasda200")
'    asdasdtest                                   RSDdasda200'
>>>
bradyt commented 4 years ago

@w1d3m0d3 What do you think about just adding a sample transaction to an auxiliary journal file, that cone could derive the indentation and alignment from? That seems more idiomatic to how existing plain text accounting apps work.

ghost commented 4 years ago

@bradyt it is, indeed, more idiomatic to PTAs, but it has the disadvantage of it being a sort of a "guessing game", it could work, though, as an example of what I meant:

1970-01-01 description
    account                                          value0.0

Does this mean that there needs to be 42 spaces between the account and value or that the decimal point should be at column 60, also, does this mean one decimal is used? What I'm getting at is that it would potentially be unable to match some weird formatting preference someone may have, however configuration options are really not in the spirit of PTA tools, as far as I can tell

bradyt commented 4 years ago

Here is how ledger-mode formats with the defaults:

1970-01-01 description
    a:b                                         1.00 EUR
    c:d:e                                      21.00 EUR
    f                                         -22.00 EUR
bradyt commented 4 years ago

Simon pointed out a related issue in chat: https://github.com/simonmichael/hledger/issues/1045.

bradyt commented 4 years ago

Presumably fixed at https://github.com/bradyt/cone/commit/e1099db5399ad724dbea4c413120e30ca609ab3a.

You're all welcome to discuss the ideas further, here, or in chat, or if you decide there's a more appropriate existing or new issue.