mirror of
https://github.com/neovim/neovim.git
synced 2025-09-17 00:38:17 +00:00
@@ -98,7 +98,6 @@ set(CONV_SOURCES
|
|||||||
mbyte.c
|
mbyte.c
|
||||||
memline.c
|
memline.c
|
||||||
message.c
|
message.c
|
||||||
ops.c
|
|
||||||
regexp.c
|
regexp.c
|
||||||
screen.c
|
screen.c
|
||||||
search.c
|
search.c
|
||||||
|
@@ -6952,7 +6952,7 @@ static void ins_reg(void)
|
|||||||
AppendCharToRedobuff(literally);
|
AppendCharToRedobuff(literally);
|
||||||
AppendCharToRedobuff(regname);
|
AppendCharToRedobuff(regname);
|
||||||
|
|
||||||
do_put(regname, NULL, BACKWARD, 1L,
|
do_put(regname, NULL, BACKWARD, 1,
|
||||||
(literally == Ctrl_P ? PUT_FIXINDENT : 0) | PUT_CURSEND);
|
(literally == Ctrl_P ? PUT_FIXINDENT : 0) | PUT_CURSEND);
|
||||||
} else if (insert_reg(regname, literally) == FAIL) {
|
} else if (insert_reg(regname, literally) == FAIL) {
|
||||||
vim_beep(BO_REG);
|
vim_beep(BO_REG);
|
||||||
@@ -7701,7 +7701,7 @@ static void ins_mouse(int c)
|
|||||||
|
|
||||||
undisplay_dollar();
|
undisplay_dollar();
|
||||||
tpos = curwin->w_cursor;
|
tpos = curwin->w_cursor;
|
||||||
if (do_mouse(NULL, c, BACKWARD, 1L, 0)) {
|
if (do_mouse(NULL, c, BACKWARD, 1, 0)) {
|
||||||
win_T *new_curwin = curwin;
|
win_T *new_curwin = curwin;
|
||||||
|
|
||||||
if (curwin != old_curwin && win_valid(old_curwin)) {
|
if (curwin != old_curwin && win_valid(old_curwin)) {
|
||||||
|
@@ -1891,7 +1891,7 @@ ex_let_one (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (p != NULL) {
|
if (p != NULL) {
|
||||||
write_reg_contents(*arg == '@' ? '"' : *arg, p, -1, FALSE);
|
write_reg_contents(*arg == '@' ? '"' : *arg, p, STRLEN(p), false);
|
||||||
arg_end = arg + 1;
|
arg_end = arg + 1;
|
||||||
}
|
}
|
||||||
xfree(ptofree);
|
xfree(ptofree);
|
||||||
@@ -14920,7 +14920,8 @@ static void f_setreg(typval_T *argvars, typval_T *rettv)
|
|||||||
}
|
}
|
||||||
*curval++ = NULL;
|
*curval++ = NULL;
|
||||||
|
|
||||||
write_reg_contents_lst(regname, lstval, -1, append, yank_type, block_len);
|
write_reg_contents_lst(regname, lstval, STRLEN(lstval),
|
||||||
|
append, yank_type, block_len);
|
||||||
|
|
||||||
free_lstval:
|
free_lstval:
|
||||||
while (curallocval > allocval)
|
while (curallocval > allocval)
|
||||||
@@ -14931,7 +14932,8 @@ free_lstval:
|
|||||||
if (strval == NULL) {
|
if (strval == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
write_reg_contents_ex(regname, strval, -1, append, yank_type, block_len);
|
write_reg_contents_ex(regname, strval, STRLEN(strval),
|
||||||
|
append, yank_type, block_len);
|
||||||
}
|
}
|
||||||
rettv->vval.v_number = 0;
|
rettv->vval.v_number = 0;
|
||||||
}
|
}
|
||||||
|
@@ -2010,9 +2010,7 @@ void ex_argdelete(exarg_T *eap)
|
|||||||
maketitle();
|
maketitle();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/// ":argdo", ":windo", ":bufdo", ":tabdo", ":cdo", ":ldo", ":cfdo" and ":lfdo"
|
||||||
* ":argdo", ":windo", ":bufdo", ":tabdo", ":cdo", ":ldo", ":cfdo" and ":lfdo"
|
|
||||||
*/
|
|
||||||
void ex_listdo(exarg_T *eap)
|
void ex_listdo(exarg_T *eap)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
@@ -2060,9 +2058,9 @@ void ex_listdo(exarg_T *eap)
|
|||||||
buf_T *buf = curbuf;
|
buf_T *buf = curbuf;
|
||||||
size_t qf_size = 0;
|
size_t qf_size = 0;
|
||||||
|
|
||||||
/* set pcmark now */
|
// set pcmark now
|
||||||
if (eap->cmdidx == CMD_bufdo) {
|
if (eap->cmdidx == CMD_bufdo) {
|
||||||
/* Advance to the first listed buffer after "eap->line1". */
|
// Advance to the first listed buffer after "eap->line1".
|
||||||
for (buf = firstbuf;
|
for (buf = firstbuf;
|
||||||
buf != NULL && (buf->b_fnum < eap->line1 || !buf->b_p_bl);
|
buf != NULL && (buf->b_fnum < eap->line1 || !buf->b_p_bl);
|
||||||
buf = buf->b_next) {
|
buf = buf->b_next) {
|
||||||
|
@@ -1536,8 +1536,9 @@ static char_u * do_one_cmd(char_u **cmdlinep,
|
|||||||
}
|
}
|
||||||
ea.cmd = skipwhite(ea.cmd);
|
ea.cmd = skipwhite(ea.cmd);
|
||||||
lnum = get_address(&ea, &ea.cmd, ea.addr_type, ea.skip, ea.addr_count == 0);
|
lnum = get_address(&ea, &ea.cmd, ea.addr_type, ea.skip, ea.addr_count == 0);
|
||||||
if (ea.cmd == NULL) /* error detected */
|
if (ea.cmd == NULL) { // error detected
|
||||||
goto doend;
|
goto doend;
|
||||||
|
}
|
||||||
if (lnum == MAXLNUM) {
|
if (lnum == MAXLNUM) {
|
||||||
if (*ea.cmd == '%') { /* '%' - all lines */
|
if (*ea.cmd == '%') { /* '%' - all lines */
|
||||||
++ea.cmd;
|
++ea.cmd;
|
||||||
@@ -7125,7 +7126,7 @@ static void ex_put(exarg_T *eap)
|
|||||||
eap->forceit = TRUE;
|
eap->forceit = TRUE;
|
||||||
}
|
}
|
||||||
curwin->w_cursor.lnum = eap->line2;
|
curwin->w_cursor.lnum = eap->line2;
|
||||||
do_put(eap->regname, NULL, eap->forceit ? BACKWARD : FORWARD, 1L,
|
do_put(eap->regname, NULL, eap->forceit ? BACKWARD : FORWARD, 1,
|
||||||
PUT_LINE|PUT_CURSLINE);
|
PUT_LINE|PUT_CURSLINE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -7135,7 +7136,7 @@ static void ex_put(exarg_T *eap)
|
|||||||
static void ex_copymove(exarg_T *eap)
|
static void ex_copymove(exarg_T *eap)
|
||||||
{
|
{
|
||||||
long n = get_address(eap, &eap->arg, eap->addr_type, false, false);
|
long n = get_address(eap, &eap->arg, eap->addr_type, false, false);
|
||||||
if (eap->arg == NULL) { /* error detected */
|
if (eap->arg == NULL) { // error detected
|
||||||
eap->nextcmd = NULL;
|
eap->nextcmd = NULL;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -7354,10 +7355,11 @@ static void ex_redir(exarg_T *eap)
|
|||||||
/* Can use both "@a" and "@a>". */
|
/* Can use both "@a" and "@a>". */
|
||||||
if (*arg == '>')
|
if (*arg == '>')
|
||||||
arg++;
|
arg++;
|
||||||
/* Make register empty when not using @A-@Z and the
|
// Make register empty when not using @A-@Z and the
|
||||||
* command is valid. */
|
// command is valid.
|
||||||
if (*arg == NUL && !isupper(redir_reg))
|
if (*arg == NUL && !isupper(redir_reg)) {
|
||||||
write_reg_contents(redir_reg, (char_u *)"", -1, FALSE);
|
write_reg_contents(redir_reg, (char_u *)"", 0, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (*arg != NUL) {
|
if (*arg != NUL) {
|
||||||
|
@@ -836,8 +836,8 @@ EXTERN int* (*iconv_errno)(void);
|
|||||||
EXTERN int State INIT(= NORMAL); /* This is the current state of the
|
EXTERN int State INIT(= NORMAL); /* This is the current state of the
|
||||||
* command interpreter. */
|
* command interpreter. */
|
||||||
|
|
||||||
EXTERN int finish_op INIT(= FALSE); /* TRUE while an operator is pending */
|
EXTERN bool finish_op INIT(= false); // true while an operator is pending
|
||||||
EXTERN long opcount INIT(= 0); /* count for pending operator */
|
EXTERN long opcount INIT(= 0); // count for pending operator
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ex mode (Q) state
|
* ex mode (Q) state
|
||||||
|
@@ -493,10 +493,11 @@ int emsg(char_u *s)
|
|||||||
* when the message should be ignored completely (used for the
|
* when the message should be ignored completely (used for the
|
||||||
* interrupt message).
|
* interrupt message).
|
||||||
*/
|
*/
|
||||||
if (cause_errthrow(s, severe, &ignore) == TRUE) {
|
if (cause_errthrow(s, severe, &ignore) == true) {
|
||||||
if (!ignore)
|
if (!ignore) {
|
||||||
did_emsg = TRUE;
|
did_emsg = true;
|
||||||
return TRUE;
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// set "v:errmsg", also when using ":silent! cmd"
|
// set "v:errmsg", also when using ":silent! cmd"
|
||||||
@@ -511,41 +512,43 @@ int emsg(char_u *s)
|
|||||||
p = get_emsg_source();
|
p = get_emsg_source();
|
||||||
if (p != NULL) {
|
if (p != NULL) {
|
||||||
STRCAT(p, "\n");
|
STRCAT(p, "\n");
|
||||||
redir_write(p, -1);
|
redir_write(p, STRLEN(p));
|
||||||
xfree(p);
|
xfree(p);
|
||||||
}
|
}
|
||||||
p = get_emsg_lnum();
|
p = get_emsg_lnum();
|
||||||
if (p != NULL) {
|
if (p != NULL) {
|
||||||
STRCAT(p, "\n");
|
STRCAT(p, "\n");
|
||||||
redir_write(p, -1);
|
redir_write(p, STRLEN(p));
|
||||||
xfree(p);
|
xfree(p);
|
||||||
}
|
}
|
||||||
redir_write(s, -1);
|
redir_write(s, STRLEN(s));
|
||||||
return TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Reset msg_silent, an error causes messages to be switched back on. */
|
// Reset msg_silent, an error causes messages to be switched back on.
|
||||||
msg_silent = 0;
|
msg_silent = 0;
|
||||||
cmd_silent = FALSE;
|
cmd_silent = FALSE;
|
||||||
|
|
||||||
if (global_busy) /* break :global command */
|
if (global_busy) { // break :global command
|
||||||
++global_busy;
|
global_busy++;
|
||||||
|
|
||||||
if (p_eb)
|
|
||||||
beep_flush(); /* also includes flush_buffers() */
|
|
||||||
else
|
|
||||||
flush_buffers(FALSE); /* flush internal buffers */
|
|
||||||
did_emsg = TRUE; /* flag for DoOneCmd() */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
emsg_on_display = TRUE; /* remember there is an error message */
|
if (p_eb) {
|
||||||
++msg_scroll; /* don't overwrite a previous message */
|
beep_flush(); // also includes flush_buffers()
|
||||||
attr = hl_attr(HLF_E); /* set highlight mode for error messages */
|
} else {
|
||||||
if (msg_scrolled != 0)
|
flush_buffers(false); // flush internal buffers
|
||||||
need_wait_return = TRUE; /* needed in case emsg() is called after
|
}
|
||||||
* wait_return has reset need_wait_return
|
did_emsg = true; // flag for DoOneCmd()
|
||||||
* and a redraw is expected because
|
}
|
||||||
* msg_scrolled is non-zero */
|
|
||||||
|
emsg_on_display = true; // remember there is an error message
|
||||||
|
msg_scroll++; // don't overwrite a previous message
|
||||||
|
attr = hl_attr(HLF_E); // set highlight mode for error messages
|
||||||
|
if (msg_scrolled != 0) {
|
||||||
|
need_wait_return = true; // needed in case emsg() is called after
|
||||||
|
} // wait_return has reset need_wait_return
|
||||||
|
// and a redraw is expected because
|
||||||
|
// msg_scrolled is non-zero
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Display name and line number for the source of the error.
|
* Display name and line number for the source of the error.
|
||||||
@@ -2401,22 +2404,27 @@ static void redir_write(char_u *str, int maxlen)
|
|||||||
/* If the string doesn't start with CR or NL, go to msg_col */
|
/* If the string doesn't start with CR or NL, go to msg_col */
|
||||||
if (*s != '\n' && *s != '\r') {
|
if (*s != '\n' && *s != '\r') {
|
||||||
while (cur_col < msg_col) {
|
while (cur_col < msg_col) {
|
||||||
if (redir_reg)
|
if (redir_reg) {
|
||||||
write_reg_contents(redir_reg, (char_u *)" ", -1, TRUE);
|
write_reg_contents(redir_reg, (char_u *)" ", 1, true);
|
||||||
else if (redir_vname)
|
} else if (redir_vname) {
|
||||||
var_redir_str((char_u *)" ", -1);
|
var_redir_str((char_u *)" ", -1);
|
||||||
else if (redir_fd != NULL)
|
} else if (redir_fd != NULL) {
|
||||||
fputs(" ", redir_fd);
|
fputs(" ", redir_fd);
|
||||||
if (verbose_fd != NULL)
|
}
|
||||||
|
if (verbose_fd != NULL) {
|
||||||
fputs(" ", verbose_fd);
|
fputs(" ", verbose_fd);
|
||||||
++cur_col;
|
}
|
||||||
|
cur_col++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (redir_reg)
|
if (redir_reg) {
|
||||||
write_reg_contents(redir_reg, s, maxlen, TRUE);
|
size_t len = maxlen == -1 ? STRLEN(s) : (size_t)maxlen;
|
||||||
if (redir_vname)
|
write_reg_contents(redir_reg, s, len, true);
|
||||||
|
}
|
||||||
|
if (redir_vname) {
|
||||||
var_redir_str(s, maxlen);
|
var_redir_str(s, maxlen);
|
||||||
|
}
|
||||||
|
|
||||||
/* Write and adjust the current column. */
|
/* Write and adjust the current column. */
|
||||||
while (*s != NUL && (maxlen < 0 || (int)(s - str) < maxlen)) {
|
while (*s != NUL && (maxlen < 0 || (int)(s - str) < maxlen)) {
|
||||||
|
@@ -178,12 +178,11 @@ open_line (
|
|||||||
if (curbuf->b_p_ai
|
if (curbuf->b_p_ai
|
||||||
|| do_si
|
|| do_si
|
||||||
) {
|
) {
|
||||||
/*
|
// count white space on current line
|
||||||
* count white space on current line
|
newindent = get_indent_str(saved_line, (int)curbuf->b_p_ts, false);
|
||||||
*/
|
if (newindent == 0 && !(flags & OPENLINE_COM_LIST)) {
|
||||||
newindent = get_indent_str(saved_line, (int)curbuf->b_p_ts, FALSE);
|
newindent = second_line_indent; // for ^^D command in insert mode
|
||||||
if (newindent == 0 && !(flags & OPENLINE_COM_LIST))
|
}
|
||||||
newindent = second_line_indent; /* for ^^D command in insert mode */
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Do smart indenting.
|
* Do smart indenting.
|
||||||
@@ -612,7 +611,7 @@ open_line (
|
|||||||
if (curbuf->b_p_ai
|
if (curbuf->b_p_ai
|
||||||
|| do_si
|
|| do_si
|
||||||
)
|
)
|
||||||
newindent = get_indent_str(leader, (int)curbuf->b_p_ts, FALSE);
|
newindent = get_indent_str(leader, (int)curbuf->b_p_ts, false);
|
||||||
|
|
||||||
/* Add the indent offset */
|
/* Add the indent offset */
|
||||||
if (newindent + off < 0) {
|
if (newindent + off < 0) {
|
||||||
|
@@ -1795,10 +1795,11 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
|
|||||||
if (oap->line_count < 2)
|
if (oap->line_count < 2)
|
||||||
oap->line_count = 2;
|
oap->line_count = 2;
|
||||||
if (curwin->w_cursor.lnum + oap->line_count - 1 >
|
if (curwin->w_cursor.lnum + oap->line_count - 1 >
|
||||||
curbuf->b_ml.ml_line_count)
|
curbuf->b_ml.ml_line_count) {
|
||||||
beep_flush();
|
beep_flush();
|
||||||
else {
|
} else {
|
||||||
do_join(oap->line_count, oap->op_type == OP_JOIN, true, true, true);
|
do_join((size_t)oap->line_count, oap->op_type == OP_JOIN,
|
||||||
|
true, true, true);
|
||||||
auto_format(false, true);
|
auto_format(false, true);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -7666,7 +7667,7 @@ static void nv_join(cmdarg_T *cap)
|
|||||||
|
|
||||||
prep_redo(cap->oap->regname, cap->count0,
|
prep_redo(cap->oap->regname, cap->count0,
|
||||||
NUL, cap->cmdchar, NUL, NUL, cap->nchar);
|
NUL, cap->cmdchar, NUL, NUL, cap->nchar);
|
||||||
do_join(cap->count0, cap->nchar == NUL, true, true, true);
|
do_join((size_t)cap->count0, cap->nchar == NUL, true, true, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
428
src/nvim/ops.c
428
src/nvim/ops.c
@@ -257,8 +257,7 @@ void op_shift(oparg_T *oap, int curs_top, int amount)
|
|||||||
* shift the current line one shiftwidth left (if left != 0) or right
|
* shift the current line one shiftwidth left (if left != 0) or right
|
||||||
* leaves cursor on first blank in the line
|
* leaves cursor on first blank in the line
|
||||||
*/
|
*/
|
||||||
void
|
void shift_line(
|
||||||
shift_line (
|
|
||||||
int left,
|
int left,
|
||||||
int round,
|
int round,
|
||||||
int amount,
|
int amount,
|
||||||
@@ -369,18 +368,18 @@ static void shift_block(oparg_T *oap, int amount)
|
|||||||
memset(newp + bd.textcol + i, ' ', (size_t)j);
|
memset(newp + bd.textcol + i, ' ', (size_t)j);
|
||||||
/* the end */
|
/* the end */
|
||||||
memmove(newp + bd.textcol + i + j, bd.textstart, (size_t)len);
|
memmove(newp + bd.textcol + i + j, bd.textstart, (size_t)len);
|
||||||
} else { /* left */
|
} else { // left
|
||||||
colnr_T destination_col; /* column to which text in block will
|
colnr_T destination_col; // column to which text in block will
|
||||||
be shifted */
|
// be shifted
|
||||||
char_u *verbatim_copy_end; /* end of the part of the line which is
|
char_u *verbatim_copy_end; // end of the part of the line which is
|
||||||
copied verbatim */
|
// copied verbatim
|
||||||
colnr_T verbatim_copy_width; /* the (displayed) width of this part
|
colnr_T verbatim_copy_width; // the (displayed) width of this part
|
||||||
of line */
|
// of line
|
||||||
unsigned fill; /* nr of spaces that replace a TAB */
|
size_t fill; // nr of spaces that replace a TAB
|
||||||
unsigned new_line_len; /* the length of the line after the
|
size_t new_line_len; // the length of the line after the
|
||||||
block shift */
|
// block shift
|
||||||
size_t block_space_width;
|
colnr_T block_space_width;
|
||||||
size_t shift_amount;
|
colnr_T shift_amount;
|
||||||
char_u *non_white = bd.textstart;
|
char_u *non_white = bd.textstart;
|
||||||
colnr_T non_white_col;
|
colnr_T non_white_col;
|
||||||
|
|
||||||
@@ -409,11 +408,10 @@ static void shift_block(oparg_T *oap, int amount)
|
|||||||
block_space_width = non_white_col - oap->start_vcol;
|
block_space_width = non_white_col - oap->start_vcol;
|
||||||
/* We will shift by "total" or "block_space_width", whichever is less.
|
/* We will shift by "total" or "block_space_width", whichever is less.
|
||||||
*/
|
*/
|
||||||
shift_amount = (block_space_width < (size_t)total
|
shift_amount = (block_space_width < total ? block_space_width : total);
|
||||||
? block_space_width : (size_t)total);
|
|
||||||
|
|
||||||
/* The column to which we will shift the text. */
|
// The column to which we will shift the text.
|
||||||
destination_col = (colnr_T)(non_white_col - shift_amount);
|
destination_col = non_white_col - shift_amount;
|
||||||
|
|
||||||
/* Now let's find out how much of the beginning of the line we can
|
/* Now let's find out how much of the beginning of the line we can
|
||||||
* reuse without modification. */
|
* reuse without modification. */
|
||||||
@@ -439,20 +437,21 @@ static void shift_block(oparg_T *oap, int amount)
|
|||||||
/* If "destination_col" is different from the width of the initial
|
/* 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
|
* part of the line that will be copied, it means we encountered a tab
|
||||||
* character, which we will have to partly replace with spaces. */
|
* character, which we will have to partly replace with spaces. */
|
||||||
fill = destination_col - verbatim_copy_width;
|
assert(destination_col - verbatim_copy_width >= 0);
|
||||||
|
fill = (size_t)(destination_col - verbatim_copy_width);
|
||||||
|
|
||||||
/* The replacement line will consist of:
|
assert(verbatim_copy_end - oldp >= 0);
|
||||||
* - the beginning of the original line up to "verbatim_copy_end",
|
size_t verbatim_diff = (size_t)(verbatim_copy_end - oldp);
|
||||||
* - "fill" number of spaces,
|
// The replacement line will consist of:
|
||||||
* - the rest of the line, pointed to by non_white. */
|
// - the beginning of the original line up to "verbatim_copy_end",
|
||||||
new_line_len = (unsigned)(verbatim_copy_end - oldp)
|
// - "fill" number of spaces,
|
||||||
+ fill
|
// - the rest of the line, pointed to by non_white.
|
||||||
+ (unsigned)STRLEN(non_white) + 1;
|
new_line_len = verbatim_diff + fill + STRLEN(non_white) + 1;
|
||||||
|
|
||||||
newp = (char_u *) xmalloc((size_t)(new_line_len));
|
newp = (char_u *) xmalloc(new_line_len);
|
||||||
memmove(newp, oldp, (size_t)(verbatim_copy_end - oldp));
|
memmove(newp, oldp, verbatim_diff);
|
||||||
memset(newp + (verbatim_copy_end - oldp), ' ', (size_t)fill);
|
memset(newp + verbatim_diff, ' ', fill);
|
||||||
STRMOVE(newp + (verbatim_copy_end - oldp) + fill, non_white);
|
STRMOVE(newp + verbatim_diff + fill, non_white);
|
||||||
}
|
}
|
||||||
/* replace the line */
|
/* replace the line */
|
||||||
ml_replace(curwin->w_cursor.lnum, newp, FALSE);
|
ml_replace(curwin->w_cursor.lnum, newp, FALSE);
|
||||||
@@ -469,21 +468,20 @@ static void shift_block(oparg_T *oap, int amount)
|
|||||||
static void block_insert(oparg_T *oap, char_u *s, int b_insert, struct block_def *bdp)
|
static void block_insert(oparg_T *oap, char_u *s, int b_insert, struct block_def *bdp)
|
||||||
{
|
{
|
||||||
int p_ts;
|
int p_ts;
|
||||||
int count = 0; /* extra spaces to replace a cut TAB */
|
int count = 0; // extra spaces to replace a cut TAB
|
||||||
int spaces = 0; /* non-zero if cutting a TAB */
|
int spaces = 0; // non-zero if cutting a TAB
|
||||||
colnr_T offset; /* pointer along new line */
|
colnr_T offset; // pointer along new line
|
||||||
unsigned s_len; /* STRLEN(s) */
|
size_t s_len = STRLEN(s);
|
||||||
char_u *newp, *oldp; /* new, old lines */
|
char_u *newp, *oldp; // new, old lines
|
||||||
linenr_T lnum; /* loop var */
|
linenr_T lnum; // loop var
|
||||||
int oldstate = State;
|
int oldstate = State;
|
||||||
|
State = INSERT; // don't want REPLACE for State
|
||||||
State = INSERT; /* don't want REPLACE for State */
|
|
||||||
s_len = (unsigned)STRLEN(s);
|
|
||||||
|
|
||||||
for (lnum = oap->start.lnum + 1; lnum <= oap->end.lnum; lnum++) {
|
for (lnum = oap->start.lnum + 1; lnum <= oap->end.lnum; lnum++) {
|
||||||
block_prep(oap, bdp, lnum, TRUE);
|
block_prep(oap, bdp, lnum, true);
|
||||||
if (bdp->is_short && b_insert)
|
if (bdp->is_short && b_insert) {
|
||||||
continue; /* OP_INSERT, line ends before block start */
|
continue; // OP_INSERT, line ends before block start
|
||||||
|
}
|
||||||
|
|
||||||
oldp = ml_get(lnum);
|
oldp = ml_get(lnum);
|
||||||
|
|
||||||
@@ -523,25 +521,26 @@ static void block_insert(oparg_T *oap, char_u *s, int b_insert, struct block_def
|
|||||||
count -= off;
|
count -= off;
|
||||||
}
|
}
|
||||||
|
|
||||||
newp = (char_u *) xmalloc((size_t)(STRLEN(oldp) + s_len + count + 1));
|
assert(count >= 0);
|
||||||
|
newp = (char_u *)xmalloc(STRLEN(oldp) + s_len + (size_t)count + 1);
|
||||||
|
|
||||||
/* copy up to shifted part */
|
// copy up to shifted part
|
||||||
memmove(newp, oldp, (size_t)(offset));
|
memmove(newp, oldp, (size_t)offset);
|
||||||
oldp += offset;
|
oldp += offset;
|
||||||
|
|
||||||
/* insert pre-padding */
|
// insert pre-padding
|
||||||
memset(newp + offset, ' ', (size_t)spaces);
|
memset(newp + offset, ' ', (size_t)spaces);
|
||||||
|
|
||||||
/* copy the new text */
|
// copy the new text
|
||||||
memmove(newp + offset + spaces, s, (size_t)s_len);
|
memmove(newp + offset + spaces, s, s_len);
|
||||||
offset += s_len;
|
offset += (int)s_len;
|
||||||
|
|
||||||
if (spaces && !bdp->is_short) {
|
if (spaces && !bdp->is_short) {
|
||||||
/* insert post-padding */
|
// insert post-padding
|
||||||
memset(newp + offset + spaces, ' ', (size_t)(p_ts - spaces));
|
memset(newp + offset + spaces, ' ', (size_t)(p_ts - spaces));
|
||||||
/* We're splitting a TAB, don't copy it. */
|
// We're splitting a TAB, don't copy it.
|
||||||
oldp++;
|
oldp++;
|
||||||
/* We allowed for that TAB, remember this now */
|
// We allowed for that TAB, remember this now
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -804,7 +803,7 @@ yankreg_T *copy_register(int name)
|
|||||||
copy->y_array = NULL;
|
copy->y_array = NULL;
|
||||||
} else {
|
} else {
|
||||||
copy->y_array = xcalloc(copy->y_size, sizeof(char_u *));
|
copy->y_array = xcalloc(copy->y_size, sizeof(char_u *));
|
||||||
for (linenr_T i = 0; i < copy->y_size; i++) {
|
for (size_t i = 0; i < copy->y_size; i++) {
|
||||||
copy->y_array[i] = vim_strsave(reg->y_array[i]);
|
copy->y_array[i] = vim_strsave(reg->y_array[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -940,10 +939,8 @@ do_execreg (
|
|||||||
int silent /* set "silent" flag in typeahead buffer */
|
int silent /* set "silent" flag in typeahead buffer */
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
long i;
|
|
||||||
char_u *p;
|
char_u *p;
|
||||||
int retval = OK;
|
int retval = OK;
|
||||||
int remap;
|
|
||||||
|
|
||||||
if (regname == '@') { /* repeat previous one */
|
if (regname == '@') { /* repeat previous one */
|
||||||
if (execreg_lastc == NUL) {
|
if (execreg_lastc == NUL) {
|
||||||
@@ -1001,22 +998,21 @@ do_execreg (
|
|||||||
if (reg->y_array == NULL)
|
if (reg->y_array == NULL)
|
||||||
return FAIL;
|
return FAIL;
|
||||||
|
|
||||||
/* Disallow remaping for ":@r". */
|
// Disallow remaping for ":@r".
|
||||||
remap = colon ? REMAP_NONE : REMAP_YES;
|
int remap = colon ? REMAP_NONE : REMAP_YES;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Insert lines into typeahead buffer, from last one to first one.
|
* Insert lines into typeahead buffer, from last one to first one.
|
||||||
*/
|
*/
|
||||||
put_reedit_in_typebuf(silent);
|
put_reedit_in_typebuf(silent);
|
||||||
for (i = reg->y_size - 1; i >= 0; i--) {
|
|
||||||
char_u *escaped;
|
char_u *escaped;
|
||||||
|
for (size_t i = reg->y_size; i-- > 0;) { // from y_size - 1 to 0 included
|
||||||
// insert NL between lines and after last line if type is kMTLineWise
|
// insert NL between lines and after last line if type is kMTLineWise
|
||||||
if (reg->y_type == kMTLineWise || i < reg->y_size - 1
|
if (reg->y_type == kMTLineWise || i < reg->y_size - 1 || addcr) {
|
||||||
|| addcr) {
|
if (ins_typebuf((char_u *)"\n", remap, 0, true, silent) == FAIL) {
|
||||||
if (ins_typebuf((char_u *)"\n", remap, 0, TRUE, silent) == FAIL)
|
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
escaped = vim_strsave_escape_csi(reg->y_array[i]);
|
escaped = vim_strsave_escape_csi(reg->y_array[i]);
|
||||||
retval = ins_typebuf(escaped, remap, 0, TRUE, silent);
|
retval = ins_typebuf(escaped, remap, 0, TRUE, silent);
|
||||||
xfree(escaped);
|
xfree(escaped);
|
||||||
@@ -1045,7 +1041,7 @@ static void put_reedit_in_typebuf(int silent)
|
|||||||
buf[1] = 'R';
|
buf[1] = 'R';
|
||||||
buf[2] = NUL;
|
buf[2] = NUL;
|
||||||
} else {
|
} else {
|
||||||
buf[0] = restart_edit == 'I' ? 'i' : restart_edit;
|
buf[0] = (char_u)(restart_edit == 'I' ? 'i' : restart_edit);
|
||||||
buf[1] = NUL;
|
buf[1] = NUL;
|
||||||
}
|
}
|
||||||
if (ins_typebuf(buf, REMAP_NONE, 0, TRUE, silent) == OK)
|
if (ins_typebuf(buf, REMAP_NONE, 0, TRUE, silent) == OK)
|
||||||
@@ -1059,8 +1055,7 @@ static void put_reedit_in_typebuf(int silent)
|
|||||||
* When "esc" is TRUE it is to be taken literally: Escape CSI characters and
|
* When "esc" is TRUE it is to be taken literally: Escape CSI characters and
|
||||||
* no remapping.
|
* no remapping.
|
||||||
*/
|
*/
|
||||||
static int
|
static int put_in_typebuf(
|
||||||
put_in_typebuf (
|
|
||||||
char_u *s,
|
char_u *s,
|
||||||
int esc,
|
int esc,
|
||||||
int colon, /* add ':' before the line */
|
int colon, /* add ':' before the line */
|
||||||
@@ -1098,13 +1093,11 @@ put_in_typebuf (
|
|||||||
*
|
*
|
||||||
* return FAIL for failure, OK otherwise
|
* return FAIL for failure, OK otherwise
|
||||||
*/
|
*/
|
||||||
int
|
int insert_reg(
|
||||||
insert_reg (
|
|
||||||
int regname,
|
int regname,
|
||||||
int literally /* insert literally, not as if typed */
|
int literally /* insert literally, not as if typed */
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
long i;
|
|
||||||
int retval = OK;
|
int retval = OK;
|
||||||
char_u *arg;
|
char_u *arg;
|
||||||
int allocated;
|
int allocated;
|
||||||
@@ -1132,10 +1125,10 @@ insert_reg (
|
|||||||
xfree(arg);
|
xfree(arg);
|
||||||
} else { /* name or number register */
|
} else { /* name or number register */
|
||||||
yankreg_T *reg = get_yank_register(regname, YREG_PASTE);
|
yankreg_T *reg = get_yank_register(regname, YREG_PASTE);
|
||||||
if (reg->y_array == NULL)
|
if (reg->y_array == NULL) {
|
||||||
retval = FAIL;
|
retval = FAIL;
|
||||||
else {
|
} else {
|
||||||
for (i = 0; i < reg->y_size; i++) {
|
for (size_t i = 0; i < reg->y_size; i++) {
|
||||||
stuffescaped(reg->y_array[i], literally);
|
stuffescaped(reg->y_array[i], literally);
|
||||||
// Insert a newline between lines and after last line if
|
// Insert a newline between lines and after last line if
|
||||||
// y_type is kMTLineWise.
|
// y_type is kMTLineWise.
|
||||||
@@ -1185,8 +1178,7 @@ static void stuffescaped(char_u *arg, int literally)
|
|||||||
* If "regname" is a special register, return TRUE and store a pointer to its
|
* If "regname" is a special register, return TRUE and store a pointer to its
|
||||||
* value in "argp".
|
* value in "argp".
|
||||||
*/
|
*/
|
||||||
int
|
int get_spec_reg(
|
||||||
get_spec_reg (
|
|
||||||
int regname,
|
int regname,
|
||||||
char_u **argp,
|
char_u **argp,
|
||||||
int *allocated, /* return: TRUE when value was allocated */
|
int *allocated, /* return: TRUE when value was allocated */
|
||||||
@@ -1273,13 +1265,11 @@ get_spec_reg (
|
|||||||
/// @returns FAIL for failure, OK otherwise
|
/// @returns FAIL for failure, OK otherwise
|
||||||
bool cmdline_paste_reg(int regname, bool literally, bool remcr)
|
bool cmdline_paste_reg(int regname, bool literally, bool remcr)
|
||||||
{
|
{
|
||||||
long i;
|
|
||||||
|
|
||||||
yankreg_T *reg = get_yank_register(regname, YREG_PASTE);
|
yankreg_T *reg = get_yank_register(regname, YREG_PASTE);
|
||||||
if (reg->y_array == NULL)
|
if (reg->y_array == NULL)
|
||||||
return FAIL;
|
return FAIL;
|
||||||
|
|
||||||
for (i = 0; i < reg->y_size; i++) {
|
for (size_t i = 0; i < reg->y_size; i++) {
|
||||||
cmdline_paste_str(reg->y_array[i], literally);
|
cmdline_paste_str(reg->y_array[i], literally);
|
||||||
|
|
||||||
// Insert ^M between lines and after last line if type is kMTLineWise.
|
// Insert ^M between lines and after last line if type is kMTLineWise.
|
||||||
@@ -1311,12 +1301,14 @@ int op_delete(oparg_T *oap)
|
|||||||
struct block_def bd;
|
struct block_def bd;
|
||||||
linenr_T old_lcount = curbuf->b_ml.ml_line_count;
|
linenr_T old_lcount = curbuf->b_ml.ml_line_count;
|
||||||
|
|
||||||
if (curbuf->b_ml.ml_flags & ML_EMPTY) /* nothing to do */
|
if (curbuf->b_ml.ml_flags & ML_EMPTY) { // nothing to do
|
||||||
return OK;
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
/* Nothing to delete, return here. Do prepare undo, for op_change(). */
|
// Nothing to delete, return here. Do prepare undo, for op_change().
|
||||||
if (oap->empty)
|
if (oap->empty) {
|
||||||
return u_save_cursor();
|
return u_save_cursor();
|
||||||
|
}
|
||||||
|
|
||||||
if (!MODIFIABLE(curbuf)) {
|
if (!MODIFIABLE(curbuf)) {
|
||||||
EMSG(_(e_modifiable));
|
EMSG(_(e_modifiable));
|
||||||
@@ -1431,23 +1423,21 @@ int op_delete(oparg_T *oap)
|
|||||||
curwin->w_cursor.coladd = 0;
|
curwin->w_cursor.coladd = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* n == number of chars deleted
|
// n == number of chars deleted
|
||||||
* If we delete a TAB, it may be replaced by several characters.
|
// If we delete a TAB, it may be replaced by several characters.
|
||||||
* Thus the number of characters may increase!
|
// Thus the number of characters may increase!
|
||||||
*/
|
|
||||||
n = bd.textlen - bd.startspaces - bd.endspaces;
|
n = bd.textlen - bd.startspaces - bd.endspaces;
|
||||||
oldp = ml_get(lnum);
|
oldp = ml_get(lnum);
|
||||||
newp = (char_u *) xmalloc((size_t)(STRLEN(oldp) + 1 - n));
|
newp = (char_u *)xmalloc(STRLEN(oldp) - (size_t)n + 1);
|
||||||
/* copy up to deleted part */
|
// copy up to deleted part
|
||||||
memmove(newp, oldp, (size_t)bd.textcol);
|
memmove(newp, oldp, (size_t)bd.textcol);
|
||||||
/* insert spaces */
|
// insert spaces
|
||||||
memset(newp + bd.textcol, ' ',
|
memset(newp + bd.textcol, ' ', (size_t)(bd.startspaces + bd.endspaces));
|
||||||
(size_t)(bd.startspaces + bd.endspaces));
|
// copy the part after the deleted part
|
||||||
/* copy the part after the deleted part */
|
|
||||||
oldp += bd.textcol + bd.textlen;
|
oldp += bd.textcol + bd.textlen;
|
||||||
STRMOVE(newp + bd.textcol + bd.startspaces + bd.endspaces, oldp);
|
STRMOVE(newp + bd.textcol + bd.startspaces + bd.endspaces, oldp);
|
||||||
/* replace the line */
|
// replace the line
|
||||||
ml_replace(lnum, newp, FALSE);
|
ml_replace(lnum, newp, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
check_cursor_col();
|
check_cursor_col();
|
||||||
@@ -1552,7 +1542,7 @@ int op_delete(oparg_T *oap)
|
|||||||
curwin->w_cursor.coladd = 0;
|
curwin->w_cursor.coladd = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)del_bytes((long)n, !virtual_op,
|
(void)del_bytes((colnr_T)n, !virtual_op,
|
||||||
oap->op_type == OP_DELETE && !oap->is_VIsual);
|
oap->op_type == OP_DELETE && !oap->is_VIsual);
|
||||||
} else {
|
} else {
|
||||||
// delete characters between lines
|
// delete characters between lines
|
||||||
@@ -1572,7 +1562,7 @@ int op_delete(oparg_T *oap)
|
|||||||
// delete from start of line until op_end
|
// delete from start of line until op_end
|
||||||
n = (oap->end.col + 1 - !oap->inclusive);
|
n = (oap->end.col + 1 - !oap->inclusive);
|
||||||
curwin->w_cursor.col = 0;
|
curwin->w_cursor.col = 0;
|
||||||
(void)del_bytes((long)n, !virtual_op,
|
(void)del_bytes((colnr_T)n, !virtual_op,
|
||||||
oap->op_type == OP_DELETE && !oap->is_VIsual);
|
oap->op_type == OP_DELETE && !oap->is_VIsual);
|
||||||
curwin->w_cursor = curpos; // restore curwin->w_cursor
|
curwin->w_cursor = curpos; // restore curwin->w_cursor
|
||||||
(void)do_join(2, false, false, false, false);
|
(void)do_join(2, false, false, false, false);
|
||||||
@@ -1611,7 +1601,8 @@ static void mb_adjust_opend(oparg_T *oap)
|
|||||||
*/
|
*/
|
||||||
static inline void pchar(pos_T lp, int c)
|
static inline void pchar(pos_T lp, int c)
|
||||||
{
|
{
|
||||||
*(ml_get_buf(curbuf, lp.lnum, TRUE) + lp.col) = c;;
|
assert(c <= UCHAR_MAX);
|
||||||
|
*(ml_get_buf(curbuf, lp.lnum, true) + lp.col) = (char_u)c;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -1695,15 +1686,16 @@ int op_replace(oparg_T *oap, int c)
|
|||||||
|
|
||||||
oldp = get_cursor_line_ptr();
|
oldp = get_cursor_line_ptr();
|
||||||
oldlen = STRLEN(oldp);
|
oldlen = STRLEN(oldp);
|
||||||
newp = (char_u *) xmalloc((size_t)(oldlen + 1 + n));
|
assert(n >= 0);
|
||||||
memset(newp, NUL, (size_t)(oldlen + 1 + n));
|
newp = (char_u *)xmalloc(oldlen + 1 + (size_t)n);
|
||||||
/* copy up to deleted part */
|
memset(newp, NUL, oldlen + 1 + (size_t)n);
|
||||||
|
// copy up to deleted part
|
||||||
memmove(newp, oldp, (size_t)bd.textcol);
|
memmove(newp, oldp, (size_t)bd.textcol);
|
||||||
oldp += bd.textcol + bd.textlen;
|
oldp += bd.textcol + bd.textlen;
|
||||||
/* insert pre-spaces */
|
// insert pre-spaces
|
||||||
memset(newp + bd.textcol, ' ', (size_t)bd.startspaces);
|
memset(newp + bd.textcol, ' ', (size_t)bd.startspaces);
|
||||||
/* insert replacement chars CHECK FOR ALLOCATED SPACE */
|
// insert replacement chars CHECK FOR ALLOCATED SPACE
|
||||||
/* -1/-2 is used for entering CR literally. */
|
// -1/-2 is used for entering CR literally.
|
||||||
if (had_ctrl_v_cr || (c != '\r' && c != '\n')) {
|
if (had_ctrl_v_cr || (c != '\r' && c != '\n')) {
|
||||||
if (has_mbyte) {
|
if (has_mbyte) {
|
||||||
n = (int)STRLEN(newp);
|
n = (int)STRLEN(newp);
|
||||||
@@ -1718,8 +1710,8 @@ int op_replace(oparg_T *oap, int c)
|
|||||||
STRMOVE(newp + STRLEN(newp), oldp);
|
STRMOVE(newp + STRLEN(newp), oldp);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* Replacing with \r or \n means splitting the line. */
|
// Replacing with \r or \n means splitting the line.
|
||||||
after_p = (char_u *) xmalloc((size_t)(oldlen + 1 + n - STRLEN(newp)));
|
after_p = (char_u *)xmalloc(oldlen + 1 + (size_t)n - STRLEN(newp));
|
||||||
STRMOVE(after_p, oldp);
|
STRMOVE(after_p, oldp);
|
||||||
}
|
}
|
||||||
/* replace the line */
|
/* replace the line */
|
||||||
@@ -1992,7 +1984,7 @@ void op_insert(oparg_T *oap, long count1)
|
|||||||
// already disabled, but still need it when calling
|
// already disabled, but still need it when calling
|
||||||
// coladvance_force().
|
// coladvance_force().
|
||||||
if (curwin->w_cursor.coladd > 0) {
|
if (curwin->w_cursor.coladd > 0) {
|
||||||
int old_ve_flags = ve_flags;
|
unsigned old_ve_flags = ve_flags;
|
||||||
|
|
||||||
ve_flags = VE_ALL;
|
ve_flags = VE_ALL;
|
||||||
if (u_save_cursor() == FAIL)
|
if (u_save_cursor() == FAIL)
|
||||||
@@ -2066,7 +2058,7 @@ void op_insert(oparg_T *oap, long count1)
|
|||||||
if (oap->op_type == OP_INSERT
|
if (oap->op_type == OP_INSERT
|
||||||
&& oap->start.col + oap->start.coladd
|
&& oap->start.col + oap->start.coladd
|
||||||
!= curbuf->b_op_start_orig.col + curbuf->b_op_start_orig.coladd) {
|
!= curbuf->b_op_start_orig.col + curbuf->b_op_start_orig.coladd) {
|
||||||
size_t t = getviscol2(curbuf->b_op_start_orig.col,
|
int t = getviscol2(curbuf->b_op_start_orig.col,
|
||||||
curbuf->b_op_start_orig.coladd);
|
curbuf->b_op_start_orig.coladd);
|
||||||
oap->start.col = curbuf->b_op_start_orig.col;
|
oap->start.col = curbuf->b_op_start_orig.col;
|
||||||
pre_textlen -= t - oap->start_vcol;
|
pre_textlen -= t - oap->start_vcol;
|
||||||
@@ -2075,7 +2067,7 @@ void op_insert(oparg_T *oap, long count1)
|
|||||||
&& oap->end.col + oap->end.coladd
|
&& oap->end.col + oap->end.coladd
|
||||||
>= curbuf->b_op_start_orig.col
|
>= curbuf->b_op_start_orig.col
|
||||||
+ curbuf->b_op_start_orig.coladd) {
|
+ curbuf->b_op_start_orig.coladd) {
|
||||||
size_t t = getviscol2(curbuf->b_op_start_orig.col,
|
int t = getviscol2(curbuf->b_op_start_orig.col,
|
||||||
curbuf->b_op_start_orig.coladd);
|
curbuf->b_op_start_orig.coladd);
|
||||||
oap->start.col = curbuf->b_op_start_orig.col;
|
oap->start.col = curbuf->b_op_start_orig.col;
|
||||||
/* reset pre_textlen to the value of OP_INSERT */
|
/* reset pre_textlen to the value of OP_INSERT */
|
||||||
@@ -2109,14 +2101,13 @@ void op_insert(oparg_T *oap, long count1)
|
|||||||
firstline = ml_get(oap->start.lnum) + bd.textcol;
|
firstline = ml_get(oap->start.lnum) + bd.textcol;
|
||||||
if (oap->op_type == OP_APPEND)
|
if (oap->op_type == OP_APPEND)
|
||||||
firstline += bd.textlen;
|
firstline += bd.textlen;
|
||||||
if (pre_textlen >= 0
|
ins_len = (long)STRLEN(firstline) - pre_textlen;
|
||||||
&& (ins_len = (long)STRLEN(firstline) - pre_textlen) > 0) {
|
if (pre_textlen >= 0 && ins_len > 0) {
|
||||||
ins_text = vim_strnsave(firstline, (int)ins_len);
|
ins_text = vim_strnsave(firstline, (size_t)ins_len);
|
||||||
/* block handled here */
|
// block handled here
|
||||||
if (u_save(oap->start.lnum,
|
if (u_save(oap->start.lnum, (linenr_T)(oap->end.lnum + 1)) == OK) {
|
||||||
(linenr_T)(oap->end.lnum + 1)) == OK)
|
block_insert(oap, ins_text, (oap->op_type == OP_INSERT), &bd);
|
||||||
block_insert(oap, ins_text, (oap->op_type == OP_INSERT),
|
}
|
||||||
&bd);
|
|
||||||
|
|
||||||
curwin->w_cursor.col = oap->start.col;
|
curwin->w_cursor.col = oap->start.col;
|
||||||
check_cursor();
|
check_cursor();
|
||||||
@@ -2139,8 +2130,10 @@ int op_change(oparg_T *oap)
|
|||||||
long ins_len;
|
long ins_len;
|
||||||
long pre_textlen = 0;
|
long pre_textlen = 0;
|
||||||
long pre_indent = 0;
|
long pre_indent = 0;
|
||||||
|
char_u *newp;
|
||||||
char_u *firstline;
|
char_u *firstline;
|
||||||
char_u *ins_text, *newp, *oldp;
|
char_u *ins_text;
|
||||||
|
char_u *oldp;
|
||||||
struct block_def bd;
|
struct block_def bd;
|
||||||
|
|
||||||
l = oap->start.col;
|
l = oap->start.col;
|
||||||
@@ -2198,7 +2191,7 @@ int op_change(oparg_T *oap)
|
|||||||
long new_indent = (long)(skipwhite(firstline) - firstline);
|
long new_indent = (long)(skipwhite(firstline) - firstline);
|
||||||
|
|
||||||
pre_textlen += new_indent - pre_indent;
|
pre_textlen += new_indent - pre_indent;
|
||||||
bd.textcol += new_indent - pre_indent;
|
bd.textcol += (colnr_T)(new_indent - pre_indent);
|
||||||
}
|
}
|
||||||
|
|
||||||
ins_len = (long)STRLEN(firstline) - pre_textlen;
|
ins_len = (long)STRLEN(firstline) - pre_textlen;
|
||||||
@@ -2218,11 +2211,13 @@ int op_change(oparg_T *oap)
|
|||||||
if (bd.is_short) {
|
if (bd.is_short) {
|
||||||
vpos.lnum = linenr;
|
vpos.lnum = linenr;
|
||||||
(void)getvpos(&vpos, oap->start_vcol);
|
(void)getvpos(&vpos, oap->start_vcol);
|
||||||
} else
|
} else {
|
||||||
vpos.coladd = 0;
|
vpos.coladd = 0;
|
||||||
|
}
|
||||||
oldp = ml_get(linenr);
|
oldp = ml_get(linenr);
|
||||||
newp = (char_u *) xmalloc((size_t)(STRLEN(oldp) + vpos.coladd + ins_len + 1));
|
newp = xmalloc(STRLEN(oldp) + (size_t)vpos.coladd
|
||||||
/* copy up to block start */
|
+ (size_t)ins_len + 1);
|
||||||
|
// copy up to block start
|
||||||
memmove(newp, oldp, (size_t)bd.textcol);
|
memmove(newp, oldp, (size_t)bd.textcol);
|
||||||
offset = bd.textcol;
|
offset = bd.textcol;
|
||||||
memset(newp + offset, ' ', (size_t)vpos.coladd);
|
memset(newp + offset, ' ', (size_t)vpos.coladd);
|
||||||
@@ -2272,9 +2267,7 @@ void free_register(yankreg_T *reg)
|
|||||||
{
|
{
|
||||||
set_yreg_additional_data(reg, NULL);
|
set_yreg_additional_data(reg, NULL);
|
||||||
if (reg->y_array != NULL) {
|
if (reg->y_array != NULL) {
|
||||||
long i;
|
for (size_t i = reg->y_size; i-- > 0;) { // from y_size - 1 to 0 included
|
||||||
|
|
||||||
for (i = reg->y_size - 1; i >= 0; i--) {
|
|
||||||
xfree(reg->y_array[i]);
|
xfree(reg->y_array[i]);
|
||||||
}
|
}
|
||||||
xfree(reg->y_array);
|
xfree(reg->y_array);
|
||||||
@@ -2311,30 +2304,27 @@ bool op_yank(oparg_T *oap, bool message)
|
|||||||
|
|
||||||
static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append)
|
static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append)
|
||||||
{
|
{
|
||||||
long y_idx; /* index in y_array[] */
|
yankreg_T newreg; // new yank register when appending
|
||||||
yankreg_T *curr; /* copy of current register */
|
|
||||||
yankreg_T newreg; /* new yank register when appending */
|
|
||||||
char_u **new_ptr;
|
char_u **new_ptr;
|
||||||
linenr_T lnum; /* current line number */
|
linenr_T lnum; // current line number
|
||||||
long j;
|
size_t j;
|
||||||
MotionType yank_type = oap->motion_type;
|
MotionType yank_type = oap->motion_type;
|
||||||
long yanklines = oap->line_count;
|
size_t yanklines = (size_t)oap->line_count;
|
||||||
linenr_T yankendlnum = oap->end.lnum;
|
linenr_T yankendlnum = oap->end.lnum;
|
||||||
char_u *p;
|
char_u *p;
|
||||||
char_u *pnew;
|
char_u *pnew;
|
||||||
struct block_def bd;
|
struct block_def bd;
|
||||||
|
|
||||||
curr = reg;
|
yankreg_T *curr = reg; // copy of current register
|
||||||
/* append to existing contents */
|
// append to existing contents
|
||||||
if (append && reg->y_array != NULL)
|
if (append && reg->y_array != NULL) {
|
||||||
reg = &newreg;
|
reg = &newreg;
|
||||||
else
|
} else {
|
||||||
free_register(reg); /* free previously yanked lines */
|
free_register(reg); // free previously yanked lines
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
// If the cursor was in column 1 before and after the movement, and the
|
||||||
* If the cursor was in column 1 before and after the movement, and the
|
// operator is not inclusive, the yank is always linewise.
|
||||||
* operator is not inclusive, the yank is always linewise.
|
|
||||||
*/
|
|
||||||
if (oap->motion_type == kMTCharWise
|
if (oap->motion_type == kMTCharWise
|
||||||
&& oap->start.col == 0
|
&& oap->start.col == 0
|
||||||
&& !oap->inclusive
|
&& !oap->inclusive
|
||||||
@@ -2353,7 +2343,7 @@ static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append)
|
|||||||
reg->additional_data = NULL;
|
reg->additional_data = NULL;
|
||||||
reg->timestamp = os_time();
|
reg->timestamp = os_time();
|
||||||
|
|
||||||
y_idx = 0;
|
size_t y_idx = 0; // index in y_array[]
|
||||||
lnum = oap->start.lnum;
|
lnum = oap->start.lnum;
|
||||||
|
|
||||||
if (yank_type == kMTBlockWise) {
|
if (yank_type == kMTBlockWise) {
|
||||||
@@ -2481,7 +2471,7 @@ static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append)
|
|||||||
yanklines = 0;
|
yanklines = 0;
|
||||||
}
|
}
|
||||||
// Some versions of Vi use ">=" here, some don't...
|
// Some versions of Vi use ">=" here, some don't...
|
||||||
if (yanklines > p_report) {
|
if (yanklines > (size_t)p_report) {
|
||||||
// redisplay now, so message is not deleted
|
// redisplay now, so message is not deleted
|
||||||
update_topline_redraw();
|
update_topline_redraw();
|
||||||
if (yanklines == 1) {
|
if (yanklines == 1) {
|
||||||
@@ -2512,10 +2502,10 @@ static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void yank_copy_line(yankreg_T *reg, struct block_def *bd, long y_idx)
|
static void yank_copy_line(yankreg_T *reg, struct block_def *bd, size_t y_idx)
|
||||||
{
|
{
|
||||||
char_u *pnew = xmallocz(bd->startspaces + bd->endspaces + bd->textlen);
|
char_u *pnew = xmallocz((size_t)(bd->startspaces + bd->endspaces
|
||||||
|
+ bd->textlen));
|
||||||
reg->y_array[y_idx] = pnew;
|
reg->y_array[y_idx] = pnew;
|
||||||
memset(pnew, ' ', (size_t)bd->startspaces);
|
memset(pnew, ' ', (size_t)bd->startspaces);
|
||||||
pnew += bd->startspaces;
|
pnew += bd->startspaces;
|
||||||
@@ -2548,7 +2538,7 @@ static void yank_do_autocmd(oparg_T *oap, yankreg_T *reg)
|
|||||||
|
|
||||||
// the yanked text
|
// the yanked text
|
||||||
list_T *list = list_alloc();
|
list_T *list = list_alloc();
|
||||||
for (linenr_T i = 0; i < reg->y_size; i++) {
|
for (size_t i = 0; i < reg->y_size; i++) {
|
||||||
list_append_string(list, reg->y_array[i], -1);
|
list_append_string(list, reg->y_array[i], -1);
|
||||||
}
|
}
|
||||||
list->lv_lock = VAR_FIXED;
|
list->lv_lock = VAR_FIXED;
|
||||||
@@ -2565,7 +2555,7 @@ static void yank_do_autocmd(oparg_T *oap, yankreg_T *reg)
|
|||||||
dict_add_nr_str(dict, "regname", 0, (char_u *)buf);
|
dict_add_nr_str(dict, "regname", 0, (char_u *)buf);
|
||||||
|
|
||||||
// kind of operation (yank/delete/change)
|
// kind of operation (yank/delete/change)
|
||||||
buf[0] = get_op_char(oap->op_type);
|
buf[0] = (char)get_op_char(oap->op_type);
|
||||||
buf[1] = NUL;
|
buf[1] = NUL;
|
||||||
dict_add_nr_str(dict, "operator", 0, (char_u *)buf);
|
dict_add_nr_str(dict, "operator", 0, (char_u *)buf);
|
||||||
|
|
||||||
@@ -2589,16 +2579,17 @@ static void yank_do_autocmd(oparg_T *oap, yankreg_T *reg)
|
|||||||
void do_put(int regname, yankreg_T *reg, int dir, long count, int flags)
|
void do_put(int regname, yankreg_T *reg, int dir, long count, int flags)
|
||||||
{
|
{
|
||||||
char_u *ptr;
|
char_u *ptr;
|
||||||
char_u *newp, *oldp;
|
char_u *newp;
|
||||||
|
char_u *oldp;
|
||||||
int yanklen;
|
int yanklen;
|
||||||
int totlen = 0; /* init for gcc */
|
size_t totlen = 0; // init for gcc
|
||||||
linenr_T lnum;
|
linenr_T lnum;
|
||||||
colnr_T col;
|
colnr_T col;
|
||||||
long i; // index in y_array[]
|
size_t i; // index in y_array[]
|
||||||
MotionType y_type;
|
MotionType y_type;
|
||||||
long y_size;
|
size_t y_size;
|
||||||
int oldlen;
|
size_t oldlen;
|
||||||
long y_width = 0;
|
int y_width = 0;
|
||||||
colnr_T vcol;
|
colnr_T vcol;
|
||||||
int delcount;
|
int delcount;
|
||||||
int incr = 0;
|
int incr = 0;
|
||||||
@@ -2705,7 +2696,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags)
|
|||||||
if (curbuf->terminal) {
|
if (curbuf->terminal) {
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
// feed the lines to the terminal
|
// feed the lines to the terminal
|
||||||
for (int j = 0; j < y_size; j++) {
|
for (size_t j = 0; j < y_size; j++) {
|
||||||
if (j) {
|
if (j) {
|
||||||
// terminate the previous line
|
// terminate the previous line
|
||||||
terminal_send(curbuf->terminal, "\n", 1);
|
terminal_send(curbuf->terminal, "\n", 1);
|
||||||
@@ -2736,7 +2727,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags)
|
|||||||
if (dir == FORWARD && *p != NUL) {
|
if (dir == FORWARD && *p != NUL) {
|
||||||
mb_ptr_adv(p);
|
mb_ptr_adv(p);
|
||||||
}
|
}
|
||||||
ptr = vim_strnsave(oldp, p - oldp);
|
ptr = vim_strnsave(oldp, (size_t)(p - oldp));
|
||||||
ml_replace(curwin->w_cursor.lnum, ptr, false);
|
ml_replace(curwin->w_cursor.lnum, ptr, false);
|
||||||
nr_lines++;
|
nr_lines++;
|
||||||
dir = FORWARD;
|
dir = FORWARD;
|
||||||
@@ -2761,11 +2752,13 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (y_type == kMTBlockWise) {
|
if (y_type == kMTBlockWise) {
|
||||||
lnum = curwin->w_cursor.lnum + y_size + 1;
|
lnum = curwin->w_cursor.lnum + (linenr_T)y_size + 1;
|
||||||
if (lnum > curbuf->b_ml.ml_line_count)
|
if (lnum > curbuf->b_ml.ml_line_count) {
|
||||||
lnum = curbuf->b_ml.ml_line_count + 1;
|
lnum = curbuf->b_ml.ml_line_count + 1;
|
||||||
if (u_save(curwin->w_cursor.lnum - 1, lnum) == FAIL)
|
}
|
||||||
|
if (u_save(curwin->w_cursor.lnum - 1, lnum) == FAIL) {
|
||||||
goto end;
|
goto end;
|
||||||
|
}
|
||||||
} else if (y_type == kMTLineWise) {
|
} else if (y_type == kMTLineWise) {
|
||||||
lnum = curwin->w_cursor.lnum;
|
lnum = curwin->w_cursor.lnum;
|
||||||
/* Correct line number for closed fold. Don't move the cursor yet,
|
/* Correct line number for closed fold. Don't move the cursor yet,
|
||||||
@@ -2811,7 +2804,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags)
|
|||||||
* Block mode
|
* Block mode
|
||||||
*/
|
*/
|
||||||
if (y_type == kMTBlockWise) {
|
if (y_type == kMTBlockWise) {
|
||||||
char c = gchar_cursor();
|
int c = gchar_cursor();
|
||||||
colnr_T endcol2 = 0;
|
colnr_T endcol2 = 0;
|
||||||
|
|
||||||
if (dir == FORWARD && c != NUL) {
|
if (dir == FORWARD && c != NUL) {
|
||||||
@@ -2864,7 +2857,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags)
|
|||||||
}
|
}
|
||||||
/* get the old line and advance to the position to insert at */
|
/* get the old line and advance to the position to insert at */
|
||||||
oldp = get_cursor_line_ptr();
|
oldp = get_cursor_line_ptr();
|
||||||
oldlen = (int)STRLEN(oldp);
|
oldlen = STRLEN(oldp);
|
||||||
for (ptr = oldp; vcol < col && *ptr; ) {
|
for (ptr = oldp; vcol < col && *ptr; ) {
|
||||||
/* Count a tab for what it's worth (if list mode not on) */
|
/* Count a tab for what it's worth (if list mode not on) */
|
||||||
incr = lbr_chartabsize_adv(oldp, &ptr, (colnr_T)vcol);
|
incr = lbr_chartabsize_adv(oldp, &ptr, (colnr_T)vcol);
|
||||||
@@ -2901,10 +2894,11 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags)
|
|||||||
if (spaces < 0)
|
if (spaces < 0)
|
||||||
spaces = 0;
|
spaces = 0;
|
||||||
|
|
||||||
/* insert the new text */
|
// insert the new text
|
||||||
totlen = count * (yanklen + spaces) + bd.startspaces + bd.endspaces;
|
totlen = (size_t)(count * (yanklen + spaces)
|
||||||
newp = (char_u *) xmalloc((size_t)(totlen + oldlen + 1));
|
+ bd.startspaces + bd.endspaces);
|
||||||
/* copy part up to cursor to new line */
|
newp = (char_u *) xmalloc(totlen + oldlen + 1);
|
||||||
|
// copy part up to cursor to new line
|
||||||
ptr = newp;
|
ptr = newp;
|
||||||
memmove(ptr, oldp, (size_t)bd.textcol);
|
memmove(ptr, oldp, (size_t)bd.textcol);
|
||||||
ptr += bd.textcol;
|
ptr += bd.textcol;
|
||||||
@@ -2925,10 +2919,10 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags)
|
|||||||
/* may insert some spaces after the new text */
|
/* may insert some spaces after the new text */
|
||||||
memset(ptr, ' ', (size_t)bd.endspaces);
|
memset(ptr, ' ', (size_t)bd.endspaces);
|
||||||
ptr += bd.endspaces;
|
ptr += bd.endspaces;
|
||||||
/* move the text after the cursor to the end of the line. */
|
// move the text after the cursor to the end of the line.
|
||||||
memmove(ptr, oldp + bd.textcol + delcount,
|
memmove(ptr, oldp + bd.textcol + delcount,
|
||||||
(size_t)(oldlen - bd.textcol - delcount + 1));
|
(size_t)((int)oldlen - bd.textcol - delcount + 1));
|
||||||
ml_replace(curwin->w_cursor.lnum, newp, FALSE);
|
ml_replace(curwin->w_cursor.lnum, newp, false);
|
||||||
|
|
||||||
++curwin->w_cursor.lnum;
|
++curwin->w_cursor.lnum;
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
@@ -2943,7 +2937,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags)
|
|||||||
|
|
||||||
/* adjust '] mark */
|
/* adjust '] mark */
|
||||||
curbuf->b_op_end.lnum = curwin->w_cursor.lnum - 1;
|
curbuf->b_op_end.lnum = curwin->w_cursor.lnum - 1;
|
||||||
curbuf->b_op_end.col = bd.textcol + totlen - 1;
|
curbuf->b_op_end.col = bd.textcol + (colnr_T)totlen - 1;
|
||||||
curbuf->b_op_end.coladd = 0;
|
curbuf->b_op_end.coladd = 0;
|
||||||
if (flags & PUT_CURSEND) {
|
if (flags & PUT_CURSEND) {
|
||||||
colnr_T len;
|
colnr_T len;
|
||||||
@@ -2994,13 +2988,13 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags)
|
|||||||
*/
|
*/
|
||||||
if (y_type == kMTCharWise && y_size == 1) {
|
if (y_type == kMTCharWise && y_size == 1) {
|
||||||
do {
|
do {
|
||||||
totlen = count * yanklen;
|
totlen = (size_t)(count * yanklen);
|
||||||
if (totlen > 0) {
|
if (totlen > 0) {
|
||||||
oldp = ml_get(lnum);
|
oldp = ml_get(lnum);
|
||||||
newp = (char_u *) xmalloc((size_t)(STRLEN(oldp) + totlen + 1));
|
newp = (char_u *) xmalloc((size_t)(STRLEN(oldp) + totlen + 1));
|
||||||
memmove(newp, oldp, (size_t)col);
|
memmove(newp, oldp, (size_t)col);
|
||||||
ptr = newp + col;
|
ptr = newp + col;
|
||||||
for (i = 0; i < count; i++) {
|
for (i = 0; i < (size_t)count; i++) {
|
||||||
memmove(ptr, y_array[0], (size_t)yanklen);
|
memmove(ptr, y_array[0], (size_t)yanklen);
|
||||||
ptr += yanklen;
|
ptr += yanklen;
|
||||||
}
|
}
|
||||||
@@ -3037,7 +3031,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags)
|
|||||||
// Then append y_array[0] to first line.
|
// Then append y_array[0] to first line.
|
||||||
lnum = new_cursor.lnum;
|
lnum = new_cursor.lnum;
|
||||||
ptr = ml_get(lnum) + col;
|
ptr = ml_get(lnum) + col;
|
||||||
totlen = (int)STRLEN(y_array[y_size - 1]);
|
totlen = STRLEN(y_array[y_size - 1]);
|
||||||
newp = (char_u *) xmalloc((size_t)(STRLEN(ptr) + totlen + 1));
|
newp = (char_u *) xmalloc((size_t)(STRLEN(ptr) + totlen + 1));
|
||||||
STRCPY(newp, y_array[y_size - 1]);
|
STRCPY(newp, y_array[y_size - 1]);
|
||||||
STRCAT(newp, ptr);
|
STRCAT(newp, ptr);
|
||||||
@@ -3217,22 +3211,19 @@ int get_register_name(int num)
|
|||||||
*/
|
*/
|
||||||
void ex_display(exarg_T *eap)
|
void ex_display(exarg_T *eap)
|
||||||
{
|
{
|
||||||
int i, n;
|
|
||||||
long j;
|
|
||||||
char_u *p;
|
char_u *p;
|
||||||
yankreg_T *yb;
|
yankreg_T *yb;
|
||||||
int name;
|
int name;
|
||||||
int attr;
|
|
||||||
char_u *arg = eap->arg;
|
char_u *arg = eap->arg;
|
||||||
int clen;
|
int clen;
|
||||||
|
|
||||||
if (arg != NULL && *arg == NUL)
|
if (arg != NULL && *arg == NUL)
|
||||||
arg = NULL;
|
arg = NULL;
|
||||||
attr = hl_attr(HLF_8);
|
int attr = hl_attr(HLF_8);
|
||||||
|
|
||||||
/* Highlight title */
|
/* Highlight title */
|
||||||
MSG_PUTS_TITLE(_("\n--- Registers ---"));
|
MSG_PUTS_TITLE(_("\n--- Registers ---"));
|
||||||
for (i = -1; i < NUM_REGISTERS && !got_int; i++) {
|
for (int i = -1; i < NUM_REGISTERS && !got_int; i++) {
|
||||||
name = get_register_name(i);
|
name = get_register_name(i);
|
||||||
|
|
||||||
if (arg != NULL && vim_strchr(arg, name) == NULL) {
|
if (arg != NULL && vim_strchr(arg, name) == NULL) {
|
||||||
@@ -3261,8 +3252,8 @@ void ex_display(exarg_T *eap)
|
|||||||
msg_putchar(name);
|
msg_putchar(name);
|
||||||
MSG_PUTS(" ");
|
MSG_PUTS(" ");
|
||||||
|
|
||||||
n = (int)Columns - 6;
|
int n = (int)Columns - 6;
|
||||||
for (j = 0; j < yb->y_size && n > 1; ++j) {
|
for (size_t j = 0; j < yb->y_size && n > 1; j++) {
|
||||||
if (j) {
|
if (j) {
|
||||||
MSG_PUTS_ATTR("^J", attr);
|
MSG_PUTS_ATTR("^J", attr);
|
||||||
n -= 2;
|
n -= 2;
|
||||||
@@ -3438,7 +3429,7 @@ static char_u *skip_comment(char_u *line, int process, int include_space, int *i
|
|||||||
// to set those marks.
|
// to set those marks.
|
||||||
//
|
//
|
||||||
// return FAIL for failure, OK otherwise
|
// return FAIL for failure, OK otherwise
|
||||||
int do_join(long count,
|
int do_join(size_t count,
|
||||||
int insert_space,
|
int insert_space,
|
||||||
int save_undo,
|
int save_undo,
|
||||||
int use_formatoptions,
|
int use_formatoptions,
|
||||||
@@ -3461,24 +3452,21 @@ int do_join(long count,
|
|||||||
&& has_format_option(FO_REMOVE_COMS);
|
&& has_format_option(FO_REMOVE_COMS);
|
||||||
int prev_was_comment;
|
int prev_was_comment;
|
||||||
|
|
||||||
assert(count > 1);
|
if (save_undo && u_save(curwin->w_cursor.lnum - 1,
|
||||||
if (save_undo && u_save((linenr_T)(curwin->w_cursor.lnum - 1),
|
curwin->w_cursor.lnum + (linenr_T)count) == FAIL) {
|
||||||
(linenr_T)(curwin->w_cursor.lnum + count)) == FAIL)
|
|
||||||
return FAIL;
|
return FAIL;
|
||||||
|
}
|
||||||
/* Allocate an array to store the number of spaces inserted before each
|
// Allocate an array to store the number of spaces inserted before each
|
||||||
* line. We will use it to pre-compute the length of the new line and the
|
// line. We will use it to pre-compute the length of the new line and the
|
||||||
* proper placement of each original line in the new one. */
|
// proper placement of each original line in the new one.
|
||||||
spaces = xcalloc(count, 1);
|
spaces = xcalloc(count, 1);
|
||||||
if (remove_comments) {
|
if (remove_comments) {
|
||||||
comments = xcalloc(count, sizeof(*comments));
|
comments = xcalloc(count, sizeof(*comments));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
// Don't move anything, just compute the final line length
|
||||||
* Don't move anything, just compute the final line length
|
// and setup the array of space strings lengths
|
||||||
* and setup the array of space strings lengths
|
for (t = 0; t < (linenr_T)count; t++) {
|
||||||
*/
|
|
||||||
for (t = 0; t < count; ++t) {
|
|
||||||
curr = curr_start = ml_get((linenr_T)(curwin->w_cursor.lnum + t));
|
curr = curr_start = ml_get((linenr_T)(curwin->w_cursor.lnum + t));
|
||||||
if (t == 0 && setmark) {
|
if (t == 0 && setmark) {
|
||||||
// Set the '[ mark.
|
// Set the '[ mark.
|
||||||
@@ -3558,7 +3546,7 @@ int do_join(long count,
|
|||||||
* column. This is not Vi compatible, but Vi deletes the marks, thus that
|
* column. This is not Vi compatible, but Vi deletes the marks, thus that
|
||||||
* should not really be a problem.
|
* should not really be a problem.
|
||||||
*/
|
*/
|
||||||
for (t = count - 1;; --t) {
|
for (t = (linenr_T)count - 1;; t--) {
|
||||||
cend -= currsize;
|
cend -= currsize;
|
||||||
memmove(cend, curr, (size_t)currsize);
|
memmove(cend, curr, (size_t)currsize);
|
||||||
if (spaces[t] > 0) {
|
if (spaces[t] > 0) {
|
||||||
@@ -3595,8 +3583,8 @@ int do_join(long count,
|
|||||||
* have moved up (last line deleted), so the current lnum is kept in t.
|
* have moved up (last line deleted), so the current lnum is kept in t.
|
||||||
*/
|
*/
|
||||||
t = curwin->w_cursor.lnum;
|
t = curwin->w_cursor.lnum;
|
||||||
++curwin->w_cursor.lnum;
|
curwin->w_cursor.lnum++;
|
||||||
del_lines(count - 1, FALSE);
|
del_lines((long)count - 1, false);
|
||||||
curwin->w_cursor.lnum = t;
|
curwin->w_cursor.lnum = t;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -3778,8 +3766,8 @@ fex_format (
|
|||||||
* Set v:lnum to the first line number and v:count to the number of lines.
|
* Set v:lnum to the first line number and v:count to the number of lines.
|
||||||
* Set v:char to the character to be inserted (can be NUL).
|
* Set v:char to the character to be inserted (can be NUL).
|
||||||
*/
|
*/
|
||||||
set_vim_var_nr(VV_LNUM, lnum);
|
set_vim_var_nr(VV_LNUM, (varnumber_T)lnum);
|
||||||
set_vim_var_nr(VV_COUNT, count);
|
set_vim_var_nr(VV_COUNT, (varnumber_T)count);
|
||||||
set_vim_var_char(c);
|
set_vim_var_char(c);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -4473,7 +4461,7 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1)
|
|||||||
firstdigit = 'a';
|
firstdigit = 'a';
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
firstdigit -= Prenum1;
|
firstdigit -= (int)Prenum1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (26 - CharOrd(firstdigit) - 1 < Prenum1) {
|
if (26 - CharOrd(firstdigit) - 1 < Prenum1) {
|
||||||
@@ -4483,7 +4471,7 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1)
|
|||||||
firstdigit = 'z';
|
firstdigit = 'z';
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
firstdigit += Prenum1;
|
firstdigit += (int)Prenum1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
curwin->w_cursor.col = col;
|
curwin->w_cursor.col = col;
|
||||||
@@ -4591,7 +4579,7 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1)
|
|||||||
// Prepare the leading characters in buf1[].
|
// Prepare the leading characters in buf1[].
|
||||||
// When there are many leading zeros it could be very long.
|
// When there are many leading zeros it could be very long.
|
||||||
// Allocate a bit too much.
|
// Allocate a bit too much.
|
||||||
buf1 = xmalloc(length + NUMBUFLEN);
|
buf1 = xmalloc((size_t)length + NUMBUFLEN);
|
||||||
if (buf1 == NULL) {
|
if (buf1 == NULL) {
|
||||||
goto theend;
|
goto theend;
|
||||||
}
|
}
|
||||||
@@ -4604,7 +4592,7 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1)
|
|||||||
length--;
|
length--;
|
||||||
}
|
}
|
||||||
if (pre == 'b' || pre == 'B' || pre == 'x' || pre == 'X') {
|
if (pre == 'b' || pre == 'B' || pre == 'x' || pre == 'X') {
|
||||||
*ptr++ = pre;
|
*ptr++ = (char_u)pre;
|
||||||
length--;
|
length--;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4767,8 +4755,6 @@ static void *get_reg_wrap_one_line(char_u *s, int flags)
|
|||||||
/// @returns NULL for error.
|
/// @returns NULL for error.
|
||||||
void *get_reg_contents(int regname, int flags)
|
void *get_reg_contents(int regname, int flags)
|
||||||
{
|
{
|
||||||
long i;
|
|
||||||
|
|
||||||
// Don't allow using an expression register inside an expression.
|
// Don't allow using an expression register inside an expression.
|
||||||
if (regname == '=') {
|
if (regname == '=') {
|
||||||
if (flags & kGRegNoExpr) {
|
if (flags & kGRegNoExpr) {
|
||||||
@@ -4804,7 +4790,7 @@ void *get_reg_contents(int regname, int flags)
|
|||||||
|
|
||||||
if (flags & kGRegList) {
|
if (flags & kGRegList) {
|
||||||
list_T *list = list_alloc();
|
list_T *list = list_alloc();
|
||||||
for (int i = 0; i < reg->y_size; i++) {
|
for (size_t i = 0; i < reg->y_size; i++) {
|
||||||
list_append_string(list, reg->y_array[i], -1);
|
list_append_string(list, reg->y_array[i], -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4815,7 +4801,7 @@ void *get_reg_contents(int regname, int flags)
|
|||||||
* Compute length of resulting string.
|
* Compute length of resulting string.
|
||||||
*/
|
*/
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
for (i = 0; i < reg->y_size; i++) {
|
for (size_t i = 0; i < reg->y_size; i++) {
|
||||||
len += STRLEN(reg->y_array[i]);
|
len += STRLEN(reg->y_array[i]);
|
||||||
/*
|
/*
|
||||||
* Insert a newline between lines and after last line if
|
* Insert a newline between lines and after last line if
|
||||||
@@ -4832,7 +4818,7 @@ void *get_reg_contents(int regname, int flags)
|
|||||||
* Copy the lines of the yank register into the string.
|
* Copy the lines of the yank register into the string.
|
||||||
*/
|
*/
|
||||||
len = 0;
|
len = 0;
|
||||||
for (i = 0; i < reg->y_size; i++) {
|
for (size_t i = 0; i < reg->y_size; i++) {
|
||||||
STRCPY(retval + len, reg->y_array[i]);
|
STRCPY(retval + len, reg->y_array[i]);
|
||||||
len += STRLEN(retval + len);
|
len += STRLEN(retval + len);
|
||||||
|
|
||||||
@@ -4888,7 +4874,7 @@ void write_reg_contents(int name, const char_u *str, ssize_t len,
|
|||||||
|
|
||||||
void write_reg_contents_lst(int name, char_u **strings, int maxlen,
|
void write_reg_contents_lst(int name, char_u **strings, int maxlen,
|
||||||
bool must_append, MotionType yank_type,
|
bool must_append, MotionType yank_type,
|
||||||
long block_len)
|
colnr_T block_len)
|
||||||
{
|
{
|
||||||
if (name == '/' || name == '=') {
|
if (name == '/' || name == '=') {
|
||||||
char_u *s = strings[0];
|
char_u *s = strings[0];
|
||||||
@@ -4913,7 +4899,8 @@ void write_reg_contents_lst(int name, char_u **strings, int maxlen,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
str_to_reg(reg, yank_type, (char_u *) strings, -1, block_len, true);
|
str_to_reg(reg, yank_type, (char_u *)strings, STRLEN((char_u *)strings),
|
||||||
|
block_len, true);
|
||||||
finish_write_reg(name, reg, old_y_previous);
|
finish_write_reg(name, reg, old_y_previous);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4941,7 +4928,7 @@ void write_reg_contents_ex(int name,
|
|||||||
ssize_t len,
|
ssize_t len,
|
||||||
bool must_append,
|
bool must_append,
|
||||||
MotionType yank_type,
|
MotionType yank_type,
|
||||||
long block_len)
|
colnr_T block_len)
|
||||||
{
|
{
|
||||||
if (len < 0) {
|
if (len < 0) {
|
||||||
len = (ssize_t) STRLEN(str);
|
len = (ssize_t) STRLEN(str);
|
||||||
@@ -5005,7 +4992,7 @@ void write_reg_contents_ex(int name,
|
|||||||
if (!(reg = init_write_reg(name, &old_y_previous, must_append))) {
|
if (!(reg = init_write_reg(name, &old_y_previous, must_append))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
str_to_reg(reg, yank_type, str, len, block_len, false);
|
str_to_reg(reg, yank_type, str, (size_t)len, block_len, false);
|
||||||
finish_write_reg(name, reg, old_y_previous);
|
finish_write_reg(name, reg, old_y_previous);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -5061,7 +5048,7 @@ static void str_to_reg(yankreg_T *y_ptr, MotionType yank_type,
|
|||||||
(y_ptr->y_size + newlines) * sizeof(char_u *));
|
(y_ptr->y_size + newlines) * sizeof(char_u *));
|
||||||
y_ptr->y_array = pp;
|
y_ptr->y_array = pp;
|
||||||
|
|
||||||
linenr_T lnum = y_ptr->y_size; // The current line number.
|
size_t lnum = y_ptr->y_size; // The current line number.
|
||||||
|
|
||||||
// If called with `blocklen < 0`, we have to update the yank reg's width.
|
// If called with `blocklen < 0`, we have to update the yank reg's width.
|
||||||
size_t maxlen = 0;
|
size_t maxlen = 0;
|
||||||
@@ -5080,7 +5067,9 @@ static void str_to_reg(yankreg_T *y_ptr, MotionType yank_type,
|
|||||||
for (const char_u *start = str, *end = str + len;
|
for (const char_u *start = str, *end = str + len;
|
||||||
start < end + extraline;
|
start < end + extraline;
|
||||||
start += line_len + 1, lnum++) {
|
start += line_len + 1, lnum++) {
|
||||||
line_len = (const char_u *) xmemscan(start, '\n', end - start) - start;
|
assert(end - start >= 0);
|
||||||
|
line_len = (size_t)((char_u *)xmemscan(start, '\n',
|
||||||
|
(size_t)(end - start)) - start);
|
||||||
if (line_len > maxlen) {
|
if (line_len > maxlen) {
|
||||||
maxlen = line_len;
|
maxlen = line_len;
|
||||||
}
|
}
|
||||||
@@ -5090,7 +5079,7 @@ static void str_to_reg(yankreg_T *y_ptr, MotionType yank_type,
|
|||||||
char_u *s = xmallocz(line_len + extra);
|
char_u *s = xmallocz(line_len + extra);
|
||||||
memcpy(s, pp[lnum], extra);
|
memcpy(s, pp[lnum], extra);
|
||||||
memcpy(s + extra, start, line_len);
|
memcpy(s + extra, start, line_len);
|
||||||
ssize_t s_len = extra + line_len;
|
size_t s_len = extra + line_len;
|
||||||
|
|
||||||
if (append) {
|
if (append) {
|
||||||
xfree(pp[lnum]);
|
xfree(pp[lnum]);
|
||||||
@@ -5474,7 +5463,7 @@ static bool get_clipboard(int name, yankreg_T **target, bool quiet)
|
|||||||
free_register(reg);
|
free_register(reg);
|
||||||
|
|
||||||
list_T *args = list_alloc();
|
list_T *args = list_alloc();
|
||||||
char_u regname = name;
|
char_u regname = (char_u)name;
|
||||||
list_append_string(args, ®name, 1);
|
list_append_string(args, ®name, 1);
|
||||||
|
|
||||||
typval_T result = eval_call_provider("clipboard", "get", args);
|
typval_T result = eval_call_provider("clipboard", "get", args);
|
||||||
@@ -5519,8 +5508,8 @@ static bool get_clipboard(int name, yankreg_T **target, bool quiet)
|
|||||||
reg->y_type = kMTUnknown;
|
reg->y_type = kMTUnknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
reg->y_array = xcalloc(lines->lv_len, sizeof(uint8_t *));
|
reg->y_array = xcalloc((size_t)lines->lv_len, sizeof(uint8_t *));
|
||||||
reg->y_size = lines->lv_len;
|
reg->y_size = (size_t)lines->lv_len;
|
||||||
reg->additional_data = NULL;
|
reg->additional_data = NULL;
|
||||||
reg->timestamp = 0;
|
reg->timestamp = 0;
|
||||||
// Timestamp is not saved for clipboard registers because clipboard registers
|
// Timestamp is not saved for clipboard registers because clipboard registers
|
||||||
@@ -5551,14 +5540,15 @@ static bool get_clipboard(int name, yankreg_T **target, bool quiet)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (reg->y_type == kMTBlockWise) {
|
if (reg->y_type == kMTBlockWise) {
|
||||||
int maxlen = 0;
|
size_t maxlen = 0;
|
||||||
for (int i = 0; i < reg->y_size; i++) {
|
for (size_t i = 0; i < reg->y_size; i++) {
|
||||||
int rowlen = STRLEN(reg->y_array[i]);
|
size_t rowlen = STRLEN(reg->y_array[i]);
|
||||||
if (rowlen > maxlen) {
|
if (rowlen > maxlen) {
|
||||||
maxlen = rowlen;
|
maxlen = rowlen;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
reg->y_width = maxlen-1;
|
assert(maxlen <= INT_MAX);
|
||||||
|
reg->y_width = (int)maxlen - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
*target = reg;
|
*target = reg;
|
||||||
@@ -5566,7 +5556,7 @@ static bool get_clipboard(int name, yankreg_T **target, bool quiet)
|
|||||||
|
|
||||||
err:
|
err:
|
||||||
if (reg->y_array) {
|
if (reg->y_array) {
|
||||||
for (int i = 0; i < reg->y_size; i++) {
|
for (size_t i = 0; i < reg->y_size; i++) {
|
||||||
xfree(reg->y_array[i]);
|
xfree(reg->y_array[i]);
|
||||||
}
|
}
|
||||||
xfree(reg->y_array);
|
xfree(reg->y_array);
|
||||||
@@ -5590,7 +5580,7 @@ static void set_clipboard(int name, yankreg_T *reg)
|
|||||||
|
|
||||||
list_T *lines = list_alloc();
|
list_T *lines = list_alloc();
|
||||||
|
|
||||||
for (int i = 0; i < reg->y_size; i++) {
|
for (size_t i = 0; i < reg->y_size; i++) {
|
||||||
list_append_string(lines, reg->y_array[i], -1);
|
list_append_string(lines, reg->y_array[i], -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -5615,7 +5605,7 @@ static void set_clipboard(int name, yankreg_T *reg)
|
|||||||
}
|
}
|
||||||
list_append_string(args, ®type, 1);
|
list_append_string(args, ®type, 1);
|
||||||
|
|
||||||
char_u regname = name;
|
char_u regname = (char_u)name;
|
||||||
list_append_string(args, ®name, 1);
|
list_append_string(args, ®name, 1);
|
||||||
|
|
||||||
(void)eval_call_provider("clipboard", "set", args);
|
(void)eval_call_provider("clipboard", "set", args);
|
||||||
@@ -5678,7 +5668,7 @@ const void *op_register_iter(const void *const iter, char *const name,
|
|||||||
if (iter_reg - &(y_regs[0]) == NUM_SAVED_REGISTERS || reg_empty(iter_reg)) {
|
if (iter_reg - &(y_regs[0]) == NUM_SAVED_REGISTERS || reg_empty(iter_reg)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
size_t iter_off = iter_reg - &(y_regs[0]);
|
int iter_off = (int)(iter_reg - &(y_regs[0]));
|
||||||
*name = (char)get_register_name(iter_off);
|
*name = (char)get_register_name(iter_off);
|
||||||
*reg = *iter_reg;
|
*reg = *iter_reg;
|
||||||
while (++iter_reg - &(y_regs[0]) < NUM_SAVED_REGISTERS) {
|
while (++iter_reg - &(y_regs[0]) < NUM_SAVED_REGISTERS) {
|
||||||
|
@@ -79,7 +79,7 @@ enum GRegFlags {
|
|||||||
/// Definition of one register
|
/// Definition of one register
|
||||||
typedef struct yankreg {
|
typedef struct yankreg {
|
||||||
char_u **y_array; ///< Pointer to an array of line pointers.
|
char_u **y_array; ///< Pointer to an array of line pointers.
|
||||||
linenr_T y_size; ///< Number of lines in y_array.
|
size_t y_size; ///< Number of lines in y_array.
|
||||||
MotionType y_type; ///< Register type
|
MotionType y_type; ///< Register type
|
||||||
colnr_T y_width; ///< Register width (only valid for y_type == kBlockWise).
|
colnr_T y_width; ///< Register width (only valid for y_type == kBlockWise).
|
||||||
Timestamp timestamp; ///< Time when register was last modified.
|
Timestamp timestamp; ///< Time when register was last modified.
|
||||||
|
@@ -4030,16 +4030,17 @@ set_num_option (
|
|||||||
errmsg = e_invarg;
|
errmsg = e_invarg;
|
||||||
curwin->w_p_fdc = 12;
|
curwin->w_p_fdc = 12;
|
||||||
}
|
}
|
||||||
}
|
// 'shiftwidth' or 'tabstop'
|
||||||
/* 'shiftwidth' or 'tabstop' */
|
} else if (pp == &curbuf->b_p_sw || pp == (long *)&curbuf->b_p_ts) {
|
||||||
else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts) {
|
if (foldmethodIsIndent(curwin)) {
|
||||||
if (foldmethodIsIndent(curwin))
|
|
||||||
foldUpdateAll(curwin);
|
foldUpdateAll(curwin);
|
||||||
/* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
|
}
|
||||||
* parse 'cinoptions'. */
|
// When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
|
||||||
if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
|
// parse 'cinoptions'.
|
||||||
|
if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0) {
|
||||||
parse_cino(curbuf);
|
parse_cino(curbuf);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
/* 'maxcombine' */
|
/* 'maxcombine' */
|
||||||
else if (pp == &p_mco) {
|
else if (pp == &p_mco) {
|
||||||
if (p_mco > MAX_MCO)
|
if (p_mco > MAX_MCO)
|
||||||
@@ -5657,7 +5658,7 @@ void buf_copy_options(buf_T *buf, int flags)
|
|||||||
buf->b_p_isk = save_p_isk;
|
buf->b_p_isk = save_p_isk;
|
||||||
else {
|
else {
|
||||||
buf->b_p_isk = vim_strsave(p_isk);
|
buf->b_p_isk = vim_strsave(p_isk);
|
||||||
did_isk = TRUE;
|
did_isk = true;
|
||||||
buf->b_p_ts = p_ts;
|
buf->b_p_ts = p_ts;
|
||||||
buf->b_help = false;
|
buf->b_help = false;
|
||||||
if (buf->b_p_bt[0] == 'h')
|
if (buf->b_p_bt[0] == 'h')
|
||||||
|
@@ -1422,7 +1422,7 @@ static void shada_read(ShaDaReadDef *const sd_reader, const int flags)
|
|||||||
}
|
}
|
||||||
if (!op_register_set(cur_entry.data.reg.name, (yankreg_T) {
|
if (!op_register_set(cur_entry.data.reg.name, (yankreg_T) {
|
||||||
.y_array = (char_u **) cur_entry.data.reg.contents,
|
.y_array = (char_u **) cur_entry.data.reg.contents,
|
||||||
.y_size = (linenr_T) cur_entry.data.reg.contents_size,
|
.y_size = cur_entry.data.reg.contents_size,
|
||||||
.y_type = cur_entry.data.reg.type,
|
.y_type = cur_entry.data.reg.type,
|
||||||
.y_width = (colnr_T) cur_entry.data.reg.width,
|
.y_width = (colnr_T) cur_entry.data.reg.width,
|
||||||
.timestamp = cur_entry.timestamp,
|
.timestamp = cur_entry.timestamp,
|
||||||
@@ -2745,7 +2745,7 @@ static ShaDaWriteResult shada_write(ShaDaWriteDef *const sd_writer,
|
|||||||
if (name == NUL) {
|
if (name == NUL) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (limit_reg_lines && reg.y_size > max_reg_lines) {
|
if (limit_reg_lines && reg.y_size > (size_t)max_reg_lines) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
wms->registers[op_reg_index(name)] = (PossiblyFreedShadaEntry) {
|
wms->registers[op_reg_index(name)] = (PossiblyFreedShadaEntry) {
|
||||||
|
Reference in New Issue
Block a user