1

I have built a list containing the "job" object as returned by job_start. The code populating the list is:

let g:sc_instances = get(g:, 'sc_instances', [])
let l:job = job_start('my command and args')
call add(g:sc_instances, l:job)

I try to filter out the instances which are no longer running.

I use the following code in the function to clean up the list:

let g:sc_instances = get(g:, 'sc_instances', [])
call filter(g:sc_instances, {idx, val -> job_status(val) != "run"})

but it always leaves the list empty after execution (removes all the items). What's wrong with my code?

1

Ok shame on me, I have badly read the documentation about filter:

The function must return |TRUE| if the item should be kept.

So I just have to invert my condition.

call filter(g:sc_instances, {idx, val -> job_status(val) == "run"})

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.