Tuesday, November 26, 2013

Re: vim rpn calculator

Thank you again Gary, with your help this works:

function! RPN()
let save = &lazyredraw | set lazyredraw
normal! YpI2 k
normal! A n
exec "normal! !!dc\<cr>"
let &lazyredraw = save
endfun
imap <silent> ,= <esc>:call RPN()<cr>A

" .......1.........2.........3.........4.........5.........6....
But when I got frustrated with that,
I tried a different approach which works:

function! RPN()
normal! 0y$
let @c = system("dc '-e2k " . @@ . " n'") . " "
put c
endfun
imap <silent> ,= <esc>:call RPN()<cr>A

" .......1.........2.........3.........4.........5.........6....
I think I should be able to do something like:

function! RPN(calc)
let @c = system("dc '-e2k " . a:calc . " n'") . " "
put c
endfun
imap <silent> ,= 0y$<esc>:call RPN(@@)<cr>A

I cannot pass the yank to the function.
Is it possible?

Bill

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: