Advertisement
tarruda

Multi-threaded vim plugin

Dec 4th, 2013
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VIM 0.76 KB | None | 0 0
  1. python << EOF
  2. import vim
  3. from random import randint
  4. from time import sleep
  5. from threading import Thread
  6.  
  7. data = {
  8.     'produced': [],
  9.     'producer': None,
  10.     'stop': False
  11. }
  12.  
  13. def produce():
  14.     while not data['stop']:
  15.     sleep(2)
  16.     for i in xrange(1, 10):
  17.         data['produced'].append(randint(0, i) * 5)
  18.     vim.command("call defer('Consume')")
  19.     sleep(2)
  20. EOF
  21.  
  22. function Produce()
  23. python << EOF
  24. data['stop'] = False
  25. data['producer'] = Thread(target=produce)
  26. data['producer'].start()
  27. EOF
  28. endfunction
  29.  
  30. function Consume()
  31. python << EOF
  32. vim.current.buffer.append('Generated by separate thread: -- %s --' % ', '.join(map(str, data['produced'])))
  33. data['produced'] = []
  34. EOF
  35. endfunction
  36.  
  37. function Stop()
  38. python << EOF
  39. data['stop'] = True
  40. EOF
  41. endfunction
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement