Glad it helped. I'll post the python file if I find it. Meanwhile, here is 
a dummy skeleton of a vim function written in python to serve as an 
example. I find these useful to save for somewhat rare (say once/twice a 
year) but repeated transformations. Eg: stock splits. I can never remember 
the syntax of vimscript since I rarely use it, and hence, writing these in 
python helps.

# to be run on bean-doctor context output inside vim
function! CapGains()
python3 << EOF
import vim
from decimal import Decimal

line = vim.current.line
s = line.split()
account = s[0].replace('Assets', 'Income')
vim.current.line = f'{line} ; Hello world: {account}'
EOF
endfunction


On Saturday, June 5, 2021 at 12:59:13 AM UTC-7 [email protected] 
wrote:

> Thanks, some neat ideas there! :D
>
> On Saturday, 5 June 2021 at 3:04:46 pm UTC+10 [email protected] wrote:
>
>> On Friday, June 4, 2021 at 8:40:54 PM UTC-7 [email protected] 
>> wrote:
>>
>>> Apologies for bumping an old thread with an off-topic question, but 
>>> Redstreet, you said:
>>>
>>> > I personally have a vim plugin that uses bean-doctor context to insert 
>>> the lots.
>>>
>>> This is really interesting; I wonder if this is something that's openly 
>>> available or if it's a personal hack whether you'd be interested in 
>>> sticking it on Github?
>>>
>>
>> For conversions, it's trivial: it's a 2 or 3 line python script that 
>> scales the units and cost fields. When I have an imported transaction that 
>> looks like:
>>
>> 2000-01-01 * "Upgrade shares"
>>   Assets:XTrade:ABC -234.15 ABC
>>   Assets:XTrade:DEF 175.45 DEF
>>
>> Then what I do is: get beancount context (I've mapped this to '\g' in 
>> vim-beancount), which opens the context in a split. I then select (visual 
>> mode) all the ABC lots, and pipe it through the python script. An 
>> equivalent awk script would look roughly like:
>>
>> :'<,'>!awk '{print $1, -$2*(175.45/234.15), $3, $4, $5*(234.15/175.45), 
>> $6, $7}'
>>
>> My python script just made this easier by spitting out both sides of the 
>> transaction (DEF as well), and accepting parameters for the scale value.
>>
>>
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/beancount/66c6371e-66ee-422b-b6a6-458a1fc5689fn%40googlegroups.com.

Reply via email to