diff options
| author | Teddy Wing | 2015-10-06 04:02:00 -0400 |
|---|---|---|
| committer | Teddy Wing | 2015-10-06 04:02:00 -0400 |
| commit | 1307eacc9e6aff2213f909d3c30fdfb15c6c8050 (patch) | |
| tree | f6700ec8837da891270f2ff62cf1e6a8e063c17f | |
| parent | d0d55b5cba2950bafe42703735c705e56f6d25b4 (diff) | |
| download | vim-space-vlaze-1307eacc9e6aff2213f909d3c30fdfb15c6c8050.tar.bz2 | |
random.vim: Use :python
Ostensibly this should work and generate us a random number using Python
without having to call `system`. My hope is that this call doesn't block
rendering and execution of our game.
The trouble is that I can't get it to work because I have Python 2.7.1
installed as my system Python (which Vim is linked against), and Python
2.7.9 installed via Homebrew. Vim is looking in the Homebrew path when
it should be looking in the system path to Python and causing this
error:
Error detected while processing function space_vlaze#random#Random:
line 7:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/random.py", line 47, in <module>
from os import urandom as _urandom
ImportError: cannot import name urandom
More information:
- https://github.com/klen/python-mode/issues/87
We could get around this by not having these 2 versions of Python
installed on our system (the random implementation changed between 2.7.2
and 2.7.3) or by setting `$PYTHONHOME` in our vimrc.
Could, but I'm sick of this shite. Would have liked to be able to use
Python for this because in my opinion Python tends to be pretty fast as
interpreted languages go, but frak it I'll just use Ruby.
| -rw-r--r-- | autoload/space_vlaze/random.vim | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/autoload/space_vlaze/random.vim b/autoload/space_vlaze/random.vim index b3b151e..aef422d 100644 --- a/autoload/space_vlaze/random.vim +++ b/autoload/space_vlaze/random.vim @@ -3,5 +3,11 @@ " From: " http://vi.stackexchange.com/questions/807/how-to-generate-random-numbers/812#812 function! space_vlaze#random#Random(max) - return system('python -c "import random; print(random.randint(0, ' . a:max . '))"') + python << EOS +import random +import vim +r = random.randint(0, vim.eval('a:max')) +vim.command('let r = %d' % r) +EOS + return r endfunction |
