Skip to content

Commit

Permalink
job control: implement jobpid() to get PID of job
Browse files Browse the repository at this point in the history
  • Loading branch information
bfredl committed Jan 20, 2016
1 parent 49f0417 commit f338ea7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions runtime/doc/eval.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1894,6 +1894,7 @@ isdirectory( {directory}) Number TRUE if {directory} is a directory
islocked( {expr}) Number TRUE if {expr} is locked
items( {dict}) List key-value pairs in {dict}
jobclose({job}[, {stream}]) Number Closes a job stream(s)
jobpid({job}) Number Returns pid of a job.
jobresize({job}, {width}, {height})
Number Resize {job}'s pseudo terminal window
jobsend({job}, {data}) Number Writes {data} to {job}'s stdin
Expand Down Expand Up @@ -4157,6 +4158,9 @@ jobclose({job}[, {stream}]) {Nvim} *jobclose()*
Close {job}'s {stream}, which can be one "stdin", "stdout" or
"stderr". If {stream} is omitted, all streams are closed.

jobpid({job}) {Nvim} *jobpid()*
Return the pid (process id) of {job}.

jobresize({job}, {width}, {height}) {Nvim} *jobresize()*
Resize {job}'s pseudo terminal window to {width} and {height}.
This function will fail if used on jobs started without the
Expand Down
26 changes: 26 additions & 0 deletions src/nvim/eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -7236,6 +7236,7 @@ static struct fst {
{ "islocked", 1, 1, f_islocked },
{ "items", 1, 1, f_items },
{ "jobclose", 1, 2, f_jobclose },
{ "jobpid", 1, 1, f_jobpid },
{ "jobresize", 3, 3, f_jobresize },
{ "jobsend", 2, 2, f_jobsend },
{ "jobstart", 1, 2, f_jobstart },
Expand Down Expand Up @@ -11611,6 +11612,31 @@ static void f_jobclose(typval_T *argvars, typval_T *rettv)
}
}

// "jobpid(id)" function
static void f_jobpid(typval_T *argvars, typval_T *rettv)
{
rettv->v_type = VAR_NUMBER;
rettv->vval.v_number = 0;

if (check_restricted() || check_secure()) {
return;
}

if (argvars[0].v_type != VAR_NUMBER) {
EMSG(_(e_invarg));
return;
}

TerminalJobData *data = find_job(argvars[0].vval.v_number);
if (!data) {
EMSG(_(e_invjob));
return;
}

Process *proc = (Process *)&data->proc;
rettv->vval.v_number = proc->pid;
}

// "jobsend()" function
static void f_jobsend(typval_T *argvars, typval_T *rettv)
{
Expand Down

0 comments on commit f338ea7

Please sign in to comment.