diff options
author | Bram Moolenaar <Bram@vim.org> | 2018-06-03 14:47:35 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2018-06-03 14:47:35 +0200 |
commit | f273245f6433d5d43a5671306b520a3230c35787 (patch) | |
tree | 958293fed4c59ee0cb91a491c8c0e32aa0e618c2 /src/edit.c | |
parent | 33c5e9fa7af935c61a8aac461b9664c501003440 (diff) | |
download | vim-git-f273245f6433d5d43a5671306b520a3230c35787.tar.gz |
patch 8.1.0027: difficult to make a plugin that feeds a line to a jobv8.1.0027
Problem: Difficult to make a plugin that feeds a line to a job.
Solution: Add the nitial code for the "prompt" buftype.
Diffstat (limited to 'src/edit.c')
-rw-r--r-- | src/edit.c | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/src/edit.c b/src/edit.c index 1ae8e2db4..1b79eccac 100644 --- a/src/edit.c +++ b/src/edit.c @@ -203,6 +203,9 @@ static unsigned quote_meta(char_u *dest, char_u *str, int len); static void ins_redraw(int ready); static void ins_ctrl_v(void); +#ifdef FEAT_JOB_CHANNEL +static void init_prompt(int cmdchar_todo); +#endif static void undisplay_dollar(void); static void insert_special(int, int, int); static void internal_format(int textwidth, int second_indent, int flags, int format_only, int c); @@ -351,6 +354,9 @@ edit( int inserted_space = FALSE; /* just inserted a space */ int replaceState = REPLACE; int nomove = FALSE; /* don't move cursor on return */ +#ifdef FEAT_JOB_CHANNEL + int cmdchar_todo = cmdchar; +#endif /* Remember whether editing was restarted after CTRL-O. */ did_restart_edit = restart_edit; @@ -707,6 +713,14 @@ edit( foldCheckClose(); #endif +#ifdef FEAT_JOB_CHANNEL + if (bt_prompt(curbuf)) + { + init_prompt(cmdchar_todo); + cmdchar_todo = NUL; + } +#endif + /* * 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 @@ -1374,6 +1388,18 @@ doESCkey: goto doESCkey; } #endif +#ifdef FEAT_JOB_CHANNEL + if (bt_prompt(curbuf)) + { + buf_T *buf = curbuf; + + invoke_prompt_callback(); + if (curbuf != buf) + // buffer changed, get out of Insert mode + goto doESCkey; + break; + } +#endif if (ins_eol(c) == FAIL && !p_im) goto doESCkey; /* out of memory */ auto_format(FALSE, FALSE); @@ -1808,6 +1834,58 @@ edit_putchar(int c, int highlight) } } +#if defined(FEAT_JOB_CHANNEL) || defined(PROTO) +/* + * 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 = ml_get_curline(); + 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() +{ + return curwin->w_cursor.lnum == curbuf->b_ml.ml_line_count + && curwin->w_cursor.col >= (int)STRLEN(prompt_text()); +} +#endif + /* * Undo the previous edit_putchar(). */ |