mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
Merge pull request #4597 from bfredl/motion
convert MCHAR operator and register types to enum MotionType
This commit is contained in:
commit
121987c5cc
@ -10290,7 +10290,7 @@ static void f_getregtype(typval_T *argvars, typval_T *rettv)
|
|||||||
|
|
||||||
colnr_T reglen = 0;
|
colnr_T reglen = 0;
|
||||||
char buf[NUMBUFLEN + 2];
|
char buf[NUMBUFLEN + 2];
|
||||||
char_u reg_type = get_reg_type(regname, ®len);
|
MotionType reg_type = get_reg_type(regname, ®len);
|
||||||
format_reg_type(reg_type, reglen, buf, ARRAY_SIZE(buf));
|
format_reg_type(reg_type, reglen, buf, ARRAY_SIZE(buf));
|
||||||
|
|
||||||
rettv->v_type = VAR_STRING;
|
rettv->v_type = VAR_STRING;
|
||||||
@ -14717,11 +14717,11 @@ static void f_setreg(typval_T *argvars, typval_T *rettv)
|
|||||||
char_u *strregname;
|
char_u *strregname;
|
||||||
char_u *stropt;
|
char_u *stropt;
|
||||||
bool append = false;
|
bool append = false;
|
||||||
char_u yank_type;
|
MotionType yank_type;
|
||||||
long block_len;
|
long block_len;
|
||||||
|
|
||||||
block_len = -1;
|
block_len = -1;
|
||||||
yank_type = MAUTO;
|
yank_type = kMTUnknown;
|
||||||
|
|
||||||
strregname = get_tv_string_chk(argvars);
|
strregname = get_tv_string_chk(argvars);
|
||||||
rettv->vval.v_number = 1; /* FAIL is default */
|
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 */
|
return; /* type error */
|
||||||
for (; *stropt != NUL; ++stropt)
|
for (; *stropt != NUL; ++stropt)
|
||||||
switch (*stropt) {
|
switch (*stropt) {
|
||||||
case 'a': case 'A': /* append */
|
case 'a': case 'A': // append
|
||||||
append = true;
|
append = true;
|
||||||
break;
|
break;
|
||||||
case 'v': case 'c': /* character-wise selection */
|
case 'v': case 'c': // character-wise selection
|
||||||
yank_type = MCHAR;
|
yank_type = kMTCharWise;
|
||||||
break;
|
break;
|
||||||
case 'V': case 'l': /* line-wise selection */
|
case 'V': case 'l': // line-wise selection
|
||||||
yank_type = MLINE;
|
yank_type = kMTLineWise;
|
||||||
break;
|
break;
|
||||||
case 'b': case Ctrl_V: /* block-wise selection */
|
case 'b': case Ctrl_V: // block-wise selection
|
||||||
yank_type = MBLOCK;
|
yank_type = kMTBlockWise;
|
||||||
if (ascii_isdigit(stropt[1])) {
|
if (ascii_isdigit(stropt[1])) {
|
||||||
++stropt;
|
++stropt;
|
||||||
block_len = getdigits_long(&stropt) - 1;
|
block_len = getdigits_long(&stropt) - 1;
|
||||||
|
@ -7071,9 +7071,9 @@ static void ex_operators(exarg_T *eap)
|
|||||||
oa.start.lnum = eap->line1;
|
oa.start.lnum = eap->line1;
|
||||||
oa.end.lnum = eap->line2;
|
oa.end.lnum = eap->line2;
|
||||||
oa.line_count = eap->line2 - eap->line1 + 1;
|
oa.line_count = eap->line2 - eap->line1 + 1;
|
||||||
oa.motion_type = MLINE;
|
oa.motion_type = kMTLineWise;
|
||||||
virtual_op = FALSE;
|
virtual_op = false;
|
||||||
if (eap->cmdidx != CMD_yank) { /* position cursor for undo */
|
if (eap->cmdidx != CMD_yank) { // position cursor for undo
|
||||||
setpcmark();
|
setpcmark();
|
||||||
curwin->w_cursor.lnum = eap->line1;
|
curwin->w_cursor.lnum = eap->line1;
|
||||||
beginline(BL_SOL | BL_FIX);
|
beginline(BL_SOL | BL_FIX);
|
||||||
|
@ -1436,19 +1436,20 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
|
|||||||
}
|
}
|
||||||
curwin->w_p_lbr = false;
|
curwin->w_p_lbr = false;
|
||||||
oap->is_VIsual = VIsual_active;
|
oap->is_VIsual = VIsual_active;
|
||||||
if (oap->motion_force == 'V')
|
if (oap->motion_force == 'V') {
|
||||||
oap->motion_type = MLINE;
|
oap->motion_type = kMTLineWise;
|
||||||
else if (oap->motion_force == 'v') {
|
} else if (oap->motion_force == 'v') {
|
||||||
/* If the motion was linewise, "inclusive" will not have been set.
|
// If the motion was linewise, "inclusive" will not have been set.
|
||||||
* Use "exclusive" to be consistent. Makes "dvj" work nice. */
|
// Use "exclusive" to be consistent. Makes "dvj" work nice.
|
||||||
if (oap->motion_type == MLINE)
|
if (oap->motion_type == kMTLineWise) {
|
||||||
oap->inclusive = false;
|
oap->inclusive = false;
|
||||||
/* If the motion already was characterwise, toggle "inclusive" */
|
} else if (oap->motion_type == kMTCharWise) {
|
||||||
else if (oap->motion_type == MCHAR)
|
// If the motion already was characterwise, toggle "inclusive"
|
||||||
oap->inclusive = !oap->inclusive;
|
oap->inclusive = !oap->inclusive;
|
||||||
oap->motion_type = MCHAR;
|
}
|
||||||
|
oap->motion_type = kMTCharWise;
|
||||||
} else if (oap->motion_force == Ctrl_V) {
|
} else if (oap->motion_force == Ctrl_V) {
|
||||||
/* Change line- or characterwise motion into Visual block mode. */
|
// Change line- or characterwise motion into Visual block mode.
|
||||||
VIsual_active = true;
|
VIsual_active = true;
|
||||||
VIsual = oap->start;
|
VIsual = oap->start;
|
||||||
VIsual_mode = Ctrl_V;
|
VIsual_mode = Ctrl_V;
|
||||||
@ -1586,13 +1587,15 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
|
|||||||
* automatically. */
|
* automatically. */
|
||||||
curwin->w_valid &= ~VALID_VIRTCOL;
|
curwin->w_valid &= ~VALID_VIRTCOL;
|
||||||
} else {
|
} else {
|
||||||
/* Include folded lines completely. */
|
// Include folded lines completely.
|
||||||
if (!VIsual_active && oap->motion_type == MLINE) {
|
if (!VIsual_active && oap->motion_type == kMTLineWise) {
|
||||||
if (hasFolding(curwin->w_cursor.lnum, &curwin->w_cursor.lnum,
|
if (hasFolding(curwin->w_cursor.lnum, &curwin->w_cursor.lnum,
|
||||||
NULL))
|
NULL)) {
|
||||||
curwin->w_cursor.col = 0;
|
curwin->w_cursor.col = 0;
|
||||||
if (hasFolding(oap->start.lnum, NULL, &oap->start.lnum))
|
}
|
||||||
|
if (hasFolding(oap->start.lnum, NULL, &oap->start.lnum)) {
|
||||||
oap->start.col = (colnr_T)STRLEN(ml_get(oap->start.lnum));
|
oap->start.col = (colnr_T)STRLEN(ml_get(oap->start.lnum));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
oap->end = oap->start;
|
oap->end = oap->start;
|
||||||
oap->start = curwin->w_cursor;
|
oap->start = curwin->w_cursor;
|
||||||
@ -1663,17 +1666,16 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
// oap->inclusive defaults to true.
|
||||||
* oap->inclusive defaults to true.
|
// If oap->end is on a NUL (empty line) oap->inclusive becomes
|
||||||
* If oap->end is on a NUL (empty line) oap->inclusive becomes
|
// false. This makes "d}P" and "v}dP" work the same.
|
||||||
* false. This makes "d}P" and "v}dP" work the same.
|
if (oap->motion_force == NUL || oap->motion_type == kMTLineWise) {
|
||||||
*/
|
|
||||||
if (oap->motion_force == NUL || oap->motion_type == MLINE)
|
|
||||||
oap->inclusive = true;
|
oap->inclusive = true;
|
||||||
|
}
|
||||||
if (VIsual_mode == 'V') {
|
if (VIsual_mode == 'V') {
|
||||||
oap->motion_type = MLINE;
|
oap->motion_type = kMTLineWise;
|
||||||
} else if (VIsual_mode == 'v') {
|
} else if (VIsual_mode == 'v') {
|
||||||
oap->motion_type = MCHAR;
|
oap->motion_type = kMTCharWise;
|
||||||
if (*ml_get_pos(&(oap->end)) == NUL
|
if (*ml_get_pos(&(oap->end)) == NUL
|
||||||
&& (include_line_break || !virtual_op)
|
&& (include_line_break || !virtual_op)
|
||||||
) {
|
) {
|
||||||
@ -1731,7 +1733,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
|
|||||||
* oap->empty is set when start and end are the same. The inclusive
|
* oap->empty is set when start and end are the same. The inclusive
|
||||||
* flag affects this too, unless yanking and the end is on a NUL.
|
* flag affects this too, unless yanking and the end is on a NUL.
|
||||||
*/
|
*/
|
||||||
oap->empty = (oap->motion_type != MLINE
|
oap->empty = (oap->motion_type != kMTLineWise
|
||||||
&& (!oap->inclusive
|
&& (!oap->inclusive
|
||||||
|| (oap->op_type == OP_YANK
|
|| (oap->op_type == OP_YANK
|
||||||
&& gchar_pos(&oap->end) == NUL))
|
&& gchar_pos(&oap->end) == NUL))
|
||||||
@ -1756,23 +1758,23 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* If the end of an operator is in column one while oap->motion_type
|
* If the end of an operator is in column one while oap->motion_type
|
||||||
* is MCHAR and oap->inclusive is false, we put op_end after the last
|
* is kMTCharWise and oap->inclusive is false, we put op_end after the last
|
||||||
* character in the previous line. If op_start is on or before the
|
* character in the previous line. If op_start is on or before the
|
||||||
* first non-blank in the line, the operator becomes linewise
|
* first non-blank in the line, the operator becomes linewise
|
||||||
* (strange, but that's the way vi does it).
|
* (strange, but that's the way vi does it).
|
||||||
*/
|
*/
|
||||||
if (oap->motion_type == MCHAR
|
if (oap->motion_type == kMTCharWise
|
||||||
&& oap->inclusive == false
|
&& oap->inclusive == false
|
||||||
&& !(cap->retval & CA_NO_ADJ_OP_END)
|
&& !(cap->retval & CA_NO_ADJ_OP_END)
|
||||||
&& oap->end.col == 0
|
&& oap->end.col == 0
|
||||||
&& (!oap->is_VIsual || *p_sel == 'o')
|
&& (!oap->is_VIsual || *p_sel == 'o')
|
||||||
&& oap->line_count > 1) {
|
&& oap->line_count > 1) {
|
||||||
oap->end_adjusted = true; // remember that we did this
|
oap->end_adjusted = true; // remember that we did this
|
||||||
--oap->line_count;
|
oap->line_count--;
|
||||||
--oap->end.lnum;
|
oap->end.lnum--;
|
||||||
if (inindent(0))
|
if (inindent(0)) {
|
||||||
oap->motion_type = MLINE;
|
oap->motion_type = kMTLineWise;
|
||||||
else {
|
} else {
|
||||||
oap->end.col = (colnr_T)STRLEN(ml_get(oap->end.lnum));
|
oap->end.col = (colnr_T)STRLEN(ml_get(oap->end.lnum));
|
||||||
if (oap->end.col) {
|
if (oap->end.col) {
|
||||||
--oap->end.col;
|
--oap->end.col;
|
||||||
@ -1811,8 +1813,9 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
|
|||||||
CancelRedo();
|
CancelRedo();
|
||||||
} else {
|
} else {
|
||||||
(void)op_delete(oap);
|
(void)op_delete(oap);
|
||||||
if (oap->motion_type == MLINE && has_format_option(FO_AUTO))
|
if (oap->motion_type == kMTLineWise && has_format_option(FO_AUTO)) {
|
||||||
u_save_cursor(); /* cursor line wasn't saved yet */
|
u_save_cursor(); // cursor line wasn't saved yet
|
||||||
|
}
|
||||||
auto_format(false, true);
|
auto_format(false, true);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -2011,7 +2014,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
|
|||||||
/*
|
/*
|
||||||
* if 'sol' not set, go back to old column for some commands
|
* if 'sol' not set, go back to old column for some commands
|
||||||
*/
|
*/
|
||||||
if (!p_sol && oap->motion_type == MLINE && !oap->end_adjusted
|
if (!p_sol && oap->motion_type == kMTLineWise && !oap->end_adjusted
|
||||||
&& (oap->op_type == OP_LSHIFT || oap->op_type == OP_RSHIFT
|
&& (oap->op_type == OP_LSHIFT || oap->op_type == OP_RSHIFT
|
||||||
|| oap->op_type == OP_DELETE)) {
|
|| oap->op_type == OP_DELETE)) {
|
||||||
curwin->w_p_lbr = false;
|
curwin->w_p_lbr = false;
|
||||||
@ -2086,13 +2089,14 @@ static void op_function(oparg_T *oap)
|
|||||||
/* Set '[ and '] marks to text to be operated on. */
|
/* Set '[ and '] marks to text to be operated on. */
|
||||||
curbuf->b_op_start = oap->start;
|
curbuf->b_op_start = oap->start;
|
||||||
curbuf->b_op_end = oap->end;
|
curbuf->b_op_end = oap->end;
|
||||||
if (oap->motion_type != MLINE && !oap->inclusive)
|
if (oap->motion_type != kMTLineWise && !oap->inclusive) {
|
||||||
/* Exclude the end position. */
|
// Exclude the end position.
|
||||||
decl(&curbuf->b_op_end);
|
decl(&curbuf->b_op_end);
|
||||||
|
}
|
||||||
|
|
||||||
if (oap->motion_type == MBLOCK) {
|
if (oap->motion_type == kMTBlockWise) {
|
||||||
argv[0] = (char_u *)"block";
|
argv[0] = (char_u *)"block";
|
||||||
} else if (oap->motion_type == MLINE) {
|
} else if (oap->motion_type == kMTLineWise) {
|
||||||
argv[0] = (char_u *)"line";
|
argv[0] = (char_u *)"line";
|
||||||
} else {
|
} else {
|
||||||
argv[0] = (char_u *)"char";
|
argv[0] = (char_u *)"char";
|
||||||
@ -2530,7 +2534,7 @@ do_mouse (
|
|||||||
*/
|
*/
|
||||||
if (!is_drag && oap != NULL && oap->op_type != OP_NOP) {
|
if (!is_drag && oap != NULL && oap->op_type != OP_NOP) {
|
||||||
got_click = false;
|
got_click = false;
|
||||||
oap->motion_type = MCHAR;
|
oap->motion_type = kMTCharWise;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* When releasing the button let jump_to_mouse() know. */
|
/* When releasing the button let jump_to_mouse() know. */
|
||||||
@ -2769,21 +2773,23 @@ do_mouse (
|
|||||||
end_visual = curwin->w_cursor;
|
end_visual = curwin->w_cursor;
|
||||||
while (gc = gchar_pos(&end_visual), ascii_iswhite(gc))
|
while (gc = gchar_pos(&end_visual), ascii_iswhite(gc))
|
||||||
inc(&end_visual);
|
inc(&end_visual);
|
||||||
if (oap != NULL)
|
if (oap != NULL) {
|
||||||
oap->motion_type = MCHAR;
|
oap->motion_type = kMTCharWise;
|
||||||
|
}
|
||||||
if (oap != NULL
|
if (oap != NULL
|
||||||
&& VIsual_mode == 'v'
|
&& VIsual_mode == 'v'
|
||||||
&& !vim_iswordc(gchar_pos(&end_visual))
|
&& !vim_iswordc(gchar_pos(&end_visual))
|
||||||
&& equalpos(curwin->w_cursor, VIsual)
|
&& equalpos(curwin->w_cursor, VIsual)
|
||||||
&& (pos = findmatch(oap, NUL)) != NULL) {
|
&& (pos = findmatch(oap, NUL)) != NULL) {
|
||||||
curwin->w_cursor = *pos;
|
curwin->w_cursor = *pos;
|
||||||
if (oap->motion_type == MLINE)
|
if (oap->motion_type == kMTLineWise) {
|
||||||
VIsual_mode = 'V';
|
VIsual_mode = 'V';
|
||||||
else if (*p_sel == 'e') {
|
} else if (*p_sel == 'e') {
|
||||||
if (lt(curwin->w_cursor, VIsual))
|
if (lt(curwin->w_cursor, VIsual)) {
|
||||||
++VIsual.col;
|
VIsual.col++;
|
||||||
else
|
} else {
|
||||||
++curwin->w_cursor.col;
|
curwin->w_cursor.col++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3781,7 +3787,7 @@ static bool nv_screengo(oparg_T *oap, int dir, long dist)
|
|||||||
int width1; /* text width for first screen line */
|
int width1; /* text width for first screen line */
|
||||||
int width2; /* test width for wrapped screen line */
|
int width2; /* test width for wrapped screen line */
|
||||||
|
|
||||||
oap->motion_type = MCHAR;
|
oap->motion_type = kMTCharWise;
|
||||||
oap->inclusive = (curwin->w_curswant == MAXCOL);
|
oap->inclusive = (curwin->w_curswant == MAXCOL);
|
||||||
|
|
||||||
col_off1 = curwin_col_off();
|
col_off1 = curwin_col_off();
|
||||||
@ -4464,8 +4470,8 @@ static void nv_colon(cmdarg_T *cap)
|
|||||||
nv_operator(cap);
|
nv_operator(cap);
|
||||||
else {
|
else {
|
||||||
if (cap->oap->op_type != OP_NOP) {
|
if (cap->oap->op_type != OP_NOP) {
|
||||||
/* Using ":" as a movement is characterwise exclusive. */
|
// Using ":" as a movement is characterwise exclusive.
|
||||||
cap->oap->motion_type = MCHAR;
|
cap->oap->motion_type = kMTCharWise;
|
||||||
cap->oap->inclusive = false;
|
cap->oap->inclusive = false;
|
||||||
} else if (cap->count0) {
|
} else if (cap->count0) {
|
||||||
/* translate "count:" into ":.,.+(count - 1)" */
|
/* translate "count:" into ":.,.+(count - 1)" */
|
||||||
@ -4864,7 +4870,7 @@ static void nv_scroll(cmdarg_T *cap)
|
|||||||
linenr_T lnum;
|
linenr_T lnum;
|
||||||
int half;
|
int half;
|
||||||
|
|
||||||
cap->oap->motion_type = MLINE;
|
cap->oap->motion_type = kMTLineWise;
|
||||||
setpcmark();
|
setpcmark();
|
||||||
|
|
||||||
if (cap->cmdchar == 'L') {
|
if (cap->cmdchar == 'L') {
|
||||||
@ -4944,7 +4950,7 @@ static void nv_right(cmdarg_T *cap)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
cap->oap->motion_type = MCHAR;
|
cap->oap->motion_type = kMTCharWise;
|
||||||
cap->oap->inclusive = false;
|
cap->oap->inclusive = false;
|
||||||
PAST_LINE = (VIsual_active && *p_sel != 'o');
|
PAST_LINE = (VIsual_active && *p_sel != 'o');
|
||||||
|
|
||||||
@ -5031,7 +5037,7 @@ static void nv_left(cmdarg_T *cap)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
cap->oap->motion_type = MCHAR;
|
cap->oap->motion_type = kMTCharWise;
|
||||||
cap->oap->inclusive = false;
|
cap->oap->inclusive = false;
|
||||||
for (n = cap->count1; n > 0; --n) {
|
for (n = cap->count1; n > 0; --n) {
|
||||||
if (oneleft() == false) {
|
if (oneleft() == false) {
|
||||||
@ -5093,11 +5099,12 @@ static void nv_up(cmdarg_T *cap)
|
|||||||
cap->arg = BACKWARD;
|
cap->arg = BACKWARD;
|
||||||
nv_page(cap);
|
nv_page(cap);
|
||||||
} else {
|
} else {
|
||||||
cap->oap->motion_type = MLINE;
|
cap->oap->motion_type = kMTLineWise;
|
||||||
if (cursor_up(cap->count1, cap->oap->op_type == OP_NOP) == false)
|
if (cursor_up(cap->count1, cap->oap->op_type == OP_NOP) == false) {
|
||||||
clearopbeep(cap->oap);
|
clearopbeep(cap->oap);
|
||||||
else if (cap->arg)
|
} else if (cap->arg) {
|
||||||
beginline(BL_WHITE | BL_FIX);
|
beginline(BL_WHITE | BL_FIX);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -5111,23 +5118,24 @@ static void nv_down(cmdarg_T *cap)
|
|||||||
/* <S-Down> is page down */
|
/* <S-Down> is page down */
|
||||||
cap->arg = FORWARD;
|
cap->arg = FORWARD;
|
||||||
nv_page(cap);
|
nv_page(cap);
|
||||||
} else
|
} else if (bt_quickfix(curbuf) && cap->cmdchar == CAR) {
|
||||||
/* In a quickfix window a <CR> jumps to the error under the cursor. */
|
// In a quickfix window a <CR> jumps to the error under the cursor.
|
||||||
if (bt_quickfix(curbuf) && cap->cmdchar == CAR)
|
if (curwin->w_llist_ref == NULL) {
|
||||||
if (curwin->w_llist_ref == NULL)
|
do_cmdline_cmd(".cc"); // quickfix window
|
||||||
do_cmdline_cmd(".cc"); /* quickfix window */
|
} else {
|
||||||
else
|
do_cmdline_cmd(".ll"); // location list window
|
||||||
do_cmdline_cmd(".ll"); /* location list window */
|
}
|
||||||
else {
|
} else {
|
||||||
/* In the cmdline window a <CR> executes the command. */
|
// In the cmdline window a <CR> executes the command.
|
||||||
if (cmdwin_type != 0 && cap->cmdchar == CAR)
|
if (cmdwin_type != 0 && cap->cmdchar == CAR) {
|
||||||
cmdwin_result = CAR;
|
cmdwin_result = CAR;
|
||||||
else {
|
} else {
|
||||||
cap->oap->motion_type = MLINE;
|
cap->oap->motion_type = kMTLineWise;
|
||||||
if (cursor_down(cap->count1, cap->oap->op_type == OP_NOP) == false)
|
if (cursor_down(cap->count1, cap->oap->op_type == OP_NOP) == false) {
|
||||||
clearopbeep(cap->oap);
|
clearopbeep(cap->oap);
|
||||||
else if (cap->arg)
|
} else if (cap->arg) {
|
||||||
beginline(BL_WHITE | BL_FIX);
|
beginline(BL_WHITE | BL_FIX);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -5188,7 +5196,7 @@ static void nv_end(cmdarg_T *cap)
|
|||||||
*/
|
*/
|
||||||
static void nv_dollar(cmdarg_T *cap)
|
static void nv_dollar(cmdarg_T *cap)
|
||||||
{
|
{
|
||||||
cap->oap->motion_type = MCHAR;
|
cap->oap->motion_type = kMTCharWise;
|
||||||
cap->oap->inclusive = true;
|
cap->oap->inclusive = true;
|
||||||
/* In virtual mode when off the edge of a line and an operator
|
/* In virtual mode when off the edge of a line and an operator
|
||||||
* is pending (whew!) keep the cursor where it is.
|
* is pending (whew!) keep the cursor where it is.
|
||||||
@ -5263,18 +5271,19 @@ static int normal_search(
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
cap->oap->motion_type = MCHAR;
|
cap->oap->motion_type = kMTCharWise;
|
||||||
cap->oap->inclusive = false;
|
cap->oap->inclusive = false;
|
||||||
cap->oap->use_reg_one = true;
|
cap->oap->use_reg_one = true;
|
||||||
curwin->w_set_curswant = true;
|
curwin->w_set_curswant = true;
|
||||||
|
|
||||||
i = do_search(cap->oap, dir, pat, cap->count1,
|
i = do_search(cap->oap, dir, pat, cap->count1,
|
||||||
opt | SEARCH_OPT | SEARCH_ECHO | SEARCH_MSG, NULL);
|
opt | SEARCH_OPT | SEARCH_ECHO | SEARCH_MSG, NULL);
|
||||||
if (i == 0)
|
if (i == 0) {
|
||||||
clearop(cap->oap);
|
clearop(cap->oap);
|
||||||
else {
|
} else {
|
||||||
if (i == 2)
|
if (i == 2) {
|
||||||
cap->oap->motion_type = MLINE;
|
cap->oap->motion_type = kMTLineWise;
|
||||||
|
}
|
||||||
curwin->w_cursor.coladd = 0;
|
curwin->w_cursor.coladd = 0;
|
||||||
if (cap->oap->op_type == OP_NOP && (fdo_flags & FDO_SEARCH) && KeyTyped)
|
if (cap->oap->op_type == OP_NOP && (fdo_flags & FDO_SEARCH) && KeyTyped)
|
||||||
foldOpenCursor();
|
foldOpenCursor();
|
||||||
@ -5301,10 +5310,10 @@ static void nv_csearch(cmdarg_T *cap)
|
|||||||
else
|
else
|
||||||
t_cmd = false;
|
t_cmd = false;
|
||||||
|
|
||||||
cap->oap->motion_type = MCHAR;
|
cap->oap->motion_type = kMTCharWise;
|
||||||
if (IS_SPECIAL(cap->nchar) || searchc(cap, t_cmd) == false)
|
if (IS_SPECIAL(cap->nchar) || searchc(cap, t_cmd) == false) {
|
||||||
clearopbeep(cap->oap);
|
clearopbeep(cap->oap);
|
||||||
else {
|
} else {
|
||||||
curwin->w_set_curswant = true;
|
curwin->w_set_curswant = true;
|
||||||
/* Include a Tab for "tx" and for "dfx". */
|
/* Include a Tab for "tx" and for "dfx". */
|
||||||
if (gchar_cursor() == TAB && virtual_active() && cap->arg == FORWARD
|
if (gchar_cursor() == TAB && virtual_active() && cap->arg == FORWARD
|
||||||
@ -5336,7 +5345,7 @@ static void nv_brackets(cmdarg_T *cap)
|
|||||||
int findc;
|
int findc;
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
cap->oap->motion_type = MCHAR;
|
cap->oap->motion_type = kMTCharWise;
|
||||||
cap->oap->inclusive = false;
|
cap->oap->inclusive = false;
|
||||||
old_pos = curwin->w_cursor;
|
old_pos = curwin->w_cursor;
|
||||||
curwin->w_cursor.coladd = 0; /* TODO: don't do this for an error. */
|
curwin->w_cursor.coladd = 0; /* TODO: don't do this for an error. */
|
||||||
@ -5626,11 +5635,11 @@ static void nv_percent(cmdarg_T *cap)
|
|||||||
linenr_T lnum = curwin->w_cursor.lnum;
|
linenr_T lnum = curwin->w_cursor.lnum;
|
||||||
|
|
||||||
cap->oap->inclusive = true;
|
cap->oap->inclusive = true;
|
||||||
if (cap->count0) { /* {cnt}% : goto {cnt} percentage in file */
|
if (cap->count0) { // {cnt}% : goto {cnt} percentage in file
|
||||||
if (cap->count0 > 100)
|
if (cap->count0 > 100) {
|
||||||
clearopbeep(cap->oap);
|
clearopbeep(cap->oap);
|
||||||
else {
|
} else {
|
||||||
cap->oap->motion_type = MLINE;
|
cap->oap->motion_type = kMTLineWise;
|
||||||
setpcmark();
|
setpcmark();
|
||||||
/* Round up, so CTRL-G will give same value. Watch out for a
|
/* Round up, so CTRL-G will give same value. Watch out for a
|
||||||
* large line count, the line number must not go negative! */
|
* large line count, the line number must not go negative! */
|
||||||
@ -5644,8 +5653,8 @@ static void nv_percent(cmdarg_T *cap)
|
|||||||
curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
|
curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
|
||||||
beginline(BL_SOL | BL_FIX);
|
beginline(BL_SOL | BL_FIX);
|
||||||
}
|
}
|
||||||
} else { /* "%" : go to matching paren */
|
} else { // "%" : go to matching paren
|
||||||
cap->oap->motion_type = MCHAR;
|
cap->oap->motion_type = kMTCharWise;
|
||||||
cap->oap->use_reg_one = true;
|
cap->oap->use_reg_one = true;
|
||||||
if ((pos = findmatch(cap->oap, NUL)) == NULL)
|
if ((pos = findmatch(cap->oap, NUL)) == NULL)
|
||||||
clearopbeep(cap->oap);
|
clearopbeep(cap->oap);
|
||||||
@ -5670,7 +5679,7 @@ static void nv_percent(cmdarg_T *cap)
|
|||||||
*/
|
*/
|
||||||
static void nv_brace(cmdarg_T *cap)
|
static void nv_brace(cmdarg_T *cap)
|
||||||
{
|
{
|
||||||
cap->oap->motion_type = MCHAR;
|
cap->oap->motion_type = kMTCharWise;
|
||||||
cap->oap->use_reg_one = true;
|
cap->oap->use_reg_one = true;
|
||||||
/* The motion used to be inclusive for "(", but that is not what Vi does. */
|
/* The motion used to be inclusive for "(", but that is not what Vi does. */
|
||||||
cap->oap->inclusive = false;
|
cap->oap->inclusive = false;
|
||||||
@ -5704,7 +5713,7 @@ static void nv_mark(cmdarg_T *cap)
|
|||||||
*/
|
*/
|
||||||
static void nv_findpar(cmdarg_T *cap)
|
static void nv_findpar(cmdarg_T *cap)
|
||||||
{
|
{
|
||||||
cap->oap->motion_type = MCHAR;
|
cap->oap->motion_type = kMTCharWise;
|
||||||
cap->oap->inclusive = false;
|
cap->oap->inclusive = false;
|
||||||
cap->oap->use_reg_one = true;
|
cap->oap->use_reg_one = true;
|
||||||
curwin->w_set_curswant = true;
|
curwin->w_set_curswant = true;
|
||||||
@ -6082,10 +6091,11 @@ static void nv_cursormark(cmdarg_T *cap, int flag, pos_T *pos)
|
|||||||
else
|
else
|
||||||
check_cursor();
|
check_cursor();
|
||||||
}
|
}
|
||||||
cap->oap->motion_type = flag ? MLINE : MCHAR;
|
cap->oap->motion_type = flag ? kMTLineWise : kMTCharWise;
|
||||||
if (cap->cmdchar == '`')
|
if (cap->cmdchar == '`') {
|
||||||
cap->oap->use_reg_one = true;
|
cap->oap->use_reg_one = true;
|
||||||
cap->oap->inclusive = false; /* ignored if not MCHAR */
|
}
|
||||||
|
cap->oap->inclusive = false; // ignored if not kMTCharWise
|
||||||
curwin->w_set_curswant = true;
|
curwin->w_set_curswant = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -6562,7 +6572,7 @@ static void nv_g_cmd(cmdarg_T *cap)
|
|||||||
if (!curwin->w_p_wrap
|
if (!curwin->w_p_wrap
|
||||||
|| hasFolding(curwin->w_cursor.lnum, NULL, NULL)
|
|| hasFolding(curwin->w_cursor.lnum, NULL, NULL)
|
||||||
) {
|
) {
|
||||||
oap->motion_type = MLINE;
|
oap->motion_type = kMTLineWise;
|
||||||
i = cursor_down(cap->count1, oap->op_type == OP_NOP);
|
i = cursor_down(cap->count1, oap->op_type == OP_NOP);
|
||||||
} else
|
} else
|
||||||
i = nv_screengo(oap, FORWARD, cap->count1);
|
i = nv_screengo(oap, FORWARD, cap->count1);
|
||||||
@ -6577,7 +6587,7 @@ static void nv_g_cmd(cmdarg_T *cap)
|
|||||||
if (!curwin->w_p_wrap
|
if (!curwin->w_p_wrap
|
||||||
|| hasFolding(curwin->w_cursor.lnum, NULL, NULL)
|
|| hasFolding(curwin->w_cursor.lnum, NULL, NULL)
|
||||||
) {
|
) {
|
||||||
oap->motion_type = MLINE;
|
oap->motion_type = kMTLineWise;
|
||||||
i = cursor_up(cap->count1, oap->op_type == OP_NOP);
|
i = cursor_up(cap->count1, oap->op_type == OP_NOP);
|
||||||
} else
|
} else
|
||||||
i = nv_screengo(oap, BACKWARD, cap->count1);
|
i = nv_screengo(oap, BACKWARD, cap->count1);
|
||||||
@ -6604,7 +6614,7 @@ static void nv_g_cmd(cmdarg_T *cap)
|
|||||||
case 'm':
|
case 'm':
|
||||||
case K_HOME:
|
case K_HOME:
|
||||||
case K_KHOME:
|
case K_KHOME:
|
||||||
oap->motion_type = MCHAR;
|
oap->motion_type = kMTCharWise;
|
||||||
oap->inclusive = false;
|
oap->inclusive = false;
|
||||||
if (curwin->w_p_wrap
|
if (curwin->w_p_wrap
|
||||||
&& curwin->w_width != 0
|
&& curwin->w_width != 0
|
||||||
@ -6637,7 +6647,7 @@ static void nv_g_cmd(cmdarg_T *cap)
|
|||||||
case '_':
|
case '_':
|
||||||
/* "g_": to the last non-blank character in the line or <count> lines
|
/* "g_": to the last non-blank character in the line or <count> lines
|
||||||
* downward. */
|
* downward. */
|
||||||
cap->oap->motion_type = MCHAR;
|
cap->oap->motion_type = kMTCharWise;
|
||||||
cap->oap->inclusive = true;
|
cap->oap->inclusive = true;
|
||||||
curwin->w_curswant = MAXCOL;
|
curwin->w_curswant = MAXCOL;
|
||||||
if (cursor_down(cap->count1 - 1,
|
if (cursor_down(cap->count1 - 1,
|
||||||
@ -6665,7 +6675,7 @@ static void nv_g_cmd(cmdarg_T *cap)
|
|||||||
{
|
{
|
||||||
int col_off = curwin_col_off();
|
int col_off = curwin_col_off();
|
||||||
|
|
||||||
oap->motion_type = MCHAR;
|
oap->motion_type = kMTCharWise;
|
||||||
oap->inclusive = true;
|
oap->inclusive = true;
|
||||||
if (curwin->w_p_wrap
|
if (curwin->w_p_wrap
|
||||||
&& curwin->w_width != 0
|
&& curwin->w_width != 0
|
||||||
@ -6727,7 +6737,7 @@ static void nv_g_cmd(cmdarg_T *cap)
|
|||||||
*/
|
*/
|
||||||
case 'e':
|
case 'e':
|
||||||
case 'E':
|
case 'E':
|
||||||
oap->motion_type = MCHAR;
|
oap->motion_type = kMTCharWise;
|
||||||
curwin->w_set_curswant = true;
|
curwin->w_set_curswant = true;
|
||||||
oap->inclusive = true;
|
oap->inclusive = true;
|
||||||
if (bckend_word(cap->count1, cap->nchar == 'E', false) == false)
|
if (bckend_word(cap->count1, cap->nchar == 'E', false) == false)
|
||||||
@ -7087,17 +7097,19 @@ static void set_op_var(int optype)
|
|||||||
*/
|
*/
|
||||||
static void nv_lineop(cmdarg_T *cap)
|
static void nv_lineop(cmdarg_T *cap)
|
||||||
{
|
{
|
||||||
cap->oap->motion_type = MLINE;
|
cap->oap->motion_type = kMTLineWise;
|
||||||
if (cursor_down(cap->count1 - 1L, cap->oap->op_type == OP_NOP) == false)
|
if (cursor_down(cap->count1 - 1L, cap->oap->op_type == OP_NOP) == false) {
|
||||||
clearopbeep(cap->oap);
|
clearopbeep(cap->oap);
|
||||||
else if ( (cap->oap->op_type == OP_DELETE /* only with linewise motions */
|
} else if ((cap->oap->op_type == OP_DELETE
|
||||||
|
// only with linewise motions
|
||||||
&& cap->oap->motion_force != 'v'
|
&& cap->oap->motion_force != 'v'
|
||||||
&& cap->oap->motion_force != Ctrl_V)
|
&& cap->oap->motion_force != Ctrl_V)
|
||||||
|| cap->oap->op_type == OP_LSHIFT
|
|| cap->oap->op_type == OP_LSHIFT
|
||||||
|| cap->oap->op_type == OP_RSHIFT)
|
|| cap->oap->op_type == OP_RSHIFT) {
|
||||||
beginline(BL_SOL | BL_FIX);
|
beginline(BL_SOL | BL_FIX);
|
||||||
else if (cap->oap->op_type != OP_YANK) /* 'Y' does not move cursor */
|
} else if (cap->oap->op_type != OP_YANK) { // 'Y' does not move cursor
|
||||||
beginline(BL_WHITE | BL_FIX);
|
beginline(BL_WHITE | BL_FIX);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -7121,7 +7133,7 @@ static void nv_home(cmdarg_T *cap)
|
|||||||
*/
|
*/
|
||||||
static void nv_pipe(cmdarg_T *cap)
|
static void nv_pipe(cmdarg_T *cap)
|
||||||
{
|
{
|
||||||
cap->oap->motion_type = MCHAR;
|
cap->oap->motion_type = kMTCharWise;
|
||||||
cap->oap->inclusive = false;
|
cap->oap->inclusive = false;
|
||||||
beginline(0);
|
beginline(0);
|
||||||
if (cap->count0 > 0) {
|
if (cap->count0 > 0) {
|
||||||
@ -7140,7 +7152,7 @@ static void nv_pipe(cmdarg_T *cap)
|
|||||||
*/
|
*/
|
||||||
static void nv_bck_word(cmdarg_T *cap)
|
static void nv_bck_word(cmdarg_T *cap)
|
||||||
{
|
{
|
||||||
cap->oap->motion_type = MCHAR;
|
cap->oap->motion_type = kMTCharWise;
|
||||||
cap->oap->inclusive = false;
|
cap->oap->inclusive = false;
|
||||||
curwin->w_set_curswant = true;
|
curwin->w_set_curswant = true;
|
||||||
if (bck_word(cap->count1, cap->arg, false) == false)
|
if (bck_word(cap->count1, cap->arg, false) == false)
|
||||||
@ -7189,7 +7201,7 @@ static void nv_wordcmd(cmdarg_T *cap)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cap->oap->motion_type = MCHAR;
|
cap->oap->motion_type = kMTCharWise;
|
||||||
curwin->w_set_curswant = true;
|
curwin->w_set_curswant = true;
|
||||||
if (word_end)
|
if (word_end)
|
||||||
n = end_word(cap->count1, cap->arg, flag, false);
|
n = end_word(cap->count1, cap->arg, flag, false);
|
||||||
@ -7240,7 +7252,7 @@ static void adjust_cursor(oparg_T *oap)
|
|||||||
*/
|
*/
|
||||||
static void nv_beginline(cmdarg_T *cap)
|
static void nv_beginline(cmdarg_T *cap)
|
||||||
{
|
{
|
||||||
cap->oap->motion_type = MCHAR;
|
cap->oap->motion_type = kMTCharWise;
|
||||||
cap->oap->inclusive = false;
|
cap->oap->inclusive = false;
|
||||||
beginline(cap->arg);
|
beginline(cap->arg);
|
||||||
if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP)
|
if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP)
|
||||||
@ -7319,7 +7331,7 @@ static void nv_goto(cmdarg_T *cap)
|
|||||||
lnum = curbuf->b_ml.ml_line_count;
|
lnum = curbuf->b_ml.ml_line_count;
|
||||||
else
|
else
|
||||||
lnum = 1L;
|
lnum = 1L;
|
||||||
cap->oap->motion_type = MLINE;
|
cap->oap->motion_type = kMTLineWise;
|
||||||
setpcmark();
|
setpcmark();
|
||||||
|
|
||||||
/* When a count is given, use it instead of the default lnum */
|
/* When a count is given, use it instead of the default lnum */
|
||||||
@ -7805,7 +7817,7 @@ static void get_op_vcol(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
oap->motion_type = MBLOCK;
|
oap->motion_type = kMTBlockWise;
|
||||||
|
|
||||||
// prevent from moving onto a trail byte
|
// prevent from moving onto a trail byte
|
||||||
if (has_mbyte) {
|
if (has_mbyte) {
|
||||||
|
@ -10,18 +10,29 @@
|
|||||||
#define FIND_STRING 2 /* find any string (WORD) */
|
#define FIND_STRING 2 /* find any string (WORD) */
|
||||||
#define FIND_EVAL 4 /* include "->", "[]" and "." */
|
#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.
|
* Arguments for operators.
|
||||||
*/
|
*/
|
||||||
typedef struct oparg_S {
|
typedef struct oparg_S {
|
||||||
int op_type; // current pending operator type
|
int op_type; // current pending operator type
|
||||||
int regname; // register to use for the operator
|
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
|
int motion_force; // force motion type: 'v', 'V' or CTRL-V
|
||||||
bool use_reg_one; // true if delete uses reg 1 even when not
|
bool use_reg_one; // true if delete uses reg 1 even when not
|
||||||
// linewise
|
// linewise
|
||||||
bool inclusive; // true if char motion is inclusive (only
|
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
|
bool end_adjusted; // backuped b_op_end one char (only used by
|
||||||
// do_format())
|
// do_format())
|
||||||
pos_T start; // start of the operator
|
pos_T start; // start of the operator
|
||||||
|
381
src/nvim/ops.c
381
src/nvim/ops.c
@ -191,7 +191,7 @@ void op_shift(oparg_T *oap, int curs_top, int amount)
|
|||||||
(linenr_T)(oap->end.lnum + 1)) == FAIL)
|
(linenr_T)(oap->end.lnum + 1)) == FAIL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (oap->motion_type == MBLOCK) {
|
if (oap->motion_type == kMTBlockWise) {
|
||||||
block_col = curwin->w_cursor.col;
|
block_col = curwin->w_cursor.col;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -199,7 +199,7 @@ void op_shift(oparg_T *oap, int curs_top, int amount)
|
|||||||
first_char = *get_cursor_line_ptr();
|
first_char = *get_cursor_line_ptr();
|
||||||
if (first_char == NUL) { // empty line
|
if (first_char == NUL) { // empty line
|
||||||
curwin->w_cursor.col = 0;
|
curwin->w_cursor.col = 0;
|
||||||
} else if (oap->motion_type == MBLOCK) {
|
} else if (oap->motion_type == kMTBlockWise) {
|
||||||
shift_block(oap, amount);
|
shift_block(oap, amount);
|
||||||
} else if (first_char != '#' || !preprocs_left()) {
|
} else if (first_char != '#' || !preprocs_left()) {
|
||||||
// Move the line right if it doesn't start with '#', 'smartindent'
|
// Move the line right if it doesn't start with '#', 'smartindent'
|
||||||
@ -213,7 +213,7 @@ void op_shift(oparg_T *oap, int curs_top, int amount)
|
|||||||
/* The cursor line is not in a closed fold */
|
/* The cursor line is not in a closed fold */
|
||||||
foldOpenCursor();
|
foldOpenCursor();
|
||||||
|
|
||||||
if (oap->motion_type == MBLOCK) {
|
if (oap->motion_type == kMTBlockWise) {
|
||||||
curwin->w_cursor.lnum = oap->start.lnum;
|
curwin->w_cursor.lnum = oap->start.lnum;
|
||||||
curwin->w_cursor.col = block_col;
|
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 ">>" */
|
||||||
@ -811,17 +811,17 @@ yankreg_T *copy_register(int name)
|
|||||||
return copy;
|
return copy;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/// check if the current yank register has kMTLineWise register type
|
||||||
* return TRUE if the current yank register has type MLINE
|
bool yank_register_mline(int regname)
|
||||||
*/
|
|
||||||
int yank_register_mline(int regname)
|
|
||||||
{
|
{
|
||||||
if (regname != 0 && !valid_yank_reg(regname, false))
|
if (regname != 0 && !valid_yank_reg(regname, false)) {
|
||||||
return FALSE;
|
return false;
|
||||||
if (regname == '_') /* black hole is always empty */
|
}
|
||||||
return FALSE;
|
if (regname == '_') { // black hole is always empty
|
||||||
|
return false;
|
||||||
|
}
|
||||||
yankreg_T *reg = get_yank_register(regname, YREG_PASTE);
|
yankreg_T *reg = get_yank_register(regname, YREG_PASTE);
|
||||||
return reg->y_type == MLINE;
|
return reg->y_type == kMTLineWise;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -919,7 +919,7 @@ static int stuff_yank(int regname, char_u *p)
|
|||||||
reg->y_array = (char_u **)xmalloc(sizeof(char_u *));
|
reg->y_array = (char_u **)xmalloc(sizeof(char_u *));
|
||||||
reg->y_array[0] = p;
|
reg->y_array[0] = p;
|
||||||
reg->y_size = 1;
|
reg->y_size = 1;
|
||||||
reg->y_type = MCHAR; /* used to be MLINE, why? */
|
reg->y_type = kMTCharWise;
|
||||||
}
|
}
|
||||||
reg->timestamp = os_time();
|
reg->timestamp = os_time();
|
||||||
return OK;
|
return OK;
|
||||||
@ -1011,8 +1011,8 @@ do_execreg (
|
|||||||
for (i = reg->y_size - 1; i >= 0; i--) {
|
for (i = reg->y_size - 1; i >= 0; i--) {
|
||||||
char_u *escaped;
|
char_u *escaped;
|
||||||
|
|
||||||
/* insert NL between lines and after last line if type is MLINE */
|
// insert NL between lines and after last line if type is kMTLineWise
|
||||||
if (reg->y_type == MLINE || i < reg->y_size - 1
|
if (reg->y_type == kMTLineWise || i < reg->y_size - 1
|
||||||
|| addcr) {
|
|| addcr) {
|
||||||
if (ins_typebuf((char_u *)"\n", remap, 0, TRUE, silent) == FAIL)
|
if (ins_typebuf((char_u *)"\n", remap, 0, TRUE, silent) == FAIL)
|
||||||
return FAIL;
|
return FAIL;
|
||||||
@ -1137,12 +1137,11 @@ insert_reg (
|
|||||||
else {
|
else {
|
||||||
for (i = 0; i < reg->y_size; i++) {
|
for (i = 0; i < reg->y_size; i++) {
|
||||||
stuffescaped(reg->y_array[i], literally);
|
stuffescaped(reg->y_array[i], literally);
|
||||||
/*
|
// Insert a newline between lines and after last line if
|
||||||
* Insert a newline between lines and after last line if
|
// y_type is kMTLineWise.
|
||||||
* y_type is MLINE.
|
if (reg->y_type == kMTLineWise || i < reg->y_size - 1) {
|
||||||
*/
|
|
||||||
if (reg->y_type == MLINE || i < reg->y_size - 1)
|
|
||||||
stuffcharReadbuff('\n');
|
stuffcharReadbuff('\n');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1283,9 +1282,9 @@ bool cmdline_paste_reg(int regname, bool literally, bool remcr)
|
|||||||
for (i = 0; i < reg->y_size; i++) {
|
for (i = 0; i < reg->y_size; i++) {
|
||||||
cmdline_paste_str(reg->y_array[i], literally);
|
cmdline_paste_str(reg->y_array[i], literally);
|
||||||
|
|
||||||
// Insert ^M between lines and after last line if type is MLINE.
|
// Insert ^M between lines and after last line if type is kMTLineWise.
|
||||||
// Don't do this when "remcr" is true.
|
// Don't do this when "remcr" is true.
|
||||||
if ((reg->y_type == MLINE || i < reg->y_size - 1) && !remcr) {
|
if ((reg->y_type == kMTLineWise || i < reg->y_size - 1) && !remcr) {
|
||||||
cmdline_paste_str((char_u *)"\r", literally);
|
cmdline_paste_str((char_u *)"\r", literally);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1329,10 +1328,10 @@ int op_delete(oparg_T *oap)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Imitate the strange Vi behaviour: If the delete spans more than one
|
* Imitate the strange Vi behaviour: If the delete spans more than one
|
||||||
* line and motion_type == MCHAR and the result is a blank line, make the
|
* line and motion_type == kMTCharWise and the result is a blank line, make the
|
||||||
* delete linewise. Don't do this for the change command or Visual mode.
|
* delete linewise. Don't do this for the change command or Visual mode.
|
||||||
*/
|
*/
|
||||||
if (oap->motion_type == MCHAR
|
if (oap->motion_type == kMTCharWise
|
||||||
&& !oap->is_VIsual
|
&& !oap->is_VIsual
|
||||||
&& oap->line_count > 1
|
&& oap->line_count > 1
|
||||||
&& oap->motion_force == NUL
|
&& oap->motion_force == NUL
|
||||||
@ -1341,15 +1340,16 @@ int op_delete(oparg_T *oap)
|
|||||||
if (*ptr != NUL)
|
if (*ptr != NUL)
|
||||||
ptr += oap->inclusive;
|
ptr += oap->inclusive;
|
||||||
ptr = skipwhite(ptr);
|
ptr = skipwhite(ptr);
|
||||||
if (*ptr == NUL && inindent(0))
|
if (*ptr == NUL && inindent(0)) {
|
||||||
oap->motion_type = MLINE;
|
oap->motion_type = kMTLineWise;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check for trying to delete (e.g. "D") in an empty line.
|
* Check for trying to delete (e.g. "D") in an empty line.
|
||||||
* Note: For the change operator it is ok.
|
* Note: For the change operator it is ok.
|
||||||
*/
|
*/
|
||||||
if (oap->motion_type != MLINE
|
if (oap->motion_type != kMTLineWise
|
||||||
&& oap->line_count == 1
|
&& oap->line_count == 1
|
||||||
&& oap->op_type == OP_DELETE
|
&& oap->op_type == OP_DELETE
|
||||||
&& *ml_get(oap->start.lnum) == NUL) {
|
&& *ml_get(oap->start.lnum) == NUL) {
|
||||||
@ -1385,7 +1385,7 @@ int op_delete(oparg_T *oap)
|
|||||||
* Put deleted text into register 1 and shift number registers if the
|
* Put deleted text into register 1 and shift number registers if the
|
||||||
* delete contains a line break, or when a regname has been specified.
|
* delete contains a line break, or when a regname has been specified.
|
||||||
*/
|
*/
|
||||||
if (oap->regname != 0 || oap->motion_type == MLINE
|
if (oap->regname != 0 || oap->motion_type == kMTLineWise
|
||||||
|| oap->line_count > 1 || oap->use_reg_one) {
|
|| oap->line_count > 1 || oap->use_reg_one) {
|
||||||
free_register(&y_regs[9]); /* free register "9 */
|
free_register(&y_regs[9]); /* free register "9 */
|
||||||
for (n = 9; n > 1; n--)
|
for (n = 9; n > 1; n--)
|
||||||
@ -1398,7 +1398,7 @@ int op_delete(oparg_T *oap)
|
|||||||
|
|
||||||
/* Yank into small delete register when no named register specified
|
/* Yank into small delete register when no named register specified
|
||||||
* and the delete is within one line. */
|
* and the delete is within one line. */
|
||||||
if (oap->regname == 0 && oap->motion_type != MLINE
|
if (oap->regname == 0 && oap->motion_type != kMTLineWise
|
||||||
&& oap->line_count == 1) {
|
&& oap->line_count == 1) {
|
||||||
reg = get_yank_register('-', YREG_YANK);
|
reg = get_yank_register('-', YREG_YANK);
|
||||||
op_yank_reg(oap, false, reg, false);
|
op_yank_reg(oap, false, reg, false);
|
||||||
@ -1414,7 +1414,7 @@ int op_delete(oparg_T *oap)
|
|||||||
/*
|
/*
|
||||||
* block mode delete
|
* block mode delete
|
||||||
*/
|
*/
|
||||||
if (oap->motion_type == MBLOCK) {
|
if (oap->motion_type == kMTBlockWise) {
|
||||||
if (u_save((linenr_T)(oap->start.lnum - 1),
|
if (u_save((linenr_T)(oap->start.lnum - 1),
|
||||||
(linenr_T)(oap->end.lnum + 1)) == FAIL) {
|
(linenr_T)(oap->end.lnum + 1)) == FAIL) {
|
||||||
return FAIL;
|
return FAIL;
|
||||||
@ -1452,9 +1452,9 @@ int op_delete(oparg_T *oap)
|
|||||||
|
|
||||||
check_cursor_col();
|
check_cursor_col();
|
||||||
changed_lines(curwin->w_cursor.lnum, curwin->w_cursor.col,
|
changed_lines(curwin->w_cursor.lnum, curwin->w_cursor.col,
|
||||||
oap->end.lnum + 1, 0L);
|
oap->end.lnum + 1, 0L);
|
||||||
oap->line_count = 0; /* no lines deleted */
|
oap->line_count = 0; // no lines deleted
|
||||||
} else if (oap->motion_type == MLINE) {
|
} else if (oap->motion_type == kMTLineWise) {
|
||||||
if (oap->op_type == OP_CHANGE) {
|
if (oap->op_type == OP_CHANGE) {
|
||||||
/* Delete the lines except the first one. Temporarily move the
|
/* Delete the lines except the first one. Temporarily move the
|
||||||
* cursor to the next line. Save the current line number, if the
|
* cursor to the next line. Save the current line number, if the
|
||||||
@ -1582,7 +1582,7 @@ int op_delete(oparg_T *oap)
|
|||||||
msgmore(curbuf->b_ml.ml_line_count - old_lcount);
|
msgmore(curbuf->b_ml.ml_line_count - old_lcount);
|
||||||
|
|
||||||
setmarks:
|
setmarks:
|
||||||
if (oap->motion_type == MBLOCK) {
|
if (oap->motion_type == kMTBlockWise) {
|
||||||
curbuf->b_op_end.lnum = oap->end.lnum;
|
curbuf->b_op_end.lnum = oap->end.lnum;
|
||||||
curbuf->b_op_end.col = oap->start.col;
|
curbuf->b_op_end.col = oap->start.col;
|
||||||
} else
|
} else
|
||||||
@ -1643,7 +1643,7 @@ int op_replace(oparg_T *oap, int c)
|
|||||||
/*
|
/*
|
||||||
* block mode replace
|
* block mode replace
|
||||||
*/
|
*/
|
||||||
if (oap->motion_type == MBLOCK) {
|
if (oap->motion_type == kMTBlockWise) {
|
||||||
bd.is_MAX = (curwin->w_curswant == MAXCOL);
|
bd.is_MAX = (curwin->w_curswant == MAXCOL);
|
||||||
for (; curwin->w_cursor.lnum <= oap->end.lnum; ++curwin->w_cursor.lnum) {
|
for (; curwin->w_cursor.lnum <= oap->end.lnum; ++curwin->w_cursor.lnum) {
|
||||||
curwin->w_cursor.col = 0; /* make sure cursor position is valid */
|
curwin->w_cursor.col = 0; /* make sure cursor position is valid */
|
||||||
@ -1732,10 +1732,8 @@ int op_replace(oparg_T *oap, int c)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/*
|
// Characterwise or linewise motion replace.
|
||||||
* MCHAR and MLINE motion replace.
|
if (oap->motion_type == kMTLineWise) {
|
||||||
*/
|
|
||||||
if (oap->motion_type == MLINE) {
|
|
||||||
oap->start.col = 0;
|
oap->start.col = 0;
|
||||||
curwin->w_cursor.col = 0;
|
curwin->w_cursor.col = 0;
|
||||||
oap->end.col = (colnr_T)STRLEN(ml_get(oap->end.lnum));
|
oap->end.col = (colnr_T)STRLEN(ml_get(oap->end.lnum));
|
||||||
@ -1825,8 +1823,8 @@ void op_tilde(oparg_T *oap)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
pos = oap->start;
|
pos = oap->start;
|
||||||
if (oap->motion_type == MBLOCK) { // Visual block mode
|
if (oap->motion_type == kMTBlockWise) { // Visual block mode
|
||||||
for (; pos.lnum <= oap->end.lnum; ++pos.lnum) {
|
for (; pos.lnum <= oap->end.lnum; pos.lnum++) {
|
||||||
int one_change;
|
int one_change;
|
||||||
|
|
||||||
block_prep(oap, &bd, pos.lnum, FALSE);
|
block_prep(oap, &bd, pos.lnum, FALSE);
|
||||||
@ -1837,8 +1835,8 @@ void op_tilde(oparg_T *oap)
|
|||||||
}
|
}
|
||||||
if (did_change)
|
if (did_change)
|
||||||
changed_lines(oap->start.lnum, 0, oap->end.lnum + 1, 0L);
|
changed_lines(oap->start.lnum, 0, oap->end.lnum + 1, 0L);
|
||||||
} else { /* not block mode */
|
} else { // not block mode
|
||||||
if (oap->motion_type == MLINE) {
|
if (oap->motion_type == kMTLineWise) {
|
||||||
oap->start.col = 0;
|
oap->start.col = 0;
|
||||||
pos.col = 0;
|
pos.col = 0;
|
||||||
oap->end.col = (colnr_T)STRLEN(ml_get(oap->end.lnum));
|
oap->end.col = (colnr_T)STRLEN(ml_get(oap->end.lnum));
|
||||||
@ -1988,7 +1986,7 @@ void op_insert(oparg_T *oap, long count1)
|
|||||||
curwin->w_cursor.lnum = oap->start.lnum;
|
curwin->w_cursor.lnum = oap->start.lnum;
|
||||||
update_screen(INVERTED);
|
update_screen(INVERTED);
|
||||||
|
|
||||||
if (oap->motion_type == MBLOCK) {
|
if (oap->motion_type == kMTBlockWise) {
|
||||||
// When 'virtualedit' is used, need to insert the extra spaces before
|
// When 'virtualedit' is used, need to insert the extra spaces before
|
||||||
// doing block_prep(). When only "block" is used, virtual edit is
|
// doing block_prep(). When only "block" is used, virtual edit is
|
||||||
// already disabled, but still need it when calling
|
// already disabled, but still need it when calling
|
||||||
@ -2014,7 +2012,7 @@ void op_insert(oparg_T *oap, long count1)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (oap->op_type == OP_APPEND) {
|
if (oap->op_type == OP_APPEND) {
|
||||||
if (oap->motion_type == MBLOCK
|
if (oap->motion_type == kMTBlockWise
|
||||||
&& curwin->w_cursor.coladd == 0
|
&& curwin->w_cursor.coladd == 0
|
||||||
) {
|
) {
|
||||||
/* Move the cursor to the character right of the block. */
|
/* Move the cursor to the character right of the block. */
|
||||||
@ -2059,7 +2057,7 @@ void op_insert(oparg_T *oap, long count1)
|
|||||||
if (curwin->w_cursor.lnum != oap->start.lnum || got_int)
|
if (curwin->w_cursor.lnum != oap->start.lnum || got_int)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (oap->motion_type == MBLOCK) {
|
if (oap->motion_type == kMTBlockWise) {
|
||||||
struct block_def bd2;
|
struct block_def bd2;
|
||||||
|
|
||||||
/* The user may have moved the cursor before inserting something, try
|
/* The user may have moved the cursor before inserting something, try
|
||||||
@ -2146,7 +2144,7 @@ int op_change(oparg_T *oap)
|
|||||||
struct block_def bd;
|
struct block_def bd;
|
||||||
|
|
||||||
l = oap->start.col;
|
l = oap->start.col;
|
||||||
if (oap->motion_type == MLINE) {
|
if (oap->motion_type == kMTLineWise) {
|
||||||
l = 0;
|
l = 0;
|
||||||
if (!p_paste && curbuf->b_p_si
|
if (!p_paste && curbuf->b_p_si
|
||||||
&& !curbuf->b_p_cin
|
&& !curbuf->b_p_cin
|
||||||
@ -2168,7 +2166,7 @@ int op_change(oparg_T *oap)
|
|||||||
|
|
||||||
// check for still on same line (<CR> in inserted text meaningless)
|
// check for still on same line (<CR> in inserted text meaningless)
|
||||||
// skip blank lines too
|
// skip blank lines too
|
||||||
if (oap->motion_type == MBLOCK) {
|
if (oap->motion_type == kMTBlockWise) {
|
||||||
// Add spaces before getting the current line length.
|
// Add spaces before getting the current line length.
|
||||||
if (virtual_op && (curwin->w_cursor.coladd > 0
|
if (virtual_op && (curwin->w_cursor.coladd > 0
|
||||||
|| gchar_cursor() == NUL)) {
|
|| gchar_cursor() == NUL)) {
|
||||||
@ -2180,8 +2178,9 @@ int op_change(oparg_T *oap)
|
|||||||
bd.textcol = curwin->w_cursor.col;
|
bd.textcol = curwin->w_cursor.col;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (oap->motion_type == MLINE)
|
if (oap->motion_type == kMTLineWise) {
|
||||||
fix_indent();
|
fix_indent();
|
||||||
|
}
|
||||||
|
|
||||||
retval = edit(NUL, FALSE, (linenr_T)1);
|
retval = edit(NUL, FALSE, (linenr_T)1);
|
||||||
|
|
||||||
@ -2190,7 +2189,7 @@ int op_change(oparg_T *oap)
|
|||||||
* block.
|
* block.
|
||||||
* Don't repeat the insert when Insert mode ended with CTRL-C.
|
* Don't repeat the insert when Insert mode ended with CTRL-C.
|
||||||
*/
|
*/
|
||||||
if (oap->motion_type == MBLOCK
|
if (oap->motion_type == kMTBlockWise
|
||||||
&& oap->start.lnum != oap->end.lnum && !got_int) {
|
&& oap->start.lnum != oap->end.lnum && !got_int) {
|
||||||
// Auto-indenting may have changed the indent. If the cursor was past
|
// Auto-indenting may have changed the indent. If the cursor was past
|
||||||
// the indent, exclude that indent change from the inserted text.
|
// the indent, exclude that indent change from the inserted text.
|
||||||
@ -2318,7 +2317,7 @@ static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append)
|
|||||||
char_u **new_ptr;
|
char_u **new_ptr;
|
||||||
linenr_T lnum; /* current line number */
|
linenr_T lnum; /* current line number */
|
||||||
long j;
|
long j;
|
||||||
int yanktype = oap->motion_type;
|
MotionType yank_type = oap->motion_type;
|
||||||
long yanklines = oap->line_count;
|
long yanklines = oap->line_count;
|
||||||
linenr_T yankendlnum = oap->end.lnum;
|
linenr_T yankendlnum = oap->end.lnum;
|
||||||
char_u *p;
|
char_u *p;
|
||||||
@ -2336,19 +2335,19 @@ static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append)
|
|||||||
* If the cursor was in column 1 before and after the movement, and the
|
* If the cursor was in column 1 before and after the movement, and the
|
||||||
* operator is not inclusive, the yank is always linewise.
|
* operator is not inclusive, the yank is always linewise.
|
||||||
*/
|
*/
|
||||||
if (oap->motion_type == MCHAR
|
if (oap->motion_type == kMTCharWise
|
||||||
&& oap->start.col == 0
|
&& oap->start.col == 0
|
||||||
&& !oap->inclusive
|
&& !oap->inclusive
|
||||||
&& (!oap->is_VIsual || *p_sel == 'o')
|
&& (!oap->is_VIsual || *p_sel == 'o')
|
||||||
&& oap->end.col == 0
|
&& oap->end.col == 0
|
||||||
&& yanklines > 1) {
|
&& yanklines > 1) {
|
||||||
yanktype = MLINE;
|
yank_type = kMTLineWise;
|
||||||
--yankendlnum;
|
yankendlnum--;
|
||||||
--yanklines;
|
yanklines--;
|
||||||
}
|
}
|
||||||
|
|
||||||
reg->y_size = yanklines;
|
reg->y_size = yanklines;
|
||||||
reg->y_type = yanktype; /* set the yank register type */
|
reg->y_type = yank_type; // set the yank register type
|
||||||
reg->y_width = 0;
|
reg->y_width = 0;
|
||||||
reg->y_array = xcalloc(yanklines, sizeof(char_u *));
|
reg->y_array = xcalloc(yanklines, sizeof(char_u *));
|
||||||
reg->additional_data = NULL;
|
reg->additional_data = NULL;
|
||||||
@ -2357,7 +2356,7 @@ static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append)
|
|||||||
y_idx = 0;
|
y_idx = 0;
|
||||||
lnum = oap->start.lnum;
|
lnum = oap->start.lnum;
|
||||||
|
|
||||||
if (yanktype == MBLOCK) {
|
if (yank_type == kMTBlockWise) {
|
||||||
// Visual block mode
|
// Visual block mode
|
||||||
reg->y_width = oap->end_vcol - oap->start_vcol;
|
reg->y_width = oap->end_vcol - oap->start_vcol;
|
||||||
|
|
||||||
@ -2367,16 +2366,16 @@ static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append)
|
|||||||
|
|
||||||
for (; lnum <= yankendlnum; lnum++, y_idx++) {
|
for (; lnum <= yankendlnum; lnum++, y_idx++) {
|
||||||
switch (reg->y_type) {
|
switch (reg->y_type) {
|
||||||
case MBLOCK:
|
case kMTBlockWise:
|
||||||
block_prep(oap, &bd, lnum, FALSE);
|
block_prep(oap, &bd, lnum, false);
|
||||||
yank_copy_line(reg, &bd, y_idx);
|
yank_copy_line(reg, &bd, y_idx);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MLINE:
|
case kMTLineWise:
|
||||||
reg->y_array[y_idx] = vim_strsave(ml_get(lnum));
|
reg->y_array[y_idx] = vim_strsave(ml_get(lnum));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MCHAR:
|
case kMTCharWise:
|
||||||
{
|
{
|
||||||
colnr_T startcol = 0, endcol = MAXCOL;
|
colnr_T startcol = 0, endcol = MAXCOL;
|
||||||
int is_oneChar = FALSE;
|
int is_oneChar = FALSE;
|
||||||
@ -2437,7 +2436,9 @@ static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append)
|
|||||||
yank_copy_line(reg, &bd, y_idx);
|
yank_copy_line(reg, &bd, y_idx);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
/* NOTREACHED */
|
// NOTREACHED
|
||||||
|
case kMTUnknown:
|
||||||
|
assert(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2448,12 +2449,15 @@ static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append)
|
|||||||
xfree(curr->y_array);
|
xfree(curr->y_array);
|
||||||
curr->y_array = new_ptr;
|
curr->y_array = new_ptr;
|
||||||
|
|
||||||
if (yanktype == MLINE) /* MLINE overrides MCHAR and MBLOCK */
|
if (yank_type == kMTLineWise) {
|
||||||
curr->y_type = MLINE;
|
// kMTLineWise overrides kMTCharWise and kMTBlockWise
|
||||||
|
curr->y_type = kMTLineWise;
|
||||||
|
}
|
||||||
|
|
||||||
/* Concatenate the last line of the old block with the first line of
|
// Concatenate the last line of the old block with the first line of
|
||||||
* the new block, unless being Vi compatible. */
|
// the new block, unless being Vi compatible.
|
||||||
if (curr->y_type == MCHAR && vim_strchr(p_cpo, CPO_REGAPPEND) == NULL) {
|
if (curr->y_type == kMTCharWise
|
||||||
|
&& vim_strchr(p_cpo, CPO_REGAPPEND) == NULL) {
|
||||||
pnew = xmalloc(STRLEN(curr->y_array[curr->y_size - 1])
|
pnew = xmalloc(STRLEN(curr->y_array[curr->y_size - 1])
|
||||||
+ STRLEN(reg->y_array[0]) + 1);
|
+ STRLEN(reg->y_array[0]) + 1);
|
||||||
STRCPY(pnew, curr->y_array[--j]);
|
STRCPY(pnew, curr->y_array[--j]);
|
||||||
@ -2473,7 +2477,7 @@ static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append)
|
|||||||
redraw_later(SOME_VALID); // cursor moved to start
|
redraw_later(SOME_VALID); // cursor moved to start
|
||||||
}
|
}
|
||||||
if (message) { // Display message about yank?
|
if (message) { // Display message about yank?
|
||||||
if (yanktype == MCHAR && yanklines == 1) {
|
if (yank_type == kMTCharWise && yanklines == 1) {
|
||||||
yanklines = 0;
|
yanklines = 0;
|
||||||
}
|
}
|
||||||
// Some versions of Vi use ">=" here, some don't...
|
// Some versions of Vi use ">=" here, some don't...
|
||||||
@ -2481,12 +2485,12 @@ static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append)
|
|||||||
// redisplay now, so message is not deleted
|
// redisplay now, so message is not deleted
|
||||||
update_topline_redraw();
|
update_topline_redraw();
|
||||||
if (yanklines == 1) {
|
if (yanklines == 1) {
|
||||||
if (yanktype == MBLOCK) {
|
if (yank_type == kMTBlockWise) {
|
||||||
MSG(_("block of 1 line yanked"));
|
MSG(_("block of 1 line yanked"));
|
||||||
} else {
|
} else {
|
||||||
MSG(_("1 line yanked"));
|
MSG(_("1 line yanked"));
|
||||||
}
|
}
|
||||||
} else if (yanktype == MBLOCK) {
|
} else if (yank_type == kMTBlockWise) {
|
||||||
smsg(_("block of %" PRId64 " lines yanked"),
|
smsg(_("block of %" PRId64 " lines yanked"),
|
||||||
(int64_t)yanklines);
|
(int64_t)yanklines);
|
||||||
} else {
|
} else {
|
||||||
@ -2500,7 +2504,7 @@ static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append)
|
|||||||
*/
|
*/
|
||||||
curbuf->b_op_start = oap->start;
|
curbuf->b_op_start = oap->start;
|
||||||
curbuf->b_op_end = oap->end;
|
curbuf->b_op_end = oap->end;
|
||||||
if (yanktype == MLINE) {
|
if (yank_type == kMTLineWise) {
|
||||||
curbuf->b_op_start.col = 0;
|
curbuf->b_op_start.col = 0;
|
||||||
curbuf->b_op_end.col = MAXCOL;
|
curbuf->b_op_end.col = MAXCOL;
|
||||||
}
|
}
|
||||||
@ -2590,8 +2594,8 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags)
|
|||||||
int totlen = 0; /* init for gcc */
|
int totlen = 0; /* init for gcc */
|
||||||
linenr_T lnum;
|
linenr_T lnum;
|
||||||
colnr_T col;
|
colnr_T col;
|
||||||
long i; /* index in y_array[] */
|
long i; // index in y_array[]
|
||||||
int y_type;
|
MotionType y_type;
|
||||||
long y_size;
|
long y_size;
|
||||||
int oldlen;
|
int oldlen;
|
||||||
long y_width = 0;
|
long y_width = 0;
|
||||||
@ -2652,7 +2656,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (insert_string != NULL) {
|
if (insert_string != NULL) {
|
||||||
y_type = MCHAR;
|
y_type = kMTCharWise;
|
||||||
if (regname == '=') {
|
if (regname == '=') {
|
||||||
/* For the = register we need to split the string at NL
|
/* For the = register we need to split the string at NL
|
||||||
* characters.
|
* characters.
|
||||||
@ -2671,7 +2675,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags)
|
|||||||
++ptr;
|
++ptr;
|
||||||
/* A trailing '\n' makes the register linewise. */
|
/* A trailing '\n' makes the register linewise. */
|
||||||
if (*ptr == NUL) {
|
if (*ptr == NUL) {
|
||||||
y_type = MLINE;
|
y_type = kMTLineWise;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2712,7 +2716,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (y_type == MLINE) {
|
if (y_type == kMTLineWise) {
|
||||||
if (flags & PUT_LINE_SPLIT) {
|
if (flags & PUT_LINE_SPLIT) {
|
||||||
// "p" or "P" in Visual mode: split the lines to put the text in
|
// "p" or "P" in Visual mode: split the lines to put the text in
|
||||||
// between.
|
// between.
|
||||||
@ -2746,8 +2750,9 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags)
|
|||||||
curbuf->b_op_end = curwin->w_cursor; /* default for '] mark */
|
curbuf->b_op_end = curwin->w_cursor; /* default for '] mark */
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & PUT_LINE) /* :put command or "p" in Visual line mode. */
|
if (flags & PUT_LINE) { // :put command or "p" in Visual line mode.
|
||||||
y_type = MLINE;
|
y_type = kMTLineWise;
|
||||||
|
}
|
||||||
|
|
||||||
if (y_size == 0 || y_array == NULL) {
|
if (y_size == 0 || y_array == NULL) {
|
||||||
EMSG2(_("E353: Nothing in register %s"),
|
EMSG2(_("E353: Nothing in register %s"),
|
||||||
@ -2755,13 +2760,13 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags)
|
|||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (y_type == MBLOCK) {
|
if (y_type == kMTBlockWise) {
|
||||||
lnum = curwin->w_cursor.lnum + y_size + 1;
|
lnum = curwin->w_cursor.lnum + y_size + 1;
|
||||||
if (lnum > curbuf->b_ml.ml_line_count)
|
if (lnum > curbuf->b_ml.ml_line_count)
|
||||||
lnum = curbuf->b_ml.ml_line_count + 1;
|
lnum = curbuf->b_ml.ml_line_count + 1;
|
||||||
if (u_save(curwin->w_cursor.lnum - 1, lnum) == FAIL)
|
if (u_save(curwin->w_cursor.lnum - 1, lnum) == FAIL)
|
||||||
goto end;
|
goto end;
|
||||||
} else if (y_type == MLINE) {
|
} else if (y_type == kMTLineWise) {
|
||||||
lnum = curwin->w_cursor.lnum;
|
lnum = curwin->w_cursor.lnum;
|
||||||
/* Correct line number for closed fold. Don't move the cursor yet,
|
/* Correct line number for closed fold. Don't move the cursor yet,
|
||||||
* u_save() uses it. */
|
* u_save() uses it. */
|
||||||
@ -2785,7 +2790,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags)
|
|||||||
|
|
||||||
yanklen = (int)STRLEN(y_array[0]);
|
yanklen = (int)STRLEN(y_array[0]);
|
||||||
|
|
||||||
if (ve_flags == VE_ALL && y_type == MCHAR) {
|
if (ve_flags == VE_ALL && y_type == kMTCharWise) {
|
||||||
if (gchar_cursor() == TAB) {
|
if (gchar_cursor() == TAB) {
|
||||||
/* Don't need to insert spaces when "p" on the last position of a
|
/* Don't need to insert spaces when "p" on the last position of a
|
||||||
* tab or "P" on the first position. */
|
* tab or "P" on the first position. */
|
||||||
@ -2805,7 +2810,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags)
|
|||||||
/*
|
/*
|
||||||
* Block mode
|
* Block mode
|
||||||
*/
|
*/
|
||||||
if (y_type == MBLOCK) {
|
if (y_type == kMTBlockWise) {
|
||||||
char c = gchar_cursor();
|
char c = gchar_cursor();
|
||||||
colnr_T endcol2 = 0;
|
colnr_T endcol2 = 0;
|
||||||
|
|
||||||
@ -2953,12 +2958,10 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags)
|
|||||||
} else
|
} else
|
||||||
curwin->w_cursor.lnum = lnum;
|
curwin->w_cursor.lnum = lnum;
|
||||||
} else {
|
} else {
|
||||||
/*
|
// Character or Line mode
|
||||||
* Character or Line mode
|
if (y_type == kMTCharWise) {
|
||||||
*/
|
// if type is kMTCharWise, FORWARD is the same as BACKWARD on the next
|
||||||
if (y_type == MCHAR) {
|
// char
|
||||||
/* if type is MCHAR, FORWARD is the same as BACKWARD on the next
|
|
||||||
* char */
|
|
||||||
if (dir == FORWARD && gchar_cursor() != NUL) {
|
if (dir == FORWARD && gchar_cursor() != NUL) {
|
||||||
if (has_mbyte) {
|
if (has_mbyte) {
|
||||||
int bytelen = (*mb_ptr2len)(get_cursor_pos_ptr());
|
int bytelen = (*mb_ptr2len)(get_cursor_pos_ptr());
|
||||||
@ -2989,7 +2992,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags)
|
|||||||
/*
|
/*
|
||||||
* simple case: insert into current line
|
* simple case: insert into current line
|
||||||
*/
|
*/
|
||||||
if (y_type == MCHAR && y_size == 1) {
|
if (y_type == kMTCharWise && y_size == 1) {
|
||||||
do {
|
do {
|
||||||
totlen = count * yanklen;
|
totlen = count * yanklen;
|
||||||
if (totlen > 0) {
|
if (totlen > 0) {
|
||||||
@ -3024,18 +3027,14 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags)
|
|||||||
++curwin->w_cursor.col;
|
++curwin->w_cursor.col;
|
||||||
changed_bytes(lnum, col);
|
changed_bytes(lnum, col);
|
||||||
} else {
|
} else {
|
||||||
/*
|
// Insert at least one line. When y_type is kMTCharWise, break the first
|
||||||
* Insert at least one line. When y_type is MCHAR, break the first
|
// line in two.
|
||||||
* line in two.
|
for (cnt = 1; cnt <= count; cnt++) {
|
||||||
*/
|
|
||||||
for (cnt = 1; cnt <= count; ++cnt) {
|
|
||||||
i = 0;
|
i = 0;
|
||||||
if (y_type == MCHAR) {
|
if (y_type == kMTCharWise) {
|
||||||
/*
|
// Split the current line in two at the insert position.
|
||||||
* Split the current line in two at the insert position.
|
// First insert y_array[size - 1] in front of second line.
|
||||||
* First insert y_array[size - 1] in front of second line.
|
// Then append y_array[0] to first line.
|
||||||
* Then append y_array[0] to first line.
|
|
||||||
*/
|
|
||||||
lnum = new_cursor.lnum;
|
lnum = new_cursor.lnum;
|
||||||
ptr = ml_get(lnum) + col;
|
ptr = ml_get(lnum) + col;
|
||||||
totlen = (int)STRLEN(y_array[y_size - 1]);
|
totlen = (int)STRLEN(y_array[y_size - 1]);
|
||||||
@ -3059,10 +3058,11 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags)
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (; i < y_size; i++) {
|
for (; i < y_size; i++) {
|
||||||
if ((y_type != MCHAR || i < y_size - 1)
|
if ((y_type != kMTCharWise || i < y_size - 1)
|
||||||
&& ml_append(lnum, y_array[i], (colnr_T)0, FALSE)
|
&& ml_append(lnum, y_array[i], (colnr_T)0, false)
|
||||||
== FAIL)
|
== FAIL) {
|
||||||
goto error;
|
goto error;
|
||||||
|
}
|
||||||
lnum++;
|
lnum++;
|
||||||
++nr_lines;
|
++nr_lines;
|
||||||
if (flags & PUT_FIXINDENT) {
|
if (flags & PUT_FIXINDENT) {
|
||||||
@ -3091,22 +3091,23 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags)
|
|||||||
}
|
}
|
||||||
|
|
||||||
error:
|
error:
|
||||||
/* Adjust marks. */
|
// Adjust marks.
|
||||||
if (y_type == MLINE) {
|
if (y_type == kMTLineWise) {
|
||||||
curbuf->b_op_start.col = 0;
|
curbuf->b_op_start.col = 0;
|
||||||
if (dir == FORWARD)
|
if (dir == FORWARD)
|
||||||
curbuf->b_op_start.lnum++;
|
curbuf->b_op_start.lnum++;
|
||||||
}
|
}
|
||||||
mark_adjust(curbuf->b_op_start.lnum + (y_type == MCHAR),
|
mark_adjust(curbuf->b_op_start.lnum + (y_type == kMTCharWise),
|
||||||
(linenr_T)MAXLNUM, nr_lines, 0L);
|
(linenr_T)MAXLNUM, nr_lines, 0L);
|
||||||
|
|
||||||
/* note changed text for displaying and folding */
|
// note changed text for displaying and folding
|
||||||
if (y_type == MCHAR)
|
if (y_type == kMTCharWise) {
|
||||||
changed_lines(curwin->w_cursor.lnum, col,
|
changed_lines(curwin->w_cursor.lnum, col,
|
||||||
curwin->w_cursor.lnum + 1, nr_lines);
|
curwin->w_cursor.lnum + 1, nr_lines);
|
||||||
else
|
} else {
|
||||||
changed_lines(curbuf->b_op_start.lnum, 0,
|
changed_lines(curbuf->b_op_start.lnum, 0,
|
||||||
curbuf->b_op_start.lnum, nr_lines);
|
curbuf->b_op_start.lnum, nr_lines);
|
||||||
|
}
|
||||||
|
|
||||||
/* put '] mark at last inserted character */
|
/* put '] mark at last inserted character */
|
||||||
curbuf->b_op_end.lnum = lnum;
|
curbuf->b_op_end.lnum = lnum;
|
||||||
@ -3122,19 +3123,20 @@ error:
|
|||||||
curwin->w_cursor.lnum = lnum;
|
curwin->w_cursor.lnum = lnum;
|
||||||
beginline(BL_WHITE | BL_FIX);
|
beginline(BL_WHITE | BL_FIX);
|
||||||
} else if (flags & PUT_CURSEND) {
|
} else if (flags & PUT_CURSEND) {
|
||||||
/* put cursor after inserted text */
|
// put cursor after inserted text
|
||||||
if (y_type == MLINE) {
|
if (y_type == kMTLineWise) {
|
||||||
if (lnum >= curbuf->b_ml.ml_line_count)
|
if (lnum >= curbuf->b_ml.ml_line_count) {
|
||||||
curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
|
curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
|
||||||
else
|
} else {
|
||||||
curwin->w_cursor.lnum = lnum + 1;
|
curwin->w_cursor.lnum = lnum + 1;
|
||||||
|
}
|
||||||
curwin->w_cursor.col = 0;
|
curwin->w_cursor.col = 0;
|
||||||
} else {
|
} else {
|
||||||
curwin->w_cursor.lnum = lnum;
|
curwin->w_cursor.lnum = lnum;
|
||||||
curwin->w_cursor.col = col;
|
curwin->w_cursor.col = col;
|
||||||
}
|
}
|
||||||
} else if (y_type == MLINE) {
|
} else if (y_type == kMTLineWise) {
|
||||||
/* put cursor on first non-blank in first inserted line */
|
// put cursor on first non-blank in first inserted line
|
||||||
curwin->w_cursor.col = 0;
|
curwin->w_cursor.col = 0;
|
||||||
if (dir == FORWARD)
|
if (dir == FORWARD)
|
||||||
++curwin->w_cursor.lnum;
|
++curwin->w_cursor.lnum;
|
||||||
@ -3273,9 +3275,10 @@ void ex_display(exarg_T *eap)
|
|||||||
p += clen - 1;
|
p += clen - 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (n > 1 && yb->y_type == MLINE)
|
if (n > 1 && yb->y_type == kMTLineWise) {
|
||||||
MSG_PUTS_ATTR("^J", attr);
|
MSG_PUTS_ATTR("^J", attr);
|
||||||
ui_flush(); /* show one line at a time */
|
}
|
||||||
|
ui_flush(); // show one line at a time
|
||||||
}
|
}
|
||||||
os_breakcheck();
|
os_breakcheck();
|
||||||
}
|
}
|
||||||
@ -4265,18 +4268,18 @@ void op_addsub(oparg_T *oap, linenr_T Prenum1, bool g_cmd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
pos = oap->start;
|
pos = oap->start;
|
||||||
for (; pos.lnum <= oap->end.lnum; ++pos.lnum) {
|
for (; pos.lnum <= oap->end.lnum; pos.lnum++) {
|
||||||
if (oap->motion_type == MBLOCK) {
|
if (oap->motion_type == kMTBlockWise) {
|
||||||
// Visual block mode
|
// Visual block mode
|
||||||
block_prep(oap, &bd, pos.lnum, false);
|
block_prep(oap, &bd, pos.lnum, false);
|
||||||
pos.col = bd.textcol;
|
pos.col = bd.textcol;
|
||||||
length = bd.textlen;
|
length = bd.textlen;
|
||||||
} else if (oap->motion_type == MLINE) {
|
} else if (oap->motion_type == kMTLineWise) {
|
||||||
curwin->w_cursor.col = 0;
|
curwin->w_cursor.col = 0;
|
||||||
pos.col = 0;
|
pos.col = 0;
|
||||||
length = (colnr_T)STRLEN(ml_get(pos.lnum));
|
length = (colnr_T)STRLEN(ml_get(pos.lnum));
|
||||||
} else {
|
} else {
|
||||||
// oap->motion_type == MCHAR
|
// oap->motion_type == kMTCharWise
|
||||||
if (!oap->inclusive) {
|
if (!oap->inclusive) {
|
||||||
dec(&(oap->end));
|
dec(&(oap->end));
|
||||||
}
|
}
|
||||||
@ -4679,64 +4682,65 @@ theend:
|
|||||||
/*
|
/*
|
||||||
* Return the type of a register.
|
* Return the type of a register.
|
||||||
* Used for getregtype()
|
* Used for getregtype()
|
||||||
* Returns MAUTO for error.
|
* Returns kMTUnknown for error.
|
||||||
*/
|
*/
|
||||||
char_u get_reg_type(int regname, colnr_T *reg_width)
|
MotionType get_reg_type(int regname, colnr_T *reg_width)
|
||||||
{
|
{
|
||||||
switch (regname) {
|
switch (regname) {
|
||||||
case '%': /* file name */
|
case '%': // file name
|
||||||
case '#': /* alternate file name */
|
case '#': // alternate file name
|
||||||
case '=': /* expression */
|
case '=': // expression
|
||||||
case ':': /* last command line */
|
case ':': // last command line
|
||||||
case '/': /* last search-pattern */
|
case '/': // last search-pattern
|
||||||
case '.': /* last inserted text */
|
case '.': // last inserted text
|
||||||
case Ctrl_F: /* Filename under cursor */
|
case Ctrl_F: // Filename under cursor
|
||||||
case Ctrl_P: /* Path under cursor, expand via "path" */
|
case Ctrl_P: // Path under cursor, expand via "path"
|
||||||
case Ctrl_W: /* word under cursor */
|
case Ctrl_W: // word under cursor
|
||||||
case Ctrl_A: /* WORD (mnemonic All) under cursor */
|
case Ctrl_A: // WORD (mnemonic All) under cursor
|
||||||
case '_': /* black hole: always empty */
|
case '_': // black hole: always empty
|
||||||
return MCHAR;
|
return kMTCharWise;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (regname != NUL && !valid_yank_reg(regname, false))
|
if (regname != NUL && !valid_yank_reg(regname, false)) {
|
||||||
return MAUTO;
|
return kMTUnknown;
|
||||||
|
}
|
||||||
|
|
||||||
yankreg_T *reg = get_yank_register(regname, YREG_PASTE);
|
yankreg_T *reg = get_yank_register(regname, YREG_PASTE);
|
||||||
|
|
||||||
if (reg->y_array != NULL) {
|
if (reg->y_array != NULL) {
|
||||||
if (reg_width != NULL && reg->y_type == MBLOCK) {
|
if (reg_width != NULL && reg->y_type == kMTBlockWise) {
|
||||||
*reg_width = reg->y_width;
|
*reg_width = reg->y_width;
|
||||||
}
|
}
|
||||||
return reg->y_type;
|
return reg->y_type;
|
||||||
}
|
}
|
||||||
return MAUTO;
|
return kMTUnknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Format the register type as a string.
|
/// Format the register type as a string.
|
||||||
///
|
///
|
||||||
/// @param reg_type The register type.
|
/// @param reg_type The register type.
|
||||||
/// @param reg_width The width, only used if "reg_type" is MBLOCK.
|
/// @param reg_width The width, only used if "reg_type" is kMTBlockWise.
|
||||||
/// @param[out] buf Buffer to store formatted string. The allocated size should
|
/// @param[out] buf Buffer to store formatted string. The allocated size should
|
||||||
/// be at least NUMBUFLEN+2 to always fit the value.
|
/// be at least NUMBUFLEN+2 to always fit the value.
|
||||||
/// @param buf_len The allocated size of the buffer.
|
/// @param buf_len The allocated size of the buffer.
|
||||||
void format_reg_type(char_u reg_type, colnr_T reg_width,
|
void format_reg_type(MotionType reg_type, colnr_T reg_width,
|
||||||
char* buf, size_t buf_len)
|
char *buf, size_t buf_len)
|
||||||
FUNC_ATTR_NONNULL_ALL
|
FUNC_ATTR_NONNULL_ALL
|
||||||
{
|
{
|
||||||
assert(buf_len > 1);
|
assert(buf_len > 1);
|
||||||
switch (reg_type) {
|
switch (reg_type) {
|
||||||
case MLINE:
|
case kMTLineWise:
|
||||||
buf[0] = 'V';
|
buf[0] = 'V';
|
||||||
buf[1] = NUL;
|
buf[1] = NUL;
|
||||||
break;
|
break;
|
||||||
case MCHAR:
|
case kMTCharWise:
|
||||||
buf[0] = 'v';
|
buf[0] = 'v';
|
||||||
buf[1] = NUL;
|
buf[1] = NUL;
|
||||||
break;
|
break;
|
||||||
case MBLOCK:
|
case kMTBlockWise:
|
||||||
snprintf(buf, buf_len, CTRL_V_STR "%" PRIdCOLNR, reg_width + 1);
|
snprintf(buf, buf_len, CTRL_V_STR "%" PRIdCOLNR, reg_width + 1);
|
||||||
break;
|
break;
|
||||||
case MAUTO:
|
case kMTUnknown:
|
||||||
buf[0] = NUL;
|
buf[0] = NUL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -4821,10 +4825,11 @@ void *get_reg_contents(int regname, int flags)
|
|||||||
len += STRLEN(reg->y_array[i]);
|
len += STRLEN(reg->y_array[i]);
|
||||||
/*
|
/*
|
||||||
* Insert a newline between lines and after last line if
|
* Insert a newline between lines and after last line if
|
||||||
* y_type is MLINE.
|
* y_type is kMTLineWise.
|
||||||
*/
|
*/
|
||||||
if (reg->y_type == MLINE || i < reg->y_size - 1)
|
if (reg->y_type == kMTLineWise || i < reg->y_size - 1) {
|
||||||
++len;
|
len++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
retval = xmalloc(len + 1);
|
retval = xmalloc(len + 1);
|
||||||
@ -4839,10 +4844,11 @@ void *get_reg_contents(int regname, int flags)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Insert a NL between lines and after the last line if y_type is
|
* Insert a NL between lines and after the last line if y_type is
|
||||||
* MLINE.
|
* kMTLineWise.
|
||||||
*/
|
*/
|
||||||
if (reg->y_type == MLINE || i < reg->y_size - 1)
|
if (reg->y_type == kMTLineWise || i < reg->y_size - 1) {
|
||||||
retval[len++] = '\n';
|
retval[len++] = '\n';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
retval[len] = NUL;
|
retval[len] = NUL;
|
||||||
|
|
||||||
@ -4883,11 +4889,12 @@ static void finish_write_reg(int name, yankreg_T *reg, yankreg_T *old_y_previous
|
|||||||
void write_reg_contents(int name, const char_u *str, ssize_t len,
|
void write_reg_contents(int name, const char_u *str, ssize_t len,
|
||||||
int must_append)
|
int must_append)
|
||||||
{
|
{
|
||||||
write_reg_contents_ex(name, str, len, must_append, MAUTO, 0L);
|
write_reg_contents_ex(name, str, len, must_append, kMTUnknown, 0L);
|
||||||
}
|
}
|
||||||
|
|
||||||
void write_reg_contents_lst(int name, char_u **strings, int maxlen,
|
void write_reg_contents_lst(int name, char_u **strings, int maxlen,
|
||||||
bool must_append, int yank_type, long block_len)
|
bool must_append, MotionType yank_type,
|
||||||
|
long block_len)
|
||||||
{
|
{
|
||||||
if (name == '/' || name == '=') {
|
if (name == '/' || name == '=') {
|
||||||
char_u *s = strings[0];
|
char_u *s = strings[0];
|
||||||
@ -4933,13 +4940,13 @@ void write_reg_contents_lst(int name, char_u **strings, int maxlen,
|
|||||||
/// contents of the register. Note that regardless of
|
/// contents of the register. Note that regardless of
|
||||||
/// `must_append`, this function will append when `name`
|
/// `must_append`, this function will append when `name`
|
||||||
/// is an uppercase letter.
|
/// is an uppercase letter.
|
||||||
/// @param yank_type MCHAR, MLINE, MBLOCK or MAUTO
|
/// @param yank_type The motion type (kMTUnknown to auto detect)
|
||||||
/// @param block_len width of visual block
|
/// @param block_len width of visual block
|
||||||
void write_reg_contents_ex(int name,
|
void write_reg_contents_ex(int name,
|
||||||
const char_u *str,
|
const char_u *str,
|
||||||
ssize_t len,
|
ssize_t len,
|
||||||
bool must_append,
|
bool must_append,
|
||||||
int yank_type,
|
MotionType yank_type,
|
||||||
long block_len)
|
long block_len)
|
||||||
{
|
{
|
||||||
if (len < 0) {
|
if (len < 0) {
|
||||||
@ -5013,24 +5020,24 @@ void write_reg_contents_ex(int name,
|
|||||||
/// When the register is not empty, the string is appended.
|
/// When the register is not empty, the string is appended.
|
||||||
///
|
///
|
||||||
/// @param y_ptr pointer to yank register
|
/// @param y_ptr pointer to yank register
|
||||||
/// @param yank_type MCHAR, MLINE, MBLOCK or MAUTO
|
/// @param yank_type The motion type (kMTUnknown to auto detect)
|
||||||
/// @param str string or list of strings to put in register
|
/// @param str string or list of strings to put in register
|
||||||
/// @param len length of the string (Ignored when str_list=true.)
|
/// @param len length of the string (Ignored when str_list=true.)
|
||||||
/// @param blocklen width of visual block, or -1 for "I don't know."
|
/// @param blocklen width of visual block, or -1 for "I don't know."
|
||||||
/// @param str_list True if str is `char_u **`.
|
/// @param str_list True if str is `char_u **`.
|
||||||
static void str_to_reg(yankreg_T *y_ptr, int yank_type, const char_u *str,
|
static void str_to_reg(yankreg_T *y_ptr, MotionType yank_type,
|
||||||
size_t len, colnr_T blocklen, bool str_list)
|
const char_u *str, size_t len, colnr_T blocklen,
|
||||||
|
bool str_list)
|
||||||
FUNC_ATTR_NONNULL_ALL
|
FUNC_ATTR_NONNULL_ALL
|
||||||
{
|
{
|
||||||
if (y_ptr->y_array == NULL) { // NULL means empty register
|
if (y_ptr->y_array == NULL) { // NULL means empty register
|
||||||
y_ptr->y_size = 0;
|
y_ptr->y_size = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int type = yank_type; // MCHAR, MLINE or MBLOCK
|
if (yank_type == kMTUnknown) {
|
||||||
if (yank_type == MAUTO) {
|
yank_type = ((str_list ||
|
||||||
type = ((str_list ||
|
(len > 0 && (str[len - 1] == NL || str[len - 1] == CAR)))
|
||||||
(len > 0 && (str[len - 1] == NL || str[len - 1] == CAR)))
|
? kMTLineWise : kMTCharWise);
|
||||||
? MLINE : MCHAR);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t newlines = 0;
|
size_t newlines = 0;
|
||||||
@ -5044,11 +5051,11 @@ static void str_to_reg(yankreg_T *y_ptr, int yank_type, const char_u *str,
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
newlines = memcnt(str, '\n', len);
|
newlines = memcnt(str, '\n', len);
|
||||||
if (type == MCHAR || len == 0 || str[len - 1] != '\n') {
|
if (yank_type == kMTCharWise || len == 0 || str[len - 1] != '\n') {
|
||||||
extraline = 1;
|
extraline = 1;
|
||||||
++newlines; // count extra newline at the end
|
++newlines; // count extra newline at the end
|
||||||
}
|
}
|
||||||
if (y_ptr->y_size > 0 && y_ptr->y_type == MCHAR) {
|
if (y_ptr->y_size > 0 && y_ptr->y_type == kMTCharWise) {
|
||||||
append = true;
|
append = true;
|
||||||
--newlines; // uncount newline when appending first line
|
--newlines; // uncount newline when appending first line
|
||||||
}
|
}
|
||||||
@ -5101,11 +5108,11 @@ static void str_to_reg(yankreg_T *y_ptr, int yank_type, const char_u *str,
|
|||||||
memchrsub(pp[lnum], NUL, '\n', s_len);
|
memchrsub(pp[lnum], NUL, '\n', s_len);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
y_ptr->y_type = type;
|
y_ptr->y_type = yank_type;
|
||||||
y_ptr->y_size = lnum;
|
y_ptr->y_size = lnum;
|
||||||
set_yreg_additional_data(y_ptr, NULL);
|
set_yreg_additional_data(y_ptr, NULL);
|
||||||
y_ptr->timestamp = os_time();
|
y_ptr->timestamp = os_time();
|
||||||
if (type == MBLOCK) {
|
if (yank_type == kMTBlockWise) {
|
||||||
y_ptr->y_width = (blocklen == -1 ? (colnr_T) maxlen - 1 : blocklen);
|
y_ptr->y_width = (blocklen == -1 ? (colnr_T) maxlen - 1 : blocklen);
|
||||||
} else {
|
} else {
|
||||||
y_ptr->y_width = 0;
|
y_ptr->y_width = 0;
|
||||||
@ -5218,7 +5225,7 @@ void cursor_pos_info(void)
|
|||||||
/* Make 'sbr' empty for a moment to get the correct size. */
|
/* Make 'sbr' empty for a moment to get the correct size. */
|
||||||
p_sbr = empty_option;
|
p_sbr = empty_option;
|
||||||
oparg.is_VIsual = true;
|
oparg.is_VIsual = true;
|
||||||
oparg.motion_type = MBLOCK;
|
oparg.motion_type = kMTBlockWise;
|
||||||
oparg.op_type = OP_NOP;
|
oparg.op_type = OP_NOP;
|
||||||
getvcols(curwin, &min_pos, &max_pos,
|
getvcols(curwin, &min_pos, &max_pos,
|
||||||
&oparg.start_vcol, &oparg.end_vcol);
|
&oparg.start_vcol, &oparg.end_vcol);
|
||||||
@ -5473,16 +5480,16 @@ static bool get_clipboard(int name, yankreg_T **target, bool quiet)
|
|||||||
}
|
}
|
||||||
switch (regtype[0]) {
|
switch (regtype[0]) {
|
||||||
case 0:
|
case 0:
|
||||||
reg->y_type = MAUTO;
|
reg->y_type = kMTUnknown;
|
||||||
break;
|
break;
|
||||||
case 'v': case 'c':
|
case 'v': case 'c':
|
||||||
reg->y_type = MCHAR;
|
reg->y_type = kMTCharWise;
|
||||||
break;
|
break;
|
||||||
case 'V': case 'l':
|
case 'V': case 'l':
|
||||||
reg->y_type = MLINE;
|
reg->y_type = kMTLineWise;
|
||||||
break;
|
break;
|
||||||
case 'b': case Ctrl_V:
|
case 'b': case Ctrl_V:
|
||||||
reg->y_type = MBLOCK;
|
reg->y_type = kMTBlockWise;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
goto err;
|
goto err;
|
||||||
@ -5490,7 +5497,7 @@ static bool get_clipboard(int name, yankreg_T **target, bool quiet)
|
|||||||
} else {
|
} else {
|
||||||
lines = res;
|
lines = res;
|
||||||
// provider did not specify regtype, calculate it below
|
// provider did not specify regtype, calculate it below
|
||||||
reg->y_type = MAUTO;
|
reg->y_type = kMTUnknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
reg->y_array = xcalloc(lines->lv_len, sizeof(uint8_t *));
|
reg->y_array = xcalloc(lines->lv_len, sizeof(uint8_t *));
|
||||||
@ -5511,20 +5518,20 @@ static bool get_clipboard(int name, yankreg_T **target, bool quiet)
|
|||||||
if (reg->y_size > 0 && strlen((char*)reg->y_array[reg->y_size-1]) == 0) {
|
if (reg->y_size > 0 && strlen((char*)reg->y_array[reg->y_size-1]) == 0) {
|
||||||
// a known-to-be charwise yank might have a final linebreak
|
// a known-to-be charwise yank might have a final linebreak
|
||||||
// but otherwise there is no line after the final newline
|
// but otherwise there is no line after the final newline
|
||||||
if (reg->y_type != MCHAR) {
|
if (reg->y_type != kMTCharWise) {
|
||||||
xfree(reg->y_array[reg->y_size-1]);
|
xfree(reg->y_array[reg->y_size-1]);
|
||||||
reg->y_size--;
|
reg->y_size--;
|
||||||
if (reg->y_type == MAUTO) {
|
if (reg->y_type == kMTUnknown) {
|
||||||
reg->y_type = MLINE;
|
reg->y_type = kMTLineWise;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (reg->y_type == MAUTO) {
|
if (reg->y_type == kMTUnknown) {
|
||||||
reg->y_type = MCHAR;
|
reg->y_type = kMTCharWise;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (reg->y_type == MBLOCK) {
|
if (reg->y_type == kMTBlockWise) {
|
||||||
int maxlen = 0;
|
int maxlen = 0;
|
||||||
for (int i = 0; i < reg->y_size; i++) {
|
for (int i = 0; i < reg->y_size; i++) {
|
||||||
int rowlen = STRLEN(reg->y_array[i]);
|
int rowlen = STRLEN(reg->y_array[i]);
|
||||||
@ -5573,17 +5580,19 @@ static void set_clipboard(int name, yankreg_T *reg)
|
|||||||
|
|
||||||
char_u regtype;
|
char_u regtype;
|
||||||
switch (reg->y_type) {
|
switch (reg->y_type) {
|
||||||
case MLINE:
|
case kMTLineWise:
|
||||||
regtype = 'V';
|
regtype = 'V';
|
||||||
list_append_string(lines, (char_u*)"", 0);
|
list_append_string(lines, (char_u*)"", 0);
|
||||||
break;
|
break;
|
||||||
case MCHAR:
|
case kMTCharWise:
|
||||||
regtype = 'v';
|
regtype = 'v';
|
||||||
break;
|
break;
|
||||||
case MBLOCK:
|
case kMTBlockWise:
|
||||||
regtype = 'b';
|
regtype = 'b';
|
||||||
list_append_string(lines, (char_u*)"", 0);
|
list_append_string(lines, (char_u*)"", 0);
|
||||||
break;
|
break;
|
||||||
|
case kMTUnknown:
|
||||||
|
assert(false);
|
||||||
}
|
}
|
||||||
list_append_string(args, ®type, 1);
|
list_append_string(args, ®type, 1);
|
||||||
|
|
||||||
@ -5624,7 +5633,7 @@ static inline bool reg_empty(const yankreg_T *const reg)
|
|||||||
return (reg->y_array == NULL
|
return (reg->y_array == NULL
|
||||||
|| reg->y_size == 0
|
|| reg->y_size == 0
|
||||||
|| (reg->y_size == 1
|
|| (reg->y_size == 1
|
||||||
&& reg->y_type == MCHAR
|
&& reg->y_type == kMTCharWise
|
||||||
&& *(reg->y_array[0]) == NUL));
|
&& *(reg->y_array[0]) == NUL));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,10 +78,10 @@ enum GRegFlags {
|
|||||||
|
|
||||||
/// Definition of one register
|
/// Definition of one register
|
||||||
typedef struct yankreg {
|
typedef struct yankreg {
|
||||||
char_u **y_array; ///< Pointer to an array of line pointers.
|
char_u **y_array; ///< Pointer to an array of line pointers.
|
||||||
linenr_T y_size; ///< Number of lines in y_array.
|
linenr_T y_size; ///< Number of lines in y_array.
|
||||||
char_u y_type; ///< Register type: MLINE, MCHAR or MBLOCK.
|
MotionType y_type; ///< Register type
|
||||||
colnr_T y_width; ///< Register width (only valid for y_type == MBLOCK).
|
colnr_T y_width; ///< Register width (only valid for y_type == kBlockWise).
|
||||||
Timestamp timestamp; ///< Time when register was last modified.
|
Timestamp timestamp; ///< Time when register was last modified.
|
||||||
dict_T *additional_data; ///< Additional data from ShaDa file.
|
dict_T *additional_data; ///< Additional data from ShaDa file.
|
||||||
} yankreg_T;
|
} 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
|
* Look for matching #if, #else, #elif, or #endif
|
||||||
*/
|
*/
|
||||||
if (oap != NULL)
|
if (oap != NULL) {
|
||||||
oap->motion_type = MLINE; /* Linewise for this case only */
|
oap->motion_type = kMTLineWise; // Linewise for this case only
|
||||||
|
}
|
||||||
if (initc != '#') {
|
if (initc != '#') {
|
||||||
ptr = skipwhite(skipwhite(linep) + 1);
|
ptr = skipwhite(skipwhite(linep) + 1);
|
||||||
if (STRNCMP(ptr, "if", 2) == 0 || STRNCMP(ptr, "el", 2) == 0)
|
if (STRNCMP(ptr, "if", 2) == 0 || STRNCMP(ptr, "el", 2) == 0)
|
||||||
@ -2793,7 +2794,7 @@ current_word (
|
|||||||
redraw_curbuf_later(INVERTED); /* update the inversion */
|
redraw_curbuf_later(INVERTED); /* update the inversion */
|
||||||
} else {
|
} else {
|
||||||
oap->start = start_pos;
|
oap->start = start_pos;
|
||||||
oap->motion_type = MCHAR;
|
oap->motion_type = kMTCharWise;
|
||||||
}
|
}
|
||||||
--count;
|
--count;
|
||||||
}
|
}
|
||||||
@ -3028,7 +3029,7 @@ extend:
|
|||||||
else
|
else
|
||||||
oap->inclusive = false;
|
oap->inclusive = false;
|
||||||
oap->start = start_pos;
|
oap->start = start_pos;
|
||||||
oap->motion_type = MCHAR;
|
oap->motion_type = kMTCharWise;
|
||||||
}
|
}
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
@ -3152,7 +3153,7 @@ current_block (
|
|||||||
showmode();
|
showmode();
|
||||||
} else {
|
} else {
|
||||||
oap->start = start_pos;
|
oap->start = start_pos;
|
||||||
oap->motion_type = MCHAR;
|
oap->motion_type = kMTCharWise;
|
||||||
oap->inclusive = false;
|
oap->inclusive = false;
|
||||||
if (sol)
|
if (sol)
|
||||||
incl(&curwin->w_cursor);
|
incl(&curwin->w_cursor);
|
||||||
@ -3399,7 +3400,7 @@ again:
|
|||||||
showmode();
|
showmode();
|
||||||
} else {
|
} else {
|
||||||
oap->start = start_pos;
|
oap->start = start_pos;
|
||||||
oap->motion_type = MCHAR;
|
oap->motion_type = kMTCharWise;
|
||||||
if (lt(end_pos, start_pos)) {
|
if (lt(end_pos, start_pos)) {
|
||||||
/* End is before the start: there is no text between tags; operate
|
/* End is before the start: there is no text between tags; operate
|
||||||
* on an empty area. */
|
* on an empty area. */
|
||||||
@ -3564,7 +3565,7 @@ extend:
|
|||||||
} else {
|
} else {
|
||||||
oap->start.lnum = start_lnum;
|
oap->start.lnum = start_lnum;
|
||||||
oap->start.col = 0;
|
oap->start.col = 0;
|
||||||
oap->motion_type = MLINE;
|
oap->motion_type = kMTLineWise;
|
||||||
}
|
}
|
||||||
curwin->w_cursor.lnum = end_lnum;
|
curwin->w_cursor.lnum = end_lnum;
|
||||||
curwin->w_cursor.col = 0;
|
curwin->w_cursor.col = 0;
|
||||||
@ -3806,7 +3807,7 @@ current_quote (
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
oap->start = curwin->w_cursor;
|
oap->start = curwin->w_cursor;
|
||||||
oap->motion_type = MCHAR;
|
oap->motion_type = kMTCharWise;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set end position. */
|
/* Set end position. */
|
||||||
|
@ -283,7 +283,7 @@ typedef struct {
|
|||||||
} history_item;
|
} history_item;
|
||||||
struct reg {
|
struct reg {
|
||||||
char name;
|
char name;
|
||||||
uint8_t type;
|
MotionType type;
|
||||||
char **contents;
|
char **contents;
|
||||||
size_t contents_size;
|
size_t contents_size;
|
||||||
size_t width;
|
size_t width;
|
||||||
@ -475,7 +475,7 @@ static const ShadaEntry sd_default_values[] = {
|
|||||||
.additional_elements = NULL),
|
.additional_elements = NULL),
|
||||||
DEF_SDE(Register, reg,
|
DEF_SDE(Register, reg,
|
||||||
.name = NUL,
|
.name = NUL,
|
||||||
.type = MCHAR,
|
.type = kMTCharWise,
|
||||||
.contents = NULL,
|
.contents = NULL,
|
||||||
.contents_size = 0,
|
.contents_size = 0,
|
||||||
.width = 0,
|
.width = 0,
|
||||||
@ -1407,9 +1407,9 @@ static void shada_read(ShaDaReadDef *const sd_reader, const int flags)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case kSDItemRegister: {
|
case kSDItemRegister: {
|
||||||
if (cur_entry.data.reg.type != MCHAR
|
if (cur_entry.data.reg.type != kMTCharWise
|
||||||
&& cur_entry.data.reg.type != MLINE
|
&& cur_entry.data.reg.type != kMTLineWise
|
||||||
&& cur_entry.data.reg.type != MBLOCK) {
|
&& cur_entry.data.reg.type != kMTBlockWise) {
|
||||||
shada_free_shada_entry(&cur_entry);
|
shada_free_shada_entry(&cur_entry);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1882,7 +1882,7 @@ static ShaDaWriteResult shada_pack_entry(msgpack_packer *const packer,
|
|||||||
msgpack_pack_char(spacker, entry.data.reg.name);
|
msgpack_pack_char(spacker, entry.data.reg.name);
|
||||||
if (!CHECK_DEFAULT(entry, reg.type)) {
|
if (!CHECK_DEFAULT(entry, reg.type)) {
|
||||||
PACK_STATIC_STR(REG_KEY_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)) {
|
if (!CHECK_DEFAULT(entry, reg.width)) {
|
||||||
PACK_STATIC_STR(REG_KEY_WIDTH);
|
PACK_STATIC_STR(REG_KEY_WIDTH);
|
||||||
@ -2757,8 +2757,8 @@ static ShaDaWriteResult shada_write(ShaDaWriteDef *const sd_writer,
|
|||||||
.reg = {
|
.reg = {
|
||||||
.contents = (char **) reg.y_array,
|
.contents = (char **) reg.y_array,
|
||||||
.contents_size = (size_t) reg.y_size,
|
.contents_size = (size_t) reg.y_size,
|
||||||
.type = (uint8_t) reg.y_type,
|
.type = reg.y_type,
|
||||||
.width = (size_t) (reg.y_type == MBLOCK ? reg.y_width : 0),
|
.width = (size_t) (reg.y_type == kMTBlockWise ? reg.y_width : 0),
|
||||||
.additional_data = reg.additional_data,
|
.additional_data = reg.additional_data,
|
||||||
.name = name,
|
.name = name,
|
||||||
}
|
}
|
||||||
|
@ -201,15 +201,6 @@ enum {
|
|||||||
|
|
||||||
#define MAYBE 2 /* sometimes used for a variant on TRUE */
|
#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 STATUS_HEIGHT 1 /* height of a status line under a window */
|
||||||
#define QF_WINHEIGHT 10 /* default height for quickfix window */
|
#define QF_WINHEIGHT 10 /* default height for quickfix window */
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user