vim-ledger icon indicating copy to clipboard operation
vim-ledger copied to clipboard

Add alternate alignment method(s) for commodity, amount, and unit costs

Open avinash311 opened this issue 6 years ago • 5 comments

    Assets:Bank:ABC:Savings                            $100
    Assets:Bank:XXCanada                    50,000 CAD @ $0.72

LedgerAlign incorrectly uses the decimal point of the unit cost above to align. It should use the first number for alignment instead. Essentially: NUMBER should always align the NUMBER.

avinash311 avatar Jul 14 '19 18:07 avinash311

Really? IMO it should always align at the decimal point. It's just that in your example the $100 is missing the decimal. It is not consistent... but aligns properly.

If you put a total under $100 and $0.72 it must be aligned at the decimal point. This is the point of numeric alignment.




boydkelly avatar Jul 14 '19 19:07 boydkelly

I'm not sure I agree that this is incorrect. In fact I recently merged somebody else's contribution (11a27b44835d65e4533c5ddfeed725f90f85b6d3) that "fixes" the previous behavior by handling the case where no decimal separator is found and guessing where it would be. As in @boydkelly I would argue that this is the best way to align numbers.

Additionally note that both ledger print and hledger print get around this by adding the decimal places on for numbers that do not have them, .00 would get appended to your $100.

There is also an open issue on hledger for fixing the print command to format based on commodity decimal separators.

If you really want to see flush alignments of the amount field that disregard the decimal separator it will need to be added as an optional config flag that sets the alignment mode to a "dumber" algorithm.

alerque avatar Jul 15 '19 06:07 alerque

emacs does it the way I described. That seems more reasonable to me - align all commodities at the commodity amount, and not at the commodity unit price.

If at all, a config mode to make it a bit more like emacs (need not be exact - even the emacs mode behavior may be debatable as to how to handle missing decimal - but the emacs mode always aligns the commodity amount, and not the commodity unit price):

Emacs:

    Assets:Bank:ABC:Savings                     $100
    Assets:Bank:AACanada                      50,000 CAD @ $0.70

or
    Assets:Bank:ABC:Savings                  $100.00
    Assets:Bank:AACanada                      50,000 CAD @ $0.70
or
    Assets:Bank:ABC:Savings                  $100.00
    Assets:Bank:AACanada                   50,000.00 CAD @ $0.70
or
    Assets:Bank:ABC:Savings                     $100
    Assets:Bank:AACanada                   50,000.00 CAD @ $0.70


avinash311 avatar Jul 15 '19 10:07 avinash311

What you just described @avinash311 is almost a completely different issue that what we were replying to! Note that vim-ledger currently has virtually no understanding of what is "commodity" vs. "unit price" vs. "cost" amounts.

As a point of opinion I would argue (as I did in this comment on the related hledger issue) that the commodity rate/total cost is more likely to be the "correct" thing to line up by default because it is more likely to at least be the same currency as the other postings than in your examples (which all line up un-like commodities).

Since the plugin doesn't actually parse the ledger format or understand all the things that could go there I assume the best way to do what you want would be to offer options to line up either the first or the last space separated number. A second option could define whether to align on the raw digits of the number or the decimal location.

I don't plan on implementing this myself any time soon but would be quite happy to review and merge any contribution that wanted to offer a reasonable implementation of both behaviors.

alerque avatar Jul 15 '19 10:07 alerque

As of #107 being merged there is now one more alignment option on the table. This still needs an overhaul, but it's one little step.

alerque avatar Mar 06 '21 14:03 alerque