vim-patch:8.1.2045: the option.c file is too big (#19854)

Problem:    The option.c file is too big.
Solution:   Split off the code dealing with strings. (Yegappan Lakshmanan,
            closes vim/vim#4937)
dac1347b4d

Cherry-pick set_string_option_direct_in_win() from patch 8.1.1405.
Cherry-pick shift_line() comment change from patch 8.1.2096.
Move 'clipboard' default parsing to didset_string_options().
Reorder option flags to put Nvim-only flags at the end.
This commit is contained in:
zeertzjq
2022-08-20 17:26:44 +08:00
committed by GitHub
parent 1cc4706e94
commit ff5cfcdeab
26 changed files with 1933 additions and 1865 deletions

View File

@@ -288,13 +288,13 @@ void shift_line(int left, int round, int amount, int call_changed_bytes)
{
int count;
int i, j;
int p_sw = (int)get_sw_value_indent(curbuf);
const int sw_val = (int)get_sw_value_indent(curbuf);
count = get_indent(); // get current indent
if (round) { // round off indent
i = count / p_sw; // number of p_sw rounded down
j = count % p_sw; // extra spaces
i = count / sw_val; // number of 'shiftwidth' rounded down
j = count % sw_val; // extra spaces
if (j && left) { // first remove extra spaces
amount--;
}
@@ -306,15 +306,15 @@ void shift_line(int left, int round, int amount, int call_changed_bytes)
} else {
i += amount;
}
count = i * p_sw;
count = i * sw_val;
} else { // original vi indent
if (left) {
count -= p_sw * amount;
count -= sw_val * amount;
if (count < 0) {
count = 0;
}
} else {
count += p_sw * amount;
count += sw_val * amount;
}
}
@@ -334,9 +334,8 @@ static void shift_block(oparg_T *oap, int amount)
const int oldstate = State;
char_u *newp;
const int oldcol = curwin->w_cursor.col;
int p_sw = (int)get_sw_value_indent(curbuf);
long *p_vts = curbuf->b_p_vts_array;
const long p_ts = curbuf->b_p_ts;
const int sw_val = (int)get_sw_value_indent(curbuf);
const int ts_val = (int)curbuf->b_p_ts;
struct block_def bd;
int incr;
int i = 0, j = 0;
@@ -351,8 +350,8 @@ static void shift_block(oparg_T *oap, int amount)
}
// total is number of screen columns to be inserted/removed
int total = (int)((unsigned)amount * (unsigned)p_sw);
if ((total / p_sw) != amount) {
int total = (int)((unsigned)amount * (unsigned)sw_val);
if ((total / sw_val) != amount) {
return; // multiplication overflow
}
@@ -387,7 +386,7 @@ static void shift_block(oparg_T *oap, int amount)
// OK, now total=all the VWS reqd, and textstart points at the 1st
// non-ws char in the block.
if (!curbuf->b_p_et) {
tabstop_fromto(ws_vcol, ws_vcol + total, p_ts, p_vts, &i, &j);
tabstop_fromto(ws_vcol, ws_vcol + total, ts_val, curbuf->b_p_vts_array, &i, &j);
} else {
j = total;
}
@@ -511,7 +510,7 @@ static void shift_block(oparg_T *oap, int amount)
/// Caller must prepare for undo.
static void block_insert(oparg_T *oap, char_u *s, int b_insert, struct block_def *bdp)
{
int p_ts;
int ts_val;
int count = 0; // extra spaces to replace a cut TAB
int spaces = 0; // non-zero if cutting a TAB
colnr_T offset; // pointer along new line
@@ -530,18 +529,18 @@ static void block_insert(oparg_T *oap, char_u *s, int b_insert, struct block_def
oldp = ml_get(lnum);
if (b_insert) {
p_ts = bdp->start_char_vcols;
ts_val = bdp->start_char_vcols;
spaces = bdp->startspaces;
if (spaces != 0) {
count = p_ts - 1; // we're cutting a TAB
count = ts_val - 1; // we're cutting a TAB
}
offset = bdp->textcol;
} else { // append
p_ts = bdp->end_char_vcols;
ts_val = bdp->end_char_vcols;
if (!bdp->is_short) { // spaces = padding after block
spaces = (bdp->endspaces ? p_ts - bdp->endspaces : 0);
spaces = (bdp->endspaces ? ts_val - bdp->endspaces : 0);
if (spaces != 0) {
count = p_ts - 1; // we're cutting a TAB
count = ts_val - 1; // we're cutting a TAB
}
offset = bdp->textcol + bdp->textlen - (spaces != 0);
} else { // spaces = padding to block edge
@@ -565,7 +564,7 @@ static void block_insert(oparg_T *oap, char_u *s, int b_insert, struct block_def
assert(count >= 0);
// Make sure the allocated size matches what is actually copied below.
newp = xmalloc(STRLEN(oldp) + (size_t)spaces + s_len
+ (spaces > 0 && !bdp->is_short ? (size_t)p_ts - (size_t)spaces : 0)
+ (spaces > 0 && !bdp->is_short ? (size_t)ts_val - (size_t)spaces : 0)
+ (size_t)count + 1);
// copy up to shifted part
@@ -584,7 +583,7 @@ static void block_insert(oparg_T *oap, char_u *s, int b_insert, struct block_def
if (spaces > 0 && !bdp->is_short) {
if (*oldp == TAB) {
// insert post-padding
memset(newp + offset + spaces, ' ', (size_t)(p_ts - spaces));
memset(newp + offset + spaces, ' ', (size_t)(ts_val - spaces));
// We're splitting a TAB, don't copy it.
oldp++;
// We allowed for that TAB, remember this now