diff options
| author | James McCoy <jamessan@jamessan.com> | 2021-10-18 09:08:46 -0400 |
|---|---|---|
| committer | James McCoy <jamessan@jamessan.com> | 2021-11-01 06:41:28 -0400 |
| commit | efa924f66b183d9cf2404ce91c4f009c27e0515a (patch) | |
| tree | adc8c74cba88e76c2ae0548cd6e9b01804da9933 /src | |
| parent | 684640f5518a483cf2bc48efc8f68449379cef69 (diff) | |
| download | rneovim-efa924f66b183d9cf2404ce91c4f009c27e0515a.tar.gz rneovim-efa924f66b183d9cf2404ce91c4f009c27e0515a.tar.bz2 rneovim-efa924f66b183d9cf2404ce91c4f009c27e0515a.zip | |
vim-patch:8.1.0743: giving error messages is not flexible
Problem: Giving error messages is not flexible.
Solution: Add semsg(). Change argument from "char_u *" to "char *", also
for msg() and get rid of most MSG macros. (Ozaki Kiichi, closes
vim/vim#3302) Also make emsg() accept a "char *" argument. Get rid of
an enormous number of type casts.
https://github.com/vim/vim/commit/f9e3e09fdc93be9f0d47afbc6c7df1188c2a5a0d
Diffstat (limited to 'src')
75 files changed, 1700 insertions, 1744 deletions
diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index f51b5536e7..2f1df31858 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -1724,7 +1724,7 @@ static void write_msg(String message, bool to_err) #define PUSH_CHAR(i, pos, line_buf, msg) \ if (message.data[i] == NL || pos == LINE_BUFFER_SIZE - 1) { \ line_buf[pos] = NUL; \ - msg((char_u *)line_buf); \ + msg(line_buf); \ pos = 0; \ continue; \ } \ diff --git a/src/nvim/autocmd.c b/src/nvim/autocmd.c index d991b88131..b1d22ffc74 100644 --- a/src/nvim/autocmd.c +++ b/src/nvim/autocmd.c @@ -313,9 +313,9 @@ static void au_del_group(char_u *name) { int i = au_find_group(name); if (i == AUGROUP_ERROR) { // the group doesn't exist - EMSG2(_("E367: No such group: \"%s\""), name); + semsg(_("E367: No such group: \"%s\""), name); } else if (i == current_augroup) { - EMSG(_("E936: Cannot delete the current group")); + emsg(_("E936: Cannot delete the current group")); } else { event_T event; AutoPat *ap; @@ -372,7 +372,7 @@ void do_augroup(char_u *arg, int del_group) { if (del_group) { if (*arg == NUL) { - EMSG(_(e_argreq)); + emsg(_(e_argreq)); } else { au_del_group(arg); } @@ -469,7 +469,7 @@ static char_u *find_end_event(char_u *arg, int have_group) if (*arg == '*') { if (arg[1] && !ascii_iswhite(arg[1])) { - EMSG2(_("E215: Illegal character after *: %s"), arg); + semsg(_("E215: Illegal character after *: %s"), arg); return NULL; } pat = arg + 1; @@ -477,9 +477,9 @@ static char_u *find_end_event(char_u *arg, int have_group) for (pat = arg; *pat && *pat != '|' && !ascii_iswhite(*pat); pat = p) { if ((int)event_name2nr(pat, &p) >= NUM_EVENTS) { if (have_group) { - EMSG2(_("E216: No such event: %s"), pat); + semsg(_("E216: No such event: %s"), pat); } else { - EMSG2(_("E216: No such group or event: %s"), pat); + semsg(_("E216: No such group or event: %s"), pat); } return NULL; } @@ -651,7 +651,7 @@ void do_autocmd(char_u *arg_in, int forceit) // Check for "++once" flag. if (STRNCMP(cmd, "++once", 6) == 0 && ascii_iswhite(cmd[6])) { if (once) { - EMSG2(_(e_duparg2), "++once"); + semsg(_(e_duparg2), "++once"); } once = true; cmd = skipwhite(cmd + 6); @@ -660,7 +660,7 @@ void do_autocmd(char_u *arg_in, int forceit) // Check for "++nested" flag. if ((STRNCMP(cmd, "++nested", 8) == 0 && ascii_iswhite(cmd[8]))) { if (nested) { - EMSG2(_(e_duparg2), "++nested"); + semsg(_(e_duparg2), "++nested"); } nested = true; cmd = skipwhite(cmd + 8); @@ -669,7 +669,7 @@ void do_autocmd(char_u *arg_in, int forceit) // Check for the old (deprecated) "nested" flag. if (STRNCMP(cmd, "nested", 6) == 0 && ascii_iswhite(cmd[6])) { if (nested) { - EMSG2(_(e_duparg2), "nested"); + semsg(_(e_duparg2), "nested"); } nested = true; cmd = skipwhite(cmd + 6); @@ -699,7 +699,7 @@ void do_autocmd(char_u *arg_in, int forceit) last_group = AUGROUP_ERROR; // for listing the group name if (*arg == '*' || *arg == NUL || *arg == '|') { if (!forceit && *cmd != NUL) { - EMSG(_(e_cannot_define_autocommands_for_all_events)); + emsg(_(e_cannot_define_autocommands_for_all_events)); } else { for (event_T event = (event_T)0; event < NUM_EVENTS; event = (event_T)(event + 1)) { @@ -899,7 +899,7 @@ static int do_autocmd_event(event_T event, char_u *pat, bool once, int nested, c // refuse to add buffer-local ap if buffer number is invalid if (is_buflocal && (buflocal_nr == 0 || buflist_findnr(buflocal_nr) == NULL)) { - emsgf(_("E680: <buffer=%d>: invalid buffer number "), buflocal_nr); + semsg(_("E680: <buffer=%d>: invalid buffer number "), buflocal_nr); return FAIL; } @@ -974,7 +974,7 @@ int do_doautocmd(char_u *arg, bool do_msg, bool *did_something) group = au_get_grouparg(&arg); if (*arg == '*') { - EMSG(_("E217: Can't execute autocommands for ALL events")); + emsg(_("E217: Can't execute autocommands for ALL events")); return FAIL; } @@ -1414,7 +1414,7 @@ static bool apply_autocmds_group(event_T event, char_u *fname, char_u *fname_io, // Allow nesting of autocommands, but restrict the depth, because it's // possible to create an endless loop. if (nesting == 10) { - EMSG(_("E218: autocommand nesting too deep")); + emsg(_("E218: autocommand nesting too deep")); goto BYPASS_AU; } diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 62d41051e0..db436c0afc 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -186,7 +186,7 @@ int open_buffer(int read_stdin, exarg_T *eap, int flags) // If there is no memfile at all, exit. // This is OK, since there are no changes to lose. if (curbuf == NULL) { - EMSG(_("E82: Cannot allocate any buffer, exiting...")); + emsg(_("E82: Cannot allocate any buffer, exiting...")); // Don't try to do any saving, with "curbuf" NULL almost nothing // will work. @@ -194,7 +194,7 @@ int open_buffer(int read_stdin, exarg_T *eap, int flags) getout(2); } - EMSG(_("E83: Cannot allocate buffer, using other one...")); + emsg(_("E83: Cannot allocate buffer, using other one...")); enter_buffer(curbuf); if (old_tw != curbuf->b_p_tw) { check_colorcolumn(curwin); @@ -439,7 +439,7 @@ bool close_buffer(win_T *win, buf_T *buf, int action, bool abort_if_last) // Disallow deleting the buffer when it is locked (already being closed or // halfway a command that relies on it). Unloading is allowed. if (buf->b_locked > 0 && (del_buf || wipe_buf)) { - EMSG(_("E937: Attempt to delete a buffer that is in use")); + emsg(_("E937: Attempt to delete a buffer that is in use")); return false; } @@ -466,13 +466,13 @@ bool close_buffer(win_T *win, buf_T *buf, int action, bool abort_if_last) if (apply_autocmds(EVENT_BUFWINLEAVE, buf->b_fname, buf->b_fname, false, buf) && !bufref_valid(&bufref)) { // Autocommands deleted the buffer. - EMSG(_(e_auabort)); + emsg(_(e_auabort)); return false; } buf->b_locked--; if (abort_if_last && last_nonfloat(win)) { // Autocommands made this the only window. - EMSG(_(e_auabort)); + emsg(_(e_auabort)); return false; } @@ -483,13 +483,13 @@ bool close_buffer(win_T *win, buf_T *buf, int action, bool abort_if_last) if (apply_autocmds(EVENT_BUFHIDDEN, buf->b_fname, buf->b_fname, false, buf) && !bufref_valid(&bufref)) { // Autocommands deleted the buffer. - EMSG(_(e_auabort)); + emsg(_(e_auabort)); return false; } buf->b_locked--; if (abort_if_last && last_nonfloat(win)) { // Autocommands made this the only window. - EMSG(_(e_auabort)); + emsg(_(e_auabort)); return false; } } @@ -944,11 +944,11 @@ void handle_swap_exists(bufref_T *old_curbuf) /// @param end_bnr buffer nr or last buffer nr in a range /// /// @return error message or NULL -char_u *do_bufdel(int command, char_u *arg, int addr_count, int start_bnr, int end_bnr, int forceit) +char *do_bufdel(int command, char_u *arg, int addr_count, int start_bnr, int end_bnr, int forceit) { int do_current = 0; // delete current buffer? int deleted = 0; // number of buffers deleted - char_u *errormsg = NULL; // return value + char *errormsg = NULL; // return value int bnr; // buffer number char_u *p; @@ -957,7 +957,7 @@ char_u *do_bufdel(int command, char_u *arg, int addr_count, int start_bnr, int e } else { if (addr_count == 2) { if (*arg) { // both range and argument is not allowed - return (char_u *)_(e_trailing); + return _(e_trailing); } bnr = start_bnr; } else { // addr_count == 1 @@ -1013,7 +1013,7 @@ char_u *do_bufdel(int command, char_u *arg, int addr_count, int start_bnr, int e } else { STRCPY(IObuff, _("E517: No buffers were wiped out")); } - errormsg = IObuff; + errormsg = (char *)IObuff; } else if (deleted >= p_report) { if (command == DOBUF_UNLOAD) { smsg(NGETTEXT("%d buffer unloaded", "%d buffers unloaded", (unsigned long)deleted), @@ -1043,7 +1043,7 @@ static int empty_curbuf(int close_others, int forceit, int action) buf_T *buf = curbuf; if (action == DOBUF_UNLOAD) { - EMSG(_("E90: Cannot unload last buffer")); + emsg(_("E90: Cannot unload last buffer")); return FAIL; } @@ -1116,7 +1116,7 @@ int do_buffer(int action, int start, int dir, int count, int forceit) } while (buf != curbuf && !bufIsChanged(buf)); } if (!bufIsChanged(buf)) { - EMSG(_("E84: No modified buffer found")); + emsg(_("E84: No modified buffer found")); return FAIL; } } else if (start == DOBUF_FIRST && count) { // find specified buffer number @@ -1149,7 +1149,7 @@ int do_buffer(int action, int start, int dir, int count, int forceit) } if (bp == buf) { // back where we started, didn't find anything. - EMSG(_("E85: There is no listed buffer")); + emsg(_("E85: There is no listed buffer")); return FAIL; } } @@ -1159,12 +1159,12 @@ int do_buffer(int action, int start, int dir, int count, int forceit) if (start == DOBUF_FIRST) { // don't warn when deleting if (!unload) { - EMSGN(_(e_nobufnr), count); + semsg(_(e_nobufnr), (int64_t)count); } } else if (dir == FORWARD) { - EMSG(_("E87: Cannot go beyond last buffer")); + emsg(_("E87: Cannot go beyond last buffer")); } else { - EMSG(_("E88: Cannot go before first buffer")); + emsg(_("E88: Cannot go before first buffer")); } return FAIL; } @@ -1195,9 +1195,9 @@ int do_buffer(int action, int start, int dir, int count, int forceit) return FAIL; } } else { - EMSGN(_("E89: No write since last change for buffer %" PRId64 + semsg(_("E89: No write since last change for buffer %" PRId64 " (add ! to override)"), - buf->b_fnum); + (int64_t)buf->b_fnum); return FAIL; } } @@ -1208,7 +1208,7 @@ int do_buffer(int action, int start, int dir, int count, int forceit) return FAIL; } } else { - EMSG2(_("E89: %s will be killed (add ! to override)"), + semsg(_("E89: %s will be killed (add ! to override)"), (char *)buf->b_fname); return FAIL; } @@ -1597,9 +1597,9 @@ void no_write_message(void) { if (curbuf->terminal && channel_job_running((uint64_t)curbuf->b_p_channel)) { - EMSG(_("E948: Job still running (add ! to end the job)")); + emsg(_("E948: Job still running (add ! to end the job)")); } else { - EMSG(_("E37: No write since last change (add ! to override)")); + emsg(_("E37: No write since last change (add ! to override)")); } } @@ -1608,9 +1608,9 @@ void no_write_message_nobang(const buf_T *const buf) { if (buf->terminal && channel_job_running((uint64_t)buf->b_p_channel)) { - EMSG(_("E948: Job still running")); + emsg(_("E948: Job still running")); } else { - EMSG(_("E37: No write since last change")); + emsg(_("E37: No write since last change")); } } @@ -1793,7 +1793,7 @@ buf_T *buflist_new(char_u *ffname_arg, char_u *sfname_arg, linenr_T lnum, int fl buf->b_fnum = top_file_num++; pmap_put(handle_T)(&buffer_handles, buf->b_fnum, buf); if (top_file_num < 0) { // wrap around (may cause duplicates) - EMSG(_("W14: Warning: List of file names overflow")); + emsg(_("W14: Warning: List of file names overflow")); if (emsg_silent == 0) { ui_flush(); os_delay(3001L, true); // make sure it is noticed @@ -1962,9 +1962,9 @@ int buflist_getfile(int n, linenr_T lnum, int options, int forceit) buf = buflist_findnr(n); if (buf == NULL) { if ((options & GETF_ALT) && n == 0) { - EMSG(_(e_noalt)); + emsg(_(e_noalt)); } else { - EMSGN(_("E92: Buffer %" PRId64 " not found"), n); + semsg(_("E92: Buffer %" PRId64 " not found"), (int64_t)n); } return FAIL; } @@ -2224,9 +2224,9 @@ int buflist_findpat(const char_u *pattern, const char_u *pattern_end, bool unlis } if (match == -2) { - EMSG2(_("E93: More than one match for %s"), pattern); + semsg(_("E93: More than one match for %s"), pattern); } else if (match < 0) { - EMSG2(_("E94: No matching buffer for %s"), pattern); + semsg(_("E94: No matching buffer for %s"), pattern); } return match; } @@ -2795,7 +2795,7 @@ int setfname(buf_T *buf, char_u *ffname_arg, char_u *sfname_arg, bool message) if (obuf != NULL && obuf != buf) { if (obuf->b_ml.ml_mfp != NULL) { // it's loaded, fail if (message) { - EMSG(_("E95: Buffer with this name already exists")); + emsg(_("E95: Buffer with this name already exists")); } xfree(ffname); return FAIL; @@ -2900,7 +2900,7 @@ char_u *getaltfname(bool errmsg) if (buflist_name_nr(0, &fname, &dummy) == FAIL) { if (errmsg) { - EMSG(_(e_noalt)); + emsg(_(e_noalt)); } return NULL; } @@ -5386,7 +5386,7 @@ bool bt_dontwrite_msg(const buf_T *const buf) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT { if (bt_dontwrite(buf)) { - EMSG(_("E382: Cannot write, 'buftype' option is set")); + emsg(_("E382: Cannot write, 'buftype' option is set")); return true; } return false; diff --git a/src/nvim/change.c b/src/nvim/change.c index 2450c56838..21a4798bfe 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -759,7 +759,7 @@ int del_bytes(colnr_T count, bool fixpos_arg, bool use_delcombine) } // If "count" is negative the caller must be doing something wrong. if (count < 1) { - IEMSGN("E292: Invalid count for del_bytes(): %ld", count); + siemsg("E292: Invalid count for del_bytes(): %ld", (int64_t)count); return FAIL; } diff --git a/src/nvim/channel.c b/src/nvim/channel.c index cfeaafe77a..0eae87c1f8 100644 --- a/src/nvim/channel.c +++ b/src/nvim/channel.c @@ -319,7 +319,7 @@ Channel *channel_job_start(char **argv, CallbackReader on_stdout, CallbackReader if (pty) { if (detach) { - EMSG2(_(e_invarg2), "terminal/pty job cannot be detached"); + semsg(_(e_invarg2), "terminal/pty job cannot be detached"); shell_free_argv(argv); if (env) { tv_dict_free(env); @@ -369,7 +369,7 @@ Channel *channel_job_start(char **argv, CallbackReader on_stdout, CallbackReader int status = process_spawn(proc, has_in, has_out, has_err); if (status) { - EMSG3(_(e_jobspawn), os_strerror(status), cmd); + semsg(_(e_jobspawn), os_strerror(status), cmd); xfree(cmd); if (proc->env) { tv_dict_free(proc->env); @@ -672,7 +672,7 @@ void channel_reader_callbacks(Channel *chan, CallbackReader *reader) tv_dict_add_list(reader->self, reader->type, strlen(reader->type), data); } else { - EMSG3(_(e_streamkey), reader->type, chan->id); + semsg(_(e_streamkey), reader->type, chan->id); } } else { channel_callback_call(chan, reader); diff --git a/src/nvim/context.c b/src/nvim/context.c index 4a8e645d2c..614a3ce30e 100644 --- a/src/nvim/context.c +++ b/src/nvim/context.c @@ -316,7 +316,7 @@ static inline msgpack_sbuffer array_to_sbuf(Array array) object_to_vim(ARRAY_OBJ(array), &list_tv, &err); if (!encode_vim_list_to_buf(list_tv.vval.v_list, &sbuf.size, &sbuf.data)) { - EMSG(_("E474: Failed to convert list to msgpack string buffer")); + emsg(_("E474: Failed to convert list to msgpack string buffer")); } sbuf.alloc = sbuf.size; diff --git a/src/nvim/cursor_shape.c b/src/nvim/cursor_shape.c index 18cade1052..644bb2c324 100644 --- a/src/nvim/cursor_shape.c +++ b/src/nvim/cursor_shape.c @@ -93,7 +93,7 @@ Array mode_style_array(void) /// @param what SHAPE_CURSOR or SHAPE_MOUSE ('mouseshape') /// /// @returns error message for an illegal option, NULL otherwise. -char_u *parse_shape_opt(int what) +char *parse_shape_opt(int what) { char_u *modep; char_u *colonp; @@ -126,10 +126,10 @@ char_u *parse_shape_opt(int what) commap = vim_strchr(modep, ','); if (colonp == NULL || (commap != NUL |