Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Math Completion Feature Request #109

Open
zamlz opened this issue Jun 16, 2020 · 15 comments
Open

Math Completion Feature Request #109

zamlz opened this issue Jun 16, 2020 · 15 comments

Comments

@zamlz
Copy link

zamlz commented Jun 16, 2020

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,

$((13.50/54.75)*67.54)

Then pressing tab, evaluates the actual price? I don't know if this is possible but it would be pretty nice qol feature.

@tbm
Copy link

tbm commented Jun 17, 2020

ledger itself actually supports inline math; you could do:

2020-06-17 * foo
    Expenses:Foo        (($13.50/54.75)*67.54)
    Assets:Foo

@zamlz
Copy link
Author

zamlz commented Jun 17, 2020 via email

@zamlz zamlz closed this as completed Jun 17, 2020
@tbm
Copy link

tbm commented Jun 17, 2020

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

@alerque
Copy link
Member

alerque commented Jun 17, 2020

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.

@alerque alerque reopened this Jun 17, 2020
@zamlz
Copy link
Author

zamlz commented Jun 17, 2020

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.

@zamlz
Copy link
Author

zamlz commented Jun 18, 2020

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

@alerque
Copy link
Member

alerque commented Jun 18, 2020

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.

@zamlz
Copy link
Author

zamlz commented Aug 10, 2020

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?

@alerque
Copy link
Member

alerque commented Aug 10, 2020

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?

@zamlz
Copy link
Author

zamlz commented Aug 10, 2020 via email

@PerpetualCreativity
Copy link

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.

@zanona
Copy link

zanona commented Apr 3, 2022

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?

@alerque
Copy link
Member

alerque commented Apr 3, 2022

@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.

@parmort
Copy link
Contributor

parmort commented Aug 13, 2022

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.

@alerque
Copy link
Member

alerque commented Sep 13, 2022

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...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants