aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/eval.c
diff options
context:
space:
mode:
authorerw7 <erw7.github@gmail.com>2019-05-20 11:57:45 +0900
committererw7 <erw7.github@gmail.com>2020-02-12 15:16:32 +0900
commit4813ad48cd12a03ca50c01ac1b20518bf4df57f2 (patch)
treef0c15d85ef763dc504ac8bace7a1f08bf366feb8 /src/nvim/eval.c
parent58ec72f9fdfd186e5154ce82be1da7c65b9c8ea0 (diff)
downloadrneovim-4813ad48cd12a03ca50c01ac1b20518bf4df57f2.tar.gz
rneovim-4813ad48cd12a03ca50c01ac1b20518bf4df57f2.tar.bz2
rneovim-4813ad48cd12a03ca50c01ac1b20518bf4df57f2.zip
vim-patch:8.1.0027: difficult to make a plugin that feeds a line to a job
Problem: Difficult to make a plugin that feeds a line to a job. Solution: Add the nitial code for the "prompt" buftype. https://github.com/vim/vim/commit/f273245f6433d5d43a5671306b520a3230c35787
Diffstat (limited to 'src/nvim/eval.c')
-rw-r--r--src/nvim/eval.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 0dceca671b..b330e7161d 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -13687,3 +13687,34 @@ void ex_checkhealth(exarg_T *eap)
xfree(buf);
}
+
+void invoke_prompt_callback(void)
+{
+ typval_T rettv;
+ typval_T argv[2];
+ char_u *text;
+ char_u *prompt;
+ linenr_T lnum = curbuf->b_ml.ml_line_count;
+
+ // Add a new line for the prompt before invoking the callback, so that
+ // text can always be inserted above the last line.
+ ml_append(lnum, (char_u *)"", 0, false);
+ curwin->w_cursor.lnum = lnum + 1;
+ curwin->w_cursor.col = 0;
+
+ if (curbuf->b_prompt_callback.type == kCallbackNone) {
+ return;
+ }
+ text = ml_get(lnum);
+ prompt = prompt_text();
+ if (STRLEN(text) >= STRLEN(prompt)) {
+ text += STRLEN(prompt);
+ }
+ argv[0].v_type = VAR_STRING;
+ argv[0].vval.v_string = vim_strsave(text);
+ argv[1].v_type = VAR_UNKNOWN;
+
+ callback_call(&curbuf->b_prompt_callback, 1, argv, &rettv);
+ tv_clear(&argv[0]);
+ tv_clear(&rettv);
+}