diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/api/vim.c | 39 | ||||
-rw-r--r-- | src/nvim/ex_cmds2.c | 19 | ||||
-rw-r--r-- | src/nvim/ex_docmd.c | 9 |
3 files changed, 34 insertions, 33 deletions
diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index bf722b4f4e..6763a3a936 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -73,28 +73,29 @@ void api_vim_free_all_mem(void) map_free(String, handle_T)(namespace_ids); } -/// Executes a multiline block of ex-commands from a string. +/// Executes Vimscript (multiline block of Ex-commands), like anonymous +/// |:source|. /// -/// On execution error: fails with VimL error, does not update v:errmsg. -/// -/// @param src String containing the ex-commands -/// @param[out] err Error details (Vim error), if any -void nvim_source(String src, Error *err) FUNC_API_SINCE(7) -{ - try_start(); - do_source_str(src.data, "nvim_source(..)"); - try_end(err); -} - -/// Executes a multiline block of ex-commands from a string and returns its -/// (non-error) output. Shell |:!| output is not captured. +/// Optionally returns (non-error, non-shell |:!|) output. /// /// On execution error: fails with VimL error, does not update v:errmsg. /// -/// @param src String containing the ex-commands +/// @see |execute()| +/// @see |nvim_command()| +/// +/// @param src Vimscript code +/// @param output Capture and return all (non-error, non-shell |:!|) output /// @param[out] err Error details (Vim error), if any -String nvim_source_output(String src, Error *err) FUNC_API_SINCE(7) +String nvim_exec(String src, Boolean output, Error *err) + FUNC_API_SINCE(7) { + if (!output) { + try_start(); + do_source_str(src.data, "nvim_exec()"); + try_end(err); + return (String)STRING_INIT; + } + const int save_msg_silent = msg_silent; garray_T *const save_capture_ga = capture_ga; garray_T capture_local; @@ -103,7 +104,7 @@ String nvim_source_output(String src, Error *err) FUNC_API_SINCE(7) try_start(); msg_silent++; capture_ga = &capture_local; - do_source_str(src.data, "nvim_source_output(..)"); + do_source_str(src.data, "nvim_exec()"); capture_ga = save_capture_ga; msg_silent = save_msg_silent; try_end(err); @@ -134,6 +135,8 @@ theend: /// /// On execution error: fails with VimL error, does not update v:errmsg. /// +/// @see |nvim_exec()| +/// /// @param command Ex-command string /// @param[out] err Error details (Vim error), if any void nvim_command(String command, Error *err) @@ -436,7 +439,7 @@ theend: return (String)STRING_INIT; } -/// Evaluates a VimL expression (:help expression). +/// Evaluates a VimL |expression|. /// Dictionaries and Lists are recursively expanded. /// /// On execution error: fails with VimL error, does not update v:errmsg. diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c index bda7b4e8b5..8479c15b40 100644 --- a/src/nvim/ex_cmds2.c +++ b/src/nvim/ex_cmds2.c @@ -3047,6 +3047,9 @@ static char_u *get_str_line(int c, void *cookie, int indent, bool do_concat) return (char_u *)xstrdup(buf); } +/// Executes lines in `src` as Ex commands. +/// +/// @see do_source() int do_source_str(const char *cmd, const char *traceback_name) { char_u *save_sourcing_name = sourcing_name; @@ -3055,7 +3058,7 @@ int do_source_str(const char *cmd, const char *traceback_name) if (save_sourcing_name == NULL) { sourcing_name = (char_u *)traceback_name; } else { - snprintf((char *)sourcing_name_buf, sizeof sourcing_name_buf, + snprintf((char *)sourcing_name_buf, sizeof(sourcing_name_buf), "%s called at %s:%"PRIdLINENR, traceback_name, save_sourcing_name, save_sourcing_lnum); sourcing_name = sourcing_name_buf; @@ -3070,24 +3073,20 @@ int do_source_str(const char *cmd, const char *traceback_name) current_sctx.sc_sid = SID_STR; current_sctx.sc_seq = 0; current_sctx.sc_lnum = save_sourcing_lnum; - int retval = FAIL; - do_cmdline(NULL, get_str_line, (void *)&cookie, - DOCMD_VERBOSE | DOCMD_NOWAIT | DOCMD_REPEAT); - retval = OK; - if (got_int) { - EMSG(_(e_interr)); - } - + int retval = do_cmdline(NULL, get_str_line, (void *)&cookie, + DOCMD_VERBOSE | DOCMD_NOWAIT | DOCMD_REPEAT); current_sctx = save_current_sctx; sourcing_lnum = save_sourcing_lnum; sourcing_name = save_sourcing_name; return retval; } -/// Read the file "fname" and execute its lines as EX commands. +/// Reads the file `fname` and executes its lines as Ex commands. /// /// This function may be called recursively! /// +/// @see do_source_str +/// /// @param fname /// @param check_other check for .vimrc and _vimrc /// @param is_vimrc DOSO_ value diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 743286c64a..dc2726709f 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -421,13 +421,12 @@ int do_cmdline(char_u *cmdline, LineGetter fgetline, // If force_abort is set, we cancel everything. did_emsg = false; - /* - * KeyTyped is only set when calling vgetc(). Reset it here when not - * calling vgetc() (sourced command lines). - */ + // KeyTyped is only set when calling vgetc(). Reset it here when not + // calling vgetc() (sourced command lines). if (!(flags & DOCMD_KEYTYPED) - && !getline_equal(fgetline, cookie, getexline)) + && !getline_equal(fgetline, cookie, getexline)) { KeyTyped = false; + } /* * Continue executing command lines: |