diff options
Diffstat (limited to 'src/nvim/ex_cmds.c')
-rw-r--r-- | src/nvim/ex_cmds.c | 327 |
1 files changed, 162 insertions, 165 deletions
diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 4a23f284cc..1bd9411fa5 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -14,8 +14,8 @@ #include <string.h> #include "nvim/api/buffer.h" +#include "nvim/api/extmark.h" #include "nvim/api/private/defs.h" -#include "nvim/api/vim.h" #include "nvim/ascii.h" #include "nvim/buffer.h" #include "nvim/buffer_updates.h" @@ -120,7 +120,7 @@ void do_ascii(const exarg_T *const eap) int cc[MAX_MCO]; int c = utfc_ptr2char(get_cursor_pos_ptr(), cc); if (c == NUL) { - MSG("NUL"); + msg("NUL"); return; } @@ -222,7 +222,7 @@ void do_ascii(const exarg_T *const eap) xstrlcpy((char *)IObuff + iobuff_len, " ...", sizeof(IObuff) - iobuff_len); } - msg(IObuff); + msg((char *)IObuff); } /* @@ -303,8 +303,9 @@ void ex_align(exarg_T *eap) * Now try to move the line as much as possible to * the right. Stop when it moves too far. */ - do + do{ (void)set_indent(++new_indent, 0); + } while (linelen(NULL) <= width); --new_indent; break; @@ -522,14 +523,14 @@ void ex_sort(exarg_T *eap) } else if (!ASCII_ISALPHA(*p) && regmatch.regprog == NULL) { s = skip_regexp(p + 1, *p, true, NULL); if (*s != *p) { - EMSG(_(e_invalpat)); + emsg(_(e_invalpat)); goto sortend; } *s = NUL; // Use last search pattern if sort pattern is empty. if (s == p + 1) { if (last_search_pat() == NULL) { - EMSG(_(e_noprevre)); + emsg(_(e_noprevre)); goto sortend; } regmatch.regprog = vim_regcomp(last_search_pat(), RE_MAGIC); @@ -542,14 +543,14 @@ void ex_sort(exarg_T *eap) p = s; // continue after the regexp regmatch.rm_ic = p_ic; } else { - EMSG2(_(e_invarg2), p); + semsg(_(e_invarg2), p); goto sortend; } } // Can only have one of 'n', 'b', 'o' and 'x'. if (format_found > 1) { - EMSG(_(e_invarg)); + emsg(_(e_invarg)); goto sortend; } @@ -719,7 +720,7 @@ sortend: xfree(sortbuf2); vim_regfree(regmatch.regprog); if (got_int) { - EMSG(_(e_interr)); + emsg(_(e_interr)); } } @@ -855,7 +856,7 @@ void ex_retab(exarg_T *eap) line_breakcheck(); } if (got_int) { - EMSG(_(e_interr)); + emsg(_(e_interr)); } // If a single value was given then it can be considered equal to @@ -913,7 +914,7 @@ int do_move(linenr_T line1, linenr_T line2, linenr_T dest) linenr_T last_line; // Last line in file after adding new text if (dest >= line1 && dest < line2) { - EMSG(_("E134: Cannot move a range of lines into itself")); + emsg(_("E134: Cannot move a range of lines into itself")); return FAIL; } @@ -1014,11 +1015,7 @@ int do_move(linenr_T line1, linenr_T line2, linenr_T dest) ml_delete(line1 + extra, true); } if (!global_busy && num_lines > p_report) { - if (num_lines == 1) { - MSG(_("1 line moved")); - } else { - smsg(_("%" PRId64 " lines moved"), (int64_t)num_lines); - } + smsg(NGETTEXT("1 line moved", "%" PRId64 " lines moved", num_lines), (int64_t)num_lines); } extmark_move_region(curbuf, line1-1, 0, start_byte, @@ -1082,8 +1079,8 @@ void ex_copy(linenr_T line1, linenr_T line2, linenr_T n) curwin->w_cursor.lnum = n; while (line1 <= line2) { - /* need to use vim_strsave() because the line will be unlocked within - * ml_append() */ + // need to use vim_strsave() because the line will be unlocked within + // ml_append() p = vim_strsave(ml_get(line1)); ml_append(curwin->w_cursor.lnum, p, (colnr_T)0, false); xfree(p); @@ -1163,7 +1160,7 @@ void do_bang(int addr_count, exarg_T *eap, bool forceit, bool do_in, bool do_out } if (ins_prevcmd) { if (prevcmd == NULL) { - EMSG(_(e_noprev)); + emsg(_(e_noprev)); xfree(newcmd); return; } @@ -1206,9 +1203,9 @@ void do_bang(int addr_count, exarg_T *eap, bool forceit, bool do_in, bool do_out prevcmd = newcmd; if (bangredo) { // put cmd in redo buffer for ! command - /* If % or # appears in the command, it must have been escaped. - * Reescape them, so that redoing them does not substitute them by the - * buffername. */ + // If % or # appears in the command, it must have been escaped. + // Reescape them, so that redoing them does not substitute them by the + // buffername. char_u *cmd = vim_strsave_escaped(prevcmd, (char_u *)"%#"); AppendToRedobuffLit(cmd, -1); @@ -1237,8 +1234,8 @@ void do_bang(int addr_count, exarg_T *eap, bool forceit, bool do_in, bool do_out do_shell(newcmd, 0); } else { // :range! - /* Careful: This may recursively call do_bang() again! (because of - * autocommands) */ + // Careful: This may recursively call do_bang() again! (because of + // autocommands) do_filter(line1, line2, eap, newcmd, do_in, do_out); apply_autocmds(EVENT_SHELLFILTERPOST, NULL, NULL, false, curbuf); } @@ -1322,7 +1319,7 @@ static void do_filter(linenr_T line1, linenr_T line2, exarg_T *eap, char_u *cmd, curwin->w_cursor.lnum = line2; } else if ((do_in && (itmp = vim_tempname()) == NULL) || (do_out && (otmp = vim_tempname()) == NULL)) { - EMSG(_(e_notmp)); + emsg(_(e_notmp)); goto filterend; } @@ -1336,7 +1333,7 @@ static void do_filter(linenr_T line1, linenr_T line2, exarg_T *eap, char_u *cmd, msg_putchar('\n'); // Keep message from buf_write(). no_wait_return--; if (!aborting()) { - EMSG2(_("E482: Can't create file %s"), itmp); // Will call wait_return. + semsg(_("E482: Can't create file %s"), itmp); // Will call wait_return. } goto filterend; } @@ -1368,9 +1365,9 @@ static void do_filter(linenr_T line1, linenr_T line2, exarg_T *eap, char_u *cmd, did_check_timestamps = FALSE; need_check_timestamps = TRUE; - /* When interrupting the shell command, it may still have produced some - * useful output. Reset got_int here, so that readfile() won't cancel - * reading. */ + // When interrupting the shell command, it may still have produced some + // useful output. Reset got_int here, so that readfile() won't cancel + // reading. os_breakcheck(); got_int = FALSE; @@ -1380,7 +1377,7 @@ static void do_filter(linenr_T line1, linenr_T line2, exarg_T *eap, char_u *cmd, READ_FILTER) != OK) { if (!aborting()) { msg_putchar('\n'); - EMSG2(_(e_notread), otmp); + semsg(_(e_notread), otmp); } goto error; } @@ -1441,7 +1438,7 @@ static void do_filter(linenr_T line1, linenr_T line2, exarg_T *eap, char_u *cmd, if (do_in) { vim_snprintf(msg_buf, sizeof(msg_buf), _("%" PRId64 " lines filtered"), (int64_t)linecount); - if (msg((char_u *)msg_buf) && !msg_scroll) { + if (msg(msg_buf) && !msg_scroll) { // save message to display it after redraw set_keep_msg((char_u *)msg_buf, 0); } @@ -1461,7 +1458,7 @@ filterend: if (curbuf != old_curbuf) { --no_wait_return; - EMSG(_("E135: *Filter* Autocommands must not change current buffer")); + emsg(_("E135: *Filter* Autocommands must not change current buffer")); } if (itmp != NULL) { os_remove((char *)itmp); @@ -1500,7 +1497,7 @@ void do_shell(char_u *cmd, int flags) && msg_silent == 0) { FOR_ALL_BUFFERS(buf) { if (bufIsChanged(buf)) { - MSG_PUTS(_("[No write since last change]\n")); + msg_puts(_("[No write since last change]\n")); break; } } @@ -1739,7 +1736,7 @@ void ex_file(exarg_T *eap) && (*eap->arg != NUL || eap->line2 > 0 || eap->addr_count > 1)) { - EMSG(_(e_invarg)); + emsg(_(e_invarg)); return; } @@ -1809,7 +1806,7 @@ int do_write(exarg_T *eap) ffname = eap->arg; if (*ffname == NUL) { if (eap->cmdidx == CMD_saveas) { - EMSG(_(e_argreq)); + emsg(_(e_argreq)); goto theend; } other = FALSE; @@ -1837,9 +1834,9 @@ int do_write(exarg_T *eap) alt_buf = buflist_findname(ffname); } if (alt_buf != NULL && alt_buf->b_ml.ml_mfp != NULL) { - /* Overwriting a file that is loaded in another buffer is not a - * good idea. */ - EMSG(_(e_bufloaded)); + // Overwriting a file that is loaded in another buffer is not a + // good idea. + emsg(_(e_bufloaded)); goto theend; } } @@ -1859,11 +1856,11 @@ int do_write(exarg_T *eap) /* * Not writing the whole file is only allowed with '!'. */ - if ( (eap->line1 != 1 - || eap->line2 != curbuf->b_ml.ml_line_count) - && !eap->forceit - && !eap->append - && !p_wa) { + if ((eap->line1 != 1 + || eap->line2 != curbuf->b_ml.ml_line_count) + && !eap->forceit + && !eap->append + && !p_wa) { if (p_confirm || cmdmod.confirm) { if (vim_dialog_yesno(VIM_QUESTION, NULL, (char_u *)_("Write partial file?"), 2) != VIM_YES) { @@ -1871,7 +1868,7 @@ int do_write(exarg_T *eap) } eap->forceit = TRUE; } else { - EMSG(_("E140: Use ! to write partial buffer")); + emsg(_("E140: Use ! to write partial buffer")); goto theend; } } @@ -1979,7 +1976,7 @@ int check_overwrite(exarg_T *eap, buf_T *buf, char_u *fname, char_u *ffname, int #ifdef UNIX // It is possible to open a directory on Unix. if (os_isdir(ffname)) { - EMSG2(_(e_isadir2), ffname); + semsg(_(e_isadir2), ffname); return FAIL; } #endif @@ -1992,7 +1989,7 @@ int check_overwrite(exarg_T *eap, buf_T *buf, char_u *fname, char_u *ffname, int } eap->forceit = TRUE; } else { - EMSG(_(e_exists)); + emsg(_(e_exists)); return FAIL; } } @@ -2032,7 +2029,7 @@ int check_overwrite(exarg_T *eap, buf_T *buf, char_u *fname, char_u *ffname, int } eap->forceit = TRUE; } else { - EMSG2(_("E768: Swap file exists: %s (:silent! overrides)"), + semsg(_("E768: Swap file exists: %s (:silent! overrides)"), swapname); xfree(swapname); return FAIL; @@ -2096,7 +2093,7 @@ void do_wqall(exarg_T *eap) break; } if (buf->b_ffname == NULL) { - EMSGN(_("E141: No file name for buffer %" PRId64), buf->b_fnum); + semsg(_("E141: No file name for buffer %" PRId64), (int64_t)buf->b_fnum); ++error; } else if (check_readonly(&eap->forceit, buf) || check_overwrite(eap, buf, buf->b_fname, buf->b_ffname, @@ -2132,7 +2129,7 @@ int not_writing(void) if (p_write) { return FALSE; } - EMSG(_("E142: File not written: Writing is disabled by 'write' option")); + emsg(_("E142: File not written: Writing is disabled by 'write' option")); return TRUE; } @@ -2143,8 +2140,8 @@ int not_writing(void) */ static int check_readonly(int *forceit, buf_T *buf) { - /* Handle a file being readonly when the 'readonly' option is set or when - * the file exists and permissions are read-only. */ + // Handle a file being readonly when the 'readonly' option is set or when + // the file exists and permissions are read-only. if (!*forceit && (buf->b_p_ro || (os_path_exists(buf->b_ffname) && !os_file_is_writable((char *)buf->b_ffname)))) { @@ -2170,9 +2167,9 @@ static int check_readonly(int *forceit, buf_T *buf) return TRUE; } } else if (buf->b_p_ro) { - EMSG(_(e_readonly)); + emsg(_(e_readonly)); } else { - EMSG2(_("E505: \"%s\" is read-only (add ! to override)"), + semsg(_("E505: \"%s\" is read-only (add ! to override)"), buf->b_fname); } return TRUE; @@ -2279,6 +2276,7 @@ theend: /// ECMD_ADDBUF: don't edit, just add to buffer list /// ECMD_ALTBUF: like ECMD_ADDBUF and also set the alternate /// file +/// ECMD_NOWINENTER: Do not trigger BufWinEnter /// @param oldwin Should be "curwin" when editing a new buffer in the current /// window, NULL when splitting the window first. When not NULL /// info of the previous buffer for "oldwin" is stored. @@ -2612,8 +2610,8 @@ int do_ecmd(int fnum, char_u *ffname, char_u *sfname, exarg_T *eap, linenr_T new set_buflisted(TRUE); } - /* If autocommands change buffers under our fingers, forget about - * editing the file. */ + // If autocommands change buffers under our fingers, forget about + // editing the file. if (buf != curbuf) { goto theend; } @@ -2677,9 +2675,9 @@ int do_ecmd(int fnum, char_u *ffname, char_u *sfname, exarg_T *eap, linenr_T new } xfree(new_name); - /* If autocommands change buffers under our fingers, forget about - * re-editing the file. Should do the buf_clear_file(), but perhaps - * the autocommands changed the buffer... */ + // If autocommands change buffers under our fingers, forget about + // re-editing the file. Should do the buf_clear_file(), but perhaps + // the autocommands changed the buffer... if (buf != curbuf) { goto theend; } @@ -2711,8 +2709,8 @@ int do_ecmd(int fnum, char_u *ffname, char_u *sfname, exarg_T *eap, linenr_T new */ curwin_init(); - /* It's possible that all lines in the buffer changed. Need to update - * automatic folding for all windows where it's used. */ + // It's possible that all lines in the buffer changed. Need to update + // automatic folding for all windows where it's used. FOR_ALL_TAB_WINDOWS(tp, win) { if (win->w_buffer == curbuf) { foldUpdateAll(win); @@ -2735,7 +2733,10 @@ int do_ecmd(int fnum, char_u *ffname, char_u *sfname, exarg_T *eap, linenr_T new /* * Open the buffer and read the file. */ - if (should_abort(open_buffer(FALSE, eap, readfile_flags))) { + if (flags & ECMD_NOWINENTER) { + readfile_flags |= READ_NOWINENTER; + } + if (should_abort(open_buffer(false, eap, readfile_flags))) { retval = FAIL; } @@ -2744,15 +2745,17 @@ int do_ecmd(int fnum, char_u *ffname, char_u *sfname, exarg_T *eap, linenr_T new } handle_swap_exists(&old_curbuf); } else { - /* Read the modelines, but only to set window-local options. Any - * buffer-local options have already been set and may have been - * changed by the user. */ + // Read the modelines, but only to set window-local options. Any + // buffer-local options have already been set and may have been + // changed by the user. do_modelines(OPT_WINONLY); apply_autocmds_retval(EVENT_BUFENTER, NULL, NULL, FALSE, curbuf, &retval); - apply_autocmds_retval(EVENT_BUFWINENTER, NULL, NULL, FALSE, curbuf, - &retval); + if ((flags & ECMD_NOWINENTER) == 0) { + apply_autocmds_retval(EVENT_BUFWINENTER, NULL, NULL, false, curbuf, + &retval); + } } check_arg_idx(curwin); @@ -2778,16 +2781,16 @@ int do_ecmd(int fnum, char_u *ffname, char_u *sfname, exarg_T *eap, linenr_T new maketitle(); } - /* Tell the diff stuff that this buffer is new and/or needs updating. - * Also needed when re-editing the same buffer, because unloading will - * have removed it as a diff buffer. */ + // Tell the diff stuff that this buffer is new and/or needs updating. + // Also needed when re-editing the same buffer, because unloading will + // have removed it as a diff buffer. if (curwin->w_p_diff) { diff_buf_add(curbuf); diff_invalidate(curbuf); } - /* If the window options were changed may need to set the spell language. - * Can only do this after the buffer has been properly setup. */ + // If the window options were changed may need to set the spell language. + // Can only do this after the buffer has been properly setup. if (did_get_winopts && curwin->w_p_spell && *curwin->w_s->b_p_spl != NUL) { (void)did_set_spelllang(curwin); } @@ -2895,7 +2898,7 @@ theend: static void delbuf_msg(char_u *name) { - EMSG2(_("E143: Autocommands unexpectedly deleted new buffer %s"), + semsg(_("E143: Autocommands unexpectedly deleted new buffer %s"), name == NULL ? (char_u *)"" : name); xfree(name); au_new_curbuf.br_buf = NULL; @@ -3022,10 +3025,10 @@ void ex_append(exarg_T *eap) curbuf->b_p_ai = !curbuf->b_p_ai; } - /* "start" is set to eap->line2+1 unless that position is invalid (when - * eap->line2 pointed to the end of the buffer and nothing was appended) - * "end" is set to lnum when something has been appended, otherwise - * it is the same than "start" -- Acevedo */ + // "start" is set to eap->line2+1 unless that position is invalid (when + // eap->line2 pointed to the end of the buffer and nothing was appended) + // "end" is set to lnum when something has been appended, otherwise + // it is the same than "start" -- Acevedo curbuf->b_op_start.lnum = (eap->line2 < curbuf->b_ml.ml_line_count) ? eap->line2 + 1 : curbuf->b_ml.ml_line_count; if (eap->cmdidx != CMD_append) { @@ -3110,7 +3113,7 @@ void ex_z(exarg_T *eap) if (*x != 0) { if (!ascii_isdigit(*x)) { - EMSG(_("E144: non-numeric argument to :z")); + emsg(_("E144: non-numeric argument to :z")); return; } bigness = atol((char *)x); @@ -3129,7 +3132,6 @@ void ex_z(exarg_T *eap) // the number of '-' and '+' multiplies the distance if (*kind == '-' || *kind == '+') { for (x = kind + 1; *x == *kind; ++x) { - ; } } @@ -3221,14 +3223,14 @@ int check_secure(void) { if (secure) { secure = 2; - EMSG(_(e_curdir)); + emsg(_(e_curdir)); return TRUE; } // In the sandbox more things are not allowed, including the things // disallowed in secure mode. if (sandbox != 0) { - EMSG(_(e_sandbox)); + emsg(_(e_sandbox)); return TRUE; } return FALSE; @@ -3424,7 +3426,7 @@ static int check_regexp_delim(int c) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT { if (isalpha(c)) { - EMSG(_("E146: Regular expressions can't be delimited by letters")); + emsg(_("E146: Regular expressions can't be delimited by letters")); return FAIL; } return OK; @@ -3503,7 +3505,7 @@ static buf_T *do_sub(exarg_T *eap, proftime_T timeout, bool do_buf_event, handle if (*cmd == '\\') { ++cmd; if (vim_strchr((char_u *)"/?&", *cmd) == NULL) { - EMSG(_(e_backslash)); + emsg(_(e_backslash)); return NULL; } if (*cmd != '&') { @@ -3549,14 +3551,14 @@ static buf_T *do_sub(exarg_T *eap, proftime_T timeout, bool do_buf_event, handle } } else if (!eap->skip) { // use previous pattern and substitution if (old_sub.sub == NULL) { // there is no previous command - EMSG(_(e_nopresub)); + emsg(_(e_nopresub)); return NULL; } pat = NULL; // search_regcomp() will use previous pattern sub = (char_u *)old_sub.sub; - /* Vi compatibility quirk: repeating with ":s" keeps the cursor in the - * last column after using "$". */ + // Vi compatibility quirk: repeating with ":s" keeps the cursor in the + // last column after using "$". endcolumn = (curwin->w_curswant == MAXCOL); } @@ -3574,7 +3576,7 @@ static buf_T *do_sub(exarg_T *eap, proftime_T timeout, bool do_buf_event, handle if (ascii_isdigit(*cmd)) { i = getdigits_long(&cmd, true, 0); if (i <= 0 && !eap->skip && subflags.do_error) { - EMSG(_(e_zerocount)); + emsg(_(e_zerocount)); return NULL; } eap->line1 = eap->line2; @@ -3591,7 +3593,7 @@ static buf_T *do_sub(exarg_T *eap, proftime_T timeout, bool do_buf_event, handle if (*cmd && *cmd != '"') { // if not end-of-line or comment eap->nextcmd = check_nextcmd(cmd); if (eap->nextcmd == NULL) { - EMSG(_(e_trailing)); + emsg(_(e_trailing)); return NULL; } } @@ -3602,14 +3604,14 @@ static buf_T *do_sub(exarg_T *eap, proftime_T timeout, bool do_buf_event, handle if (!subflags.do_count && !MODIFIABLE(curbuf)) { // Substitution is not allowed in non-'modifiable' buffer - EMSG(_(e_modifiable)); + emsg(_(e_modifiable)); return NULL; } if (search_regcomp(pat, RE_SUBST, which_pat, (preview ? 0 : SEARCH_HIS), ®match) == FAIL) { if (subflags.do_error) { - EMSG(_(e_invcmd)); + emsg(_(e_invcmd)); } return NULL; } @@ -3807,8 +3809,8 @@ static buf_T *do_sub(exarg_T *eap, proftime_T timeout, bool do_buf_event, handle if (subflags.do_ask && !preview) { int typed = 0; - /* change State to CONFIRM, so that the mouse works - * properly */ + // change State to CONFIRM, so that the mouse works + // properly int save_State = State; State = CONFIRM; setmouse(); // disable mouse in xterm @@ -3864,9 +3866,9 @@ static buf_T *do_sub(exarg_T *eap, proftime_T timeout, bool do_buf_event, handle const bool save_p_lz = p_lz; int save_p_fen = curwin->w_p_fen; - curwin->w_p_fen = FALSE; - /* Invert the matched string. - * Remove the inversion afterwards. */ + curwin->w_p_fen = false; + // Invert the matched string. + // Remove the inversion afterwards. int temp = RedrawingDisabled; RedrawingDisabled = 0; @@ -3874,11 +3876,11 @@ static buf_T *do_sub(exarg_T *eap, proftime_T timeout, bool do_buf_event, handle p_lz = false; if (new_start != NULL) { - /* There already was a substitution, we would - * like to show this to the user. We cannot - * really update the line, it would change - * what matches. Temporarily replace the line - * and change it back afterwards. */ + // There already was a substitution, we would + // like to show this to the user. We cannot + // really update the line, it would change + // what matches. Temporarily replace the line + // and change it back afterwards. orig_line = vim_strsave(ml_get(lnum)); char_u *new_line = concat_str(new_start, sub_firstline + copycol); @@ -3908,8 +3910,8 @@ static buf_T *do_sub(exarg_T *eap, proftime_T timeout, bool do_buf_event, handle } msg_starthere(); i = msg_scroll; - msg_scroll = 0; /* truncate msg when - needed */ + msg_scroll = 0; // truncate msg when + // needed msg_no_more = true; msg_ext_set_kind("confirm_sub"); smsg_attr(HL_ATTR(HLF_R), // Same highlight as wait_return(). @@ -4364,7 +4366,7 @@ skip: } } if (!preview && !do_sub_msg(subflags.do_count) && subflags.do_ask) { - MSG(""); + msg(""); } } else { global_need_beginline = true; @@ -4375,13 +4377,13 @@ skip: } else if (!global_busy) { if (got_int) { // interrupted - EMSG(_(e_interr)); + emsg(_(e_interr)); } else if (got_match) { // did find something but nothing substituted - MSG(""); + msg(""); } else if (subflags.do_error) { // nothing found - EMSG2(_(e_patnotf2), get_search_pat()); + semsg(_(e_patnotf2), get_search_pat()); } } @@ -4403,7 +4405,7 @@ skip: if (got_quit || profile_passed_limit(timeout)) { // Too slow, disable. set_string_option_direct("icm", -1, (char_u *)"", OPT_FREE, SID_NONE); - } else if (*p_icm != NUL && pat != NULL) { + } else if (*p_icm != NUL && pat != NULL) { if (pre_src_id == 0) { // Get a unique new src_id, saved in a static pre_src_id = (int)nvim_create_namespace((String)STRING_INIT); @@ -4450,30 +4452,28 @@ bool do_sub_msg(bool count_only) } else { *msg_buf = NUL; } - if (sub_nsubs == 1) { - vim_snprintf_add(msg_buf, sizeof(msg_buf), - "%s", count_only ? _("1 match") : _("1 substitution")); - } else { - vim_snprintf_add(msg_buf, sizeof(msg_buf), - count_only ? _("%" PRId64 " matches") - : _("%" PRId64 " substitutions"), - (int64_t)sub_nsubs); - } - if (sub_nlines == 1) { - vim_snprintf_add(msg_buf, sizeof(msg_buf), - "%s", _(" on 1 line")); - } else { - vim_snprintf_add(msg_buf, sizeof(msg_buf), - _(" on %" PRId64 " lines"), (int64_t)sub_nlines); - } - if (msg((char_u *)msg_buf)) { + + char *msg_single = count_only + ? NGETTEXT("%" PRId64 " match on %" PRId64 " line", + "%" PRId64 " matches on %" PRId64 " line", sub_nsubs) + : NGETTEXT("%" PRId64 " substitution on %" PRId64 " line", + "%" PRId64 " substitutions on %" PRId64 " line", sub_nsubs); + char *msg_plural = count_only + ? NGETTEXT("%" PRId64 " match on %" PRId64 " lines", + "%" PRId64 " matches on %" PRId64 " lines", sub_nsubs) + : NGETTEXT("%" PRId64 " substitution on %" PRId64 " lines", + "%" PRId64 " substitutions on %" PRId64 " lines", sub_nsubs); + vim_snprintf_add((char *)msg_buf, sizeof(msg_buf), + NGETTEXT(msg_single, msg_plural, sub_nlines), + (int64_t)sub_nsubs, (int64_t)sub_nlines); + if (msg(msg_buf)) { // save message to display it after redraw set_keep_msg((char_u *)msg_buf, 0); } return true; } if (got_int) { - EMSG(_(e_interr)); + emsg(_(e_interr)); return true; } return false; @@ -4524,7 +4524,7 @@ void ex_global(exarg_T *eap) if (global_busy && (eap->line1 != 1 || eap->line2 != curbuf->b_ml.ml_line_count)) { // will increment global_busy to break out of the loop - EMSG(_("E147: Cannot do :global recursive with a range")); + emsg(_("E147: Cannot do :global recursive with a range")); return; } @@ -4544,7 +4544,7 @@ void ex_global(exarg_T *eap) if (*cmd == '\\') { ++cmd; if (vim_strchr((char_u *)"/?&", *cmd) == NULL) { - EMSG(_(e_backslash)); + emsg(_(e_backslash)); return; } if (*cmd == '&') { @@ -4555,7 +4555,7 @@ void ex_global(exarg_T *eap) ++cmd; pat = (char_u *)""; } else if (*cmd == NUL) { - EMSG(_("E148: Regular expression missing from global")); + emsg(_("E148: Regular expression missing from global")); return; } else if (check_regexp_delim(*cmd) == FAIL) { return; @@ -4572,7 +4572,7 @@ void ex_global(exarg_T *eap) } if (search_regcomp(pat, RE_BOTH, which_pat, SEARCH_HIS, ®match) == FAIL) { - EMSG(_(e_invcmd)); + emsg(_(e_invcmd)); return; } @@ -4598,7 +4598,7 @@ void ex_global(exarg_T *eap) // pass 2: execute the command for each line that has been marked if (got_int) { - MSG(_(e_interr)); + msg(_(e_interr)); } else if (ndone == 0) { if (type == 'v') { smsg(_("Pattern found in every line: %s"), pat); @@ -4718,7 +4718,6 @@ bool prepare_tagpreview(bool undo_sync) } - /* * ":help": open a read-only window on a help file */ @@ -4756,7 +4755,7 @@ void ex_help(exarg_T *eap) arg = eap->arg; if (eap->forceit && *arg == NUL && !curbuf->b_help) { - EMSG(_("E478: Don't panic!")); + emsg(_("E478: Don't panic!")); return; } @@ -4800,9 +4799,9 @@ void ex_help(exarg_T *eap) } if (i >= num_matches || n == FAIL) { if (lang != NULL) { - EMSG3(_("E661: Sorry, no '%s' help for %s"), lang, arg); + semsg(_("E661: Sorry, no '%s' help for %s"), lang, arg); } else { - EMSG2(_("E149: Sorry, no help for %s"), arg); + semsg(_("E149: Sorry, no help for %s"), arg); } if (n != FAIL) { FreeWild(num_matches, matches); @@ -4878,8 +4877,8 @@ void ex_help(exarg_T *eap) if (!p_im) { restart_edit = 0; // don't want insert mode in help file } - /* Restore KeyTyped, setting 'filetype=help' may reset it. - * It is needed for do_tag top open folds under the cursor. */ + // Restore KeyTyped, setting 'filetype=help' may reset it. + // It is needed for do_tag top open folds under the cursor. KeyTyped = old_KeyTyped; do_tag(tag, DT_HELP, 1, FALSE, TRUE); @@ -5073,11 +5072,10 @@ int find_help_tags(const char_u *arg, int *num_matches, char_u ***matches, bool STRCPY(d + 4, "\\$"); } } else { - /* Replace: - * "[:...:]" with "\[:...:]" - * "[++...]" with "\[++...]" - * "\{" with "\\{" -- matching "} \}" - */ + // Replace: + // "[:...:]" with "\[:...:]" + // "[++...]" with "\[++...]" + // "\{" with "\\{" -- matching "} \}" if ((arg[0] == '[' && (arg[1] == ':' || (arg[1] == '+' && arg[2] == '+'))) || (arg[0] == '\\' && arg[1] == '{')) { @@ -5170,7 +5168,7 @@ int find_help_tags(const char_u *arg, int *num_matches, char_u ***matches, bool // If tag contains "({" or "([", tag terminates at the "(". // This is for help on functions, e.g.: abs({expr}). - if (*s == '(' && (s[1] == '{' || s[1] =='[')) { + if (*s == '(' && (s[1] == '{' || s[1] == '[')) { break; } @@ -5327,8 +5325,8 @@ void fix_help_buffer(void) continue; } - /* Go through all directories in 'runtimepath', skipping - * $VIMRUNTIME. */ + // Go through all directories in 'runtimepath', skipping + // $VIMRUNTIME. char_u *p = p_rtp; while (*p != NUL) { copy_option_part(&p, NameBuff, MAXPATHL, ","); @@ -5345,7 +5343,7 @@ void fix_help_buffer(void) if (!add_pathsep((char *)NameBuff) || STRLCAT(NameBuff, "doc/*.??[tx]", sizeof(NameBuff)) >= MAXPATHL) { - EMSG(_(e_fnametoolong)); + emsg(_(e_fnametoolong)); continue; } @@ -5413,10 +5411,9 @@ void fix_help_buffer(void) if (*s == '\r' || *s == '\n') { *s = NUL; } - /* The text is utf-8 when a byte - * above 127 is found and no - * illegal byte sequence is found. - */ + // The text is utf-8 when a byte + // above 127 is found and no + // illegal byte sequence is found. if (*s >= 0x80 && this_utf != kFalse) { this_utf = kTrue; const int l = utf_ptr2len(s); @@ -5427,9 +5424,9 @@ void fix_help_buffer(void) } ++s; } - /* The help file is latin1 or utf-8; - * conversion to the current - * 'encoding' may be required. */ + // The help file is latin1 or utf-8; + // conversion to the current + // 'encoding' may be required. vc.vc_type = CONV_NONE; convert_setup(&vc, (char_u *)(this_utf == kTrue ? "utf-8" : "latin1"), @@ -5507,7 +5504,7 @@ static void helptags_one(char_u *dir, const char_u *ext, const char_u *tagfname, if (dirlen >= MAXPATHL || STRLCAT(NameBuff, "/**/*", sizeof(NameBuff)) >= MAXPATHL // NOLINT || STRLCAT(NameBuff, ext, sizeof(NameBuff)) >= MAXPATHL) { - EMSG(_(e_fnametoolong)); + emsg(_(e_fnametoolong)); return; } @@ -5518,7 +5515,7 @@ static void helptags_one(char_u *dir, const char_u *ext, const char_u *tagfname, EW_FILE|EW_SILENT) == FAIL || filecount == 0) { if (!got_int) { - EMSG2(_("E151: No match: %s"), NameBuff); + semsg(_("E151: No match: %s"), NameBuff); } return; } @@ -5530,14 +5527,14 @@ static void helptags_one(char_u *dir, const char_u *ext, const char_u *tagfname, memcpy(NameBuff, dir, dirlen + 1); if (!add_pathsep((char *)NameBuff) || STRLCAT(NameBuff, tagfname, sizeof(NameBuff)) >= MAXPATHL) { - EMSG(_(e_fnametoolong)); + emsg(_(e_fnametoolong)); return; } FILE *const fd_tags = os_fopen((char *)NameBuff, "w"); if (fd_tags == NULL) { if (!ignore_writeerr) { - EMSG2(_("E152: Cannot open %s for writing"), NameBuff); + semsg(_("E152: Cannot open %s for writing"), NameBuff); } FreeWild(filecount, files); return; @@ -5559,7 +5556,7 @@ static void helptags_one(char_u *dir, const char_u *ext, const char_u *tagfname, for (int fi = 0; fi < filecount && !got_int; fi++) { FILE *const fd = os_fopen((char *)files[fi], "r"); if (fd == NULL) { - EMSG2(_("E153: Unable to open %s for reading"), files[fi]); + semsg(_("E153: Unable to open %s for reading"), files[fi]); continue; } const char_u *const fname = files[fi] + dirlen + 1; @@ -5587,7 +5584,7 @@ static void helptags_one(char_u *dir, const char_u *ext, const char_u *tagfname, if (utf8 == kNone) { // first file utf8 = this_utf8; } else if (utf8 != this_utf8) { - EMSG2(_("E670: Mix of help file encodings within a language: %s"), + semsg(_("E670: Mix of help file encodings within a language: %s"), files[fi]); mix = !got_int; got_int = TRUE; @@ -5646,7 +5643,7 @@ static void helptags_one(char_u *dir, const char_u *ext, const char_u *tagfname, vim_snprintf((char *)NameBuff, MAXPATHL, _("E154: Duplicate tag \"%s\" in file %s/%s"), ((char_u **)ga.ga_data)[i], dir, p2 + 1); - EMSG(NameBuff); + emsg((char *)NameBuff); *p2 = '\t'; break; } @@ -5702,7 +5699,7 @@ static void do_helptags(char_u *dirname, bool add_help_tags, bool ignore_writeer STRLCPY(NameBuff, dirname, sizeof(NameBuff)); if (!add_pathsep((char *)NameBuff) || STRLCAT(NameBuff, "**", sizeof(NameBuff)) >= MAXPATHL) { - EMSG(_(e_fnametoolong)); + emsg(_(e_fnametoolong)); return; } @@ -5712,12 +5709,12 @@ static void do_helptags(char_u *dirname, bool add_help_tags, bool ignore_writeer if (gen_expand_wildcards(1, buff_list, &filecount, &files, EW_FILE|EW_SILENT) == FAIL || filecount == 0) { - EMSG2(_("E151: No match: %s"), NameBuff); + semsg(_("E151: No match: %s"), NameBuff); return; } - /* Go over all files in the directory to find out what languages are - * present. */ + // Go over all files in the directory to find out what languages are + // present. int j; ga_init(&ga, 1, 10); for (int i = 0; i < filecount; i++) { @@ -5807,7 +5804,7 @@ void ex_helptags(exarg_T *eap) dirname = ExpandOne(&xpc, eap->arg, NULL, WILD_LIST_NOTFOUND|WILD_SILENT, WILD_EXPAND_FREE); if (dirname == NULL || !os_isdir(dirname)) { - EMSG2(_("E150: Not a directory: %s"), eap->arg); + semsg(_("E150: Not a directory: %s"), eap->arg); } else { do_helptags(dirname, add_help_tags, false); } @@ -6128,7 +6125,7 @@ void ex_oldfiles(exarg_T *eap) long nr = 0; if (l == NULL) { - msg((char_u *)_("No old files")); + msg(_("No old files")); } else { msg_start(); msg_scroll = true; @@ -6140,7 +6137,7 @@ void ex_oldfiles(exarg_T *eap) const char *fname = tv_get_string(TV_LIST_ITEM_TV(li)); if (!message_filtered((char_u *)fname)) { msg_outnum(nr); - MSG_PUTS(": "); + msg_puts(": "); msg_outtrans((char_u *)tv_get_string(TV_LIST_ITEM_TV(li))); msg_clr_eos(); msg_putchar('\n'); |