forked from aniani/vim
patch 8.1.0226: too many #ifdefs
Problem: Too many #ifdefs. Solution: Graduate the +vreplace feature, it's not much code and quite a few #ifdefs.
This commit is contained in:
87
src/edit.c
87
src/edit.c
@@ -463,7 +463,6 @@ edit(
|
||||
{
|
||||
ResetRedobuff();
|
||||
AppendNumberToRedobuff(count);
|
||||
#ifdef FEAT_VREPLACE
|
||||
if (cmdchar == 'V' || cmdchar == 'v')
|
||||
{
|
||||
/* "gR" or "gr" command */
|
||||
@@ -471,7 +470,6 @@ edit(
|
||||
AppendCharToRedobuff((cmdchar == 'v') ? 'r' : 'R');
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
if (cmdchar == K_PS)
|
||||
AppendCharToRedobuff('a');
|
||||
@@ -497,7 +495,6 @@ edit(
|
||||
#endif
|
||||
State = REPLACE;
|
||||
}
|
||||
#ifdef FEAT_VREPLACE
|
||||
else if (cmdchar == 'V' || cmdchar == 'v')
|
||||
{
|
||||
State = VREPLACE;
|
||||
@@ -505,7 +502,6 @@ edit(
|
||||
orig_line_count = curbuf->b_ml.ml_line_count;
|
||||
vr_lines_changed = 1;
|
||||
}
|
||||
#endif
|
||||
else
|
||||
State = INSERT;
|
||||
|
||||
@@ -2042,7 +2038,6 @@ change_indent(
|
||||
int save_p_list;
|
||||
int start_col;
|
||||
colnr_T vc;
|
||||
#ifdef FEAT_VREPLACE
|
||||
colnr_T orig_col = 0; /* init for GCC */
|
||||
char_u *new_line, *orig_line = NULL; /* init for GCC */
|
||||
|
||||
@@ -2052,7 +2047,6 @@ change_indent(
|
||||
orig_line = vim_strsave(ml_get_curline()); /* Deal with NULL below */
|
||||
orig_col = curwin->w_cursor.col;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* for the following tricks we don't want list mode */
|
||||
save_p_list = curwin->w_p_list;
|
||||
@@ -2091,17 +2085,13 @@ change_indent(
|
||||
(void)set_indent(amount, call_changed_bytes ? SIN_CHANGED : 0);
|
||||
else
|
||||
{
|
||||
#ifdef FEAT_VREPLACE
|
||||
int save_State = State;
|
||||
|
||||
/* Avoid being called recursively. */
|
||||
if (State & VREPLACE_FLAG)
|
||||
State = INSERT;
|
||||
#endif
|
||||
shift_line(type == INDENT_DEC, round, 1, call_changed_bytes);
|
||||
#ifdef FEAT_VREPLACE
|
||||
State = save_State;
|
||||
#endif
|
||||
}
|
||||
insstart_less -= curwin->w_cursor.col;
|
||||
|
||||
@@ -2233,7 +2223,6 @@ change_indent(
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef FEAT_VREPLACE
|
||||
/*
|
||||
* For VREPLACE mode, we also have to fix the replace stack. In this case
|
||||
* it is always possible because we backspace over the whole line and then
|
||||
@@ -2266,7 +2255,6 @@ change_indent(
|
||||
|
||||
vim_free(new_line);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -2288,8 +2276,6 @@ truncate_spaces(char_u *line)
|
||||
line[i + 1] = NUL;
|
||||
}
|
||||
|
||||
#if defined(FEAT_VREPLACE) || defined(FEAT_INS_EXPAND) \
|
||||
|| defined(FEAT_COMMENTS) || defined(PROTO)
|
||||
/*
|
||||
* Backspace the cursor until the given column. Handles REPLACE and VREPLACE
|
||||
* modes correctly. May also be used when not in insert mode at all.
|
||||
@@ -2308,7 +2294,6 @@ backspace_until_column(int col)
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Like del_char(), but make sure not to go before column "limit_col".
|
||||
@@ -6224,9 +6209,7 @@ insertchar(
|
||||
&& (force_format
|
||||
|| (!VIM_ISWHITE(c)
|
||||
&& !((State & REPLACE_FLAG)
|
||||
#ifdef FEAT_VREPLACE
|
||||
&& !(State & VREPLACE_FLAG)
|
||||
#endif
|
||||
&& *ml_get_cursor() != NUL)
|
||||
&& (curwin->w_cursor.lnum != Insstart.lnum
|
||||
|| ((!has_format_option(FO_INS_LONG)
|
||||
@@ -6471,11 +6454,7 @@ internal_format(
|
||||
* When 'ai' is off we don't want a space under the cursor to be
|
||||
* deleted. Replace it with an 'x' temporarily.
|
||||
*/
|
||||
if (!curbuf->b_p_ai
|
||||
#ifdef FEAT_VREPLACE
|
||||
&& !(State & VREPLACE_FLAG)
|
||||
#endif
|
||||
)
|
||||
if (!curbuf->b_p_ai && !(State & VREPLACE_FLAG))
|
||||
{
|
||||
cc = gchar_cursor();
|
||||
if (VIM_ISWHITE(cc))
|
||||
@@ -6496,10 +6475,8 @@ internal_format(
|
||||
int end_foundcol = 0; /* column for start of word */
|
||||
colnr_T len;
|
||||
colnr_T virtcol;
|
||||
#ifdef FEAT_VREPLACE
|
||||
int orig_col = 0;
|
||||
char_u *saved_text = NULL;
|
||||
#endif
|
||||
colnr_T col;
|
||||
colnr_T end_col;
|
||||
|
||||
@@ -6669,11 +6646,9 @@ internal_format(
|
||||
* stack functions. VREPLACE does not use this, and backspaces
|
||||
* over the text instead.
|
||||
*/
|
||||
#ifdef FEAT_VREPLACE
|
||||
if (State & VREPLACE_FLAG)
|
||||
orig_col = startcol; /* Will start backspacing from here */
|
||||
else
|
||||
#endif
|
||||
replace_offset = startcol - end_foundcol;
|
||||
|
||||
/*
|
||||
@@ -6688,7 +6663,6 @@ internal_format(
|
||||
if (startcol < 0)
|
||||
startcol = 0;
|
||||
|
||||
#ifdef FEAT_VREPLACE
|
||||
if (State & VREPLACE_FLAG)
|
||||
{
|
||||
/*
|
||||
@@ -6706,7 +6680,6 @@ internal_format(
|
||||
backspace_until_column(foundcol);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
/* put cursor after pos. to break line */
|
||||
if (!fo_white_par)
|
||||
@@ -6744,12 +6717,10 @@ internal_format(
|
||||
get_number_indent(curwin->w_cursor.lnum - 1);
|
||||
if (second_indent >= 0)
|
||||
{
|
||||
#ifdef FEAT_VREPLACE
|
||||
if (State & VREPLACE_FLAG)
|
||||
change_indent(INDENT_SET, second_indent,
|
||||
FALSE, NUL, TRUE);
|
||||
else
|
||||
#endif
|
||||
#ifdef FEAT_COMMENTS
|
||||
if (leader_len > 0 && second_indent - leader_len > 0)
|
||||
{
|
||||
@@ -6778,7 +6749,6 @@ internal_format(
|
||||
first_line = FALSE;
|
||||
}
|
||||
|
||||
#ifdef FEAT_VREPLACE
|
||||
if (State & VREPLACE_FLAG)
|
||||
{
|
||||
/*
|
||||
@@ -6789,7 +6759,6 @@ internal_format(
|
||||
vim_free(saved_text);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
/*
|
||||
* Check if cursor is not past the NUL off the line, cindent
|
||||
@@ -7140,13 +7109,11 @@ stop_arrow(void)
|
||||
}
|
||||
|
||||
ai_col = 0;
|
||||
#ifdef FEAT_VREPLACE
|
||||
if (State & VREPLACE_FLAG)
|
||||
{
|
||||
orig_line_count = curbuf->b_ml.ml_line_count;
|
||||
vr_lines_changed = 1;
|
||||
}
|
||||
#endif
|
||||
ResetRedobuff();
|
||||
AppendToRedobuff((char_u *)"1i"); /* pretend we start an insertion */
|
||||
new_insert_skip = 2;
|
||||
@@ -7983,7 +7950,6 @@ replace_flush(void)
|
||||
replace_do_bs(int limit_col)
|
||||
{
|
||||
int cc;
|
||||
#ifdef FEAT_VREPLACE
|
||||
int orig_len = 0;
|
||||
int ins_len;
|
||||
int orig_vcols = 0;
|
||||
@@ -7991,12 +7957,10 @@ replace_do_bs(int limit_col)
|
||||
char_u *p;
|
||||
int i;
|
||||
int vcol;
|
||||
#endif
|
||||
|
||||
cc = replace_pop();
|
||||
if (cc > 0)
|
||||
{
|
||||
#ifdef FEAT_VREPLACE
|
||||
if (State & VREPLACE_FLAG)
|
||||
{
|
||||
/* Get the number of screen cells used by the character we are
|
||||
@@ -8004,29 +7968,23 @@ replace_do_bs(int limit_col)
|
||||
getvcol(curwin, &curwin->w_cursor, NULL, &start_vcol, NULL);
|
||||
orig_vcols = chartabsize(ml_get_cursor(), start_vcol);
|
||||
}
|
||||
#endif
|
||||
#ifdef FEAT_MBYTE
|
||||
if (has_mbyte)
|
||||
{
|
||||
(void)del_char_after_col(limit_col);
|
||||
# ifdef FEAT_VREPLACE
|
||||
if (State & VREPLACE_FLAG)
|
||||
orig_len = (int)STRLEN(ml_get_cursor());
|
||||
# endif
|
||||
replace_push(cc);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
pchar_cursor(cc);
|
||||
#ifdef FEAT_VREPLACE
|
||||
if (State & VREPLACE_FLAG)
|
||||
orig_len = (int)STRLEN(ml_get_cursor()) - 1;
|
||||
#endif
|
||||
}
|
||||
replace_pop_ins();
|
||||
|
||||
#ifdef FEAT_VREPLACE
|
||||
if (State & VREPLACE_FLAG)
|
||||
{
|
||||
/* Get the number of screen cells used by the inserted characters */
|
||||
@@ -8052,7 +8010,6 @@ replace_do_bs(int limit_col)
|
||||
}
|
||||
curwin->w_cursor.col -= ins_len;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* mark the buffer as changed and prepare for displaying */
|
||||
changed_bytes(curwin->w_cursor.lnum, curwin->w_cursor.col);
|
||||
@@ -8966,11 +8923,9 @@ ins_insert(int replaceState)
|
||||
|
||||
# ifdef FEAT_EVAL
|
||||
set_vim_var_string(VV_INSERTMODE,
|
||||
(char_u *)((State & REPLACE_FLAG) ? "i" :
|
||||
# ifdef FEAT_VREPLACE
|
||||
replaceState == VREPLACE ? "v" :
|
||||
# endif
|
||||
"r"), 1);
|
||||
(char_u *)((State & REPLACE_FLAG) ? "i"
|
||||
: replaceState == VREPLACE ? "v"
|
||||
: "r"), 1);
|
||||
# endif
|
||||
apply_autocmds(EVENT_INSERTCHANGE, NULL, NULL, FALSE, curbuf);
|
||||
if (State & REPLACE_FLAG)
|
||||
@@ -8990,11 +8945,9 @@ ins_insert(int replaceState)
|
||||
static void
|
||||
ins_ctrl_o(void)
|
||||
{
|
||||
#ifdef FEAT_VREPLACE
|
||||
if (State & VREPLACE_FLAG)
|
||||
restart_edit = 'V';
|
||||
else
|
||||
#endif
|
||||
if (State & REPLACE_FLAG)
|
||||
restart_edit = 'R';
|
||||
else
|
||||
@@ -9067,14 +9020,12 @@ ins_del(void)
|
||||
else
|
||||
{
|
||||
curwin->w_cursor.col = temp;
|
||||
#ifdef FEAT_VREPLACE
|
||||
/* Adjust orig_line_count in case more lines have been deleted than
|
||||
* have been added. That makes sure, that open_line() later
|
||||
* can access all buffer lines correctly */
|
||||
if (State & VREPLACE_FLAG &&
|
||||
orig_line_count > curbuf->b_ml.ml_line_count)
|
||||
orig_line_count = curbuf->b_ml.ml_line_count;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else if (del_char(FALSE) == FAIL) /* delete char under cursor */
|
||||
@@ -9229,10 +9180,8 @@ ins_bs(
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef FEAT_VREPLACE
|
||||
if (!(State & VREPLACE_FLAG)
|
||||
|| curwin->w_cursor.lnum > orig_line_count)
|
||||
#endif
|
||||
{
|
||||
temp = gchar_cursor(); /* remember current char */
|
||||
--curwin->w_cursor.lnum;
|
||||
@@ -9256,10 +9205,8 @@ ins_bs(
|
||||
if (temp == NUL && gchar_cursor() != NUL)
|
||||
inc_cursor();
|
||||
}
|
||||
#ifdef FEAT_VREPLACE
|
||||
else
|
||||
dec_cursor();
|
||||
#endif
|
||||
|
||||
/*
|
||||
* In REPLACE mode we have to put back the text that was replaced
|
||||
@@ -9386,11 +9333,9 @@ ins_bs(
|
||||
&& curwin->w_cursor.col < Insstart_orig.col)
|
||||
Insstart_orig.col = curwin->w_cursor.col;
|
||||
|
||||
#ifdef FEAT_VREPLACE
|
||||
if (State & VREPLACE_FLAG)
|
||||
ins_char(' ');
|
||||
else
|
||||
#endif
|
||||
{
|
||||
ins_str((char_u *)" ");
|
||||
if ((State & REPLACE_FLAG))
|
||||
@@ -10231,11 +10176,9 @@ ins_tab(void)
|
||||
ins_char(' ');
|
||||
while (--temp > 0)
|
||||
{
|
||||
#ifdef FEAT_VREPLACE
|
||||
if (State & VREPLACE_FLAG)
|
||||
ins_char(' ');
|
||||
else
|
||||
#endif
|
||||
{
|
||||
ins_str((char_u *)" ");
|
||||
if (State & REPLACE_FLAG) /* no char replaced */
|
||||
@@ -10255,10 +10198,8 @@ ins_tab(void)
|
||||
#endif
|
||||
{
|
||||
char_u *ptr;
|
||||
#ifdef FEAT_VREPLACE
|
||||
char_u *saved_line = NULL; /* init for GCC */
|
||||
pos_T pos;
|
||||
#endif
|
||||
pos_T fpos;
|
||||
pos_T *cursor;
|
||||
colnr_T want_vcol, vcol;
|
||||
@@ -10269,7 +10210,6 @@ ins_tab(void)
|
||||
* Get the current line. For VREPLACE mode, don't make real changes
|
||||
* yet, just work on a copy of the line.
|
||||
*/
|
||||
#ifdef FEAT_VREPLACE
|
||||
if (State & VREPLACE_FLAG)
|
||||
{
|
||||
pos = curwin->w_cursor;
|
||||
@@ -10280,7 +10220,6 @@ ins_tab(void)
|
||||
ptr = saved_line + pos.col;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
ptr = ml_get_cursor();
|
||||
cursor = &curwin->w_cursor;
|
||||
@@ -10360,11 +10299,7 @@ ins_tab(void)
|
||||
{
|
||||
STRMOVE(ptr, ptr + i);
|
||||
/* correct replace stack. */
|
||||
if ((State & REPLACE_FLAG)
|
||||
#ifdef FEAT_VREPLACE
|
||||
&& !(State & VREPLACE_FLAG)
|
||||
#endif
|
||||
)
|
||||
if ((State & REPLACE_FLAG) && !(State & VREPLACE_FLAG))
|
||||
for (temp = i; --temp >= 0; )
|
||||
replace_join(repl_off);
|
||||
}
|
||||
@@ -10378,7 +10313,6 @@ ins_tab(void)
|
||||
#endif
|
||||
cursor->col -= i;
|
||||
|
||||
#ifdef FEAT_VREPLACE
|
||||
/*
|
||||
* In VREPLACE mode, we haven't changed anything yet. Do it now by
|
||||
* backspacing over the changed spacing and then inserting the new
|
||||
@@ -10394,13 +10328,10 @@ ins_tab(void)
|
||||
ins_bytes_len(saved_line + change_col,
|
||||
cursor->col - change_col);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef FEAT_VREPLACE
|
||||
if (State & VREPLACE_FLAG)
|
||||
vim_free(saved_line);
|
||||
#endif
|
||||
curwin->w_p_list = save_list;
|
||||
}
|
||||
|
||||
@@ -10427,11 +10358,7 @@ ins_eol(int c)
|
||||
* character under the cursor. Only push a NUL on the replace stack,
|
||||
* nothing to put back when the NL is deleted.
|
||||
*/
|
||||
if ((State & REPLACE_FLAG)
|
||||
#ifdef FEAT_VREPLACE
|
||||
&& !(State & VREPLACE_FLAG)
|
||||
#endif
|
||||
)
|
||||
if ((State & REPLACE_FLAG) && !(State & VREPLACE_FLAG))
|
||||
replace_push(NUL);
|
||||
|
||||
/*
|
||||
@@ -10700,11 +10627,9 @@ ins_try_si(int c)
|
||||
curwin->w_cursor = *pos;
|
||||
i = get_indent();
|
||||
curwin->w_cursor = old_pos;
|
||||
#ifdef FEAT_VREPLACE
|
||||
if (State & VREPLACE_FLAG)
|
||||
change_indent(INDENT_SET, i, FALSE, NUL, TRUE);
|
||||
else
|
||||
#endif
|
||||
(void)set_indent(i, SIN_CHANGED);
|
||||
}
|
||||
else if (curwin->w_cursor.col > 0)
|
||||
|
Reference in New Issue
Block a user