Skip to content

Commit

Permalink
Squashed 'autoload/minpac/' changes from 8eae0c4..0fb846e
Browse files Browse the repository at this point in the history
0fb846e avoid has_key check for on_stdout
236debf Merge pull request #43 from prabirshrestha/fix-retry
c4d6144 Set waittime
8fc5956 Increment l:retry
f6b87c1 Trim null
69a4a5c Merge pull request #42 from mattn/fix-null
35b369f Trim null
36e97f0 Merge pull request #41 from mattn/tcp
2addfc3 Skip neovim
625cd40 Add test for async#job#connect
fa1b82d Retry
a4f4005 Add async#job#connect
6102020 Add :AsyncEmbed
d15123a Add default value when reading 'close_stdin' from input options
bb3aceb Make `opts` argument of `async#job#send`, optional
732cf48 Pass `close_stdin` as a Dictionary rather than bool argument
ab499e8 Better / safer management of non-blocking channels
a0f4e4e Wait for transmit buffer to be empty, before calling `ch_close_in`
ada658f Add support for sending data and closing stdin at the same time
42371b5 fix not restoring cpoptions
f67ecb5 Support 'cwd' option in jobstart
627a8c4 Do NOT remove job in job_stop but on_exit
8998efb Add tests for Neovim
91c3f2b Do NOT raise E900 on invalid jobid
f301455 doc: Update Embedding section
8da445b default to noblock if supported by vim 8 to avoid deadlocks causing vim to hang (#31)
4bde72e Don't use workaround (#30)
ff9177c add async#job#pid() (#28)
0521409 Fix variable name in example (#19)
d721851 Merge pull request #25 from prabirshrestha/add-test
633414e Use partial argument
79d54f4 Merge pull request #27 from prabirshrestha/revert-22
c980166 Revert #22
d7c52bc Fix test
d5e8819 Install vim
2a883ee Fix test
519430b Add tests
7627c81 Merge pull request #24 from prabirshrestha/fix-heavy
ca41dab Buffer size must be more large
300493e Merge pull request #22 from mattn/fix-block
017c6a8 Fix .travis.yml
7b1dfec Fix .travis.yml
d10fdb9 Start timer to read lazy
89bec95 Add "sleep 1m" to read blocked channel

git-subtree-dir: autoload/minpac
git-subtree-split: 0fb846e1eb3c2bf04d52a57f41088afb3395212e
  • Loading branch information
k-takata committed May 5, 2021
1 parent aa39df8 commit cab599d
Show file tree
Hide file tree
Showing 8 changed files with 336 additions and 62 deletions.
12 changes: 10 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,17 @@ language: viml
sudo: required
dist: trusty

install:
- export VIM_VERSION=master
- bash test/install-vim.sh
- export PATH=$HOME/vim/bin:$PATH

before_script:
- git clone --depth 1 --branch v1.5.4 --single-branch https://github.com/thinca/vim-themis /tmp/vim-themis

script:
- pip install --user --upgrade vim-vint
- pip install --user --upgrade vim-vint pathlib enum34 typing
- python --version
- vim --version
- vint --version
- vint autoload
- /tmp/vim-themis/bin/themis --reporter dot
30 changes: 8 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,14 @@ else
echom 'job failed to start'
endif
" If you want to get the process id of the job
let pid = async#job#pid(jobid)
" If you want to wait the job:
call async#job#wait([job], 5000) " timeout: 5 sec
call async#job#wait([jobid], 5000) " timeout: 5 sec
" If you want to stop the job:
call async#job#stop(job)
call async#job#stop(jobid)
```

## APIs
Expand All @@ -43,36 +46,19 @@ APIs are based on neovim's job control APIs.
* [jobstart()](https://neovim.io/doc/user/eval.html#jobstart%28%29)
* [jobstop()](https://neovim.io/doc/user/eval.html#jobstop%28%29)
* [jobwait()](https://neovim.io/doc/user/eval.html#jobwait%28%29)
* [jobpid()](https://neovim.io/doc/user/eval.html#jobpid%28%29)

## Embedding

Async.vim can be either embedded with other plugins or be used as an external plugin.
If you want to embed all you need is to change these 4 function names async#job# to what ever you want. E.g.:
If you want to embed run the following vim command.

```vim
" public apis {{{
function! yourplugin#job#start(cmd, opts) abort
return s:job_start(a:cmd, a:opts)
endfunction
function! yourplugin#job#stop(jobid) abort
call s:job_stop(a:jobid)
endfunction
function! yourplugin#job#send(jobid, data) abort
call s:job_send(a:jobid, a:data)
endfunction
function! yourplugin#job#wait(jobids, ...) abort
let l:timeout = get(a:000, 0, -1)
return s:job_wait(a:jobids, l:timeout)
endfunction
" }}}
:AsyncEmbed path=./autoload/myplugin/job.vim namespace=myplugin#job
```

## Todos
* Fallback to sync `system()` calls in vim that doesn't support `job`
* `job_stop` and `job_send` is treated as noop when using `system()`
* `on_stderr` doesn't work when using `system()`
* Fallback to python/ruby threads and vimproc instead of using `system()` for better compatibility (PRs welcome!!!)

48 changes: 48 additions & 0 deletions autoload/async/embedder.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
let s:autoload_root = expand('<sfile>:p:h:h')
let s:git_dir = simplify(expand('<sfile>:p:h:h:h') . '/.git')

function! s:get_git_commit() abort
if !executable('git') || !isdirectory(s:git_dir)
return 'UNKNOWN'
endif

let l:git = 'git --git-dir=' . shellescape(s:git_dir) . ' '
let l:commit = trim(system(l:git . 'rev-parse HEAD'))
let l:is_dirty = system(l:git . 'status --porcelain') =~? '\S'

return l:commit . (l:is_dirty ? ' (dirty)' : '')
endfunction

function! async#embedder#embed(...) abort
let l:args = {}

for l:arg in a:000
let l:idx = stridx(l:arg, '=')
let l:key = l:arg[:l:idx - 1]
let l:value = l:arg[l:idx + 1:]
let l:args[l:key] = l:value
endfor

if !has_key(l:args, 'path')
echom 'path required'
return
endif

if !has_key(l:args, 'namespace')
echom 'namespace required'
endif


let l:lines = readfile(s:autoload_root . '/async/job.vim')
let l:lines = map(l:lines, {_, l -> substitute(l, '\V\C\<async#job', l:args['namespace'], 'g')})

let l:content = [
\ printf('" https://github.com/prabirshrestha/async.vim#%s', s:get_git_commit()),
\ '" :AsyncEmbed ' . join(a:000, ' '),
\ '',
\ ]

let l:content += l:lines
call mkdir(fnamemodify(l:args['path'], ':h'), 'p')
call writefile(l:content, l:args['path'])
endfunction
Loading

0 comments on commit cab599d

Please sign in to comment.