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/channel.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/channel.c')
-rw-r--r-- | src/channel.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/channel.c b/src/channel.c index 504d6b609..40a3e955d 100644 --- a/src/channel.c +++ b/src/channel.c @@ -5836,4 +5836,38 @@ job_stop(job_T *job, typval_T *argvars, char *type) return 1; } + void +invoke_prompt_callback(void) +{ + typval_T rettv; + int dummy; + 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 == NULL) + 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; + + call_func(curbuf->b_prompt_callback, + (int)STRLEN(curbuf->b_prompt_callback), + &rettv, 1, argv, NULL, 0L, 0L, &dummy, TRUE, + curbuf->b_prompt_partial, NULL); + clear_tv(&argv[0]); + clear_tv(&rettv); +} + #endif /* FEAT_JOB_CHANNEL */ |