aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/ops.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/ops.c')
-rw-r--r--src/nvim/ops.c203
1 files changed, 91 insertions, 112 deletions
diff --git a/src/nvim/ops.c b/src/nvim/ops.c
index 3a8f7c42a5..7d7db2a8a6 100644
--- a/src/nvim/ops.c
+++ b/src/nvim/ops.c
@@ -210,7 +210,6 @@ void op_shift(oparg_T *oap, int curs_top, int amount)
{
long i;
int first_char;
- char_u *s;
int block_col = 0;
if (u_save((linenr_T)(oap->start.lnum - 1),
@@ -249,27 +248,21 @@ void op_shift(oparg_T *oap, int curs_top, int amount)
foldOpenCursor();
if (oap->line_count > p_report) {
+ char *op;
if (oap->op_type == OP_RSHIFT) {
- s = (char_u *)">";
+ op = ">";
} else {
- s = (char_u *)"<";
+ op = "<";
}
- if (oap->line_count == 1) {
- if (amount == 1) {
- sprintf((char *)IObuff, _("1 line %sed 1 time"), s);
- } else {
- sprintf((char *)IObuff, _("1 line %sed %d times"), s, amount);
- }
- } else {
- if (amount == 1) {
- sprintf((char *)IObuff, _("%" PRId64 " lines %sed 1 time"),
- (int64_t)oap->line_count, s);
- } else {
- sprintf((char *)IObuff, _("%" PRId64 " lines %sed %d times"),
- (int64_t)oap->line_count, s, amount);
- }
- }
- msg_attr_keep(IObuff, 0, true, false);
+
+ char *msg_line_single = NGETTEXT("%" PRId64 " line %sed %d time",
+ "%" PRId64 " line %sed %d times", amount);
+ char *msg_line_plural = NGETTEXT("%" PRId64 " lines %sed %d time",
+ "%" PRId64 " lines %sed %d times", amount);
+ vim_snprintf((char *)IObuff, IOSIZE,
+ NGETTEXT(msg_line_single, msg_line_plural, oap->line_count),
+ (int64_t)oap->line_count, op, amount);
+ msg_attr_keep((char *)IObuff, 0, true, false);
}
/*
@@ -391,8 +384,8 @@ static void shift_block(oparg_T *oap, int amount)
total += incr;
bd.start_vcol += incr;
}
- /* OK, now total=all the VWS reqd, and textstart points at the 1st
- * non-ws char in the block. */
+ // OK, now total=all the VWS reqd, and textstart points at the 1st
+ // non-ws char in the block.
if (!curbuf->b_p_et) {
tabstop_fromto(ws_vcol, ws_vcol + total, p_ts, p_vts, &i, &j);
} else {
@@ -459,14 +452,14 @@ static void shift_block(oparg_T *oap, int amount)
// The column to which we will shift the text.
destination_col = non_white_col - shift_amount;
- /* Now let's find out how much of the beginning of the line we can
- * reuse without modification. */
+ // Now let's find out how much of the beginning of the line we can
+ // reuse without modification.
verbatim_copy_end = bd.textstart;
verbatim_copy_width = bd.start_vcol;
- /* If "bd.startspaces" is set, "bd.textstart" points to the character
- * preceding the block. We have to subtract its width to obtain its
- * column number. */
+ // If "bd.startspaces" is set, "bd.textstart" points to the character
+ // preceding the block. We have to subtract its width to obtain its
+ // column number.
if (bd.startspaces) {
verbatim_copy_width -= bd.start_char_vcols;
}
@@ -482,9 +475,9 @@ static void shift_block(oparg_T *oap, int amount)
MB_PTR_ADV(verbatim_copy_end);
}
- /* If "destination_col" is different from the width of the initial
- * part of the line that will be copied, it means we encountered a tab
- * character, which we will have to partly replace with spaces. */
+ // If "destination_col" is different from the width of the initial
+ // part of the line that will be copied, it means we encountered a tab
+ // character, which we will have to partly replace with spaces.
assert(destination_col - verbatim_copy_width >= 0);
fill = (size_t)(destination_col - verbatim_copy_width);
@@ -640,7 +633,7 @@ void op_reindent(oparg_T *oap, Indenter how)
// Don't even try when 'modifiable' is off.
if (!MODIFIABLE(curbuf)) {
- EMSG(_(e_modifiable));
+ emsg(_(e_modifiable));
return;
}
@@ -695,11 +688,9 @@ void op_reindent(oparg_T *oap, Indenter how)
if (oap->line_count > p_report) {
i = oap->line_count - (i + 1);
- if (i == 1) {
- MSG(_("1 line indented "));
- } else {
- smsg(_("%" PRId64 " lines indented "), (int64_t)i);
- }
+ smsg(NGETTEXT("%" PRId64 " line indented ",
+ "%" PRId64 " lines indented ", i),
+ (int64_t)i);
}
// set '[ and '] marks
curbuf->b_op_start = oap->start;
@@ -930,7 +921,7 @@ int do_record(int c)
if (ui_has(kUIMessages)) {
showmode();
} else {
- MSG("");
+ msg("");
}
p = get_recorded();
if (p == NULL) {
@@ -1018,7 +1009,7 @@ int do_execreg(int regname, int colon, int addcr, int silent)
if (regname == '@') { // repeat previous one
if (execreg_lastc == NUL) {
- EMSG(_("E748: No previously used register"));
+ emsg(_("E748: No previously used register"));
return FAIL;
}
regname = execreg_lastc;
@@ -1036,7 +1027,7 @@ int do_execreg(int regname, int colon, int addcr, int silent)
if (regname == ':') { // use last command line
if (last_cmdline == NULL) {
- EMSG(_(e_nolastcmd));
+ emsg(_(e_nolastcmd));
return FAIL;
}
// don't keep the cmdline containing @:
@@ -1066,7 +1057,7 @@ int do_execreg(int regname, int colon, int addcr, int silent)
} else if (regname == '.') { // use last inserted text
p = get_last_insert_save();
if (p == NULL) {
- EMSG(_(e_noinstext));
+ emsg(_(e_noinstext));
return FAIL;
}
retval = put_in_typebuf(p, false, colon, silent);
@@ -1291,14 +1282,14 @@ bool get_spec_reg(int regname, char_u **argp, bool *allocated, bool errmsg)
case ':': // last command line
if (last_cmdline == NULL && errmsg) {
- EMSG(_(e_nolastcmd));
+ emsg(_(e_nolastcmd));
}
*argp = last_cmdline;
return true;
case '/': // last search-pattern
if (last_search_pat() == NULL && errmsg) {
- EMSG(_(e_noprevre));
+ emsg(_(e_noprevre));
}
*argp = last_search_pat();
return true;
@@ -1307,7 +1298,7 @@ bool get_spec_reg(int regname, char_u **argp, bool *allocated, bool errmsg)
*argp = get_last_insert_save();
*allocated = true;
if (*argp == NULL && errmsg) {
- EMSG(_(e_noinstext));
+ emsg(_(e_noinstext));
}
return true;
@@ -1424,7 +1415,7 @@ int op_delete(oparg_T *oap)
}
if (!MODIFIABLE(curbuf)) {
- EMSG(_(e_modifiable));
+ emsg(_(e_modifiable));
return FAIL;
}
@@ -1500,8 +1491,8 @@ int op_delete(oparg_T *oap)
did_yank = true;
}
- /* Yank into small delete register when no named register specified
- * and the delete is within one line. */
+ // Yank into small delete register when no named register specified
+ // and the delete is within one line.
if (oap->regname == 0 && oap->motion_type != kMTLineWise
&& oap->line_count == 1) {
reg = get_yank_register('-', YREG_YANK);
@@ -1659,9 +1650,8 @@ int op_delete(oparg_T *oap)
n = oap->end.col - oap->start.col + 1 - !oap->inclusive;
if (virtual_op) {
- /* fix up things for virtualedit-delete:
- * break the tabs which are going to get in our way
- */
+ // fix up things for virtualedit-delete:
+ // break the tabs which are going to get in our way
char_u *curline = get_cursor_line_ptr();
int len = (int)STRLEN(curline);
@@ -1788,7 +1778,7 @@ int op_replace(oparg_T *oap, int c)
char_u *after_p = NULL;
int had_ctrl_v_cr = false;
- if ((curbuf->b_ml.ml_flags & ML_EMPTY ) || oap->empty) {
+ if ((curbuf->b_ml.ml_flags & ML_EMPTY) || oap->empty) {
return OK; // nothing to do
}
if (c == REPLACE_CR_NCHAR) {
@@ -1818,12 +1808,11 @@ int op_replace(oparg_T *oap, int c)
continue; // nothing to replace
}
- /* n == number of extra chars required
- * If we split a TAB, it may be replaced by several characters.
- * Thus the number of characters may increase!
- */
- /* If the range starts in virtual space, count the initial
- * coladd offset as part of "startspaces" */
+ // n == number of extra chars required
+ // If we split a TAB, it may be replaced by several characters.
+ // Thus the number of characters may increase!
+ // If the range starts in virtual space, count the initial
+ // coladd offset as part of "startspaces"
if (virtual_op && bd.is_short && *bd.textstart == NUL) {
pos_T vpos;
@@ -1848,7 +1837,7 @@ int op_replace(oparg_T *oap, int c)
// A double-wide character can be replaced only up to half the
// times.
- if ((*mb_char2cells)(c) > 1) {
+ if (utf_char2cells(c) > 1) {
if ((numc & 1) && !bd.is_short) {
++bd.endspaces;
++n;
@@ -1858,7 +1847,7 @@ int op_replace(oparg_T *oap, int c)
// Compute bytes needed, move character count to num_chars.
num_chars = numc;
- numc *= (*mb_char2len)(c);
+ numc *= utf_char2len(c);
oldp = get_cursor_line_ptr();
oldlen = (int)STRLEN(oldp);
@@ -1937,11 +1926,11 @@ int op_replace(oparg_T *oap, int c)
while (ltoreq(curwin->w_cursor, oap->end)) {
n = gchar_cursor();
if (n != NUL) {
- if ((*mb_char2len)(c) > 1 || (*mb_char2len)(n) > 1) {
+ if (utf_char2len(c) > 1 || utf_char2len(n) > 1) {
// This is slow, but it handles replacing a single-byte
// with a multi-byte and the other way around.
if (curwin->w_cursor.lnum == oap->end.lnum) {
- oap->end.col += (*mb_char2len)(c) - (*mb_char2len)(n);
+ oap->end.col += utf_char2len(c) - utf_char2len(n);
}
replace_character(c);
} else {
@@ -2075,11 +2064,9 @@ void op_tilde(oparg_T *oap)
curbuf->b_op_end = oap->end;
if (oap->line_count > p_report) {
- if (oap->line_count == 1) {
- MSG(_("1 line changed"));
- } else {
- smsg(_("%" PRId64 " lines changed"), (int64_t)oap->line_count);
- }
+ smsg(NGETTEXT("%" PRId64 " line changed",
+ "%" PRId64 " lines changed", oap->line_count),
+ (int64_t)oap->line_count);
}
}
@@ -2255,15 +2242,15 @@ void op_insert(oparg_T *oap, long count1)
// When a tab was inserted, and the characters in front of the tab
// have been converted to a tab as well, the column of the cursor
- // might have actually been reduced, so need to adjust here. */
+ // might have actually been reduced, so need to adjust here.
if (t1.lnum == curbuf->b_op_start_orig.lnum
&& lt(curbuf->b_op_start_orig, t1)) {
oap->start = curbuf->b_op_start_orig;
}
- /* If user has moved off this line, we don't know what to do, so do
- * nothing.
- * Also don't repeat the insert when Insert mode ended with CTRL-C. */
+ // If user has moved off this line, we don't know what to do, so do
+ // nothing.
+ // Also don't repeat the insert when Insert mode ended with CTRL-C.
if (curwin->w_cursor.lnum != oap->start.lnum || got_int) {
return;
}
@@ -2440,8 +2427,8 @@ int op_change(oparg_T *oap)
ins_len = (long)STRLEN(firstline) - pre_textlen;
if (ins_len > 0) {
- /* Subsequent calls to ml_get() flush the firstline data - take a
- * copy of the inserted text. */
+ // Subsequent calls to ml_get() flush the firstline data - take a
+ // copy of the inserted text.
ins_text = (char_u *)xmalloc((size_t)(ins_len + 1));
STRLCPY(ins_text, firstline + bd.textcol, ins_len + 1);
for (linenr = oap->start.lnum + 1; linenr <= oap->end.lnum;
@@ -2450,8 +2437,8 @@ int op_change(oparg_T *oap)
if (!bd.is_short || virtual_op) {
pos_T vpos;
- /* If the block starts in virtual space, count the
- * initial coladd offset as part of "startspaces" */
+ // If the block starts in virtual space, count the
+ // initial coladd offset as part of "startspaces"
if (bd.is_short) {
vpos.lnum = linenr;
(void)getvpos(&vpos, oap->start_vcol);
@@ -2734,17 +2721,14 @@ static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append)
// redisplay now, so message is not deleted
update_topline_redraw();
- if (yanklines == 1) {
- if (yank_type == kMTBlockWise) {
- smsg(_("block of 1 line yanked%s"), namebuf);
- } else {
- smsg(_("1 line yanked%s"), namebuf);
- }
- } else if (yank_type == kMTBlockWise) {
- smsg(_("block of %" PRId64 " lines yanked%s"),
+ if (yank_type == kMTBlockWise) {
+ smsg(NGETTEXT("block of %" PRId64 " line yanked%s",
+ "block of %" PRId64 " lines yanked%s", yanklines),
(int64_t)yanklines, namebuf);
} else {
- smsg(_("%" PRId64 " lines yanked%s"), (int64_t)yanklines, namebuf);
+ smsg(NGETTEXT("%" PRId64 " line yanked%s",
+ "%" PRId64 " lines yanked%s", yanklines),
+ (int64_t)yanklines, namebuf);
}
}
}
@@ -2955,7 +2939,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags)
bool one_past_line = (*cursor_pos == NUL);
bool eol = false;
if (!one_past_line) {
- eol = (*(cursor_pos + mb_ptr2len(cursor_pos)) == NUL);
+ eol = (*(cursor_pos + utfc_ptr2len(cursor_pos)) == NUL);
}
bool ve_allows = (ve_flags == VE_ALL || ve_flags == VE_ONEMORE);
@@ -3091,7 +3075,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags)
}
if (y_size == 0 || y_array == NULL) {
- EMSG2(_("E353: Nothing in register %s"),
+ semsg(_("E353: Nothing in register %s"),
regname == 0 ? (char_u *)"\"" : transchar(regname));
goto end;
}
@@ -3333,7 +3317,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags)
// if type is kMTCharWise, FORWARD is the same as BACKWARD on the next
// char
if (dir == FORWARD && gchar_cursor() != NUL) {
- int bytelen = (*mb_ptr2len)(get_cursor_pos_ptr());
+ int bytelen = utfc_ptr2len(get_cursor_pos_ptr());
// put it on the next of the multi-byte character.
col += bytelen;
@@ -3710,22 +3694,22 @@ void ex_display(exarg_T *eap)
msg_puts(" ");
msg_putchar('"');
msg_putchar(name);
- MSG_PUTS(" ");
+ msg_puts(" ");
int n = Columns - 11;
for (size_t j = 0; j < yb->y_size && n > 1; j++) {
if (j) {
- MSG_PUTS_ATTR("^J", attr);
+ msg_puts_attr("^J", attr);
n -= 2;
}
for (p = yb->y_array[j]; *p && (n -= ptr2cells(p)) >= 0; p++) { // -V1019 NOLINT(whitespace/line_length)
- clen = (*mb_ptr2len)(p);
+ clen = utfc_ptr2len(p);
msg_outtrans_len(p, clen);
p += clen - 1;
}
}
if (n > 1 && yb->y_type == kMTLineWise) {
- MSG_PUTS_ATTR("^J", attr);
+ msg_puts_attr("^J", attr);
}
ui_flush(); // show one line at a time
}
@@ -3834,9 +3818,8 @@ char_u *skip_comment(char_u *line, bool process, bool include_space, bool *is_co
*is_comment = false;
if (leader_offset != -1) {
- /* Let's check whether the line ends with an unclosed comment.
- * If the last comment leader has COM_END in flags, there's no comment.
- */
+ // Let's check whether the line ends with an unclosed comment.
+ // If the last comment leader has COM_END in flags, there's no comment.
while (*comment_flags) {
if (*comment_flags == COM_END
|| *comment_flags == ':') {
@@ -3859,11 +3842,10 @@ char_u *skip_comment(char_u *line, bool process, bool include_space, bool *is_co
return line;
}
- /* Find:
- * - COM_END,
- * - colon,
- * whichever comes first.
- */
+ // Find:
+ // - COM_END,
+ // - colon,
+ // whichever comes first.
while (*comment_flags) {
if (*comment_flags == COM_END
|| *comment_flags == ':') {
@@ -4145,7 +4127,6 @@ static int same_leader(linenr_T lnum, int leader1_len, char_u *leader1_flags, in
*/
line1 = vim_strsave(ml_get(lnum));
for (idx1 = 0; ascii_iswhite(line1[idx1]); ++idx1) {
- ;
}
line2 = ml_get(lnum + 1);
for (idx2 = 0; idx2 < leader2_len; ++idx2) {
@@ -4655,8 +4636,8 @@ static void block_prep(oparg_T *oap, struct block_def *bdp, linenr_T lnum, bool
bdp->endspaces = oap->end_vcol - oap->start_vcol + 1;
}
} else {
- /* notice: this converts partly selected Multibyte characters to
- * spaces, too. */
+ // notice: this converts partly selected Multibyte characters to
+ // spaces, too.
bdp->startspaces = bdp->start_vcol - oap->start_vcol;
if (is_del && bdp->startspaces) {
bdp->startspaces = bdp->start_char_vcols - bdp->startspaces;
@@ -4813,11 +4794,9 @@ void op_addsub(oparg_T *oap, linenr_T Prenum1, bool g_cmd)
}
if (change_cnt > p_report) {
- if (change_cnt == 1) {
- MSG(_("1 line changed"));
- } else {
- smsg(_("%" PRId64 " lines changed"), (int64_t)change_cnt);
- }
+ smsg(NGETTEXT("%" PRId64 " lines changed",
+ "%" PRId64 " lines changed", change_cnt),
+ (int64_t)change_cnt);
}
}
}
@@ -5404,7 +5383,7 @@ void write_reg_contents_lst(int name, char_u **strings, bool must_append, Motion
if (strings[0] == NULL) {
s = (char_u *)"";
} else if (strings[1] != NULL) {
- EMSG(_("E883: search pattern and expression register may not "
+ emsg(_("E883: search pattern and expression register may not "
"contain two or more lines"));
return;
}
@@ -5466,7 +5445,7 @@ void write_reg_contents_ex(int name, const char_u *str, ssize_t len, bool must_a
buf = buflist_findnr(num);
if (buf == NULL) {
- EMSGN(_(e_nobufnr), (long)num);
+ semsg(_(e_nobufnr), (int64_t)num);
}
} else {
buf = buflist_findnr(buflist_findpat(str, str + STRLEN(str),
@@ -5661,8 +5640,8 @@ static varnumber_T line_count_info(char_u *line, varnumber_T *wc, varnumber_T *c
} else if (!ascii_isspace(line[i])) {
is_word = 1;
}
- ++chars;
- i += (*mb_ptr2len)(line + i);
+ chars++;
+ i += utfc_ptr2len(line + i);
}
if (is_word) {
@@ -5708,7 +5687,7 @@ void cursor_pos_info(dict_T *dict)
// Compute the length of the file in characters.
if (curbuf->b_ml.ml_flags & ML_EMPTY) {
if (dict == NULL) {
- MSG(_(no_lines_msg));
+ msg(_(no_lines_msg));
return;
}
} else {
@@ -5906,7 +5885,7 @@ void cursor_pos_info(dict_T *dict)
// Don't shorten this message, the user asked for it.
p = p_shm;
p_shm = (char_u *)"";
- msg(IObuff);
+ msg((char *)IObuff);
p_shm = p;
}
}
@@ -5968,7 +5947,7 @@ static yankreg_T *adjust_clipboard_name(int *name, bool quiet, bool writing)
clipboard_didwarn = true;
// Do NOT error (emsg()) here--if it interrupts :redir we get into
// a weird state, stuck in "redirect mode".
- msg((char_u *)MSG_NO_CLIP);
+ msg(MSG_NO_CLIP);
}
// ... else, be silent (don't flood during :while, :redir, etc.).
goto end;
@@ -6206,7 +6185,7 @@ err:
reg->additional_data = NULL;
reg->timestamp = 0;
if (errmsg) {
- EMSG("clipboard: provider returned invalid data");
+ emsg("clipboard: provider returned invalid data");
}
*target = reg;
return false;