Skip to content

Commit 1d7e5d4

Browse files
author
Richard Bateman
committed
Added l9 lib to try to fix error
1 parent 25ef714 commit 1d7e5d4

File tree

9 files changed

+1244
-0
lines changed

9 files changed

+1244
-0
lines changed

.vim/bundle/vim-fuzzyfinder/autoload/l9.vim

Lines changed: 570 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#!/usr/bin/env python
2+
3+
from __future__ import with_statement
4+
import vim
5+
import os
6+
import subprocess
7+
import threading
8+
import Queue
9+
10+
11+
class Asyncer:
12+
13+
def __init__(self):
14+
self._workers = {}
15+
16+
def execute(self, var_key, var_command, var_cwd, var_input, var_appends):
17+
key = vim.eval(var_key)
18+
command = vim.eval(var_command)
19+
cwd = vim.eval(var_cwd)
20+
input = vim.eval(var_input)
21+
appends = vim.eval(var_appends)
22+
if key not in self._workers:
23+
self._workers[key] = Worker()
24+
self._workers[key].start()
25+
self._workers[key].put(Executor(command, cwd, input, appends))
26+
27+
def print_output(self, var_key):
28+
key = vim.eval(var_key)
29+
if key not in self._workers:
30+
return
31+
for l in self._workers[key].copy_outputs():
32+
print l,
33+
34+
def print_worker_keys(self):
35+
for k in self._workers.keys():
36+
print k
37+
38+
def print_active_worker_keys(self):
39+
for k in self._workers.keys():
40+
print k
41+
42+
43+
class Worker(threading.Thread):
44+
45+
def __init__(self):
46+
threading.Thread.__init__(self)
47+
self._queue = Queue.Queue()
48+
self._lines = []
49+
self._lock = threading.Lock()
50+
51+
def run(self):
52+
while True:
53+
self._queue.get().execute(self)
54+
self._queue.task_done()
55+
56+
def put(self, executor):
57+
self._queue.put(executor)
58+
59+
def clear_outputs(self):
60+
with self._lock:
61+
self._lines = []
62+
63+
def record_output(self, line):
64+
with self._lock:
65+
self._lines.append(line)
66+
67+
def copy_outputs(self):
68+
with self._lock:
69+
return self._lines[:]
70+
71+
72+
class Executor:
73+
74+
def __init__(self, command, cwd, input, appends):
75+
self._command = command
76+
self._cwd = cwd
77+
self._input = input
78+
self._appends = appends
79+
80+
def execute(self, worker):
81+
if not self._appends:
82+
worker.clear_outputs()
83+
os.chdir(self._cwd)
84+
p = subprocess.Popen(self._command, shell=True, stdin=subprocess.PIPE,
85+
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
86+
p.stdin.write(self._input)
87+
line = p.stdout.readline()
88+
while line:
89+
worker.record_output(line)
90+
line = p.stdout.readline()
91+
92+
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
"=============================================================================
2+
" Copyright (C) 2009-2010 Takeshi NISHIDA
3+
"
4+
"=============================================================================
5+
" LOAD GUARD {{{1
6+
7+
if !l9#guardScriptLoading(expand('<sfile>:p'), 0, 0, ['has("python")'])
8+
finish
9+
endif
10+
11+
" }}}1
12+
"=============================================================================
13+
" ASYNC EXECUTE {{{1
14+
15+
"
16+
function s:checkKey(key)
17+
if a:key =~ '\n' || a:key !~ '\S'
18+
throw "Asyncer: Invalid key: " . a:key
19+
endif
20+
endfunction
21+
22+
"
23+
function l9#async#execute(key, cmd, cwd, input, appends)
24+
call s:checkKey(a:key)
25+
python asyncer.execute('a:key', 'a:cmd', 'a:cwd', 'a:input', 'a:appends')
26+
endfunction
27+
28+
"
29+
function l9#async#read(key)
30+
call s:checkKey(a:key)
31+
redir => result
32+
silent python asyncer.print_output('a:key')
33+
redir END
34+
" NOTE: "\n" is somehow inserted by redir.
35+
return (result[0] ==# "\n" ? result[1:] : result)
36+
endfunction
37+
38+
"
39+
function l9#async#listWorkers()
40+
redir => result
41+
silent python asyncer.print_worker_keys()
42+
redir END
43+
return split(result, "\n")
44+
endfunction
45+
46+
"
47+
function l9#async#listActiveWorkers()
48+
redir => result
49+
silent python asyncer.print_active_worker_keys()
50+
redir END
51+
return split(result, "\n")
52+
endfunction
53+
54+
" }}}1
55+
"=============================================================================
56+
" INITIALIZATION {{{1
57+
58+
let s:ASYNC_PY_PATH = fnamemodify(expand('<sfile>:p:h'), ':p') . 'async.py'
59+
60+
pyfile `=s:ASYNC_PY_PATH`
61+
python asyncer = Asyncer()
62+
63+
" }}}1
64+
"=============================================================================
65+
" vim: set fdm=marker:
66+
67+
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
"=============================================================================
2+
" Copyright (C) 2009-2010 Takeshi NISHIDA
3+
"
4+
"=============================================================================
5+
" LOAD GUARD {{{1
6+
7+
if !l9#guardScriptLoading(expand('<sfile>:p'), 0, 0, [])
8+
finish
9+
endif
10+
11+
" }}}1
12+
"=============================================================================
13+
" QUICKFIX {{{1
14+
15+
" Returns non-zero if quickfix window is opened.
16+
function l9#quickfix#isWindowOpened()
17+
return count(map(range(1, winnr('$')), 'getwinvar(v:val, "&buftype")'), 'quickfix') > 0
18+
endfunction
19+
20+
" Opens quickfix window if quickfix is not empty, and echo the number of errors.
21+
"
22+
" a:onlyRecognized: if non-zero, opens only if quickfix has recognized errors.
23+
" a:holdCursor: if non-zero, the cursor won't move to quickfix window.
24+
function l9#quickfix#openIfNotEmpty(onlyRecognized, holdCursor)
25+
let numErrors = len(filter(getqflist(), 'v:val.valid'))
26+
let numOthers = len(getqflist()) - numErrors
27+
if numErrors > 0 || (!a:onlyRecognized && numOthers > 0)
28+
copen
29+
if a:holdCursor
30+
wincmd p
31+
endif
32+
else
33+
cclose
34+
endif
35+
redraw
36+
if numOthers > 0
37+
echo printf('Quickfix: %d(+%d)', numErrors, numOthers)
38+
else
39+
echo printf('Quickfix: %d', numErrors)
40+
endif
41+
endfunction
42+
43+
" Toggles Quickfix window
44+
function l9#quickfix#toggleWindow()
45+
if l9#quickfix#isWindowOpened()
46+
cclose
47+
else
48+
call l9#quickfix#openIfNotEmpty(0, 0)
49+
endif
50+
endfunction
51+
52+
" Creates quickfix list form given lines and opens the quickfix window if
53+
" errors exists.
54+
"
55+
" a:lines:
56+
" a:jump: if non-zero, jump to the first error.
57+
function l9#quickfix#setMakeResult(lines)
58+
cexpr a:lines
59+
call l9#quickfix#openIfNotEmpty(0, 1)
60+
endfunction
61+
62+
" Compares quickfix entries for sorting.
63+
function l9#quickfix#compareEntries(e0, e1)
64+
if a:e0.bufnr != a:e1.bufnr
65+
let i0 = bufname(a:e0.bufnr)
66+
let i1 = bufname(a:e1.bufnr)
67+
elseif a:e0.lnum != a:e1.lnum
68+
let i0 = a:e0.lnum
69+
let i1 = a:e1.lnum
70+
elseif a:e0.col != a:e1.col
71+
let i0 = a:e0.col
72+
let i1 = a:e1.col
73+
else
74+
return 0
75+
endif
76+
return (i0 > i1 ? +1 : -1)
77+
endfunction
78+
79+
" Sorts quickfix
80+
function l9#quickfix#sort()
81+
call setqflist(sort(getqflist(), 'l9#quickfix#compareEntries'), 'r')
82+
endfunction
83+
84+
" Highlights Quickfix lines by :sign.
85+
" Inspired by errormarker plugin.
86+
"
87+
" You can customize the highlighting via L9ErrorLine and L9WarningLine
88+
" highlight groups.
89+
function l9#quickfix#placeSign()
90+
let warnings = []
91+
let errors = []
92+
for e in filter(getqflist(), 'v:val.valid')
93+
let warning = (e.type ==? 'w' || e.text =~? '^\s*warning:')
94+
call add((warning ? warnings : errors), [e.bufnr, e.lnum])
95+
endfor
96+
sign unplace *
97+
call l9#placeSign('L9WarningLine', '>>', '', warnings)
98+
call l9#placeSign('L9ErrorLine', '>>', '', errors)
99+
endfunction
100+
101+
highlight default L9ErrorLine ctermfg=white ctermbg=52 guibg=#5F0000
102+
highlight default L9WarningLine ctermfg=white ctermbg=17 guibg=#00005F
103+
104+
" }}}1
105+
"=============================================================================
106+
" vim: set fdm=marker:
107+
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
"=============================================================================
2+
" Copyright (C) 2009-2010 Takeshi NISHIDA
3+
"
4+
"=============================================================================
5+
" LOAD GUARD {{{1
6+
7+
if !l9#guardScriptLoading(expand('<sfile>:p'), 0, 0, [])
8+
finish
9+
endif
10+
11+
" }}}1
12+
"=============================================================================
13+
" TEMPORARY BUFFER {{{1
14+
15+
" each key is a buffer name.
16+
let s:dataMap = {}
17+
18+
"
19+
function s:onBufDelete(bufname)
20+
if exists('s:dataMap[a:bufname].listener.onClose')
21+
call s:dataMap[a:bufname].listener.onClose(s:dataMap[a:bufname].written)
22+
endif
23+
if bufnr('%') == s:dataMap[a:bufname].bufNr && winnr('#') != 0
24+
" if winnr('#') returns 0, "wincmd p" causes ringing the bell.
25+
wincmd p
26+
endif
27+
endfunction
28+
29+
"
30+
function s:onBufWriteCmd(bufname)
31+
if !exists('s:dataMap[a:bufname].listener.onWrite') ||
32+
\ s:dataMap[a:bufname].listener.onWrite(getline(1, '$'))
33+
setlocal nomodified
34+
let s:dataMap[a:bufname].written = 1
35+
call l9#tempbuffer#close(a:bufname)
36+
else
37+
endif
38+
endfunction
39+
40+
" a:bufname:
41+
" a:height: Window height. If 0, default height is used.
42+
" If less than 0, the window becomes full-screen.
43+
" a:listener:
44+
" a:listener.onClose(written)
45+
function l9#tempbuffer#openScratch(bufname, filetype, lines, topleft, vertical, height, listener)
46+
let openCmdPrefix = (a:topleft ? 'topleft ' : '')
47+
\ . (a:vertical ? 'vertical ' : '')
48+
\ . (a:height > 0 ? a:height : '')
49+
if !exists('s:dataMap[a:bufname]') || !bufexists(s:dataMap[a:bufname].bufNr)
50+
execute openCmdPrefix . 'new'
51+
else
52+
call l9#tempbuffer#close(a:bufname)
53+
execute openCmdPrefix . 'split'
54+
execute 'silent ' . s:dataMap[a:bufname].bufNr . 'buffer'
55+
endif
56+
if a:height < 0
57+
only
58+
endif
59+
setlocal buflisted noswapfile bufhidden=delete modifiable noreadonly buftype=nofile
60+
let &l:filetype = a:filetype
61+
silent file `=a:bufname`
62+
call setline(1, a:lines)
63+
setlocal nomodified
64+
augroup L9TempBuffer
65+
autocmd! * <buffer>
66+
execute printf('autocmd BufDelete <buffer> call s:onBufDelete (%s)', string(a:bufname))
67+
execute printf('autocmd BufWriteCmd <buffer> nested call s:onBufWriteCmd(%s)', string(a:bufname))
68+
augroup END
69+
let s:dataMap[a:bufname] = {
70+
\ 'bufNr': bufnr('%'),
71+
\ 'written': 0,
72+
\ 'listener': a:listener,
73+
\ }
74+
endfunction
75+
76+
"
77+
function l9#tempbuffer#openReadOnly(bufname, filetype, lines, topleft, vertical, height, listener)
78+
call l9#tempbuffer#openScratch(a:bufname, a:filetype, a:lines, a:topleft, a:vertical, a:height, a:listener)
79+
setlocal nomodifiable readonly
80+
endfunction
81+
82+
" a:listener:
83+
" a:listener.onClose(written)
84+
" a:listener.onWrite(lines)
85+
function l9#tempbuffer#openWritable(bufname, filetype, lines, topleft, vertical, height, listener)
86+
call l9#tempbuffer#openScratch(a:bufname, a:filetype, a:lines, a:topleft, a:vertical, a:height, a:listener)
87+
setlocal buftype=acwrite
88+
endfunction
89+
90+
" makes specified temp buffer current.
91+
function l9#tempbuffer#moveTo(bufname)
92+
return l9#moveToBufferWindowInCurrentTabpage(s:dataMap[a:bufname].bufNr) ||
93+
\ l9#moveToBufferWindowInOtherTabpage(s:dataMap[a:bufname].bufNr)
94+
endfunction
95+
96+
"
97+
function l9#tempbuffer#close(bufname)
98+
if !l9#tempbuffer#isOpen(a:bufname)
99+
return
100+
endif
101+
execute printf('%dbdelete!', s:dataMap[a:bufname].bufNr)
102+
endfunction
103+
104+
"
105+
function l9#tempbuffer#isOpen(bufname)
106+
return exists('s:dataMap[a:bufname]') && bufloaded(s:dataMap[a:bufname].bufNr)
107+
endfunction
108+
109+
" }}}1
110+
"=============================================================================
111+
" vim: set fdm=marker:
112+

0 commit comments

Comments
 (0)