aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--runtime/doc/eval.txt4
-rw-r--r--src/nvim/eval.c26
2 files changed, 30 insertions, 0 deletions
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt
index 9207f1a85c..ce002eed37 100644
--- a/runtime/doc/eval.txt
+++ b/runtime/doc/eval.txt
@@ -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
@@ -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
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index be032efcf0..8e8232b44d 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -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 },
@@ -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)
{