To: vim_dev@googlegroups.com Subject: Patch 8.0.1742 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.0.1742 Problem: Cannot get a list of all the jobs. Cannot get the command of the job. Solution: When job_info() is called without an argument return a list of jobs. Otherwise, include the command that the job is running. (Yegappan Lakshmanan) Files: runtime/doc/eval.txt, src/channel.c, src/evalfunc.c, src/proto/channel.pro, src/structs.h, src/testdir/test_channel.vim *** ../vim-8.0.1741/runtime/doc/eval.txt 2018-04-14 17:05:29.791581088 +0200 --- runtime/doc/eval.txt 2018-04-21 19:42:07.998454101 +0200 *************** *** 2231,2237 **** isnan({expr}) Number |TRUE| if {expr} is NaN items({dict}) List key-value pairs in {dict} job_getchannel({job}) Channel get the channel handle for {job} ! job_info({job}) Dict get information about {job} job_setoptions({job}, {options}) none set options for {job} job_start({command} [, {options}]) Job start a job --- 2234,2240 ---- isnan({expr}) Number |TRUE| if {expr} is NaN items({dict}) List key-value pairs in {dict} job_getchannel({job}) Channel get the channel handle for {job} ! job_info([{job}]) Dict get information about {job} job_setoptions({job}, {options}) none set options for {job} job_start({command} [, {options}]) Job start a job *** ../vim-8.0.1741/src/channel.c 2018-04-14 14:37:02.760137708 +0200 --- src/channel.c 2018-04-21 19:42:59.922160306 +0200 *************** *** 5002,5007 **** --- 5002,5009 ---- static void job_free_contents(job_T *job) { + int i; + ch_log(job->jv_channel, "Freeing job"); if (job->jv_channel != NULL) { *************** *** 5019,5024 **** --- 5021,5032 ---- vim_free(job->jv_tty_out); vim_free(job->jv_stoponexit); free_callback(job->jv_exit_cb, job->jv_exit_partial); + if (job->argv != NULL) + { + for (i = 0; job->argv[i] != NULL; i++) + vim_free(job->argv[i]); + vim_free(job->argv); + } } static void *************** *** 5463,5468 **** --- 5471,5478 ---- #endif jobopt_T opt; ch_part_T part; + int len; + int i; job = job_alloc(); if (job == NULL) *************** *** 5593,5603 **** #endif } #ifdef USE_ARGV if (ch_log_active()) { garray_T ga; - int i; ga_init2(&ga, (int)sizeof(char), 200); for (i = 0; i < argc; ++i) --- 5603,5623 ---- #endif } + /* Save the command used to start the job */ + len = 0; + for (i = 0; argv[i] != NULL; i++) + len++; + job->argv = (char_u **)alloc(sizeof(char_u *) * (len + 1)); + if (job->argv == NULL) + goto theend; + for (i = 0; argv[i] != NULL; i++) + job->argv[i] = vim_strsave((char_u *)argv[i]); + job->argv[i] = NULL; + #ifdef USE_ARGV if (ch_log_active()) { garray_T ga; ga_init2(&ga, (int)sizeof(char), 200); for (i = 0; i < argc; ++i) *************** *** 5661,5666 **** --- 5681,5688 ---- { dictitem_T *item; varnumber_T nr; + list_T *l; + int i; dict_add_nr_str(dict, "status", 0L, (char_u *)job_status(job)); *************** *** 5689,5694 **** --- 5711,5743 ---- dict_add_nr_str(dict, "exitval", job->jv_exitval, NULL); dict_add_nr_str(dict, "exit_cb", 0L, job->jv_exit_cb); dict_add_nr_str(dict, "stoponexit", 0L, job->jv_stoponexit); + + l = list_alloc(); + if (l != NULL) + { + dict_add_list(dict, "cmd", l); + for (i = 0; job->argv[i] != NULL; i++) + list_append_string(l, job->argv[i], -1); + } + } + + /* + * Implementation of job_info() to return info for all jobs. + */ + void + job_info_all(list_T *l) + { + job_T *job; + typval_T tv; + + for (job = first_job; job != NULL; job = job->jv_next) + { + tv.v_type = VAR_JOB; + tv.vval.v_job = job; + + if (list_append_tv(l, &tv) != OK) + return; + } } /* *** ../vim-8.0.1741/src/evalfunc.c 2018-04-14 17:05:29.787581114 +0200 --- src/evalfunc.c 2018-04-21 19:34:27.321052611 +0200 *************** *** 682,688 **** {"items", 1, 1, f_items}, #ifdef FEAT_JOB_CHANNEL {"job_getchannel", 1, 1, f_job_getchannel}, ! {"job_info", 1, 1, f_job_info}, {"job_setoptions", 2, 2, f_job_setoptions}, {"job_start", 1, 2, f_job_start}, {"job_status", 1, 1, f_job_status}, --- 682,688 ---- {"items", 1, 1, f_items}, #ifdef FEAT_JOB_CHANNEL {"job_getchannel", 1, 1, f_job_getchannel}, ! {"job_info", 0, 1, f_job_info}, {"job_setoptions", 2, 2, f_job_setoptions}, {"job_start", 1, 2, f_job_start}, {"job_status", 1, 1, f_job_status}, *************** *** 7007,7016 **** static void f_job_info(typval_T *argvars, typval_T *rettv) { ! job_T *job = get_job_arg(&argvars[0]); ! if (job != NULL && rettv_dict_alloc(rettv) != FAIL) ! job_info(job, rettv->vval.v_dict); } /* --- 7007,7021 ---- static void f_job_info(typval_T *argvars, typval_T *rettv) { ! if (argvars[0].v_type != VAR_UNKNOWN) ! { ! job_T *job = get_job_arg(&argvars[0]); ! if (job != NULL && rettv_dict_alloc(rettv) != FAIL) ! job_info(job, rettv->vval.v_dict); ! } ! else if (rettv_list_alloc(rettv) == OK) ! job_info_all(rettv->vval.v_list); } /* *** ../vim-8.0.1741/src/proto/channel.pro 2018-04-08 12:38:22.194293134 +0200 --- src/proto/channel.pro 2018-04-21 19:31:38.621998469 +0200 *************** *** 68,72 **** --- 68,73 ---- job_T *job_start(typval_T *argvars, char **argv_arg, jobopt_T *opt_arg); char *job_status(job_T *job); void job_info(job_T *job, dict_T *dict); + void job_info_all(list_T *l); int job_stop(job_T *job, typval_T *argvars, char *type); /* vim: set ft=c : */ *** ../vim-8.0.1741/src/structs.h 2018-04-18 23:01:07.196520488 +0200 --- src/structs.h 2018-04-21 19:31:38.625998446 +0200 *************** *** 271,280 **** # define w_p_scl w_onebuf_opt.wo_scl /* 'signcolumn' */ #endif #ifdef FEAT_TERMINAL ! char_u *wo_tk; ! #define w_p_tk w_onebuf_opt.wo_tk /* 'termkey' */ ! char_u *wo_tms; ! #define w_p_tms w_onebuf_opt.wo_tms /* 'termsize' */ #endif #ifdef FEAT_EVAL --- 271,280 ---- # define w_p_scl w_onebuf_opt.wo_scl /* 'signcolumn' */ #endif #ifdef FEAT_TERMINAL ! char_u *wo_twk; ! # define w_p_twk w_onebuf_opt.wo_twk /* 'termwinkey' */ ! char_u *wo_tws; ! # define w_p_tws w_onebuf_opt.wo_tws /* 'termwinsize' */ #endif #ifdef FEAT_EVAL *************** *** 1488,1493 **** --- 1488,1494 ---- int jv_copyID; channel_T *jv_channel; /* channel for I/O, reference counted */ + char_u **argv; /* command line used to start the job */ }; /* *************** *** 2262,2267 **** --- 2263,2271 ---- #ifdef FEAT_LISP char_u *b_p_lw; /* 'lispwords' local value */ #endif + #ifdef FEAT_TERMINAL + long b_p_twsl; /* 'termwinscroll' */ + #endif /* end of buffer options */ *** ../vim-8.0.1741/src/testdir/test_channel.vim 2018-04-11 20:53:45.765218228 +0200 --- src/testdir/test_channel.vim 2018-04-21 19:38:09.931799121 +0200 *************** *** 508,513 **** --- 508,523 ---- let info = job_info(job) call assert_equal("dead", info.status) call assert_equal("term", info.stoponexit) + call assert_equal(2, len(info.cmd)) + call assert_equal("test_channel_pipe.py", info.cmd[1]) + + let found = 0 + for j in job_info() + if j == job + let found += 1 + endif + endfor + call assert_equal(1, found) endfunc func Test_nl_pipe() *** ../vim-8.0.1741/src/version.c 2018-04-21 19:08:50.613513429 +0200 --- src/version.c 2018-04-21 19:33:32.037363033 +0200 *************** *** 763,764 **** --- 763,766 ---- { /* Add new patch number below this line */ + /**/ + 1742, /**/ -- "Marriage is a wonderful institution... but who wants to live in an institution?" - Groucho Marx /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///