Open zamlz opened 4 years ago
ledger itself actually supports inline math; you could do:
2020-06-17 * foo
Expenses:Foo (($13.50/54.75)*67.54)
Assets:Foo
Oh I was not aware of this. However, the journal file itself will still have the the unexpanded for right? I guess that's fine for my purposes. Thanks, I'll try this out next time I need to do this!
On Tue, Jun 16, 2020 at 5:04 PM Martin Michlmayr notifications@github.com wrote:
ledger itself actually supports inline math; you could do:
2020-06-17 foo Expenses:Foo (($13.50/54.75)67.54) Assets:Foo
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ledger/vim-ledger/issues/109#issuecomment-645071333, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACSAQS6B7MNJBNT2ZNTYBKLRXACARANCNFSM4N76G6NA .
Yes, the example I posted is a valid ledger transaction. If you run ledger on it, you'll see that ledger automatically calculates $16.65
I'm actually going to re-open this issue because I've wanted something like it myself ... and hledger
does not support inline math like this. Some way that the plugin could assist with math expressions would be nice. Passing them off to Lua or Python on a special command (not a completion per-se, just a command that can be invoked via a binding at any point) might be a very nice addition.
oh wow, so the few times ledger and hledger break compatibility is with this issue. Interesting, I originally started with hledger so maybe thats why I remember this not being a thing.
Okay lets take a look at this example real quick.
2020-06-18 Bought some food at place A
liabilities:credit-card $-44.67
assets:reimbursements:friend (($12.75/30.50)*44.67)
expenses:food:takeout ((($12.75+(2.0*2.50))/30.50)*44.67)
Firstly, the second expression doesn't evaluate properly in ledger, not sure why so but its not related to this project. More importantly, I noticed is that I can't press tab after I've entered the expression to auto align it with the ruler. Instead the expression gets deleted entirely. My vimrc has,
let g:ledger_maxwidth = 80
let g:ledger_align_at = 77
I'm not even sure I want to think about where this would align to. We haven't even properly fixed up the various ways a normal commodity and amount should align. Also that suggests that we'll definitely want a different keymap for completion vs. align vs. math.
I want to add to this that maybe having inline completion benefits ledger users too, not just hledger. I've been spliting bills with people and over the weeks and have been using inline expressions. Now the register report does print it out as rounded numbers, and using the report my friends were able to pay me back. But overtime, my god was I shocked when I saw that my friend somehow owed my a single cent lol. I guess internally, its keep track of the values as float which is an absolute no-no. and it carries over transactions. I converted them back actual values and rounded each of the transactions and my friends didn't owe me cents anymore. I'm not crazy for thinking it should be rounded right?
Sure, you can round my 0.50000001 bitcoins up to ₿1.00 any day.
Sarcasm aside, what would it round to? You do realize that even in USD micro transactions (smaller than 1¢) are a thing right?
Yeah I get that. But its weird when I look at the reg report and then tell my friend he owes me this much (from assets:reimbursements:friend1) and eventually after many different transactions with him, a couple cents start to appear there. Its just sitting there unaccounted for lol. Overtime it would become a noticeable sum. But thats very different from how a lot of bill splitting apps do things. The split the bill and round, and thats all there is to it. Its just a different use case I guess.
On Mon, Aug 10, 2020 at 2:42 PM Caleb Maclennan notifications@github.com wrote:
Sure, you can round my 0.50000001 bitcoins up to ₿1.00 any day.
Sarcasm aside, what would it round to? You do realize that even in USD micro transactions (smaller than 1¢) are a thing right?
— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/ledger/vim-ledger/issues/109#issuecomment-671604501, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACSAQSZU44FUVH4J4U5EWY3SABSULANCNFSM4N76G6NA .
Then pressing tab, evaluates the actual price?
See first comment on Using Vim as a calculator. Something similar could probably be incorporated into this plugin.
A useful use case, IMO, would be for automatic transactions which always require both ends:
= income:salary
bank:foo $1.234
savings:bar $1.293
investment:baz $1.939
bank:busines $-0.000 ; i.e we could have `:call ledger#balance_transaction()`
2022-04-05 Salary
bank:business $5.000
income:salary
Although, perhaps this would fall outside the scope of this issue?
@zanona That use case is pretty substantially different that what is being discussed in this issue. I suggest you open a new issue to even discuss that so we can keep this issue on topic. Thanks.
Something worth taking a look at might be the g=
operator tpope put in scriptease. It calls the builtin eval()
function over the motion/selection. This could probably be adapted for ledger.
I'm strongly tempted to close this as "won't fix". My reasoning is that it isn't anything specific to ledger at all and other solutions exist.
For example I've recently switched from deoplete to cmp for my general purpose completion handling (mostly for Lua instead of Python integration and more LSP/Treesitter/etc. sources available). Along with that I've enabled several sources by default. For ledger files I've only enabled one source: calc.
So now I have descriptions and accounts completing via this plugin and math expressions via cmp + calc. That seems to work fine for most basic math functions I would want.
For more advanced currency based expressions that will be left in ledger will handle them. If you want math expressions that complete on input I would suggest a completion framework with a math source.
That leaves one possible grey area: wanting to take valid ledger input and reduce it to something else using ledger
. For that I can see adding a function that passes the input though and gets a print back, but I don't have an example use case for this.
If somebody has a use for that third type of thing please speak up with example and what ledger command would need to be run to get an answer back. If there is anything we do with this third option it will probably be a paragraph format rule not a completion...
Hi, I would love if there was a math completion like feature request. I often find myself having to open up a python shell and doing some quick math but would be nice if I compute things from within the temrinal.
Something like,
Then pressing tab, evaluates the actual price? I don't know if this is possible but it would be pretty nice qol feature.