aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/edit.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/edit.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/edit.c')
-rw-r--r--src/nvim/edit.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/nvim/edit.c b/src/nvim/edit.c
index e253905057..64510589fd 100644
--- a/src/nvim/edit.c
+++ b/src/nvim/edit.c
@@ -574,6 +574,12 @@ static int insert_check(VimState *state)
foldCheckClose();
}
+ int cmdchar_todo = s->cmdchar;
+ if (bt_prompt(curbuf)) {
+ init_prompt(cmdchar_todo);
+ cmdchar_todo = NUL;
+ }
+
// If we inserted a character at the last position of the last line in the
// window, scroll the window one line up. This avoids an extra redraw. This
// is detected when the cursor column is smaller after inserting something.
@@ -1143,6 +1149,14 @@ check_pum:
cmdwin_result = CAR;
return 0;
}
+ if (bt_prompt(curbuf)) {
+ invoke_prompt_callback();
+ if (curbuf != buf) {
+ // buffer changed, get out of Insert mode
+ return 0;
+ }
+ break;
+ }
if (!ins_eol(s->c) && !p_im) {
return 0; // out of memory
}
@@ -1569,6 +1583,50 @@ void edit_putchar(int c, int highlight)
}
}
+// Return the effective prompt for the current buffer.
+char_u *prompt_text(void)
+{
+ if (curbuf->b_prompt_text == NULL) {
+ return (char_u *)"% ";
+ }
+ return curbuf->b_prompt_text;
+}
+
+// Prepare for prompt mode: Make sure the last line has the prompt text.
+// Move the cursor to this line.
+static void init_prompt(int cmdchar_todo)
+{
+ char_u *prompt = prompt_text();
+ char_u *text;
+
+ curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
+ text = get_cursor_line_ptr();
+ if (STRNCMP(text, prompt, STRLEN(prompt)) != 0) {
+ // prompt is missing, insert it or append a line with it
+ if (*text == NUL) {
+ ml_replace(curbuf->b_ml.ml_line_count, prompt, true);
+ } else {
+ ml_append(curbuf->b_ml.ml_line_count, prompt, 0, false);
+ }
+ curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
+ coladvance((colnr_T)MAXCOL);
+ changed_bytes(curbuf->b_ml.ml_line_count, 0);
+ }
+ if (cmdchar_todo == 'A') {
+ coladvance((colnr_T)MAXCOL);
+ }
+ if (cmdchar_todo == 'I' || curwin->w_cursor.col <= (int)STRLEN(prompt)) {
+ curwin->w_cursor.col = STRLEN(prompt);
+ }
+}
+
+// Return TRUE if the cursor is in the editable position of the prompt line.
+int prompt_curpos_editable(void)
+{
+ return curwin->w_cursor.lnum == curbuf->b_ml.ml_line_count
+ && curwin->w_cursor.col >= (int)STRLEN(prompt_text());
+}
+
/*
* Undo the previous edit_putchar().
*/