summaryrefslogtreecommitdiff
path: root/vimrc
diff options
context:
space:
mode:
authorjohannst <stoelp@eit.uni-kl.de>2017-11-11 23:54:46 +0100
committerjohannst <stoelp@eit.uni-kl.de>2017-11-11 23:54:46 +0100
commit097b25858e2b7969d9e5b2daba9de92000beadc9 (patch)
treeac26832e79d50973d8dccc9d7d8aaef7df2ceeba /vimrc
parentb52d446245dd12ab3757be944a569d96aeb051d7 (diff)
downloaddotfiles-097b25858e2b7969d9e5b2daba9de92000beadc9.tar.gz
dotfiles-097b25858e2b7969d9e5b2daba9de92000beadc9.zip
vimrc: Factored out AsyncCmdProcessor as own vim plugin
Diffstat (limited to 'vimrc')
-rw-r--r--vimrc132
1 files changed, 5 insertions, 127 deletions
diff --git a/vimrc b/vimrc
index 87df409..fee1ae6 100644
--- a/vimrc
+++ b/vimrc
@@ -35,6 +35,7 @@ Plugin 'ctrlpvim/ctrlp.vim'
"Plugin 'vim-scripts/OmniCppComplete'
Plugin 'vim-scripts/YankRing.vim'
Plugin 'johannst/Clever-Tabs'
+Plugin 'johannst/AsyncCmdProcessor.vim'
call vundle#end()
@@ -129,6 +130,10 @@ if index(s:gEnabledPlugins, 'vim-scripts/OmniCppComplete')!=-1
set completeopt=menuone,menu,longest,preview
endif
+if index(s:gEnabledPlugins, 'johannst/AsyncCmdProcessor.vim')!=-1
+ execute "nnoremap <leader>fg :Async find . -type f -exec grep -nHI {} +"repeat('<Left>', 6)
+endif
+
"}}}
"{{{ Vim Basic
@@ -423,133 +428,6 @@ if !empty(glob('.local_vimrc'))
endif
"}}}
-"{{{ Async Command Processor
-
-if v:version>=800
- " job_start was not working without CB
- function! s:StdOutCB(job, message)
- endfunction
-
- " job_start was not working without CB
- function! s:StdErrCB(job, message)
- endfunction
-
- let s:gAsyncJobReturnStatus='*'
- function! s:JobExitCB(job, status)
- "execute 'cbuffer! ' . g:stderr_buffer
- "execute 'caddbuffer ' . s:async_buffer
- echom 'AsyncCmdProcessor: Job exited'
- let s:gAsyncJobReturnStatus = a:status
- let s:gAsyncJobRunning=0
- endfunction
-
- let s:gAsyncJobRunning=0
- let g:gAsyncBuffer=0
- function! s:AsyncCmdProcessor(...)
- if a:0 == 0
- echom 'AsyncCmdProcessor: no cmd specified'
- return
- endif
-
- if s:gAsyncJobRunning == 1
- echom 'AsyncCmdProcessor: currently only one job at a time supported'
- return
- endif
- let s:gAsyncJobReturnStatus='*'
- let s:gAsyncJobRunning=1
-
- let l:current_buffer = bufnr('%')
- let g:gAsyncBuffer = s:CreateLogBuffer('async_buffer')
- execute 'b ' . l:current_buffer
-
- " concatenate command string
- let l:cmd = ''
- for arg in a:000
- let l:cmd = l:cmd. ' ' . arg
- endfor
- echom l:cmd
-
- let s:gAsyncJob = job_start(l:cmd, {
- \ 'out_io': 'buffer',
- \ 'out_buf': g:gAsyncBuffer,
- \ 'out_cb': function('s:StdOutCB'),
- \ 'out_msg': '0',
- \ 'err_io': 'buffer',
- \ 'err_buf': g:gAsyncBuffer,
- \ 'err_cb': function('s:StdErrCB'),
- \ 'err_msg': '0',
- \ 'exit_cb': function('s:JobExitCB')
- \})
- endfunction
-
- " can not be script local because used in statusline
- function! GetAsyncJobStatus()
- if exists('s:gAsyncJob')
- return job_status(s:gAsyncJob) . ':' . s:gAsyncJobReturnStatus
- endif
- return '*:*'
- endfunction
-
- function! s:KillAsyncJob()
- if exists('s:gAsyncJob')
- let l:dudel = job_stop(s:gAsyncJob)
- execute 'sleep 200ms'
- if job_status(s:gAsyncJob) !=? 'dead'
- echom 'Failed to kill AsyncJob'
- endif
- endif
- endfunction
-
- let s:fname_filters = [ '\(.\{-}\):\%(\(\d\+\)\%(:\(\d\+\):\)\?\)\?' ]
- " matches current line(from beginning indep of cursor position) against fname_filters
- " the first file name found from beginning of line is opened in window evaluated by 'wincmd w'
- function! s:OpenFirstFileNameMatch()
- " TODO: experimenting <cWORD>
- let l:line = getline('.')
-
- let l:file_info = []
- let l:file_info = matchlist(line, s:fname_filters[0])
-
- if !empty(l:file_info)
- for path in split(&path, ',') " take first match from path
- if ( empty(path) && !empty(glob(l:file_info[1])) ) || !empty(glob(path . '/' . l:file_info[1]))
- let l:fname = l:file_info[1]
- let l:lnum = l:file_info[2] == ''? '1' : l:file_info[2]
- let l:cnum = l:file_info[3] == ''? '1' : l:file_info[3]
- execute 'wincmd w'
- execute 'open ' . l:fname
- call cursor(l:lnum, l:cnum)
- execute 'wincmd p'
- break
- endif
- endfor
- endif
- endfunction
-
- function! s:CreateLogBuffer(buffer_name)
- let l:buffer_num = bufnr(a:buffer_name, 1)
- execute 'b ' . l:buffer_num
- execute '%d'
- execute 'setlocal buflisted'
- execute 'setlocal buftype=nofile'
- execute 'setlocal noswapfile'
- execute 'setlocal wrap'
- nnoremap <buffer> <CR> :call <SID>OpenFirstFileNameMatch()<CR>
- " go line by line in wrapped lines
- nnoremap <buffer> j gj
- nnoremap <buffer> k gk
- return l:buffer_num
- endfunction
-
- command! -complete=file -nargs=* Async call s:AsyncCmdProcessor(<f-args>)
- " Space after :Async explicitly wanted ;)
- nnoremap <leader>a :Async
- nnoremap <leader>ab :execute ':buffer ' . g:gAsyncBuffer<CR>
- nnoremap <leader>ak :call <SID>KillAsyncJob()<CR>
- execute "nnoremap <leader>fg :Async find . -type f -exec grep -nHI {} +"repeat('<Left>', 6)
-endif
-
-"}}}
"{{{ Sandbox
let s:sandbox_enable = 1