Commit 6cc15ccc authored by Björn Linse's avatar Björn Linse

normal: convert MCHAR etc operator and register types to enum MotionType

parent 3dc8cdc1
......@@ -10290,7 +10290,7 @@ static void f_getregtype(typval_T *argvars, typval_T *rettv)
colnr_T reglen = 0;
char buf[NUMBUFLEN + 2];
char_u reg_type = get_reg_type(regname, &reglen);
MotionType reg_type = get_reg_type(regname, &reglen);
format_reg_type(reg_type, reglen, buf, ARRAY_SIZE(buf));
rettv->v_type = VAR_STRING;
......@@ -14717,11 +14717,11 @@ static void f_setreg(typval_T *argvars, typval_T *rettv)
char_u *strregname;
char_u *stropt;
bool append = false;
char_u yank_type;
MotionType yank_type;
long block_len;
block_len = -1;
yank_type = MAUTO;
yank_type = kMTUnknown;
strregname = get_tv_string_chk(argvars);
rettv->vval.v_number = 1; /* FAIL is default */
......@@ -14738,17 +14738,17 @@ static void f_setreg(typval_T *argvars, typval_T *rettv)
return; /* type error */
for (; *stropt != NUL; ++stropt)
switch (*stropt) {
case 'a': case 'A': /* append */
case 'a': case 'A': // append
append = true;
break;
case 'v': case 'c': /* character-wise selection */
yank_type = MCHAR;
case 'v': case 'c': // character-wise selection
yank_type = kMTCharWise;
break;
case 'V': case 'l': /* line-wise selection */
yank_type = MLINE;
case 'V': case 'l': // line-wise selection
yank_type = kMTLineWise;
break;
case 'b': case Ctrl_V: /* block-wise selection */
yank_type = MBLOCK;
case 'b': case Ctrl_V: // block-wise selection
yank_type = kMTBlockWise;
if (ascii_isdigit(stropt[1])) {
++stropt;
block_len = getdigits_long(&stropt) - 1;
......
......@@ -7071,9 +7071,9 @@ static void ex_operators(exarg_T *eap)
oa.start.lnum = eap->line1;
oa.end.lnum = eap->line2;
oa.line_count = eap->line2 - eap->line1 + 1;
oa.motion_type = MLINE;
virtual_op = FALSE;
if (eap->cmdidx != CMD_yank) { /* position cursor for undo */
oa.motion_type = kMTLineWise;
virtual_op = false;
if (eap->cmdidx != CMD_yank) { // position cursor for undo
setpcmark();
curwin->w_cursor.lnum = eap->line1;
beginline(BL_SOL | BL_FIX);
......
This diff is collapsed.
......@@ -10,18 +10,29 @@
#define FIND_STRING 2 /* find any string (WORD) */
#define FIND_EVAL 4 /* include "->", "[]" and "." */
/// Motion types, used for operators and for yank/delete registers.
///
/// The three valid numerical values must not be changed, as they
/// are used in external communication and serialization.
typedef enum {
kMTCharWise = 0, ///< character-wise movement/register
kMTLineWise = 1, ///< line-wise movement/register
kMTBlockWise = 2, ///< block-wise movement/register
kMTUnknown = -1 ///< Unknown or invalid motion type
} MotionType;
/*
* Arguments for operators.
*/
typedef struct oparg_S {
int op_type; // current pending operator type
int regname; // register to use for the operator
int motion_type; // type of the current cursor motion
MotionType motion_type; // type of the current cursor motion
int motion_force; // force motion type: 'v', 'V' or CTRL-V
bool use_reg_one; // true if delete uses reg 1 even when not
// linewise
bool inclusive; // true if char motion is inclusive (only
// valid when motion_type is MCHAR)
// valid when motion_type is kMTCharWise)
bool end_adjusted; // backuped b_op_end one char (only used by
// do_format())
pos_T start; // start of the operator
......
This diff is collapsed.
......@@ -78,10 +78,10 @@ enum GRegFlags {
/// Definition of one register
typedef struct yankreg {
char_u **y_array; ///< Pointer to an array of line pointers.
linenr_T y_size; ///< Number of lines in y_array.
char_u y_type; ///< Register type: MLINE, MCHAR or MBLOCK.
colnr_T y_width; ///< Register width (only valid for y_type == MBLOCK).
char_u **y_array; ///< Pointer to an array of line pointers.
linenr_T y_size; ///< Number of lines in y_array.
MotionType y_type; ///< Register type
colnr_T y_width; ///< Register width (only valid for y_type == kBlockWise).
Timestamp timestamp; ///< Time when register was last modified.
dict_T *additional_data; ///< Additional data from ShaDa file.
} yankreg_T;
......
......@@ -1647,8 +1647,9 @@ pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int64_t maxtravel)
/*
* Look for matching #if, #else, #elif, or #endif
*/
if (oap != NULL)
oap->motion_type = MLINE; /* Linewise for this case only */
if (oap != NULL) {
oap->motion_type = kMTLineWise; // Linewise for this case only
}
if (initc != '#') {
ptr = skipwhite(skipwhite(linep) + 1);
if (STRNCMP(ptr, "if", 2) == 0 || STRNCMP(ptr, "el", 2) == 0)
......@@ -2793,7 +2794,7 @@ current_word (
redraw_curbuf_later(INVERTED); /* update the inversion */
} else {
oap->start = start_pos;
oap->motion_type = MCHAR;
oap->motion_type = kMTCharWise;
}
--count;
}
......@@ -3028,7 +3029,7 @@ extend:
else
oap->inclusive = false;
oap->start = start_pos;
oap->motion_type = MCHAR;
oap->motion_type = kMTCharWise;
}
return OK;
}
......@@ -3152,7 +3153,7 @@ current_block (
showmode();
} else {
oap->start = start_pos;
oap->motion_type = MCHAR;
oap->motion_type = kMTCharWise;
oap->inclusive = false;
if (sol)
incl(&curwin->w_cursor);
......@@ -3399,7 +3400,7 @@ again:
showmode();
} else {
oap->start = start_pos;
oap->motion_type = MCHAR;
oap->motion_type = kMTCharWise;
if (lt(end_pos, start_pos)) {
/* End is before the start: there is no text between tags; operate
* on an empty area. */
......@@ -3564,7 +3565,7 @@ extend:
} else {
oap->start.lnum = start_lnum;
oap->start.col = 0;
oap->motion_type = MLINE;
oap->motion_type = kMTLineWise;
}
curwin->w_cursor.lnum = end_lnum;
curwin->w_cursor.col = 0;
......@@ -3806,7 +3807,7 @@ current_quote (
}
} else {
oap->start = curwin->w_cursor;
oap->motion_type = MCHAR;
oap->motion_type = kMTCharWise;
}
/* Set end position. */
......
......@@ -283,7 +283,7 @@ typedef struct {
} history_item;
struct reg {
char name;
uint8_t type;
MotionType type;
char **contents;
size_t contents_size;
size_t width;
......@@ -475,7 +475,7 @@ static const ShadaEntry sd_default_values[] = {
.additional_elements = NULL),
DEF_SDE(Register, reg,
.name = NUL,
.type = MCHAR,
.type = kMTCharWise,
.contents = NULL,
.contents_size = 0,
.width = 0,
......@@ -1407,9 +1407,9 @@ static void shada_read(ShaDaReadDef *const sd_reader, const int flags)
break;
}
case kSDItemRegister: {
if (cur_entry.data.reg.type != MCHAR
&& cur_entry.data.reg.type != MLINE
&& cur_entry.data.reg.type != MBLOCK) {
if (cur_entry.data.reg.type != kMTCharWise
&& cur_entry.data.reg.type != kMTLineWise
&& cur_entry.data.reg.type != kMTBlockWise) {
shada_free_shada_entry(&cur_entry);
break;
}
......@@ -1882,7 +1882,7 @@ static ShaDaWriteResult shada_pack_entry(msgpack_packer *const packer,
msgpack_pack_char(spacker, entry.data.reg.name);
if (!CHECK_DEFAULT(entry, reg.type)) {
PACK_STATIC_STR(REG_KEY_TYPE);
msgpack_pack_uint8(spacker, entry.data.reg.type);
msgpack_pack_uint8(spacker, (uint8_t)entry.data.reg.type);
}
if (!CHECK_DEFAULT(entry, reg.width)) {
PACK_STATIC_STR(REG_KEY_WIDTH);
......@@ -2757,8 +2757,8 @@ static ShaDaWriteResult shada_write(ShaDaWriteDef *const sd_writer,
.reg = {
.contents = (char **) reg.y_array,
.contents_size = (size_t) reg.y_size,
.type = (uint8_t) reg.y_type,
.width = (size_t) (reg.y_type == MBLOCK ? reg.y_width : 0),
.type = reg.y_type,
.width = (size_t) (reg.y_type == kMTBlockWise ? reg.y_width : 0),
.additional_data = reg.additional_data,
.name = name,
}
......
......@@ -201,15 +201,6 @@ enum {
#define MAYBE 2 /* sometimes used for a variant on TRUE */
/*
* Motion types, used for operators and for yank/delete registers.
*/
#define MCHAR 0 /* character-wise movement/register */
#define MLINE 1 /* line-wise movement/register */
#define MBLOCK 2 /* block-wise register */
#define MAUTO 0xff /* Decide between MLINE/MCHAR */
#define STATUS_HEIGHT 1 /* height of a status line under a window */
#define QF_WINHEIGHT 10 /* default height for quickfix window */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment