summaryrefslogtreecommitdiff
path: root/autoload/l9/async.vim
blob: fa66e9f1b3932d69bee7eb28b51d8205a7f88d33 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
"=============================================================================
" Copyright (C) 2009-2010 Takeshi NISHIDA
"
"=============================================================================
" LOAD GUARD {{{1

if !l9#guardScriptLoading(expand('<sfile>:p'), 0, 0, ['has("python")'])
  finish
endif

" }}}1
"=============================================================================
" ASYNC EXECUTE {{{1

"
function s:checkKey(key)
  if a:key =~ '\n' || a:key !~ '\S'
    throw "Asyncer: Invalid key: " . a:key
  endif
endfunction

" 
function l9#async#execute(key, cmd, cwd, input, appends)
  call s:checkKey(a:key)
  python asyncer.execute('a:key', 'a:cmd', 'a:cwd', 'a:input', 'a:appends')
endfunction

"
function l9#async#read(key)
  call s:checkKey(a:key)
  redir => result
  silent python asyncer.print_output('a:key')
  redir END
  " NOTE: "\n" is somehow inserted by redir.
  return (result[0] ==# "\n" ? result[1:] : result)
endfunction

"
function l9#async#listWorkers()
  redir => result
  silent python asyncer.print_worker_keys()
  redir END
  return split(result, "\n")
endfunction

"
function l9#async#listActiveWorkers()
  redir => result
  silent python asyncer.print_active_worker_keys()
  redir END
  return split(result, "\n")
endfunction

" }}}1
"=============================================================================
" INITIALIZATION {{{1

let s:ASYNC_PY_PATH = fnamemodify(expand('<sfile>:p:h'), ':p') . 'async.py'

pyfile `=s:ASYNC_PY_PATH`
python asyncer = Asyncer()

" }}}1
"=============================================================================
" vim: set fdm=marker: