patch 8.2.1588: cannot read back the prompt of a prompt buffer
Problem: Cannot read back the prompt of a prompt buffer.
Solution: Add prompt_getprompt(). (Ben Jackson, closes #6851)
diff --git a/src/channel.c b/src/channel.c
index 1a899e8..5bf561e 100644
--- a/src/channel.c
+++ b/src/channel.c
@@ -6368,6 +6368,29 @@
set_callback(&buf->b_prompt_interrupt, &callback);
}
+
+/*
+ * "prompt_getprompt({buffer})" function
+ */
+ void
+f_prompt_getprompt(typval_T *argvars, typval_T *rettv)
+{
+ buf_T *buf;
+
+ // return an empty string by default, e.g. it's not a prompt buffer
+ rettv->v_type = VAR_STRING;
+ rettv->vval.v_string = NULL;
+
+ buf = tv_get_buf_from_arg(&argvars[0]);
+ if (buf == NULL)
+ return;
+
+ if (!bt_prompt(buf))
+ return;
+
+ rettv->vval.v_string = vim_strsave(buf_prompt_text(buf));
+}
+
/*
* "prompt_setprompt({buffer}, {text})" function
*/