aboutsummaryrefslogtreecommitdiff
path: root/src/ops.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ops.c')
-rw-r--r--src/ops.c141
1 files changed, 75 insertions, 66 deletions
diff --git a/src/ops.c b/src/ops.c
index 948e98aa54..d3ad950e23 100644
--- a/src/ops.c
+++ b/src/ops.c
@@ -234,7 +234,7 @@ void op_shift(oparg_T *oap, int curs_top, int amount)
if (oap->block_mode) {
curwin->w_cursor.lnum = oap->start.lnum;
curwin->w_cursor.col = block_col;
- } else if (curs_top) { /* put cursor on first line, for ">>" */
+ } else if (curs_top) { /* put cursor on first line, for ">>" */
curwin->w_cursor.lnum = oap->start.lnum;
beginline(BL_SOL | BL_FIX); /* shift_line() may have set cursor.col */
} else
@@ -250,7 +250,7 @@ void op_shift(oparg_T *oap, int curs_top, int amount)
sprintf((char *)IObuff, _("1 line %sed 1 time"), s);
else
sprintf((char *)IObuff, _("1 line %sed %d times"), s, amount);
- } else {
+ } else {
if (amount == 1)
sprintf((char *)IObuff, _("%ld lines %sed 1 time"),
oap->line_count, s);
@@ -301,7 +301,7 @@ shift_line (
} else
i += amount;
count = i * p_sw;
- } else { /* original vi indent */
+ } else { /* original vi indent */
if (left) {
count -= p_sw * amount;
if (count < 0)
@@ -388,7 +388,7 @@ static void shift_block(oparg_T *oap, int amount)
copy_spaces(newp + bd.textcol + i, (size_t)j);
/* the end */
mch_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
be shifted */
char_u *verbatim_copy_end; /* end of the part of the line which is
@@ -511,14 +511,14 @@ static void block_insert(oparg_T *oap, char_u *s, int b_insert, struct block_def
if (spaces != 0)
count = p_ts - 1; /* we're cutting a TAB */
offset = bdp->textcol;
- } else { /* append */
+ } else { /* append */
p_ts = bdp->end_char_vcols;
if (!bdp->is_short) { /* spaces = padding after block */
spaces = (bdp->endspaces ? p_ts - bdp->endspaces : 0);
if (spaces != 0)
count = p_ts - 1; /* we're cutting a TAB */
offset = bdp->textcol + bdp->textlen - (spaces != 0);
- } else { /* spaces = padding to block edge */
+ } else { /* spaces = padding to block edge */
/* if $ used, just append to EOL (ie spaces==0) */
if (!bdp->is_MAX)
spaces = (oap->end_vcol - bdp->end_vcol) + 1;
@@ -657,7 +657,8 @@ static char_u *expr_line = NULL;
* Get an expression for the "\"=expr1" or "CTRL-R =expr1"
* Returns '=' when OK, NUL otherwise.
*/
-int get_expr_register(void) {
+int get_expr_register(void)
+{
char_u *new_line;
new_line = getcmdline('=', 0L, 0);
@@ -684,7 +685,8 @@ void set_expr_line(char_u *new_line)
* Get the result of the '=' register expression.
* Returns a pointer to allocated memory, or NULL for failure.
*/
-char_u *get_expr_line(void) {
+char_u *get_expr_line(void)
+{
char_u *expr_copy;
char_u *rv;
static int nested = 0;
@@ -713,7 +715,8 @@ char_u *get_expr_line(void) {
/*
* Get the '=' register expression itself, without evaluating it.
*/
-char_u *get_expr_line_src(void) {
+char_u *get_expr_line_src(void)
+{
if (expr_line == NULL)
return NULL;
return vim_strsave(expr_line);
@@ -869,7 +872,7 @@ int do_record(int c)
regname = c;
retval = OK;
}
- } else { /* stop recording */
+ } else { /* stop recording */
/*
* Get the recorded key hits. K_SPECIAL and CSI will be escaped, this
* needs to be removed again to put it in a register. exec_reg then
@@ -933,7 +936,7 @@ static int stuff_yank(int regname, char_u *p)
vim_free(p);
vim_free(*pp);
*pp = lp;
- } else {
+ } else {
free_yank_all();
if ((y_current->y_array =
(char_u **)alloc((unsigned)sizeof(char_u *))) == NULL) {
@@ -1007,13 +1010,13 @@ do_execreg (
retval = put_in_typebuf(p, TRUE, TRUE, silent);
}
vim_free(p);
- } else if (regname == '=') {
+ } else if (regname == '=') {
p = get_expr_line();
if (p == NULL)
return FAIL;
retval = put_in_typebuf(p, TRUE, colon, silent);
vim_free(p);
- } else if (regname == '.') { /* use last inserted text */
+ } else if (regname == '.') { /* use last inserted text */
p = get_last_insert_save();
if (p == NULL) {
EMSG(_(e_noinstext));
@@ -1021,7 +1024,7 @@ do_execreg (
}
retval = put_in_typebuf(p, FALSE, colon, silent);
vim_free(p);
- } else {
+ } else {
get_yank_register(regname, FALSE);
if (y_current->y_array == NULL)
return FAIL;
@@ -1071,7 +1074,7 @@ static void put_reedit_in_typebuf(int silent)
buf[0] = 'g';
buf[1] = 'R';
buf[2] = NUL;
- } else {
+ } else {
buf[0] = restart_edit == 'I' ? 'i' : restart_edit;
buf[1] = NUL;
}
@@ -1158,7 +1161,7 @@ insert_reg (
stuffescaped(arg, literally);
if (allocated)
vim_free(arg);
- } else { /* name or number register */
+ } else { /* name or number register */
get_yank_register(regname, FALSE);
if (y_current->y_array == NULL)
retval = FAIL;
@@ -1517,7 +1520,7 @@ int op_delete(oparg_T *oap)
changed_lines(curwin->w_cursor.lnum, curwin->w_cursor.col,
oap->end.lnum + 1, 0L);
oap->line_count = 0; /* no lines deleted */
- } else if (oap->motion_type == MLINE) {
+ } else if (oap->motion_type == MLINE) {
if (oap->op_type == OP_CHANGE) {
/* Delete the lines except the first one. Temporarily move the
* cursor to the next line. Save the current line number, if the
@@ -1541,12 +1544,12 @@ int op_delete(oparg_T *oap)
/* leave cursor past last char in line */
if (oap->line_count > 1)
u_clearline(); /* "U" command not possible after "2cc" */
- } else {
+ } else {
del_lines(oap->line_count, TRUE);
beginline(BL_WHITE | BL_FIX);
u_clearline(); /* "U" command not possible after "dd" */
}
- } else {
+ } else {
if (virtual_op) {
int endcol = 0;
@@ -1619,12 +1622,12 @@ int op_delete(oparg_T *oap)
&& n > (int)STRLEN(ml_get(oap->end.lnum))) {
/* Special case: gH<Del> deletes the last line. */
del_lines(1L, FALSE);
- } else {
+ } else {
(void)del_bytes((long)n, !virtual_op, oap->op_type == OP_DELETE
&& !oap->is_VIsual
);
}
- } else { /* delete characters between lines */
+ } else { /* delete characters between lines */
pos_T curpos;
int delete_last_line;
@@ -1651,7 +1654,7 @@ int op_delete(oparg_T *oap)
curwin->w_cursor = curpos; /* restore curwin->w_cursor */
if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count)
curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
- } else {
+ } else {
/* delete from start of line until op_end */
curwin->w_cursor.col = 0;
(void)del_bytes((long)n, !virtual_op, oap->op_type == OP_DELETE
@@ -1796,7 +1799,7 @@ int op_replace(oparg_T *oap, int c)
/* copy the part after the changed part */
STRMOVE(newp + STRLEN(newp), oldp);
}
- } else {
+ } else {
/* Replacing with \r or \n means splitting the line. */
after_p = alloc_check(
(unsigned)(oldlen + 1 + n - STRLEN(newp)));
@@ -1812,7 +1815,7 @@ int op_replace(oparg_T *oap, int c)
vim_free(after_p);
}
}
- } else {
+ } else {
/*
* MCHAR and MLINE motion replace.
*/
@@ -1839,7 +1842,7 @@ int op_replace(oparg_T *oap, int c)
State = n;
/* Backup to the replaced character. */
dec_cursor();
- } else {
+ } else {
if (n == TAB) {
int end_vcol = 0;
@@ -1855,7 +1858,7 @@ int op_replace(oparg_T *oap, int c)
}
pchar(curwin->w_cursor, c);
}
- } else if (virtual_op && curwin->w_cursor.lnum == oap->end.lnum) {
+ } else if (virtual_op && curwin->w_cursor.lnum == oap->end.lnum) {
int virtcols = oap->end.coladd;
if (curwin->w_cursor.lnum == oap->start.lnum
@@ -1919,7 +1922,7 @@ void op_tilde(oparg_T *oap)
}
if (did_change)
changed_lines(oap->start.lnum, 0, oap->end.lnum + 1, 0L);
- } else { /* not block mode */
+ } else { /* not block mode */
if (oap->motion_type == MLINE) {
oap->start.col = 0;
pos.col = 0;
@@ -2030,7 +2033,7 @@ int swapchar(int op_type, pos_T *pos)
nc = ROT13(c, 'a');
else if (op_type != OP_LOWER)
nc = MB_TOUPPER(c);
- } else if (MB_ISUPPER(c)) {
+ } else if (MB_ISUPPER(c)) {
if (op_type == OP_ROT13)
nc = ROT13(c, 'A');
else if (op_type != OP_UPPER)
@@ -2112,7 +2115,7 @@ void op_insert(oparg_T *oap, long count1)
ins_char(' ');
bd.textlen += bd.endspaces;
}
- } else {
+ } else {
curwin->w_cursor = oap->end;
check_cursor_col();
@@ -2320,7 +2323,8 @@ int op_change(oparg_T *oap)
/*
* set all the yank registers to empty (called from main())
*/
-void init_yank(void) {
+void init_yank(void)
+{
int i;
for (i = 0; i < NUM_REGISTERS; ++i)
@@ -2328,7 +2332,8 @@ void init_yank(void) {
}
#if defined(EXITFREE) || defined(PROTO)
-void clear_registers(void) {
+void clear_registers(void)
+{
int i;
for (i = 0; i < NUM_REGISTERS; ++i) {
@@ -2357,7 +2362,8 @@ static void free_yank(long n)
}
}
-static void free_yank_all(void) {
+static void free_yank_all(void)
+{
free_yank(y_current->y_size);
}
@@ -2496,7 +2502,7 @@ int op_yank(oparg_T *oap, int deleting, int mess)
bd.startspaces = oap->end.coladd
- oap->start.coladd + oap->inclusive;
endcol = startcol;
- } else {
+ } else {
bd.endspaces = oap->end.coladd
+ oap->inclusive;
endcol -= oap->inclusive;
@@ -2731,11 +2737,11 @@ do_put (
if (y_array == NULL)
goto end;
}
- } else {
+ } else {
y_size = 1; /* use fake one-line yank register */
y_array = &insert_string;
}
- } else {
+ } else {
get_yank_register(regname, FALSE);
y_type = y_current->y_type;
@@ -2787,7 +2793,7 @@ do_put (
lnum = curbuf->b_ml.ml_line_count + 1;
if (u_save(curwin->w_cursor.lnum - 1, lnum) == FAIL)
goto end;
- } else if (y_type == MLINE) {
+ } else if (y_type == MLINE) {
lnum = curwin->w_cursor.lnum;
/* Correct line number for closed fold. Don't move the cursor yet,
* u_save() uses it. */
@@ -2980,7 +2986,7 @@ do_put (
curwin->w_cursor.col = len;
} else
curwin->w_cursor.lnum = lnum;
- } else {
+ } else {
/*
* Character or Line mode
*/
@@ -2997,7 +3003,7 @@ do_put (
curwin->w_cursor.col += bytelen;
curbuf->b_op_end.col += bytelen;
}
- } else {
+ } else {
++col;
if (yanklen) {
++curwin->w_cursor.col;
@@ -3051,7 +3057,7 @@ do_put (
if (totlen && (restart_edit != 0 || (flags & PUT_CURSEND)))
++curwin->w_cursor.col;
changed_bytes(lnum, col);
- } else {
+ } else {
/*
* Insert at least one line. When y_type is MCHAR, break the first
* line in two.
@@ -3153,7 +3159,7 @@ error:
/* ":put": put cursor on last inserted line */
curwin->w_cursor.lnum = lnum;
beginline(BL_WHITE | BL_FIX);
- } else if (flags & PUT_CURSEND) {
+ } else if (flags & PUT_CURSEND) {
/* put cursor after inserted text */
if (y_type == MLINE) {
if (lnum >= curbuf->b_ml.ml_line_count)
@@ -3161,11 +3167,11 @@ error:
else
curwin->w_cursor.lnum = lnum + 1;
curwin->w_cursor.col = 0;
- } else {
+ } else {
curwin->w_cursor.lnum = lnum;
curwin->w_cursor.col = col;
}
- } else if (y_type == MLINE) {
+ } else if (y_type == MLINE) {
/* put cursor on first non-blank in first inserted line */
curwin->w_cursor.col = 0;
if (dir == FORWARD)
@@ -3195,7 +3201,8 @@ end:
* When the cursor is on the NUL past the end of the line and it should not be
* there move it left.
*/
-void adjust_cursor_eol(void) {
+void adjust_cursor_eol(void)
+{
if (curwin->w_cursor.col > 0
&& gchar_cursor() == NUL
&& (ve_flags & VE_ONEMORE) == 0
@@ -3216,7 +3223,8 @@ void adjust_cursor_eol(void) {
/*
* Return TRUE if lines starting with '#' should be left aligned.
*/
-int preprocs_left(void) {
+int preprocs_left(void)
+{
return
(curbuf->b_p_si && !curbuf->b_p_cin) ||
(curbuf->b_p_cin && in_cinkeys('#', ' ', TRUE)
@@ -3555,7 +3563,7 @@ int do_join(long count, int insert_space, int save_undo, int use_formatoptions)
mb_ptr_back(curr, cend);
endcurr2 = (*mb_ptr2char)(cend);
}
- } else {
+ } else {
endcurr1 = *(curr + currsize - 1);
if (currsize > 1)
endcurr2 = *(curr + currsize - 2);
@@ -3900,7 +3908,7 @@ format_lines (
next_is_not_par = TRUE;
next_leader_len = 0;
next_leader_flags = NULL;
- } else {
+ } else {
next_is_not_par = fmt_check_par(curwin->w_cursor.lnum + 1
, &next_leader_len, &next_leader_flags, do_comments
);
@@ -3919,7 +3927,7 @@ format_lines (
if (is_not_par) {
if (line_count < 0)
break;
- } else {
+ } else {
/*
* For the first line of a paragraph, check indent of second line.
* Don't do this for comments and empty lines.
@@ -3933,16 +3941,16 @@ format_lines (
/* no comment found */
second_indent =
get_indent_lnum(curwin->w_cursor.lnum + 1);
- } else {
+ } else {
second_indent = next_leader_len;
do_comments_list = 1;
}
- } else if (do_number_indent) {
+ } else if (do_number_indent) {
if (leader_len == 0 && next_leader_len == 0) {
/* no comment found */
second_indent =
get_number_indent(curwin->w_cursor.lnum);
- } else {
+ } else {
/* get_number_indent() is now "comment aware"... */
second_indent =
get_number_indent(curwin->w_cursor.lnum);
@@ -4015,7 +4023,7 @@ format_lines (
(void)del_bytes((long)next_leader_len, FALSE, FALSE);
mark_col_adjust(curwin->w_cursor.lnum, (colnr_T)0, 0L,
(long)-next_leader_len);
- } else if (second_indent > 0) { /* the "leader" for FO_Q_SECOND */
+ } else if (second_indent > 0) { /* the "leader" for FO_Q_SECOND */
char_u *p = ml_get_curline();
int indent = (int)(skipwhite(p) - p);
@@ -4179,7 +4187,7 @@ static void block_prep(oparg_T *oap, struct block_def *bdp, linenr_T lnum, int i
if (vim_iswhite(*pstart)) {
bdp->pre_whitesp += incr;
bdp->pre_whitesp_c++;
- } else {
+ } else {
bdp->pre_whitesp = 0;
bdp->pre_whitesp_c = 0;
}
@@ -4192,7 +4200,7 @@ static void block_prep(oparg_T *oap, struct block_def *bdp, linenr_T lnum, int i
bdp->is_short = TRUE;
if (!is_del || oap->op_type == OP_APPEND)
bdp->endspaces = oap->end_vcol - oap->start_vcol + 1;
- } else {
+ } else {
/* notice: this converts partly selected Multibyte characters to
* spaces, too. */
bdp->startspaces = bdp->start_vcol - oap->start_vcol;
@@ -4207,7 +4215,7 @@ static void block_prep(oparg_T *oap, struct block_def *bdp, linenr_T lnum, int i
else if (oap->op_type == OP_APPEND) {
bdp->startspaces += oap->end_vcol - oap->start_vcol + 1;
bdp->endspaces = bdp->start_char_vcols - bdp->startspaces;
- } else {
+ } else {
bdp->startspaces = oap->end_vcol - oap->start_vcol + 1;
if (is_del && oap->op_type != OP_LSHIFT) {
/* just putting the sum of those two into
@@ -4218,7 +4226,7 @@ static void block_prep(oparg_T *oap, struct block_def *bdp, linenr_T lnum, int i
bdp->endspaces = bdp->end_vcol - oap->end_vcol - 1;
}
}
- } else {
+ } else {
prev_pend = pend;
while (bdp->end_vcol <= oap->end_vcol && *pend != NUL) {
/* Count a tab for what it's worth (if list mode not on) */
@@ -4240,7 +4248,7 @@ static void block_prep(oparg_T *oap, struct block_def *bdp, linenr_T lnum, int i
+ oap->inclusive;
else
bdp->endspaces = 0; /* replace doesn't add characters */
- } else if (bdp->end_vcol > oap->end_vcol) {
+ } else if (bdp->end_vcol > oap->end_vcol) {
bdp->endspaces = bdp->end_vcol - oap->end_vcol - 1;
if (!is_del && bdp->endspaces) {
bdp->endspaces = incr - bdp->endspaces;
@@ -4326,7 +4334,7 @@ int do_addsub(int command, linenr_T Prenum1)
* Found hexadecimal number, move to its start.
*/
--col;
- } else {
+ } else {
/*
* Search forward and then backward to find the start of number.
*/
@@ -4368,7 +4376,7 @@ int do_addsub(int command, linenr_T Prenum1)
firstdigit = 'a';
} else
firstdigit -= Prenum1;
- } else {
+ } else {
if (26 - CharOrd(firstdigit) - 1 < Prenum1) {
if (isupper(firstdigit))
firstdigit = 'Z';
@@ -4380,7 +4388,7 @@ int do_addsub(int command, linenr_T Prenum1)
curwin->w_cursor.col = col;
(void)del_char(FALSE);
ins_char(firstdigit);
- } else {
+ } else {
negative = FALSE;
if (col > 0 && ptr[col - 1] == '-') { /* negative number */
--col;
@@ -4417,7 +4425,7 @@ int do_addsub(int command, linenr_T Prenum1)
n = 1 + (n ^ (unsigned long)-1);
negative ^= TRUE;
}
- } else { /* add */
+ } else { /* add */
if (n < oldn) {
n = (n ^ (unsigned long)-1);
negative ^= TRUE;
@@ -4584,7 +4592,7 @@ int read_viminfo_register(vir_T *virp, int force)
if (size == 0) {
vim_free(array);
y_current->y_array = NULL;
- } else if (size < limit) {
+ } else if (size < limit) {
y_current->y_array =
(char_u **)alloc((unsigned)(size * sizeof(char_u *)));
for (i = 0; i < size; i++)
@@ -5035,7 +5043,8 @@ static long line_count_info(char_u *line, long *wc, long *cc, long limit, int eo
* In Visual mode, give some info about the selected region. (In this case,
* the *_count_cursor variables store running totals for the selection.)
*/
-void cursor_pos_info(void) {
+void cursor_pos_info(void)
+{
char_u *p;
char_u buf1[50];
char_u buf2[40];
@@ -5058,7 +5067,7 @@ void cursor_pos_info(void) {
*/
if (curbuf->b_ml.ml_flags & ML_EMPTY) {
MSG(_(no_lines_msg));
- } else {
+ } else {
if (get_fileformat(curbuf) == EOL_DOS)
eol_size = 2;
else
@@ -5068,7 +5077,7 @@ void cursor_pos_info(void) {
if (lt(VIsual, curwin->w_cursor)) {
min_pos = VIsual;
max_pos = curwin->w_cursor;
- } else {
+ } else {
min_pos = curwin->w_cursor;
max_pos = VIsual;
}
@@ -5146,7 +5155,7 @@ void cursor_pos_info(void) {
&& (long)STRLEN(s) < len)
byte_count_cursor -= eol_size;
}
- } else {
+ } else {
/* In non-visual mode, check for the line the cursor is on */
if (lnum == curwin->w_cursor.lnum) {
word_count_cursor += word_count;
@@ -5192,7 +5201,7 @@ void cursor_pos_info(void) {
word_count_cursor, word_count,
char_count_cursor, char_count,
byte_count_cursor, byte_count);
- } else {
+ } else {
p = ml_get_curline();
validate_virtcol();
col_print(buf1, sizeof(buf1), (int)curwin->w_cursor.col + 1,