diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2023-11-30 20:35:25 +0000 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2023-11-30 20:35:25 +0000 |
commit | 1b7b916b7631ddf73c38e3a0070d64e4636cb2f3 (patch) | |
tree | cd08258054db80bb9a11b1061bb091c70b76926a /src/nvim/ex_cmds2.c | |
parent | eaa89c11d0f8aefbb512de769c6c82f61a8baca3 (diff) | |
parent | 4a8bf24ac690004aedf5540fa440e788459e5e34 (diff) | |
download | rneovim-1b7b916b7631ddf73c38e3a0070d64e4636cb2f3.tar.gz rneovim-1b7b916b7631ddf73c38e3a0070d64e4636cb2f3.tar.bz2 rneovim-1b7b916b7631ddf73c38e3a0070d64e4636cb2f3.zip |
Merge remote-tracking branch 'upstream/master' into aucmd_textputpostaucmd_textputpost
Diffstat (limited to 'src/nvim/ex_cmds2.c')
-rw-r--r-- | src/nvim/ex_cmds2.c | 103 |
1 files changed, 37 insertions, 66 deletions
diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c index d08823bc30..1722b7902b 100644 --- a/src/nvim/ex_cmds2.c +++ b/src/nvim/ex_cmds2.c @@ -1,6 +1,3 @@ -// This is an open source non-commercial project. Dear PVS-Studio, please check -// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com - /// @file ex_cmds2.c /// /// Some more functions for command line commands @@ -12,14 +9,14 @@ #include <string.h> #include "nvim/arglist.h" -#include "nvim/ascii.h" +#include "nvim/ascii_defs.h" #include "nvim/autocmd.h" #include "nvim/buffer.h" +#include "nvim/bufwrite.h" #include "nvim/change.h" #include "nvim/channel.h" #include "nvim/eval.h" #include "nvim/eval/typval.h" -#include "nvim/eval/typval_defs.h" #include "nvim/eval/vars.h" #include "nvim/ex_cmds.h" #include "nvim/ex_cmds2.h" @@ -29,28 +26,30 @@ #include "nvim/fileio.h" #include "nvim/gettext.h" #include "nvim/globals.h" -#include "nvim/highlight_defs.h" -#include "nvim/macros.h" +#include "nvim/highlight.h" +#include "nvim/macros_defs.h" #include "nvim/mark.h" -#include "nvim/memline_defs.h" #include "nvim/memory.h" #include "nvim/message.h" #include "nvim/move.h" #include "nvim/normal.h" -#include "nvim/option.h" +#include "nvim/option_vars.h" #include "nvim/os/os_defs.h" #include "nvim/path.h" -#include "nvim/pos.h" +#include "nvim/pos_defs.h" #include "nvim/quickfix.h" #include "nvim/runtime.h" #include "nvim/undo.h" -#include "nvim/vim.h" +#include "nvim/vim_defs.h" #include "nvim/window.h" #ifdef INCLUDE_GENERATED_DECLARATIONS # include "ex_cmds2.c.generated.h" #endif +static const char e_compiler_not_supported_str[] + = N_("E666: Compiler not supported: %s"); + void ex_ruby(exarg_T *eap) { script_host_execute("ruby", eap); @@ -102,7 +101,6 @@ void ex_perldo(exarg_T *eap) /// @return FAIL for failure, OK otherwise int autowrite(buf_T *buf, int forceit) { - int r; bufref_T bufref; if (!(p_aw || p_awa) || !p_write @@ -112,7 +110,7 @@ int autowrite(buf_T *buf, int forceit) return FAIL; } set_bufref(&bufref, buf); - r = buf_write_all(buf, forceit); + int r = buf_write_all(buf, forceit); // Writing may succeed but the buffer still changed, e.g., when there is a // conversion error. We do want to return FAIL then. @@ -201,7 +199,7 @@ void dialog_changed(buf_T *buf, bool checkall) .forceit = false, }; - dialog_msg((char *)buff, _("Save changes to \"%s\"?"), buf->b_fname); + dialog_msg(buff, _("Save changes to \"%s\"?"), buf->b_fname); if (checkall) { ret = vim_dialog_yesnoallcancel(VIM_QUESTION, NULL, buff, 1); } else { @@ -274,9 +272,7 @@ bool can_abandon(buf_T *buf, int forceit) /// Add a buffer number to "bufnrs", unless it's already there. static void add_bufnum(int *bufnrs, int *bufnump, int nr) { - int i; - - for (i = 0; i < *bufnump; i++) { + for (int i = 0; i < *bufnump; i++) { if (bufnrs[i] == nr) { return; } @@ -297,11 +293,9 @@ static void add_bufnum(int *bufnrs, int *bufnump, int nr) bool check_changed_any(bool hidden, bool unload) { bool ret = false; - int save; int i; int bufnum = 0; size_t bufcount = 0; - int *bufnrs; // Make a list of all buffers, with the most important ones first. FOR_ALL_BUFFERS(buf) { @@ -312,7 +306,7 @@ bool check_changed_any(bool hidden, bool unload) return false; } - bufnrs = xmalloc(sizeof(*bufnrs) * bufcount); + int *bufnrs = xmalloc(sizeof(*bufnrs) * bufcount); // curbuf bufnrs[bufnum++] = curbuf->b_fnum; @@ -380,7 +374,7 @@ bool check_changed_any(bool hidden, bool unload) ? semsg(_("E947: Job still running in buffer \"%s\""), buf->b_fname) : semsg(_("E162: No write since last change for buffer \"%s\""), buf_spname(buf) != NULL ? buf_spname(buf) : buf->b_fname)) { - save = no_wait_return; + int save = no_wait_return; no_wait_return = false; wait_return(false); no_wait_return = save; @@ -430,15 +424,14 @@ int check_fname(void) /// @return FAIL for failure, OK otherwise int buf_write_all(buf_T *buf, int forceit) { - int retval; buf_T *old_curbuf = curbuf; - retval = (buf_write(buf, buf->b_ffname, buf->b_fname, - (linenr_T)1, buf->b_ml.ml_line_count, NULL, - false, forceit, true, false)); + int retval = (buf_write(buf, buf->b_ffname, buf->b_fname, + 1, buf->b_ml.ml_line_count, NULL, + false, forceit, true, false)); if (curbuf != old_curbuf) { msg_source(HL_ATTR(HLF_W)); - msg(_("Warning: Entered other buffer unexpectedly (check autocommands)")); + msg(_("Warning: Entered other buffer unexpectedly (check autocommands)"), 0); } return retval; } @@ -446,12 +439,11 @@ int buf_write_all(buf_T *buf, int forceit) /// ":argdo", ":windo", ":bufdo", ":tabdo", ":cdo", ":ldo", ":cfdo" and ":lfdo" void ex_listdo(exarg_T *eap) { - int i; - win_T *wp; - tabpage_T *tp; - int next_fnum = 0; char *save_ei = NULL; - char *p_shm_save; + + // Temporarily override SHM_OVER and SHM_OVERALL to avoid that file + // message overwrites output from the command. + msg_listdo_overwrite++; if (eap->cmdidx != CMD_windo && eap->cmdidx != CMD_tabdo) { // Don't do syntax HL autocommands. Skipping the syntax file is a @@ -469,10 +461,11 @@ void ex_listdo(exarg_T *eap) || !check_changed(curbuf, CCGD_AW | (eap->forceit ? CCGD_FORCEIT : 0) | CCGD_EXCMD)) { - i = 0; + int next_fnum = 0; + int i = 0; // start at the eap->line1 argument/window/buffer - wp = firstwin; - tp = first_tabpage; + win_T *wp = firstwin; + tabpage_T *tp = first_tabpage; switch (eap->cmdidx) { case CMD_windo: for (; wp != NULL && i + 1 < eap->line1; wp = wp->w_next) { @@ -542,11 +535,7 @@ void ex_listdo(exarg_T *eap) if (curwin->w_arg_idx != i || !editing_arg_idx(curwin)) { // Clear 'shm' to avoid that the file message overwrites // any output from the command. - p_shm_save = xstrdup(p_shm); - set_option_value_give_err("shm", 0L, "", 0); do_argfile(eap, i); - set_option_value_give_err("shm", 0L, p_shm_save, 0); - xfree(p_shm_save); } if (curwin->w_arg_idx != i) { break; @@ -609,13 +598,8 @@ void ex_listdo(exarg_T *eap) break; } - // Go to the next buffer. Clear 'shm' to avoid that the file - // message overwrites any output from the command. - p_shm_save = xstrdup(p_shm); - set_option_value_give_err("shm", 0L, "", 0); + // Go to the next buffer. goto_buffer(eap, DOBUF_FIRST, FORWARD, next_fnum); - set_option_value_give_err("shm", 0L, p_shm_save, 0); - xfree(p_shm_save); // If autocommands took us elsewhere, quit here. if (curbuf->b_fnum != next_fnum) { @@ -632,13 +616,7 @@ void ex_listdo(exarg_T *eap) size_t qf_idx = qf_get_cur_idx(eap); - // Clear 'shm' to avoid that the file message overwrites - // any output from the command. - p_shm_save = xstrdup(p_shm); - set_option_value_give_err("shm", 0L, "", 0); ex_cnext(eap); - set_option_value_give_err("shm", 0L, p_shm_save, 0); - xfree(p_shm_save); // If jumping to the next quickfix entry fails, quit here. if (qf_get_cur_idx(eap) == qf_idx) { @@ -665,6 +643,7 @@ void ex_listdo(exarg_T *eap) listcmd_busy = false; } + msg_listdo_overwrite--; if (save_ei != NULL) { buf_T *bnext; aco_save_T aco; @@ -697,9 +676,7 @@ void ex_listdo(exarg_T *eap) /// ":compiler[!] {name}" void ex_compiler(exarg_T *eap) { - char *buf; char *old_cur_comp = NULL; - char *p; if (*eap->arg == NUL) { // List all compiler scripts. @@ -709,7 +686,7 @@ void ex_compiler(exarg_T *eap) } size_t bufsize = strlen(eap->arg) + 14; - buf = xmalloc(bufsize); + char *buf = xmalloc(bufsize); if (eap->forceit) { // ":compiler! {name}" sets global options @@ -730,20 +707,16 @@ void ex_compiler(exarg_T *eap) do_unlet(S_LEN("g:current_compiler"), true); do_unlet(S_LEN("b:current_compiler"), true); - snprintf(buf, bufsize, "compiler/%s.vim", eap->arg); - if (source_runtime(buf, DIP_ALL) == FAIL) { - // Try lua compiler - snprintf(buf, bufsize, "compiler/%s.lua", eap->arg); - if (source_runtime(buf, DIP_ALL) == FAIL) { - semsg(_("E666: compiler not supported: %s"), eap->arg); - } + snprintf(buf, bufsize, "compiler/%s.*", eap->arg); + if (source_runtime_vim_lua(buf, DIP_ALL) == FAIL) { + semsg(_(e_compiler_not_supported_str), eap->arg); } xfree(buf); do_cmdline_cmd(":delcommand CompilerSet"); // Set "b:current_compiler" from "current_compiler". - p = get_var_value("g:current_compiler"); + char *p = get_var_value("g:current_compiler"); if (p != NULL) { set_internal_string_var("b:current_compiler", p); } @@ -762,14 +735,13 @@ void ex_compiler(exarg_T *eap) /// ":checktime [buffer]" void ex_checktime(exarg_T *eap) { - buf_T *buf; int save_no_check_timestamps = no_check_timestamps; no_check_timestamps = 0; if (eap->addr_count == 0) { // default is all buffers check_timestamps(false); } else { - buf = buflist_findnr((int)eap->line2); + buf_T *buf = buflist_findnr((int)eap->line2); if (buf != NULL) { // cannot happen? (void)buf_check_timestamp(buf); } @@ -816,7 +788,7 @@ static void script_host_do_range(char *name, exarg_T *eap) list_T *args = tv_list_alloc(3); tv_list_append_number(args, (int)eap->line1); tv_list_append_number(args, (int)eap->line2); - tv_list_append_string(args, (const char *)eap->arg, -1); + tv_list_append_string(args, eap->arg, -1); (void)eval_call_provider(name, "do_range", args, true); } } @@ -827,7 +799,6 @@ static void script_host_do_range(char *name, exarg_T *eap) void ex_drop(exarg_T *eap) { bool split = false; - buf_T *buf; // Check if the first argument is already being edited in a window. If // so, jump to that window. @@ -855,7 +826,7 @@ void ex_drop(exarg_T *eap) // ":drop file ...": Edit the first argument. Jump to an existing // window if possible, edit in current window if the current buffer // can be abandoned, otherwise open a new window. - buf = buflist_findnr(ARGLIST[0].ae_fnum); + buf_T *buf = buflist_findnr(ARGLIST[0].ae_fnum); FOR_ALL_TAB_WINDOWS(tp, wp) { if (wp->w_buffer == buf) { |