On 8/18/2012 3:05 AM, Maxim Philippov wrote:
суббота, 18 августа 2012 г., 0:51:46 UTC+4 пользователь Vlad Irnov написал:
There are plugins that implement REPL-like behavior:

http://www.vim.org/scripts/script.php?script_id=3484

http://www.vim.org/scripts/script.php?script_id=3327

http://www.vim.org/scripts/script.php?script_id=3231

and probably other.


It makes no sense for :python commands to behave differently from

other commands. That is, we currently need to type

:echo 2+2

to see the result, why :python should be different?

Though this scripts are useful, I think typing ":py 2+2" is more fluent (and maybe more 
lightweight) than ":PyInteractiveEval 2+2" or running full REPL session.

We need to type ":echo 2+2" because of the vim's script syntax, ":4" by itself 
is a command, there is no need for this in python.

Often I forget to call "print" because as a python user I expect expression 
result to be printed automatically. It is difficult to switch from python REPL to vim's 
current implementation, so why not have the best from both worlds? =)


A macro like

   py3<<EOL
   def python_with_print(*args):
      global py_res
      py_res=None
      try:
          eval(compile('py_res='+'
   '.join(args),'<string>','exec'),globals())
      except:
          eval(compile(' '.join(args),'<string>','exec'),globals())
      print(py_res)
   EOL
   command! -narg=* Py py3 python_with_print(<f-args>)

in $MYVIMRC
would allow you to write

   :Py from math import *
   :Py sin(30*pi/180)

an you would get results or None on the command line.

Regards,
Roland

--
You received this message from the "vim_dev" 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

Raspunde prin e-mail lui