aboutsummaryrefslogtreecommitdiff
path: root/runtime/doc/job_control.txt
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/doc/job_control.txt')
-rw-r--r--runtime/doc/job_control.txt25
1 files changed, 19 insertions, 6 deletions
diff --git a/runtime/doc/job_control.txt b/runtime/doc/job_control.txt
index 587eba4162..1aa7ce06d6 100644
--- a/runtime/doc/job_control.txt
+++ b/runtime/doc/job_control.txt
@@ -40,7 +40,7 @@ for details.
Job control is achieved by calling a combination of the |jobstart()|,
|jobsend()| and |jobstop()| functions. Here's an example:
>
- function s:JobHandler(job_id, data, event)
+ function! s:JobHandler(job_id, data, event) dict
if a:event == 'stdout'
let str = self.shell.' stdout: '.join(a:data)
elseif a:event == 'stderr'
@@ -84,28 +84,41 @@ Here's what is happening:
program.
2: The event type, which is "stdout", "stderr" or "exit".
+ Note: Buffered stdout/stderr data which has not been flushed by the sender
+ will not trigger the "stdout" callback (but if the process ends, the
+ "exit" callback will be triggered).
+ For example, "ruby -e" buffers output, so small strings will be
+ buffered unless "auto-flushing" ($stdout.sync=true) is enabled. >
+ function! Receive(job_id, data, event)
+ echom printf('%s: %s',a:event,string(a:data))
+ endfunction
+ call jobstart(['ruby', '-e',
+ \ '$stdout.sync = true; 5.times do sleep 1 and puts "Hello Ruby!" end'],
+ \ {'on_stdout': 'Receive'})
+< https://github.com/neovim/neovim/issues/1592
+
The options dictionary is passed as the "self" variable to the callback
function. Here's a more object-oriented version of the above:
>
let Shell = {}
- function Shell.on_stdout(job_id, data)
+ function Shell.on_stdout(job_id, data) dict
call append(line('$'), self.get_name().' stdout: '.join(a:data))
endfunction
- function Shell.on_stderr(job_id, data)
+ function Shell.on_stderr(job_id, data) dict
call append(line('$'), self.get_name().' stderr: '.join(a:data))
endfunction
- function Shell.on_exit(job_id, data)
+ function Shell.on_exit(job_id, data) dict
call append(line('$'), self.get_name().' exited')
endfunction
- function Shell.get_name()
+ function Shell.get_name() dict
return 'shell '.self.name
endfunction
- function Shell.new(name, ...)
+ function Shell.new(name, ...) dict
let instance = extend(copy(g:Shell), {'name': a:name})
let argv = ['bash']
if a:0 > 0