aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/eval.c
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2020-02-12 00:24:50 -0800
committerGitHub <noreply@github.com>2020-02-12 00:24:50 -0800
commit68de6b17b8660adfeda93e46cec6ee6ebc7ebcf5 (patch)
tree8f60b4a224a943bdfe943c6395d210612212c351 /src/nvim/eval.c
parent58ec72f9fdfd186e5154ce82be1da7c65b9c8ea0 (diff)
parentd54b5997b7472f6c8a6f224801e2cd2e8ddf017b (diff)
downloadrneovim-68de6b17b8660adfeda93e46cec6ee6ebc7ebcf5.tar.gz
rneovim-68de6b17b8660adfeda93e46cec6ee6ebc7ebcf5.tar.bz2
rneovim-68de6b17b8660adfeda93e46cec6ee6ebc7ebcf5.zip
Merge #10433 from erw7/vim-8.1.0027
vim-patch:8.1.{27,32,36,69,70,71,91,92}
Diffstat (limited to 'src/nvim/eval.c')
-rw-r--r--src/nvim/eval.c56
1 files changed, 53 insertions, 3 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 0dceca671b..ddafe1981f 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -5152,6 +5152,10 @@ bool garbage_collect(bool testing)
}
// buffer ShaDa additional data
ABORTING(set_ref_dict)(buf->additional_data, copyID);
+
+ // buffer callback functions
+ set_ref_in_callback(&buf->b_prompt_callback, copyID, NULL, NULL);
+ set_ref_in_callback(&buf->b_prompt_interrupt, copyID, NULL, NULL);
}
FOR_ALL_TAB_WINDOWS(tp, wp) {
@@ -7315,9 +7319,7 @@ dict_T *get_win_info(win_T *wp, int16_t tpnr, int16_t winnr)
return dict;
}
-/*
- * Find window specified by "vp" in tabpage "tp".
- */
+// Find window specified by "vp" in tabpage "tp".
win_T *
find_win_by_nr(
typval_T *vp,
@@ -13687,3 +13689,51 @@ 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);
+}
+
+// Return true When the interrupt callback was invoked.
+bool invoke_prompt_interrupt(void)
+{
+ typval_T rettv;
+ typval_T argv[1];
+
+ if (curbuf->b_prompt_interrupt.type == kCallbackNone) {
+ return false;
+ }
+ argv[0].v_type = VAR_UNKNOWN;
+
+ got_int = false; // don't skip executing commands
+ callback_call(&curbuf->b_prompt_interrupt, 0, argv, &rettv);
+ tv_clear(&rettv);
+ return true;
+}