mirror of
https://github.com/neovim/neovim.git
synced 2025-09-27 13:38:34 +00:00
refactor: follow style guide
- reduce variable scope - prefer initialization over declaration and assignment
This commit is contained in:
225
src/nvim/ops.c
225
src/nvim/ops.c
@@ -527,11 +527,10 @@ static void block_insert(oparg_T *oap, char *s, int b_insert, struct block_def *
|
||||
colnr_T offset; // pointer along new line
|
||||
size_t s_len = strlen(s);
|
||||
char *newp, *oldp; // new, old lines
|
||||
linenr_T lnum; // loop var
|
||||
int oldstate = State;
|
||||
State = MODE_INSERT; // don't want MODE_REPLACE for State
|
||||
|
||||
for (lnum = oap->start.lnum + 1; lnum <= oap->end.lnum; lnum++) {
|
||||
for (linenr_T lnum = oap->start.lnum + 1; lnum <= oap->end.lnum; lnum++) {
|
||||
block_prep(oap, bdp, lnum, true);
|
||||
if (bdp->is_short && b_insert) {
|
||||
continue; // OP_INSERT, line ends before block start
|
||||
@@ -646,7 +645,6 @@ void op_reindent(oparg_T *oap, Indenter how)
|
||||
// for each line separately, especially when undoing.
|
||||
if (u_savecommon(curbuf, start_lnum - 1, start_lnum + oap->line_count,
|
||||
start_lnum + oap->line_count, false) == OK) {
|
||||
char *l;
|
||||
int amount;
|
||||
for (i = oap->line_count - 1; i >= 0 && !got_int; i--) {
|
||||
// it's a slow thing to do, so give feedback so there's no worry
|
||||
@@ -662,7 +660,7 @@ void op_reindent(oparg_T *oap, Indenter how)
|
||||
// indented, unless there is only one line.
|
||||
if (i != oap->line_count - 1 || oap->line_count == 1
|
||||
|| how != get_lisp_indent) {
|
||||
l = skipwhite(get_cursor_line_ptr());
|
||||
char *l = skipwhite(get_cursor_line_ptr());
|
||||
if (*l == NUL) { // empty or blank line
|
||||
amount = 0;
|
||||
} else {
|
||||
@@ -715,9 +713,7 @@ static char *expr_line = NULL;
|
||||
/// @return '=' when OK, NUL otherwise.
|
||||
int get_expr_register(void)
|
||||
{
|
||||
char *new_line;
|
||||
|
||||
new_line = getcmdline('=', 0, 0, true);
|
||||
char *new_line = getcmdline('=', 0, 0, true);
|
||||
if (new_line == NULL) {
|
||||
return NUL;
|
||||
}
|
||||
@@ -742,8 +738,6 @@ void set_expr_line(char *new_line)
|
||||
/// @return a pointer to allocated memory, or NULL for failure.
|
||||
char *get_expr_line(void)
|
||||
{
|
||||
char *expr_copy;
|
||||
char *rv;
|
||||
static int nested = 0;
|
||||
|
||||
if (expr_line == NULL) {
|
||||
@@ -752,7 +746,7 @@ char *get_expr_line(void)
|
||||
|
||||
// Make a copy of the expression, because evaluating it may cause it to be
|
||||
// changed.
|
||||
expr_copy = xstrdup(expr_line);
|
||||
char *expr_copy = xstrdup(expr_line);
|
||||
|
||||
// When we are invoked recursively limit the evaluation to 10 levels.
|
||||
// Then return the string as-is.
|
||||
@@ -761,7 +755,7 @@ char *get_expr_line(void)
|
||||
}
|
||||
|
||||
nested++;
|
||||
rv = eval_to_string(expr_copy, true);
|
||||
char *rv = eval_to_string(expr_copy, true);
|
||||
nested--;
|
||||
xfree(expr_copy);
|
||||
return rv;
|
||||
@@ -888,7 +882,6 @@ bool yank_register_mline(int regname)
|
||||
int do_record(int c)
|
||||
{
|
||||
static int regname;
|
||||
yankreg_T *old_y_previous;
|
||||
int retval;
|
||||
|
||||
if (reg_recording == 0) {
|
||||
@@ -942,7 +935,7 @@ int do_record(int c)
|
||||
} else {
|
||||
// We don't want to change the default register here, so save and
|
||||
// restore the current register name.
|
||||
old_y_previous = y_previous;
|
||||
yankreg_T *old_y_previous = y_previous;
|
||||
|
||||
retval = stuff_yank(regname, p);
|
||||
|
||||
@@ -1023,13 +1016,11 @@ static char *execreg_line_continuation(char **lines, size_t *idx)
|
||||
garray_T ga;
|
||||
ga_init(&ga, (int)sizeof(char), 400);
|
||||
|
||||
char *p;
|
||||
|
||||
// search backwards to find the first line of this command.
|
||||
// Any line not starting with \ or "\ is the start of the
|
||||
// command.
|
||||
while (--i > 0) {
|
||||
p = skipwhite(lines[i]);
|
||||
char *p = skipwhite(lines[i]);
|
||||
if (*p != '\\' && (p[0] != '"' || p[1] != '\\' || p[2] != ' ')) {
|
||||
break;
|
||||
}
|
||||
@@ -1039,7 +1030,7 @@ static char *execreg_line_continuation(char **lines, size_t *idx)
|
||||
// join all the lines
|
||||
ga_concat(&ga, lines[cmd_start]);
|
||||
for (size_t j = cmd_start + 1; j <= cmd_end; j++) {
|
||||
p = skipwhite(lines[j]);
|
||||
char *p = skipwhite(lines[j]);
|
||||
if (*p == '\\') {
|
||||
// Adjust the growsize to the current length to
|
||||
// speed up concatenating many lines.
|
||||
@@ -1066,7 +1057,6 @@ static char *execreg_line_continuation(char **lines, size_t *idx)
|
||||
/// @return FAIL for failure, OK otherwise
|
||||
int do_execreg(int regname, int colon, int addcr, int silent)
|
||||
{
|
||||
char *p;
|
||||
int retval = OK;
|
||||
|
||||
if (regname == '@') { // repeat previous one
|
||||
@@ -1095,12 +1085,12 @@ int do_execreg(int regname, int colon, int addcr, int silent)
|
||||
// don't keep the cmdline containing @:
|
||||
XFREE_CLEAR(new_last_cmdline);
|
||||
// Escape all control characters with a CTRL-V
|
||||
p = vim_strsave_escaped_ext(last_cmdline,
|
||||
"\001\002\003\004\005\006\007"
|
||||
"\010\011\012\013\014\015\016\017"
|
||||
"\020\021\022\023\024\025\026\027"
|
||||
"\030\031\032\033\034\035\036\037",
|
||||
Ctrl_V, false);
|
||||
char *p = vim_strsave_escaped_ext(last_cmdline,
|
||||
"\001\002\003\004\005\006\007"
|
||||
"\010\011\012\013\014\015\016\017"
|
||||
"\020\021\022\023\024\025\026\027"
|
||||
"\030\031\032\033\034\035\036\037",
|
||||
Ctrl_V, false);
|
||||
// When in Visual mode "'<,'>" will be prepended to the command.
|
||||
// Remove it when it's already there.
|
||||
if (VIsual_active && strncmp(p, "'<,'>", 5) == 0) {
|
||||
@@ -1110,14 +1100,14 @@ int do_execreg(int regname, int colon, int addcr, int silent)
|
||||
}
|
||||
xfree(p);
|
||||
} else if (regname == '=') {
|
||||
p = get_expr_line();
|
||||
char *p = get_expr_line();
|
||||
if (p == NULL) {
|
||||
return FAIL;
|
||||
}
|
||||
retval = put_in_typebuf(p, true, colon, silent);
|
||||
xfree(p);
|
||||
} else if (regname == '.') { // use last inserted text
|
||||
p = get_last_insert_save();
|
||||
char *p = get_last_insert_save();
|
||||
if (p == NULL) {
|
||||
emsg(_(e_noinstext));
|
||||
return FAIL;
|
||||
@@ -1147,7 +1137,7 @@ int do_execreg(int regname, int colon, int addcr, int silent)
|
||||
char *str = reg->y_array[i];
|
||||
bool free_str = false;
|
||||
if (colon && i > 0) {
|
||||
p = skipwhite(str);
|
||||
char *p = skipwhite(str);
|
||||
if (*p == '\\' || (p[0] == '"' && p[1] == '\\' && p[2] == ' ')) {
|
||||
str = execreg_line_continuation(reg->y_array, &i);
|
||||
free_str = true;
|
||||
@@ -1302,8 +1292,6 @@ int insert_reg(int regname, bool literally_arg)
|
||||
/// @return true if "regname" is a special register,
|
||||
bool get_spec_reg(int regname, char **argp, bool *allocated, bool errmsg)
|
||||
{
|
||||
size_t cnt;
|
||||
|
||||
*argp = NULL;
|
||||
*allocated = false;
|
||||
switch (regname) {
|
||||
@@ -1360,9 +1348,9 @@ bool get_spec_reg(int regname, char **argp, bool *allocated, bool errmsg)
|
||||
if (!errmsg) {
|
||||
return false;
|
||||
}
|
||||
cnt = find_ident_under_cursor(argp, (regname == Ctrl_W
|
||||
? (FIND_IDENT|FIND_STRING)
|
||||
: FIND_STRING));
|
||||
size_t cnt = find_ident_under_cursor(argp, (regname == Ctrl_W
|
||||
? (FIND_IDENT|FIND_STRING)
|
||||
: FIND_STRING));
|
||||
*argp = cnt ? xmemdupz(*argp, cnt) : NULL;
|
||||
*allocated = true;
|
||||
return true;
|
||||
@@ -1439,10 +1427,7 @@ static void shift_delete_registers(bool y_append)
|
||||
/// @return FAIL if undo failed, OK otherwise.
|
||||
int op_delete(oparg_T *oap)
|
||||
{
|
||||
int n;
|
||||
linenr_T lnum;
|
||||
char *ptr;
|
||||
char *newp, *oldp;
|
||||
struct block_def bd = { 0 };
|
||||
linenr_T old_lcount = curbuf->b_ml.ml_line_count;
|
||||
|
||||
@@ -1475,7 +1460,7 @@ int op_delete(oparg_T *oap)
|
||||
&& oap->line_count > 1
|
||||
&& oap->motion_force == NUL
|
||||
&& oap->op_type == OP_DELETE) {
|
||||
ptr = ml_get(oap->end.lnum) + oap->end.col;
|
||||
char *ptr = ml_get(oap->end.lnum) + oap->end.col;
|
||||
if (*ptr != NUL) {
|
||||
ptr += oap->inclusive;
|
||||
}
|
||||
@@ -1572,9 +1557,9 @@ int op_delete(oparg_T *oap)
|
||||
// "n" == number of chars deleted
|
||||
// If we delete a TAB, it may be replaced by several characters.
|
||||
// Thus the number of characters may increase!
|
||||
n = bd.textlen - bd.startspaces - bd.endspaces;
|
||||
oldp = ml_get(lnum);
|
||||
newp = xmalloc(strlen(oldp) - (size_t)n + 1);
|
||||
int n = bd.textlen - bd.startspaces - bd.endspaces;
|
||||
char *oldp = ml_get(lnum);
|
||||
char *newp = xmalloc(strlen(oldp) - (size_t)n + 1);
|
||||
// copy up to deleted part
|
||||
memmove(newp, oldp, (size_t)bd.textcol);
|
||||
// insert spaces
|
||||
@@ -1685,7 +1670,7 @@ int op_delete(oparg_T *oap)
|
||||
display_dollar(oap->end.col - !oap->inclusive);
|
||||
}
|
||||
|
||||
n = oap->end.col - oap->start.col + 1 - !oap->inclusive;
|
||||
int n = oap->end.col - oap->start.col + 1 - !oap->inclusive;
|
||||
|
||||
if (virtual_op) {
|
||||
// fix up things for virtualedit-delete:
|
||||
@@ -1734,7 +1719,7 @@ int op_delete(oparg_T *oap)
|
||||
del_lines(oap->line_count - 2, false);
|
||||
|
||||
// delete from start of line until op_end
|
||||
n = (oap->end.col + 1 - !oap->inclusive);
|
||||
int n = (oap->end.col + 1 - !oap->inclusive);
|
||||
curwin->w_cursor.col = 0;
|
||||
(void)del_bytes((colnr_T)n, !virtual_op,
|
||||
oap->op_type == OP_DELETE && !oap->is_VIsual);
|
||||
@@ -2043,7 +2028,6 @@ static int op_replace(oparg_T *oap, int c)
|
||||
/// Handle the (non-standard vi) tilde operator. Also for "gu", "gU" and "g?".
|
||||
void op_tilde(oparg_T *oap)
|
||||
{
|
||||
pos_T pos;
|
||||
struct block_def bd;
|
||||
int did_change = false;
|
||||
|
||||
@@ -2052,7 +2036,7 @@ void op_tilde(oparg_T *oap)
|
||||
return;
|
||||
}
|
||||
|
||||
pos = oap->start;
|
||||
pos_T pos = oap->start;
|
||||
if (oap->motion_type == kMTBlockWise) { // Visual block mode
|
||||
for (; pos.lnum <= oap->end.lnum; pos.lnum++) {
|
||||
int one_change;
|
||||
@@ -2204,11 +2188,9 @@ bool swapchar(int op_type, pos_T *pos)
|
||||
void op_insert(oparg_T *oap, int count1)
|
||||
{
|
||||
int pre_textlen = 0;
|
||||
char *firstline;
|
||||
colnr_T ind_pre_col = 0;
|
||||
int ind_pre_vcol = 0;
|
||||
struct block_def bd;
|
||||
pos_T t1;
|
||||
|
||||
// edit() changes this - record it for OP_APPEND
|
||||
bd.is_MAX = (curwin->w_curswant == MAXCOL);
|
||||
@@ -2245,7 +2227,7 @@ void op_insert(oparg_T *oap, int count1)
|
||||
// Get indent information
|
||||
ind_pre_col = (colnr_T)getwhitecols_curline();
|
||||
ind_pre_vcol = get_indent();
|
||||
firstline = ml_get(oap->start.lnum) + bd.textcol;
|
||||
char *firstline = ml_get(oap->start.lnum) + bd.textcol;
|
||||
|
||||
if (oap->op_type == OP_APPEND) {
|
||||
firstline += bd.textlen;
|
||||
@@ -2285,7 +2267,7 @@ void op_insert(oparg_T *oap, int count1)
|
||||
}
|
||||
}
|
||||
|
||||
t1 = oap->start;
|
||||
pos_T t1 = oap->start;
|
||||
const pos_T start_insert = curwin->w_cursor;
|
||||
(void)edit(NUL, false, (linenr_T)count1);
|
||||
|
||||
@@ -2376,7 +2358,7 @@ void op_insert(oparg_T *oap, int count1)
|
||||
|
||||
// Subsequent calls to ml_get() flush the firstline data - take a
|
||||
// copy of the required string.
|
||||
firstline = ml_get(oap->start.lnum);
|
||||
char *firstline = ml_get(oap->start.lnum);
|
||||
const size_t len = strlen(firstline);
|
||||
colnr_T add = bd.textcol;
|
||||
colnr_T offset = 0; // offset when cursor was moved in insert mode
|
||||
@@ -2419,7 +2401,6 @@ void op_insert(oparg_T *oap, int count1)
|
||||
/// @return true if edit() returns because of a CTRL-O command
|
||||
int op_change(oparg_T *oap)
|
||||
{
|
||||
int retval;
|
||||
int pre_textlen = 0;
|
||||
int pre_indent = 0;
|
||||
char *firstline;
|
||||
@@ -2468,7 +2449,7 @@ int op_change(oparg_T *oap)
|
||||
const bool save_finish_op = finish_op;
|
||||
finish_op = false;
|
||||
|
||||
retval = edit(NUL, false, 1);
|
||||
int retval = edit(NUL, false, 1);
|
||||
|
||||
finish_op = save_finish_op;
|
||||
|
||||
@@ -2597,13 +2578,9 @@ bool op_yank(oparg_T *oap, bool message)
|
||||
static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append)
|
||||
{
|
||||
yankreg_T newreg; // new yank register when appending
|
||||
char **new_ptr;
|
||||
linenr_T lnum; // current line number
|
||||
MotionType yank_type = oap->motion_type;
|
||||
size_t yanklines = (size_t)oap->line_count;
|
||||
linenr_T yankendlnum = oap->end.lnum;
|
||||
char *p;
|
||||
char *pnew;
|
||||
struct block_def bd;
|
||||
|
||||
yankreg_T *curr = reg; // copy of current register
|
||||
@@ -2635,7 +2612,7 @@ static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append)
|
||||
reg->timestamp = os_time();
|
||||
|
||||
size_t y_idx = 0; // index in y_array[]
|
||||
lnum = oap->start.lnum;
|
||||
linenr_T lnum = oap->start.lnum; // current line number
|
||||
|
||||
if (yank_type == kMTBlockWise) {
|
||||
// Visual block mode
|
||||
@@ -2661,7 +2638,7 @@ static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append)
|
||||
colnr_T startcol = 0, endcol = MAXCOL;
|
||||
int is_oneChar = false;
|
||||
colnr_T cs, ce;
|
||||
p = ml_get(lnum);
|
||||
char *p = ml_get(lnum);
|
||||
bd.startspaces = 0;
|
||||
bd.endspaces = 0;
|
||||
|
||||
@@ -2725,7 +2702,7 @@ static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append)
|
||||
|
||||
if (curr != reg) { // append the new block to the old block
|
||||
size_t j;
|
||||
new_ptr = xmalloc(sizeof(char *) * (curr->y_size + reg->y_size));
|
||||
char **new_ptr = xmalloc(sizeof(char *) * (curr->y_size + reg->y_size));
|
||||
for (j = 0; j < curr->y_size; j++) {
|
||||
new_ptr[j] = curr->y_array[j];
|
||||
}
|
||||
@@ -2741,8 +2718,8 @@ static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append)
|
||||
// the new block, unless being Vi compatible.
|
||||
if (curr->y_type == kMTCharWise
|
||||
&& vim_strchr(p_cpo, CPO_REGAPPEND) == NULL) {
|
||||
pnew = xmalloc(strlen(curr->y_array[curr->y_size - 1])
|
||||
+ strlen(reg->y_array[0]) + 1);
|
||||
char *pnew = xmalloc(strlen(curr->y_array[curr->y_size - 1])
|
||||
+ strlen(reg->y_array[0]) + 1);
|
||||
STRCPY(pnew, curr->y_array[--j]);
|
||||
STRCAT(pnew, reg->y_array[0]);
|
||||
xfree(curr->y_array[j]);
|
||||
@@ -2902,34 +2879,23 @@ static void do_autocmd_textyankpost(oparg_T *oap, yankreg_T *reg)
|
||||
/// @param dir BACKWARD for 'P', FORWARD for 'p'
|
||||
void do_put(int regname, yankreg_T *reg, int dir, int count, int flags)
|
||||
{
|
||||
char *ptr;
|
||||
char *newp;
|
||||
char *oldp;
|
||||
int yanklen;
|
||||
size_t totlen = 0; // init for gcc
|
||||
linenr_T lnum = 0;
|
||||
colnr_T col = 0;
|
||||
size_t i; // index in y_array[]
|
||||
MotionType y_type;
|
||||
size_t y_size;
|
||||
size_t oldlen;
|
||||
int y_width = 0;
|
||||
colnr_T vcol = 0;
|
||||
int delcount;
|
||||
int incr = 0;
|
||||
struct block_def bd;
|
||||
char **y_array = NULL;
|
||||
linenr_T nr_lines = 0;
|
||||
pos_T new_cursor;
|
||||
int indent;
|
||||
int orig_indent = 0; // init for gcc
|
||||
int indent_diff = 0; // init for gcc
|
||||
bool first_indent = true;
|
||||
int lendiff = 0;
|
||||
pos_T old_pos;
|
||||
char *insert_string = NULL;
|
||||
bool allocated = false;
|
||||
int cnt;
|
||||
const pos_T orig_start = curbuf->b_op_start;
|
||||
const pos_T orig_end = curbuf->b_op_end;
|
||||
unsigned cur_ve_flags = get_ve_flags();
|
||||
@@ -3046,7 +3012,7 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags)
|
||||
// Loop twice: count the number of lines and save them.
|
||||
while (true) {
|
||||
y_size = 0;
|
||||
ptr = insert_string;
|
||||
char *ptr = insert_string;
|
||||
while (ptr != NULL) {
|
||||
if (y_array != NULL) {
|
||||
y_array[y_size] = ptr;
|
||||
@@ -3104,11 +3070,11 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags)
|
||||
if (dir == FORWARD && *p != NUL) {
|
||||
MB_PTR_ADV(p);
|
||||
}
|
||||
ptr = xstrdup(p);
|
||||
char *ptr = xstrdup(p);
|
||||
ml_append(curwin->w_cursor.lnum, ptr, 0, false);
|
||||
xfree(ptr);
|
||||
|
||||
oldp = get_cursor_line_ptr();
|
||||
char *oldp = get_cursor_line_ptr();
|
||||
p = oldp + curwin->w_cursor.col;
|
||||
if (dir == FORWARD && *p != NUL) {
|
||||
MB_PTR_ADV(p);
|
||||
@@ -3173,7 +3139,7 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags)
|
||||
goto end;
|
||||
}
|
||||
|
||||
yanklen = (int)strlen(y_array[0]);
|
||||
int yanklen = (int)strlen(y_array[0]);
|
||||
|
||||
if (cur_ve_flags == VE_ALL && y_type == kMTCharWise) {
|
||||
if (gchar_cursor() == TAB) {
|
||||
@@ -3194,7 +3160,7 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags)
|
||||
}
|
||||
|
||||
lnum = curwin->w_cursor.lnum;
|
||||
col = curwin->w_cursor.col;
|
||||
colnr_T col = curwin->w_cursor.col;
|
||||
|
||||
// Block mode
|
||||
if (y_type == kMTBlockWise) {
|
||||
@@ -3235,7 +3201,7 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags)
|
||||
}
|
||||
curwin->w_cursor.coladd = 0;
|
||||
bd.textcol = 0;
|
||||
for (i = 0; i < y_size; i++) {
|
||||
for (size_t i = 0; i < y_size; i++) {
|
||||
int spaces = 0;
|
||||
char shortline;
|
||||
// can just be 0 or 1, needed for blockwise paste beyond the current
|
||||
@@ -3245,7 +3211,7 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags)
|
||||
bd.startspaces = 0;
|
||||
bd.endspaces = 0;
|
||||
vcol = 0;
|
||||
delcount = 0;
|
||||
int delcount = 0;
|
||||
|
||||
// add a new line
|
||||
if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) {
|
||||
@@ -3256,8 +3222,8 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags)
|
||||
lines_appended = 1;
|
||||
}
|
||||
// get the old line and advance to the position to insert at
|
||||
oldp = get_cursor_line_ptr();
|
||||
oldlen = strlen(oldp);
|
||||
char *oldp = get_cursor_line_ptr();
|
||||
size_t oldlen = strlen(oldp);
|
||||
chartabsize_T cts;
|
||||
init_chartabsize_arg(&cts, curwin, curwin->w_cursor.lnum, 0, oldp, oldp);
|
||||
|
||||
@@ -3267,7 +3233,7 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags)
|
||||
cts.cts_vcol += incr;
|
||||
}
|
||||
vcol = cts.cts_vcol;
|
||||
ptr = cts.cts_ptr;
|
||||
char *ptr = cts.cts_ptr;
|
||||
bd.textcol = (colnr_T)(ptr - oldp);
|
||||
clear_chartabsize_arg(&cts);
|
||||
|
||||
@@ -3318,7 +3284,7 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags)
|
||||
|
||||
totlen = (size_t)count * (size_t)(yanklen + spaces) + (size_t)bd.startspaces +
|
||||
(size_t)bd.endspaces;
|
||||
newp = xmalloc(totlen + oldlen + 1);
|
||||
char *newp = xmalloc(totlen + oldlen + 1);
|
||||
|
||||
// copy part up to cursor to new line
|
||||
ptr = newp;
|
||||
@@ -3409,7 +3375,7 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags)
|
||||
// Line mode: BACKWARD is the same as FORWARD on the previous line
|
||||
lnum--;
|
||||
}
|
||||
new_cursor = curwin->w_cursor;
|
||||
pos_T new_cursor = curwin->w_cursor;
|
||||
|
||||
// simple case: insert into one line at a time
|
||||
if (y_type == kMTCharWise && y_size == 1) {
|
||||
@@ -3445,8 +3411,8 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags)
|
||||
} else {
|
||||
totlen = (size_t)count * (size_t)yanklen;
|
||||
do {
|
||||
oldp = ml_get(lnum);
|
||||
oldlen = strlen(oldp);
|
||||
char *oldp = ml_get(lnum);
|
||||
size_t oldlen = strlen(oldp);
|
||||
if (lnum > start_lnum) {
|
||||
pos_T pos = {
|
||||
.lnum = lnum,
|
||||
@@ -3461,10 +3427,10 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags)
|
||||
lnum++;
|
||||
continue;
|
||||
}
|
||||
newp = xmalloc(totlen + oldlen + 1);
|
||||
char *newp = xmalloc(totlen + oldlen + 1);
|
||||
memmove(newp, oldp, (size_t)col);
|
||||
ptr = newp + col;
|
||||
for (i = 0; i < (size_t)count; i++) {
|
||||
char *ptr = newp + col;
|
||||
for (size_t i = 0; i < (size_t)count; i++) {
|
||||
memmove(ptr, y_array[0], (size_t)yanklen);
|
||||
ptr += yanklen;
|
||||
}
|
||||
@@ -3506,20 +3472,19 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags)
|
||||
}
|
||||
} else {
|
||||
linenr_T new_lnum = new_cursor.lnum;
|
||||
size_t len;
|
||||
|
||||
// Insert at least one line. When y_type is kMTCharWise, break the first
|
||||
// line in two.
|
||||
for (cnt = 1; cnt <= count; cnt++) {
|
||||
i = 0;
|
||||
for (int cnt = 1; cnt <= count; cnt++) {
|
||||
size_t i = 0;
|
||||
if (y_type == kMTCharWise) {
|
||||
// Split the current line in two at the insert position.
|
||||
// First insert y_array[size - 1] in front of second line.
|
||||
// Then append y_array[0] to first line.
|
||||
lnum = new_cursor.lnum;
|
||||
ptr = ml_get(lnum) + col;
|
||||
char *ptr = ml_get(lnum) + col;
|
||||
totlen = strlen(y_array[y_size - 1]);
|
||||
newp = xmalloc((size_t)(strlen(ptr) + totlen + 1));
|
||||
char *newp = xmalloc((size_t)(strlen(ptr) + totlen + 1));
|
||||
STRCPY(newp, y_array[y_size - 1]);
|
||||
STRCAT(newp, ptr);
|
||||
// insert second line
|
||||
@@ -3527,7 +3492,7 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags)
|
||||
new_lnum++;
|
||||
xfree(newp);
|
||||
|
||||
oldp = ml_get(lnum);
|
||||
char *oldp = ml_get(lnum);
|
||||
newp = xmalloc((size_t)col + (size_t)yanklen + 1);
|
||||
// copy first part of line
|
||||
memmove(newp, oldp, (size_t)col);
|
||||
@@ -3549,9 +3514,9 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags)
|
||||
lnum++;
|
||||
nr_lines++;
|
||||
if (flags & PUT_FIXINDENT) {
|
||||
old_pos = curwin->w_cursor;
|
||||
pos_T old_pos = curwin->w_cursor;
|
||||
curwin->w_cursor.lnum = lnum;
|
||||
ptr = ml_get(lnum);
|
||||
char *ptr = ml_get(lnum);
|
||||
if (cnt == count && i == y_size - 1) {
|
||||
lendiff = (int)strlen(ptr);
|
||||
}
|
||||
@@ -3626,7 +3591,7 @@ error:
|
||||
// Put the '] mark on the first byte of the last inserted character.
|
||||
// Correct the length for change in indent.
|
||||
curbuf->b_op_end.lnum = new_lnum;
|
||||
len = strlen(y_array[y_size - 1]);
|
||||
size_t len = strlen(y_array[y_size - 1]);
|
||||
col = (colnr_T)len - lendiff;
|
||||
if (col > 1) {
|
||||
curbuf->b_op_end.col = col - 1;
|
||||
@@ -3766,7 +3731,6 @@ void ex_display(exarg_T *eap)
|
||||
char *p;
|
||||
yankreg_T *yb;
|
||||
char *arg = eap->arg;
|
||||
int clen;
|
||||
int type;
|
||||
|
||||
if (arg != NULL && *arg == NUL) {
|
||||
@@ -3833,7 +3797,7 @@ void ex_display(exarg_T *eap)
|
||||
}
|
||||
for (p = yb->y_array[j];
|
||||
*p != NUL && (n -= ptr2cells(p)) >= 0; p++) {
|
||||
clen = utfc_ptr2len(p);
|
||||
int clen = utfc_ptr2len(p);
|
||||
msg_outtrans_len(p, clen, 0);
|
||||
p += clen - 1;
|
||||
}
|
||||
@@ -3932,7 +3896,6 @@ static void dis_msg(const char *p, bool skip_esc)
|
||||
char *skip_comment(char *line, bool process, bool include_space, bool *is_comment)
|
||||
{
|
||||
char *comment_flags = NULL;
|
||||
int lead_len;
|
||||
int leader_offset = get_last_leader_offset(line, &comment_flags);
|
||||
|
||||
*is_comment = false;
|
||||
@@ -3955,7 +3918,7 @@ char *skip_comment(char *line, bool process, bool include_space, bool *is_commen
|
||||
return line;
|
||||
}
|
||||
|
||||
lead_len = get_leader_len(line, &comment_flags, false, include_space);
|
||||
int lead_len = get_leader_len(line, &comment_flags, false, include_space);
|
||||
|
||||
if (lead_len == 0) {
|
||||
return line;
|
||||
@@ -3996,14 +3959,10 @@ int do_join(size_t count, int insert_space, int save_undo, int use_formatoptions
|
||||
char *curr = NULL;
|
||||
char *curr_start = NULL;
|
||||
char *cend;
|
||||
char *newp;
|
||||
char *spaces; // number of spaces inserted before a line
|
||||
int endcurr1 = NUL;
|
||||
int endcurr2 = NUL;
|
||||
int currsize = 0; // size of the current line
|
||||
int sumsize = 0; // size of the long new line
|
||||
linenr_T t;
|
||||
colnr_T col = 0;
|
||||
int ret = OK;
|
||||
int *comments = NULL;
|
||||
int remove_comments = (use_formatoptions == true)
|
||||
@@ -4018,7 +3977,7 @@ int do_join(size_t count, int insert_space, int save_undo, int use_formatoptions
|
||||
// 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
|
||||
// proper placement of each original line in the new one.
|
||||
spaces = xcalloc(count, 1);
|
||||
char *spaces = xcalloc(count, 1); // number of spaces inserted before a line
|
||||
if (remove_comments) {
|
||||
comments = xcalloc(count, sizeof(*comments));
|
||||
}
|
||||
@@ -4026,7 +3985,7 @@ int do_join(size_t count, int insert_space, int save_undo, int use_formatoptions
|
||||
// Don't move anything yet, just compute the final line length
|
||||
// and setup the array of space strings lengths
|
||||
// This loops forward over joined lines.
|
||||
for (t = 0; t < (linenr_T)count; t++) {
|
||||
for (linenr_T t = 0; t < (linenr_T)count; t++) {
|
||||
curr_start = ml_get(curwin->w_cursor.lnum + t);
|
||||
curr = curr_start;
|
||||
if (t == 0 && setmark && (cmdmod.cmod_flags & CMOD_LOCKMARKS) == 0) {
|
||||
@@ -4098,10 +4057,10 @@ int do_join(size_t count, int insert_space, int save_undo, int use_formatoptions
|
||||
}
|
||||
|
||||
// store the column position before last line
|
||||
col = sumsize - currsize - spaces[count - 1];
|
||||
colnr_T col = sumsize - currsize - spaces[count - 1];
|
||||
|
||||
// allocate the space for the new line
|
||||
newp = xmalloc((size_t)sumsize + 1);
|
||||
char *newp = xmalloc((size_t)sumsize + 1);
|
||||
cend = newp + sumsize;
|
||||
*cend = 0;
|
||||
|
||||
@@ -4114,7 +4073,7 @@ int do_join(size_t count, int insert_space, int save_undo, int use_formatoptions
|
||||
|
||||
curbuf_splice_pending++;
|
||||
|
||||
for (t = (linenr_T)count - 1;; t--) {
|
||||
for (linenr_T t = (linenr_T)count - 1;; t--) {
|
||||
cend -= currsize;
|
||||
memmove(cend, curr, (size_t)currsize);
|
||||
if (spaces[t] > 0) {
|
||||
@@ -4163,7 +4122,7 @@ int do_join(size_t count, int insert_space, int save_undo, int use_formatoptions
|
||||
// Delete following lines. To do this we move the cursor there
|
||||
// briefly, and then move it back. After del_lines() the cursor may
|
||||
// have moved up (last line deleted), so the current lnum is kept in t.
|
||||
t = curwin->w_cursor.lnum;
|
||||
linenr_T t = curwin->w_cursor.lnum;
|
||||
curwin->w_cursor.lnum++;
|
||||
del_lines((int)count - 1, false);
|
||||
curwin->w_cursor.lnum = t;
|
||||
@@ -4227,11 +4186,6 @@ static void restore_lbr(bool lbr_saved)
|
||||
static void block_prep(oparg_T *oap, struct block_def *bdp, linenr_T lnum, bool is_del)
|
||||
{
|
||||
int incr = 0;
|
||||
char *pend;
|
||||
char *pstart;
|
||||
char *line;
|
||||
char *prev_pstart;
|
||||
char *prev_pend;
|
||||
// Avoid a problem with unwanted linebreaks in block mode.
|
||||
const bool lbr_saved = reset_lbr();
|
||||
|
||||
@@ -4247,8 +4201,8 @@ static void block_prep(oparg_T *oap, struct block_def *bdp, linenr_T lnum, bool
|
||||
bdp->end_char_vcols = 0;
|
||||
bdp->start_char_vcols = 0;
|
||||
|
||||
line = ml_get(lnum);
|
||||
prev_pstart = line;
|
||||
char *line = ml_get(lnum);
|
||||
char *prev_pstart = line;
|
||||
|
||||
chartabsize_T cts;
|
||||
init_chartabsize_arg(&cts, curwin, lnum, bdp->start_vcol, line, line);
|
||||
@@ -4267,7 +4221,7 @@ static void block_prep(oparg_T *oap, struct block_def *bdp, linenr_T lnum, bool
|
||||
MB_PTR_ADV(cts.cts_ptr);
|
||||
}
|
||||
bdp->start_vcol = cts.cts_vcol;
|
||||
pstart = cts.cts_ptr;
|
||||
char *pstart = cts.cts_ptr;
|
||||
clear_chartabsize_arg(&cts);
|
||||
|
||||
bdp->start_char_vcols = incr;
|
||||
@@ -4284,7 +4238,7 @@ static void block_prep(oparg_T *oap, struct block_def *bdp, linenr_T lnum, bool
|
||||
if (is_del && bdp->startspaces) {
|
||||
bdp->startspaces = bdp->start_char_vcols - bdp->startspaces;
|
||||
}
|
||||
pend = pstart;
|
||||
char *pend = pstart;
|
||||
bdp->end_vcol = bdp->start_vcol;
|
||||
if (bdp->end_vcol > oap->end_vcol) { // it's all in one character
|
||||
bdp->is_oneChar = true;
|
||||
@@ -4306,7 +4260,7 @@ static void block_prep(oparg_T *oap, struct block_def *bdp, linenr_T lnum, bool
|
||||
}
|
||||
} else {
|
||||
init_chartabsize_arg(&cts, curwin, lnum, bdp->end_vcol, line, pend);
|
||||
prev_pend = pend;
|
||||
char *prev_pend = pend;
|
||||
while (cts.cts_vcol <= oap->end_vcol && *cts.cts_ptr != NUL) {
|
||||
// Count a tab for what it's worth (if list mode not on)
|
||||
prev_pend = cts.cts_ptr;
|
||||
@@ -4358,7 +4312,6 @@ static void block_prep(oparg_T *oap, struct block_def *bdp, linenr_T lnum, bool
|
||||
/// @param[in] g_cmd Prefixed with `g`.
|
||||
void op_addsub(oparg_T *oap, linenr_T Prenum1, bool g_cmd)
|
||||
{
|
||||
pos_T pos;
|
||||
struct block_def bd;
|
||||
ssize_t change_cnt = 0;
|
||||
linenr_T amount = Prenum1;
|
||||
@@ -4369,7 +4322,7 @@ void op_addsub(oparg_T *oap, linenr_T Prenum1, bool g_cmd)
|
||||
disable_fold_update++;
|
||||
|
||||
if (!VIsual_active) {
|
||||
pos = curwin->w_cursor;
|
||||
pos_T pos = curwin->w_cursor;
|
||||
if (u_save_cursor() == FAIL) {
|
||||
disable_fold_update--;
|
||||
return;
|
||||
@@ -4389,7 +4342,7 @@ void op_addsub(oparg_T *oap, linenr_T Prenum1, bool g_cmd)
|
||||
return;
|
||||
}
|
||||
|
||||
pos = oap->start;
|
||||
pos_T pos = oap->start;
|
||||
for (; pos.lnum <= oap->end.lnum; pos.lnum++) {
|
||||
if (oap->motion_type == kMTBlockWise) {
|
||||
// Visual block mode
|
||||
@@ -4466,17 +4419,11 @@ void op_addsub(oparg_T *oap, linenr_T Prenum1, bool g_cmd)
|
||||
/// @return true if some character was changed.
|
||||
int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1)
|
||||
{
|
||||
int col;
|
||||
char *buf1 = NULL;
|
||||
char buf2[NUMBUFLEN];
|
||||
int pre; // 'X' or 'x': hex; '0': octal; 'B' or 'b': bin
|
||||
static bool hexupper = false; // 0xABC
|
||||
uvarnumber_T n;
|
||||
uvarnumber_T oldn;
|
||||
char *ptr;
|
||||
int c;
|
||||
int todel;
|
||||
int firstdigit;
|
||||
bool negative = false;
|
||||
bool was_positive = true;
|
||||
bool visual = VIsual_active;
|
||||
@@ -4500,8 +4447,8 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1)
|
||||
}
|
||||
|
||||
curwin->w_cursor = *pos;
|
||||
ptr = ml_get(pos->lnum);
|
||||
col = pos->col;
|
||||
char *ptr = ml_get(pos->lnum);
|
||||
int col = pos->col;
|
||||
|
||||
if (*ptr == NUL || col + !!save_coladd >= (int)strlen(ptr)) {
|
||||
goto theend;
|
||||
@@ -4594,7 +4541,7 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1)
|
||||
}
|
||||
|
||||
// If a number was found, and saving for undo works, replace the number.
|
||||
firstdigit = (uint8_t)ptr[col];
|
||||
int firstdigit = (uint8_t)ptr[col];
|
||||
if (!ascii_isdigit(firstdigit) && !(do_alpha && ASCII_ISALPHA(firstdigit))) {
|
||||
beep_flush();
|
||||
goto theend;
|
||||
@@ -4670,7 +4617,7 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1)
|
||||
subtract ^= true;
|
||||
}
|
||||
|
||||
oldn = n;
|
||||
uvarnumber_T oldn = n;
|
||||
|
||||
if (!overflow) { // if number is too big don't add/subtract
|
||||
n = subtract ? n - (uvarnumber_T)Prenum1
|
||||
@@ -4717,8 +4664,8 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1)
|
||||
curwin->w_cursor.col = col;
|
||||
startpos = curwin->w_cursor;
|
||||
did_change = true;
|
||||
todel = length;
|
||||
c = gchar_cursor();
|
||||
int todel = length;
|
||||
int c = gchar_cursor();
|
||||
|
||||
// Don't include the '-' in the length, only the length of the part
|
||||
// after it is kept the same.
|
||||
@@ -5311,7 +5258,6 @@ static varnumber_T line_count_info(char *line, varnumber_T *wc, varnumber_T *cc,
|
||||
/// @param dict when not NULL, store the info there instead of showing it.
|
||||
void cursor_pos_info(dict_T *dict)
|
||||
{
|
||||
char *p;
|
||||
char buf1[50];
|
||||
char buf2[40];
|
||||
varnumber_T byte_count = 0;
|
||||
@@ -5334,7 +5280,6 @@ void cursor_pos_info(dict_T *dict)
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
linenr_T lnum;
|
||||
int eol_size;
|
||||
varnumber_T last_check = 100000;
|
||||
int line_count_selected = 0;
|
||||
@@ -5382,7 +5327,7 @@ void cursor_pos_info(dict_T *dict)
|
||||
line_count_selected = max_pos.lnum - min_pos.lnum + 1;
|
||||
}
|
||||
|
||||
for (lnum = 1; lnum <= curbuf->b_ml.ml_line_count; lnum++) {
|
||||
for (linenr_T lnum = 1; lnum <= curbuf->b_ml.ml_line_count; lnum++) {
|
||||
// Check for a CTRL-C every 100000 characters.
|
||||
if (byte_count > last_check) {
|
||||
os_breakcheck();
|
||||
@@ -5488,7 +5433,7 @@ void cursor_pos_info(dict_T *dict)
|
||||
(int64_t)byte_count_cursor, (int64_t)byte_count);
|
||||
}
|
||||
} else {
|
||||
p = get_cursor_line_ptr();
|
||||
char *p = get_cursor_line_ptr();
|
||||
validate_virtcol();
|
||||
col_print(buf1, sizeof(buf1), (int)curwin->w_cursor.col + 1,
|
||||
(int)curwin->w_virtcol + 1);
|
||||
@@ -5529,7 +5474,7 @@ void cursor_pos_info(dict_T *dict)
|
||||
}
|
||||
if (dict == NULL) {
|
||||
// Don't shorten this message, the user asked for it.
|
||||
p = p_shm;
|
||||
char *p = p_shm;
|
||||
p_shm = "";
|
||||
if (p_ch < 1) {
|
||||
msg_start();
|
||||
|
Reference in New Issue
Block a user