mirror of
https://github.com/neovim/neovim.git
synced 2025-09-29 06:28:35 +00:00
refactor(options): autogenerate valid values and flag enums for options (#31089)
Problem: Option metadata like list of valid values for an option and option flags are not listed in the `options.lua` file and are instead manually defined in C, which means option metadata is split between several places. Solution: Put metadata such as list of valid values for an option and option flags in `options.lua`, and autogenerate the corresponding C variables and enums. Supersedes #28659 Co-authored-by: glepnir <glephunter@gmail.com>
This commit is contained in:
@@ -2187,7 +2187,7 @@ void op_insert(oparg_T *oap, int count1)
|
||||
if (u_save_cursor() == FAIL) {
|
||||
return;
|
||||
}
|
||||
curwin->w_ve_flags = VE_ALL;
|
||||
curwin->w_ve_flags = kOptVeFlagAll;
|
||||
coladvance_force(oap->op_type == OP_APPEND
|
||||
? oap->end_vcol + 1 : getviscol());
|
||||
if (oap->op_type == OP_APPEND) {
|
||||
@@ -2873,7 +2873,7 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags)
|
||||
eol = (*(cursor_pos + utfc_ptr2len(cursor_pos)) == NUL);
|
||||
}
|
||||
|
||||
bool ve_allows = (cur_ve_flags == VE_ALL || cur_ve_flags == VE_ONEMORE);
|
||||
bool ve_allows = (cur_ve_flags == kOptVeFlagAll || cur_ve_flags == kOptVeFlagOnemore);
|
||||
bool eof = curbuf->b_ml.ml_line_count == curwin->w_cursor.lnum
|
||||
&& one_past_line;
|
||||
if (ve_allows || !(eol || eof)) {
|
||||
@@ -3057,7 +3057,7 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags)
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (cur_ve_flags == VE_ALL && y_type == kMTCharWise) {
|
||||
if (cur_ve_flags == kOptVeFlagAll && y_type == kMTCharWise) {
|
||||
if (gchar_cursor() == TAB) {
|
||||
int viscol = getviscol();
|
||||
OptInt ts = curbuf->b_p_ts;
|
||||
@@ -3086,7 +3086,7 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags)
|
||||
colnr_T endcol2 = 0;
|
||||
|
||||
if (dir == FORWARD && c != NUL) {
|
||||
if (cur_ve_flags == VE_ALL) {
|
||||
if (cur_ve_flags == kOptVeFlagAll) {
|
||||
getvcol(curwin, &curwin->w_cursor, &col, NULL, &endcol2);
|
||||
} else {
|
||||
getvcol(curwin, &curwin->w_cursor, NULL, NULL, &col);
|
||||
@@ -3100,7 +3100,7 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags)
|
||||
}
|
||||
|
||||
col += curwin->w_cursor.coladd;
|
||||
if (cur_ve_flags == VE_ALL
|
||||
if (cur_ve_flags == kOptVeFlagAll
|
||||
&& (curwin->w_cursor.coladd > 0 || endcol2 == curwin->w_cursor.col)) {
|
||||
if (dir == FORWARD && c == NUL) {
|
||||
col++;
|
||||
@@ -3560,7 +3560,7 @@ error:
|
||||
// Make sure the cursor is not after the NUL.
|
||||
int len = get_cursor_line_len();
|
||||
if (curwin->w_cursor.col > len) {
|
||||
if (cur_ve_flags == VE_ALL) {
|
||||
if (cur_ve_flags == kOptVeFlagAll) {
|
||||
curwin->w_cursor.coladd = curwin->w_cursor.col - len;
|
||||
}
|
||||
curwin->w_cursor.col = len;
|
||||
@@ -3592,7 +3592,7 @@ void adjust_cursor_eol(void)
|
||||
|
||||
const bool adj_cursor = (curwin->w_cursor.col > 0
|
||||
&& gchar_cursor() == NUL
|
||||
&& (cur_ve_flags & VE_ONEMORE) == 0
|
||||
&& (cur_ve_flags & kOptVeFlagOnemore) == 0
|
||||
&& !(restart_edit || (State & MODE_INSERT)));
|
||||
if (!adj_cursor) {
|
||||
return;
|
||||
@@ -3601,7 +3601,7 @@ void adjust_cursor_eol(void)
|
||||
// Put the cursor on the last character in the line.
|
||||
dec_cursor();
|
||||
|
||||
if (cur_ve_flags == VE_ALL) {
|
||||
if (cur_ve_flags == kOptVeFlagAll) {
|
||||
colnr_T scol, ecol;
|
||||
|
||||
// Coladd is set to the width of the last character.
|
||||
@@ -6076,7 +6076,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
|
||||
case OP_DELETE:
|
||||
VIsual_reselect = false; // don't reselect now
|
||||
if (empty_region_error) {
|
||||
vim_beep(BO_OPER);
|
||||
vim_beep(kOptBoFlagOperator);
|
||||
CancelRedo();
|
||||
} else {
|
||||
op_delete(oap);
|
||||
@@ -6092,7 +6092,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
|
||||
case OP_YANK:
|
||||
if (empty_region_error) {
|
||||
if (!gui_yank) {
|
||||
vim_beep(BO_OPER);
|
||||
vim_beep(kOptBoFlagOperator);
|
||||
CancelRedo();
|
||||
}
|
||||
} else {
|
||||
@@ -6106,7 +6106,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
|
||||
case OP_CHANGE:
|
||||
VIsual_reselect = false; // don't reselect now
|
||||
if (empty_region_error) {
|
||||
vim_beep(BO_OPER);
|
||||
vim_beep(kOptBoFlagOperator);
|
||||
CancelRedo();
|
||||
} else {
|
||||
// This is a new edit command, not a restart. Need to
|
||||
@@ -6169,7 +6169,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
|
||||
case OP_LOWER:
|
||||
case OP_ROT13:
|
||||
if (empty_region_error) {
|
||||
vim_beep(BO_OPER);
|
||||
vim_beep(kOptBoFlagOperator);
|
||||
CancelRedo();
|
||||
} else {
|
||||
op_tilde(oap);
|
||||
@@ -6211,7 +6211,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
|
||||
case OP_APPEND:
|
||||
VIsual_reselect = false; // don't reselect now
|
||||
if (empty_region_error) {
|
||||
vim_beep(BO_OPER);
|
||||
vim_beep(kOptBoFlagOperator);
|
||||
CancelRedo();
|
||||
} else {
|
||||
// This is a new edit command, not a restart. Need to
|
||||
@@ -6246,7 +6246,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
|
||||
case OP_REPLACE:
|
||||
VIsual_reselect = false; // don't reselect now
|
||||
if (empty_region_error) {
|
||||
vim_beep(BO_OPER);
|
||||
vim_beep(kOptBoFlagOperator);
|
||||
CancelRedo();
|
||||
} else {
|
||||
// Restore linebreak, so that when the user edits it looks as before.
|
||||
@@ -6284,7 +6284,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
|
||||
case OP_NR_ADD:
|
||||
case OP_NR_SUB:
|
||||
if (empty_region_error) {
|
||||
vim_beep(BO_OPER);
|
||||
vim_beep(kOptBoFlagOperator);
|
||||
CancelRedo();
|
||||
} else {
|
||||
VIsual_active = true;
|
||||
@@ -6344,7 +6344,7 @@ static yankreg_T *adjust_clipboard_name(int *name, bool quiet, bool writing)
|
||||
|
||||
yankreg_T *target = NULL;
|
||||
bool explicit_cb_reg = (*name == '*' || *name == '+');
|
||||
bool implicit_cb_reg = (*name == NUL) && (cb_flags & CB_UNNAMEDMASK);
|
||||
bool implicit_cb_reg = (*name == NUL) && (cb_flags & (kOptCbFlagUnnamed | kOptCbFlagUnnamedplus));
|
||||
if (!explicit_cb_reg && !implicit_cb_reg) {
|
||||
goto end;
|
||||
}
|
||||
@@ -6363,7 +6363,7 @@ static yankreg_T *adjust_clipboard_name(int *name, bool quiet, bool writing)
|
||||
|
||||
if (explicit_cb_reg) {
|
||||
target = &y_regs[*name == '*' ? STAR_REGISTER : PLUS_REGISTER];
|
||||
if (writing && (cb_flags & (*name == '*' ? CB_UNNAMED : CB_UNNAMEDPLUS))) {
|
||||
if (writing && (cb_flags & (*name == '*' ? kOptCbFlagUnnamed : kOptCbFlagUnnamedplus))) {
|
||||
clipboard_needs_update = false;
|
||||
}
|
||||
goto end;
|
||||
@@ -6377,8 +6377,8 @@ static yankreg_T *adjust_clipboard_name(int *name, bool quiet, bool writing)
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (cb_flags & CB_UNNAMEDPLUS) {
|
||||
*name = (cb_flags & CB_UNNAMED && writing) ? '"' : '+';
|
||||
if (cb_flags & kOptCbFlagUnnamedplus) {
|
||||
*name = (cb_flags & kOptCbFlagUnnamed && writing) ? '"' : '+';
|
||||
target = &y_regs[PLUS_REGISTER];
|
||||
} else {
|
||||
*name = '*';
|
||||
|
Reference in New Issue
Block a user