mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 03:18:16 +00:00
vim-patch:9.0.1208: code is indented more than necessary (#21846)
Problem: Code is indented more than necessary.
Solution: Use an early return where it makes sense. (Yegappan Lakshmanan,
closes vim/vim#11819)
a41e221935
Cherry-pick check_text_or_curbuf_locked() from patch 9.0.0947.
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
This commit is contained in:
@@ -451,12 +451,34 @@ static int find_command(int cmdchar)
|
|||||||
/// message, return true.
|
/// message, return true.
|
||||||
static bool check_text_locked(oparg_T *oap)
|
static bool check_text_locked(oparg_T *oap)
|
||||||
{
|
{
|
||||||
if (text_locked()) {
|
if (!text_locked()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (oap != NULL) {
|
||||||
clearopbeep(oap);
|
clearopbeep(oap);
|
||||||
text_locked_msg();
|
}
|
||||||
|
text_locked_msg();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// If text is locked, "curbuf->b_ro_locked" or "allbuf_lock" is set:
|
||||||
|
/// Give an error message, possibly beep and return true.
|
||||||
|
/// "oap" may be NULL.
|
||||||
|
static bool check_text_or_curbuf_locked(oparg_T *oap)
|
||||||
|
{
|
||||||
|
if (check_text_locked(oap)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
|
if (!curbuf_locked()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (oap != NULL) {
|
||||||
|
clearop(oap);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Normal state entry point. This is called on:
|
/// Normal state entry point. This is called on:
|
||||||
@@ -1107,8 +1129,7 @@ static int normal_execute(VimState *state, int key)
|
|||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((nv_cmds[s->idx].cmd_flags & NV_NCW)
|
if ((nv_cmds[s->idx].cmd_flags & NV_NCW) && check_text_or_curbuf_locked(&s->oa)) {
|
||||||
&& (check_text_locked(&s->oa) || curbuf_locked())) {
|
|
||||||
// this command is not allowed now
|
// this command is not allowed now
|
||||||
s->command_finished = true;
|
s->command_finished = true;
|
||||||
goto finish;
|
goto finish;
|
||||||
@@ -2191,17 +2212,19 @@ static void nv_addsub(cmdarg_T *cap)
|
|||||||
/// CTRL-F, CTRL-B, etc: Scroll page up or down.
|
/// CTRL-F, CTRL-B, etc: Scroll page up or down.
|
||||||
static void nv_page(cmdarg_T *cap)
|
static void nv_page(cmdarg_T *cap)
|
||||||
{
|
{
|
||||||
if (!checkclearop(cap->oap)) {
|
if (checkclearop(cap->oap)) {
|
||||||
if (mod_mask & MOD_MASK_CTRL) {
|
return;
|
||||||
// <C-PageUp>: tab page back; <C-PageDown>: tab page forward
|
}
|
||||||
if (cap->arg == BACKWARD) {
|
|
||||||
goto_tabpage(-(int)cap->count1);
|
if (mod_mask & MOD_MASK_CTRL) {
|
||||||
} else {
|
// <C-PageUp>: tab page back; <C-PageDown>: tab page forward
|
||||||
goto_tabpage((int)cap->count0);
|
if (cap->arg == BACKWARD) {
|
||||||
}
|
goto_tabpage(-(int)cap->count1);
|
||||||
} else {
|
} else {
|
||||||
(void)onepage(cap->arg, cap->count1);
|
goto_tabpage((int)cap->count0);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
(void)onepage(cap->arg, cap->count1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2215,14 +2238,15 @@ static void nv_gd(oparg_T *oap, int nchar, int thisblock)
|
|||||||
if ((len = find_ident_under_cursor(&ptr, FIND_IDENT)) == 0
|
if ((len = find_ident_under_cursor(&ptr, FIND_IDENT)) == 0
|
||||||
|| !find_decl((char_u *)ptr, len, nchar == 'd', thisblock, SEARCH_START)) {
|
|| !find_decl((char_u *)ptr, len, nchar == 'd', thisblock, SEARCH_START)) {
|
||||||
clearopbeep(oap);
|
clearopbeep(oap);
|
||||||
} else {
|
return;
|
||||||
if ((fdo_flags & FDO_SEARCH) && KeyTyped && oap->op_type == OP_NOP) {
|
}
|
||||||
foldOpenCursor();
|
|
||||||
}
|
if ((fdo_flags & FDO_SEARCH) && KeyTyped && oap->op_type == OP_NOP) {
|
||||||
// clear any search statistics
|
foldOpenCursor();
|
||||||
if (messaging() && !msg_silent && !shortmess(SHM_SEARCHCOUNT)) {
|
}
|
||||||
clear_cmdline = true;
|
// clear any search statistics
|
||||||
}
|
if (messaging() && !msg_silent && !shortmess(SHM_SEARCHCOUNT)) {
|
||||||
|
clear_cmdline = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3195,44 +3219,45 @@ static void nv_colon(cmdarg_T *cap)
|
|||||||
|
|
||||||
if (VIsual_active && !is_cmdkey && !is_lua) {
|
if (VIsual_active && !is_cmdkey && !is_lua) {
|
||||||
nv_operator(cap);
|
nv_operator(cap);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cap->oap->op_type != OP_NOP) {
|
||||||
|
// Using ":" as a movement is charwise exclusive.
|
||||||
|
cap->oap->motion_type = kMTCharWise;
|
||||||
|
cap->oap->inclusive = false;
|
||||||
|
} else if (cap->count0 && !is_cmdkey && !is_lua) {
|
||||||
|
// translate "count:" into ":.,.+(count - 1)"
|
||||||
|
stuffcharReadbuff('.');
|
||||||
|
if (cap->count0 > 1) {
|
||||||
|
stuffReadbuff(",.+");
|
||||||
|
stuffnumReadbuff(cap->count0 - 1L);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// When typing, don't type below an old message
|
||||||
|
if (KeyTyped) {
|
||||||
|
compute_cmdrow();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_lua) {
|
||||||
|
cmd_result = map_execute_lua();
|
||||||
} else {
|
} else {
|
||||||
if (cap->oap->op_type != OP_NOP) {
|
// get a command line and execute it
|
||||||
// Using ":" as a movement is charwise exclusive.
|
cmd_result = do_cmdline(NULL, is_cmdkey ? getcmdkeycmd : getexline, NULL,
|
||||||
cap->oap->motion_type = kMTCharWise;
|
cap->oap->op_type != OP_NOP ? DOCMD_KEEPLINE : 0);
|
||||||
cap->oap->inclusive = false;
|
}
|
||||||
} else if (cap->count0 && !is_cmdkey && !is_lua) {
|
|
||||||
// translate "count:" into ":.,.+(count - 1)"
|
|
||||||
stuffcharReadbuff('.');
|
|
||||||
if (cap->count0 > 1) {
|
|
||||||
stuffReadbuff(",.+");
|
|
||||||
stuffnumReadbuff(cap->count0 - 1L);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// When typing, don't type below an old message
|
if (cmd_result == false) {
|
||||||
if (KeyTyped) {
|
// The Ex command failed, do not execute the operator.
|
||||||
compute_cmdrow();
|
clearop(cap->oap);
|
||||||
}
|
} else if (cap->oap->op_type != OP_NOP
|
||||||
|
&& (cap->oap->start.lnum > curbuf->b_ml.ml_line_count
|
||||||
if (is_lua) {
|
|| cap->oap->start.col >
|
||||||
cmd_result = map_execute_lua();
|
(colnr_T)strlen(ml_get(cap->oap->start.lnum))
|
||||||
} else {
|
|| did_emsg)) {
|
||||||
// get a command line and execute it
|
// The start of the operator has become invalid by the Ex command.
|
||||||
cmd_result = do_cmdline(NULL, is_cmdkey ? getcmdkeycmd : getexline, NULL,
|
clearopbeep(cap->oap);
|
||||||
cap->oap->op_type != OP_NOP ? DOCMD_KEEPLINE : 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cmd_result == false) {
|
|
||||||
// The Ex command failed, do not execute the operator.
|
|
||||||
clearop(cap->oap);
|
|
||||||
} else if (cap->oap->op_type != OP_NOP
|
|
||||||
&& (cap->oap->start.lnum > curbuf->b_ml.ml_line_count
|
|
||||||
|| cap->oap->start.col >
|
|
||||||
(colnr_T)strlen(ml_get(cap->oap->start.lnum))
|
|
||||||
|| did_emsg)) {
|
|
||||||
// The start of the operator has become invalid by the Ex command.
|
|
||||||
clearopbeep(cap->oap);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3263,14 +3288,16 @@ static void nv_ctrlh(cmdarg_T *cap)
|
|||||||
/// CTRL-L: clear screen and redraw.
|
/// CTRL-L: clear screen and redraw.
|
||||||
static void nv_clear(cmdarg_T *cap)
|
static void nv_clear(cmdarg_T *cap)
|
||||||
{
|
{
|
||||||
if (!checkclearop(cap->oap)) {
|
if (checkclearop(cap->oap)) {
|
||||||
// Clear all syntax states to force resyncing.
|
return;
|
||||||
syn_stack_free_all(curwin->w_s);
|
|
||||||
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
|
|
||||||
wp->w_s->b_syn_slow = false;
|
|
||||||
}
|
|
||||||
redraw_later(curwin, UPD_CLEAR);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Clear all syntax states to force resyncing.
|
||||||
|
syn_stack_free_all(curwin->w_s);
|
||||||
|
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
|
||||||
|
wp->w_s->b_syn_slow = false;
|
||||||
|
}
|
||||||
|
redraw_later(curwin, UPD_CLEAR);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// CTRL-O: In Select mode: switch to Visual mode for one command.
|
/// CTRL-O: In Select mode: switch to Visual mode for one command.
|
||||||
@@ -3301,21 +3328,23 @@ static void nv_hat(cmdarg_T *cap)
|
|||||||
/// "Z" commands.
|
/// "Z" commands.
|
||||||
static void nv_Zet(cmdarg_T *cap)
|
static void nv_Zet(cmdarg_T *cap)
|
||||||
{
|
{
|
||||||
if (!checkclearopq(cap->oap)) {
|
if (checkclearopq(cap->oap)) {
|
||||||
switch (cap->nchar) {
|
return;
|
||||||
// "ZZ": equivalent to ":x".
|
}
|
||||||
case 'Z':
|
|
||||||
do_cmdline_cmd("x");
|
|
||||||
break;
|
|
||||||
|
|
||||||
// "ZQ": equivalent to ":q!" (Elvis compatible).
|
switch (cap->nchar) {
|
||||||
case 'Q':
|
// "ZZ": equivalent to ":x".
|
||||||
do_cmdline_cmd("q!");
|
case 'Z':
|
||||||
break;
|
do_cmdline_cmd("x");
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
// "ZQ": equivalent to ":q!" (Elvis compatible).
|
||||||
clearopbeep(cap->oap);
|
case 'Q':
|
||||||
}
|
do_cmdline_cmd("q!");
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
clearopbeep(cap->oap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3846,13 +3875,14 @@ static void nv_up(cmdarg_T *cap)
|
|||||||
// <S-Up> is page up
|
// <S-Up> is page up
|
||||||
cap->arg = BACKWARD;
|
cap->arg = BACKWARD;
|
||||||
nv_page(cap);
|
nv_page(cap);
|
||||||
} else {
|
return;
|
||||||
cap->oap->motion_type = kMTLineWise;
|
}
|
||||||
if (cursor_up(cap->count1, cap->oap->op_type == OP_NOP) == false) {
|
|
||||||
clearopbeep(cap->oap);
|
cap->oap->motion_type = kMTLineWise;
|
||||||
} else if (cap->arg) {
|
if (cursor_up(cap->count1, cap->oap->op_type == OP_NOP) == false) {
|
||||||
beginline(BL_WHITE | BL_FIX);
|
clearopbeep(cap->oap);
|
||||||
}
|
} else if (cap->arg) {
|
||||||
|
beginline(BL_WHITE | BL_FIX);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3895,11 +3925,7 @@ static void nv_gotofile(cmdarg_T *cap)
|
|||||||
char *ptr;
|
char *ptr;
|
||||||
linenr_T lnum = -1;
|
linenr_T lnum = -1;
|
||||||
|
|
||||||
if (check_text_locked(cap->oap)) {
|
if (check_text_or_curbuf_locked(cap->oap)) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (curbuf_locked()) {
|
|
||||||
clearop(cap->oap);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4058,22 +4084,23 @@ static void nv_csearch(cmdarg_T *cap)
|
|||||||
cap->oap->motion_type = kMTCharWise;
|
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 {
|
return;
|
||||||
curwin->w_set_curswant = true;
|
}
|
||||||
// Include a Tab for "tx" and for "dfx".
|
|
||||||
if (gchar_cursor() == TAB && virtual_active() && cap->arg == FORWARD
|
|
||||||
&& (t_cmd || cap->oap->op_type != OP_NOP)) {
|
|
||||||
colnr_T scol, ecol;
|
|
||||||
|
|
||||||
getvcol(curwin, &curwin->w_cursor, &scol, NULL, &ecol);
|
curwin->w_set_curswant = true;
|
||||||
curwin->w_cursor.coladd = ecol - scol;
|
// Include a Tab for "tx" and for "dfx".
|
||||||
} else {
|
if (gchar_cursor() == TAB && virtual_active() && cap->arg == FORWARD
|
||||||
curwin->w_cursor.coladd = 0;
|
&& (t_cmd || cap->oap->op_type != OP_NOP)) {
|
||||||
}
|
colnr_T scol, ecol;
|
||||||
adjust_for_sel(cap);
|
|
||||||
if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) {
|
getvcol(curwin, &curwin->w_cursor, &scol, NULL, &ecol);
|
||||||
foldOpenCursor();
|
curwin->w_cursor.coladd = ecol - scol;
|
||||||
}
|
} else {
|
||||||
|
curwin->w_cursor.coladd = 0;
|
||||||
|
}
|
||||||
|
adjust_for_sel(cap);
|
||||||
|
if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) {
|
||||||
|
foldOpenCursor();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4395,25 +4422,28 @@ static void nv_brace(cmdarg_T *cap)
|
|||||||
cap->oap->inclusive = false;
|
cap->oap->inclusive = false;
|
||||||
curwin->w_set_curswant = true;
|
curwin->w_set_curswant = true;
|
||||||
|
|
||||||
if (findsent(cap->arg, cap->count1) == false) {
|
if (findsent(cap->arg, cap->count1) == FAIL) {
|
||||||
clearopbeep(cap->oap);
|
clearopbeep(cap->oap);
|
||||||
} else {
|
return;
|
||||||
// Don't leave the cursor on the NUL past end of line.
|
}
|
||||||
adjust_cursor(cap->oap);
|
|
||||||
curwin->w_cursor.coladd = 0;
|
// Don't leave the cursor on the NUL past end of line.
|
||||||
if ((fdo_flags & FDO_BLOCK) && KeyTyped && cap->oap->op_type == OP_NOP) {
|
adjust_cursor(cap->oap);
|
||||||
foldOpenCursor();
|
curwin->w_cursor.coladd = 0;
|
||||||
}
|
if ((fdo_flags & FDO_BLOCK) && KeyTyped && cap->oap->op_type == OP_NOP) {
|
||||||
|
foldOpenCursor();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// "m" command: Mark a position.
|
/// "m" command: Mark a position.
|
||||||
static void nv_mark(cmdarg_T *cap)
|
static void nv_mark(cmdarg_T *cap)
|
||||||
{
|
{
|
||||||
if (!checkclearop(cap->oap)) {
|
if (checkclearop(cap->oap)) {
|
||||||
if (setmark(cap->nchar) == false) {
|
return;
|
||||||
clearopbeep(cap->oap);
|
}
|
||||||
}
|
|
||||||
|
if (setmark(cap->nchar) == false) {
|
||||||
|
clearopbeep(cap->oap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4427,11 +4457,12 @@ static void nv_findpar(cmdarg_T *cap)
|
|||||||
curwin->w_set_curswant = true;
|
curwin->w_set_curswant = true;
|
||||||
if (!findpar(&cap->oap->inclusive, cap->arg, cap->count1, NUL, false)) {
|
if (!findpar(&cap->oap->inclusive, cap->arg, cap->count1, NUL, false)) {
|
||||||
clearopbeep(cap->oap);
|
clearopbeep(cap->oap);
|
||||||
} else {
|
return;
|
||||||
curwin->w_cursor.coladd = 0;
|
}
|
||||||
if ((fdo_flags & FDO_BLOCK) && KeyTyped && cap->oap->op_type == OP_NOP) {
|
|
||||||
foldOpenCursor();
|
curwin->w_cursor.coladd = 0;
|
||||||
}
|
if ((fdo_flags & FDO_BLOCK) && KeyTyped && cap->oap->op_type == OP_NOP) {
|
||||||
|
foldOpenCursor();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4452,14 +4483,16 @@ static void nv_undo(cmdarg_T *cap)
|
|||||||
/// <Undo> command.
|
/// <Undo> command.
|
||||||
static void nv_kundo(cmdarg_T *cap)
|
static void nv_kundo(cmdarg_T *cap)
|
||||||
{
|
{
|
||||||
if (!checkclearopq(cap->oap)) {
|
if (checkclearopq(cap->oap)) {
|
||||||
if (bt_prompt(curbuf)) {
|
return;
|
||||||
clearopbeep(cap->oap);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
u_undo((int)cap->count1);
|
|
||||||
curwin->w_set_curswant = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (bt_prompt(curbuf)) {
|
||||||
|
clearopbeep(cap->oap);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
u_undo((int)cap->count1);
|
||||||
|
curwin->w_set_curswant = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Handle the "r" command.
|
/// Handle the "r" command.
|
||||||
@@ -4670,15 +4703,20 @@ static void nv_Replace(cmdarg_T *cap)
|
|||||||
VIsual_mode_orig = VIsual_mode; // remember original area for gv
|
VIsual_mode_orig = VIsual_mode; // remember original area for gv
|
||||||
VIsual_mode = 'V';
|
VIsual_mode = 'V';
|
||||||
nv_operator(cap);
|
nv_operator(cap);
|
||||||
} else if (!checkclearopq(cap->oap)) {
|
return;
|
||||||
if (!MODIFIABLE(curbuf)) {
|
}
|
||||||
emsg(_(e_modifiable));
|
|
||||||
} else {
|
if (checkclearopq(cap->oap)) {
|
||||||
if (virtual_active()) {
|
return;
|
||||||
coladvance(getviscol());
|
}
|
||||||
}
|
|
||||||
invoke_edit(cap, false, cap->arg ? 'V' : 'R', false);
|
if (!MODIFIABLE(curbuf)) {
|
||||||
|
emsg(_(e_modifiable));
|
||||||
|
} else {
|
||||||
|
if (virtual_active()) {
|
||||||
|
coladvance(getviscol());
|
||||||
}
|
}
|
||||||
|
invoke_edit(cap, false, cap->arg ? 'V' : 'R', false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4689,20 +4727,25 @@ static void nv_vreplace(cmdarg_T *cap)
|
|||||||
cap->cmdchar = 'r';
|
cap->cmdchar = 'r';
|
||||||
cap->nchar = cap->extra_char;
|
cap->nchar = cap->extra_char;
|
||||||
nv_replace(cap); // Do same as "r" in Visual mode for now
|
nv_replace(cap); // Do same as "r" in Visual mode for now
|
||||||
} else if (!checkclearopq(cap->oap)) {
|
return;
|
||||||
if (!MODIFIABLE(curbuf)) {
|
}
|
||||||
emsg(_(e_modifiable));
|
|
||||||
} else {
|
if (checkclearopq(cap->oap)) {
|
||||||
if (cap->extra_char == Ctrl_V) { // get another character
|
return;
|
||||||
cap->extra_char = get_literal(false);
|
}
|
||||||
}
|
|
||||||
stuffcharReadbuff(cap->extra_char);
|
if (!MODIFIABLE(curbuf)) {
|
||||||
stuffcharReadbuff(ESC);
|
emsg(_(e_modifiable));
|
||||||
if (virtual_active()) {
|
} else {
|
||||||
coladvance(getviscol());
|
if (cap->extra_char == Ctrl_V) { // get another character
|
||||||
}
|
cap->extra_char = get_literal(false);
|
||||||
invoke_edit(cap, true, 'v', false);
|
|
||||||
}
|
}
|
||||||
|
stuffcharReadbuff(cap->extra_char);
|
||||||
|
stuffcharReadbuff(ESC);
|
||||||
|
if (virtual_active()) {
|
||||||
|
coladvance(getviscol());
|
||||||
|
}
|
||||||
|
invoke_edit(cap, true, 'v', false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4903,42 +4946,44 @@ static void nv_pcmark(cmdarg_T *cap)
|
|||||||
MarkMoveRes move_res = 0; // Result from moving to the mark
|
MarkMoveRes move_res = 0; // Result from moving to the mark
|
||||||
const bool old_KeyTyped = KeyTyped; // getting file may reset it.
|
const bool old_KeyTyped = KeyTyped; // getting file may reset it.
|
||||||
|
|
||||||
if (!checkclearopq(cap->oap)) {
|
if (checkclearopq(cap->oap)) {
|
||||||
if (cap->cmdchar == TAB && mod_mask == MOD_MASK_CTRL) {
|
return;
|
||||||
if (!goto_tabpage_lastused()) {
|
}
|
||||||
clearopbeep(cap->oap);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cap->cmdchar == 'g') {
|
if (cap->cmdchar == TAB && mod_mask == MOD_MASK_CTRL) {
|
||||||
fm = get_changelist(curbuf, curwin, (int)cap->count1);
|
if (!goto_tabpage_lastused()) {
|
||||||
} else {
|
|
||||||
fm = get_jumplist(curwin, (int)cap->count1);
|
|
||||||
flags |= KMarkNoContext | kMarkJumpList;
|
|
||||||
}
|
|
||||||
// Changelist and jumplist have their own error messages. Therefore avoid
|
|
||||||
// calling nv_mark_move_to() when not found to avoid incorrect error
|
|
||||||
// messages.
|
|
||||||
if (fm != NULL) {
|
|
||||||
move_res = nv_mark_move_to(cap, flags, fm);
|
|
||||||
} else if (cap->cmdchar == 'g') {
|
|
||||||
if (curbuf->b_changelistlen == 0) {
|
|
||||||
emsg(_("E664: changelist is empty"));
|
|
||||||
} else if (cap->count1 < 0) {
|
|
||||||
emsg(_("E662: At start of changelist"));
|
|
||||||
} else {
|
|
||||||
emsg(_("E663: At end of changelist"));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
clearopbeep(cap->oap);
|
clearopbeep(cap->oap);
|
||||||
}
|
}
|
||||||
if (cap->oap->op_type == OP_NOP
|
return;
|
||||||
&& (move_res & kMarkSwitchedBuf || move_res & kMarkChangedLine)
|
}
|
||||||
&& (fdo_flags & FDO_MARK)
|
|
||||||
&& old_KeyTyped) {
|
if (cap->cmdchar == 'g') {
|
||||||
foldOpenCursor();
|
fm = get_changelist(curbuf, curwin, (int)cap->count1);
|
||||||
|
} else {
|
||||||
|
fm = get_jumplist(curwin, (int)cap->count1);
|
||||||
|
flags |= KMarkNoContext | kMarkJumpList;
|
||||||
|
}
|
||||||
|
// Changelist and jumplist have their own error messages. Therefore avoid
|
||||||
|
// calling nv_mark_move_to() when not found to avoid incorrect error
|
||||||
|
// messages.
|
||||||
|
if (fm != NULL) {
|
||||||
|
move_res = nv_mark_move_to(cap, flags, fm);
|
||||||
|
} else if (cap->cmdchar == 'g') {
|
||||||
|
if (curbuf->b_changelistlen == 0) {
|
||||||
|
emsg(_("E664: changelist is empty"));
|
||||||
|
} else if (cap->count1 < 0) {
|
||||||
|
emsg(_("E662: At start of changelist"));
|
||||||
|
} else {
|
||||||
|
emsg(_("E663: At end of changelist"));
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
clearopbeep(cap->oap);
|
||||||
|
}
|
||||||
|
if (cap->oap->op_type == OP_NOP
|
||||||
|
&& (move_res & kMarkSwitchedBuf || move_res & kMarkChangedLine)
|
||||||
|
&& (fdo_flags & FDO_MARK)
|
||||||
|
&& old_KeyTyped) {
|
||||||
|
foldOpenCursor();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -5669,42 +5714,46 @@ static void nv_g_cmd(cmdarg_T *cap)
|
|||||||
/// Handle "o" and "O" commands.
|
/// Handle "o" and "O" commands.
|
||||||
static void n_opencmd(cmdarg_T *cap)
|
static void n_opencmd(cmdarg_T *cap)
|
||||||
{
|
{
|
||||||
if (!checkclearopq(cap->oap)) {
|
if (checkclearopq(cap->oap)) {
|
||||||
if (cap->cmdchar == 'O') {
|
return;
|
||||||
// Open above the first line of a folded sequence of lines
|
}
|
||||||
(void)hasFolding(curwin->w_cursor.lnum,
|
|
||||||
&curwin->w_cursor.lnum, NULL);
|
if (cap->cmdchar == 'O') {
|
||||||
} else {
|
// Open above the first line of a folded sequence of lines
|
||||||
// Open below the last line of a folded sequence of lines
|
(void)hasFolding(curwin->w_cursor.lnum,
|
||||||
(void)hasFolding(curwin->w_cursor.lnum,
|
&curwin->w_cursor.lnum, NULL);
|
||||||
NULL, &curwin->w_cursor.lnum);
|
} else {
|
||||||
}
|
// Open below the last line of a folded sequence of lines
|
||||||
if (u_save((linenr_T)(curwin->w_cursor.lnum -
|
(void)hasFolding(curwin->w_cursor.lnum,
|
||||||
(cap->cmdchar == 'O' ? 1 : 0)),
|
NULL, &curwin->w_cursor.lnum);
|
||||||
(linenr_T)(curwin->w_cursor.lnum +
|
}
|
||||||
(cap->cmdchar == 'o' ? 1 : 0)))
|
if (u_save((linenr_T)(curwin->w_cursor.lnum -
|
||||||
&& open_line(cap->cmdchar == 'O' ? BACKWARD : FORWARD,
|
(cap->cmdchar == 'O' ? 1 : 0)),
|
||||||
has_format_option(FO_OPEN_COMS) ? OPENLINE_DO_COM : 0,
|
(linenr_T)(curwin->w_cursor.lnum +
|
||||||
0, NULL)) {
|
(cap->cmdchar == 'o' ? 1 : 0)))
|
||||||
if (win_cursorline_standout(curwin)) {
|
&& open_line(cap->cmdchar == 'O' ? BACKWARD : FORWARD,
|
||||||
// force redraw of cursorline
|
has_format_option(FO_OPEN_COMS) ? OPENLINE_DO_COM : 0,
|
||||||
curwin->w_valid &= ~VALID_CROW;
|
0, NULL)) {
|
||||||
}
|
if (win_cursorline_standout(curwin)) {
|
||||||
invoke_edit(cap, false, cap->cmdchar, true);
|
// force redraw of cursorline
|
||||||
|
curwin->w_valid &= ~VALID_CROW;
|
||||||
}
|
}
|
||||||
|
invoke_edit(cap, false, cap->cmdchar, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// "." command: redo last change.
|
/// "." command: redo last change.
|
||||||
static void nv_dot(cmdarg_T *cap)
|
static void nv_dot(cmdarg_T *cap)
|
||||||
{
|
{
|
||||||
if (!checkclearopq(cap->oap)) {
|
if (checkclearopq(cap->oap)) {
|
||||||
// If "restart_edit" is true, the last but one command is repeated
|
return;
|
||||||
// instead of the last command (inserting text). This is used for
|
}
|
||||||
// CTRL-O <.> in insert mode.
|
|
||||||
if (start_redo(cap->count0, restart_edit != 0 && !arrow_used) == false) {
|
// If "restart_edit" is true, the last but one command is repeated
|
||||||
clearopbeep(cap->oap);
|
// instead of the last command (inserting text). This is used for
|
||||||
}
|
// CTRL-O <.> in insert mode.
|
||||||
|
if (start_redo(cap->count0, restart_edit != 0 && !arrow_used) == false) {
|
||||||
|
clearopbeep(cap->oap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -5728,10 +5777,12 @@ static void nv_redo_or_register(cmdarg_T *cap)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!checkclearopq(cap->oap)) {
|
if (checkclearopq(cap->oap)) {
|
||||||
u_redo((int)cap->count1);
|
return;
|
||||||
curwin->w_set_curswant = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
u_redo((int)cap->count1);
|
||||||
|
curwin->w_set_curswant = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Handle "U" command.
|
/// Handle "U" command.
|
||||||
@@ -5743,10 +5794,15 @@ static void nv_Undo(cmdarg_T *cap)
|
|||||||
cap->cmdchar = 'g';
|
cap->cmdchar = 'g';
|
||||||
cap->nchar = 'U';
|
cap->nchar = 'U';
|
||||||
nv_operator(cap);
|
nv_operator(cap);
|
||||||
} else if (!checkclearopq(cap->oap)) {
|
return;
|
||||||
u_undoline();
|
|
||||||
curwin->w_set_curswant = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (checkclearopq(cap->oap)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
u_undoline();
|
||||||
|
curwin->w_set_curswant = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// '~' command: If tilde is not an operator and Visual is off: swap case of a
|
/// '~' command: If tilde is not an operator and Visual is off: swap case of a
|
||||||
@@ -6309,16 +6365,21 @@ static void nv_record(cmdarg_T *cap)
|
|||||||
cap->cmdchar = 'g';
|
cap->cmdchar = 'g';
|
||||||
cap->nchar = 'q';
|
cap->nchar = 'q';
|
||||||
nv_operator(cap);
|
nv_operator(cap);
|
||||||
} else if (!checkclearop(cap->oap)) {
|
return;
|
||||||
if (cap->nchar == ':' || cap->nchar == '/' || cap->nchar == '?') {
|
}
|
||||||
stuffcharReadbuff(cap->nchar);
|
|
||||||
stuffcharReadbuff(K_CMDWIN);
|
if (checkclearop(cap->oap)) {
|
||||||
} else {
|
return;
|
||||||
// (stop) recording into a named register, unless executing a
|
}
|
||||||
// register.
|
|
||||||
if (reg_executing == 0 && do_record(cap->nchar) == FAIL) {
|
if (cap->nchar == ':' || cap->nchar == '/' || cap->nchar == '?') {
|
||||||
clearopbeep(cap->oap);
|
stuffcharReadbuff(cap->nchar);
|
||||||
}
|
stuffcharReadbuff(K_CMDWIN);
|
||||||
|
} else {
|
||||||
|
// (stop) recording into a named register, unless executing a
|
||||||
|
// register.
|
||||||
|
if (reg_executing == 0 && do_record(cap->nchar) == FAIL) {
|
||||||
|
clearopbeep(cap->oap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6360,24 +6421,29 @@ static void nv_join(cmdarg_T *cap)
|
|||||||
{
|
{
|
||||||
if (VIsual_active) { // join the visual lines
|
if (VIsual_active) { // join the visual lines
|
||||||
nv_operator(cap);
|
nv_operator(cap);
|
||||||
} else if (!checkclearop(cap->oap)) {
|
return;
|
||||||
if (cap->count0 <= 1) {
|
|
||||||
cap->count0 = 2; // default for join is two lines!
|
|
||||||
}
|
|
||||||
if (curwin->w_cursor.lnum + cap->count0 - 1 >
|
|
||||||
curbuf->b_ml.ml_line_count) {
|
|
||||||
// can't join when on the last line
|
|
||||||
if (cap->count0 <= 2) {
|
|
||||||
clearopbeep(cap->oap);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
cap->count0 = curbuf->b_ml.ml_line_count - curwin->w_cursor.lnum + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
prep_redo(cap->oap->regname, cap->count0,
|
|
||||||
NUL, cap->cmdchar, NUL, NUL, cap->nchar);
|
|
||||||
do_join((size_t)cap->count0, cap->nchar == NUL, true, true, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (checkclearop(cap->oap)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cap->count0 <= 1) {
|
||||||
|
cap->count0 = 2; // default for join is two lines!
|
||||||
|
}
|
||||||
|
if (curwin->w_cursor.lnum + cap->count0 - 1 >
|
||||||
|
curbuf->b_ml.ml_line_count) {
|
||||||
|
// can't join when on the last line
|
||||||
|
if (cap->count0 <= 2) {
|
||||||
|
clearopbeep(cap->oap);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
cap->count0 = curbuf->b_ml.ml_line_count - curwin->w_cursor.lnum + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
prep_redo(cap->oap->regname, cap->count0,
|
||||||
|
NUL, cap->cmdchar, NUL, NUL, cap->nchar);
|
||||||
|
do_join((size_t)cap->count0, cap->nchar == NUL, true, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// "P", "gP", "p" and "gp" commands.
|
/// "P", "gP", "p" and "gp" commands.
|
||||||
@@ -6407,117 +6473,121 @@ static void nv_put_opt(cmdarg_T *cap, bool fix_indent)
|
|||||||
} else {
|
} else {
|
||||||
clearopbeep(cap->oap);
|
clearopbeep(cap->oap);
|
||||||
}
|
}
|
||||||
} else if (bt_prompt(curbuf) && !prompt_curpos_editable()) {
|
return;
|
||||||
clearopbeep(cap->oap);
|
|
||||||
} else {
|
|
||||||
if (fix_indent) {
|
|
||||||
dir = (cap->cmdchar == ']' && cap->nchar == 'p')
|
|
||||||
? FORWARD : BACKWARD;
|
|
||||||
flags |= PUT_FIXINDENT;
|
|
||||||
} else {
|
|
||||||
dir = (cap->cmdchar == 'P'
|
|
||||||
|| ((cap->cmdchar == 'g' || cap->cmdchar == 'z')
|
|
||||||
&& cap->nchar == 'P')) ? BACKWARD : FORWARD;
|
|
||||||
}
|
|
||||||
prep_redo_cmd(cap);
|
|
||||||
if (cap->cmdchar == 'g') {
|
|
||||||
flags |= PUT_CURSEND;
|
|
||||||
} else if (cap->cmdchar == 'z') {
|
|
||||||
flags |= PUT_BLOCK_INNER;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (VIsual_active) {
|
|
||||||
// Putting in Visual mode: The put text replaces the selected
|
|
||||||
// text. First delete the selected text, then put the new text.
|
|
||||||
// Need to save and restore the registers that the delete
|
|
||||||
// overwrites if the old contents is being put.
|
|
||||||
was_visual = true;
|
|
||||||
regname = cap->oap->regname;
|
|
||||||
bool keep_registers = cap->cmdchar == 'P';
|
|
||||||
// '+' and '*' could be the same selection
|
|
||||||
bool clipoverwrite = (regname == '+' || regname == '*') && (cb_flags & CB_UNNAMEDMASK);
|
|
||||||
if (regname == 0 || regname == '"' || clipoverwrite
|
|
||||||
|| ascii_isdigit(regname) || regname == '-') {
|
|
||||||
// The delete might overwrite the register we want to put, save it first
|
|
||||||
savereg = copy_register(regname);
|
|
||||||
}
|
|
||||||
|
|
||||||
// To place the cursor correctly after a blockwise put, and to leave the
|
|
||||||
// text in the correct position when putting over a selection with
|
|
||||||
// 'virtualedit' and past the end of the line, we use the 'c' operator in
|
|
||||||
// do_put(), which requires the visual selection to still be active.
|
|
||||||
if (!VIsual_active || VIsual_mode == 'V' || regname != '.') {
|
|
||||||
// Now delete the selected text. Avoid messages here.
|
|
||||||
cap->cmdchar = 'd';
|
|
||||||
cap->nchar = NUL;
|
|
||||||
cap->oap->regname = keep_registers ? '_' : NUL;
|
|
||||||
msg_silent++;
|
|
||||||
nv_operator(cap);
|
|
||||||
do_pending_operator(cap, 0, false);
|
|
||||||
empty = (curbuf->b_ml.ml_flags & ML_EMPTY);
|
|
||||||
msg_silent--;
|
|
||||||
|
|
||||||
// delete PUT_LINE_BACKWARD;
|
|
||||||
cap->oap->regname = regname;
|
|
||||||
}
|
|
||||||
|
|
||||||
// When deleted a linewise Visual area, put the register as
|
|
||||||
// lines to avoid it joined with the next line. When deletion was
|
|
||||||
// charwise, split a line when putting lines.
|
|
||||||
if (VIsual_mode == 'V') {
|
|
||||||
flags |= PUT_LINE;
|
|
||||||
} else if (VIsual_mode == 'v') {
|
|
||||||
flags |= PUT_LINE_SPLIT;
|
|
||||||
}
|
|
||||||
if (VIsual_mode == Ctrl_V && dir == FORWARD) {
|
|
||||||
flags |= PUT_LINE_FORWARD;
|
|
||||||
}
|
|
||||||
dir = BACKWARD;
|
|
||||||
if ((VIsual_mode != 'V'
|
|
||||||
&& curwin->w_cursor.col < curbuf->b_op_start.col)
|
|
||||||
|| (VIsual_mode == 'V'
|
|
||||||
&& curwin->w_cursor.lnum < curbuf->b_op_start.lnum)) {
|
|
||||||
// cursor is at the end of the line or end of file, put
|
|
||||||
// forward.
|
|
||||||
dir = FORWARD;
|
|
||||||
}
|
|
||||||
// May have been reset in do_put().
|
|
||||||
VIsual_active = true;
|
|
||||||
}
|
|
||||||
do_put(cap->oap->regname, savereg, dir, cap->count1, flags);
|
|
||||||
|
|
||||||
// If a register was saved, free it
|
|
||||||
if (savereg != NULL) {
|
|
||||||
free_register(savereg);
|
|
||||||
xfree(savereg);
|
|
||||||
}
|
|
||||||
|
|
||||||
// What to reselect with "gv"? Selecting the just put text seems to
|
|
||||||
// be the most useful, since the original text was removed.
|
|
||||||
if (was_visual) {
|
|
||||||
curbuf->b_visual.vi_start = curbuf->b_op_start;
|
|
||||||
curbuf->b_visual.vi_end = curbuf->b_op_end;
|
|
||||||
// need to adjust cursor position
|
|
||||||
if (*p_sel == 'e') {
|
|
||||||
inc(&curbuf->b_visual.vi_end);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// When all lines were selected and deleted do_put() leaves an empty
|
|
||||||
// line that needs to be deleted now.
|
|
||||||
if (empty && *ml_get(curbuf->b_ml.ml_line_count) == NUL) {
|
|
||||||
ml_delete(curbuf->b_ml.ml_line_count, true);
|
|
||||||
deleted_lines(curbuf->b_ml.ml_line_count + 1, 1);
|
|
||||||
|
|
||||||
// If the cursor was in that line, move it to the end of the last
|
|
||||||
// line.
|
|
||||||
if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) {
|
|
||||||
curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
|
|
||||||
coladvance(MAXCOL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
auto_format(false, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (bt_prompt(curbuf) && !prompt_curpos_editable()) {
|
||||||
|
clearopbeep(cap->oap);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fix_indent) {
|
||||||
|
dir = (cap->cmdchar == ']' && cap->nchar == 'p')
|
||||||
|
? FORWARD : BACKWARD;
|
||||||
|
flags |= PUT_FIXINDENT;
|
||||||
|
} else {
|
||||||
|
dir = (cap->cmdchar == 'P'
|
||||||
|
|| ((cap->cmdchar == 'g' || cap->cmdchar == 'z')
|
||||||
|
&& cap->nchar == 'P')) ? BACKWARD : FORWARD;
|
||||||
|
}
|
||||||
|
prep_redo_cmd(cap);
|
||||||
|
if (cap->cmdchar == 'g') {
|
||||||
|
flags |= PUT_CURSEND;
|
||||||
|
} else if (cap->cmdchar == 'z') {
|
||||||
|
flags |= PUT_BLOCK_INNER;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (VIsual_active) {
|
||||||
|
// Putting in Visual mode: The put text replaces the selected
|
||||||
|
// text. First delete the selected text, then put the new text.
|
||||||
|
// Need to save and restore the registers that the delete
|
||||||
|
// overwrites if the old contents is being put.
|
||||||
|
was_visual = true;
|
||||||
|
regname = cap->oap->regname;
|
||||||
|
bool keep_registers = cap->cmdchar == 'P';
|
||||||
|
// '+' and '*' could be the same selection
|
||||||
|
bool clipoverwrite = (regname == '+' || regname == '*') && (cb_flags & CB_UNNAMEDMASK);
|
||||||
|
if (regname == 0 || regname == '"' || clipoverwrite
|
||||||
|
|| ascii_isdigit(regname) || regname == '-') {
|
||||||
|
// The delete might overwrite the register we want to put, save it first
|
||||||
|
savereg = copy_register(regname);
|
||||||
|
}
|
||||||
|
|
||||||
|
// To place the cursor correctly after a blockwise put, and to leave the
|
||||||
|
// text in the correct position when putting over a selection with
|
||||||
|
// 'virtualedit' and past the end of the line, we use the 'c' operator in
|
||||||
|
// do_put(), which requires the visual selection to still be active.
|
||||||
|
if (!VIsual_active || VIsual_mode == 'V' || regname != '.') {
|
||||||
|
// Now delete the selected text. Avoid messages here.
|
||||||
|
cap->cmdchar = 'd';
|
||||||
|
cap->nchar = NUL;
|
||||||
|
cap->oap->regname = keep_registers ? '_' : NUL;
|
||||||
|
msg_silent++;
|
||||||
|
nv_operator(cap);
|
||||||
|
do_pending_operator(cap, 0, false);
|
||||||
|
empty = (curbuf->b_ml.ml_flags & ML_EMPTY);
|
||||||
|
msg_silent--;
|
||||||
|
|
||||||
|
// delete PUT_LINE_BACKWARD;
|
||||||
|
cap->oap->regname = regname;
|
||||||
|
}
|
||||||
|
|
||||||
|
// When deleted a linewise Visual area, put the register as
|
||||||
|
// lines to avoid it joined with the next line. When deletion was
|
||||||
|
// charwise, split a line when putting lines.
|
||||||
|
if (VIsual_mode == 'V') {
|
||||||
|
flags |= PUT_LINE;
|
||||||
|
} else if (VIsual_mode == 'v') {
|
||||||
|
flags |= PUT_LINE_SPLIT;
|
||||||
|
}
|
||||||
|
if (VIsual_mode == Ctrl_V && dir == FORWARD) {
|
||||||
|
flags |= PUT_LINE_FORWARD;
|
||||||
|
}
|
||||||
|
dir = BACKWARD;
|
||||||
|
if ((VIsual_mode != 'V'
|
||||||
|
&& curwin->w_cursor.col < curbuf->b_op_start.col)
|
||||||
|
|| (VIsual_mode == 'V'
|
||||||
|
&& curwin->w_cursor.lnum < curbuf->b_op_start.lnum)) {
|
||||||
|
// cursor is at the end of the line or end of file, put
|
||||||
|
// forward.
|
||||||
|
dir = FORWARD;
|
||||||
|
}
|
||||||
|
// May have been reset in do_put().
|
||||||
|
VIsual_active = true;
|
||||||
|
}
|
||||||
|
do_put(cap->oap->regname, savereg, dir, cap->count1, flags);
|
||||||
|
|
||||||
|
// If a register was saved, free it
|
||||||
|
if (savereg != NULL) {
|
||||||
|
free_register(savereg);
|
||||||
|
xfree(savereg);
|
||||||
|
}
|
||||||
|
|
||||||
|
// What to reselect with "gv"? Selecting the just put text seems to
|
||||||
|
// be the most useful, since the original text was removed.
|
||||||
|
if (was_visual) {
|
||||||
|
curbuf->b_visual.vi_start = curbuf->b_op_start;
|
||||||
|
curbuf->b_visual.vi_end = curbuf->b_op_end;
|
||||||
|
// need to adjust cursor position
|
||||||
|
if (*p_sel == 'e') {
|
||||||
|
inc(&curbuf->b_visual.vi_end);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// When all lines were selected and deleted do_put() leaves an empty
|
||||||
|
// line that needs to be deleted now.
|
||||||
|
if (empty && *ml_get(curbuf->b_ml.ml_line_count) == NUL) {
|
||||||
|
ml_delete(curbuf->b_ml.ml_line_count, true);
|
||||||
|
deleted_lines(curbuf->b_ml.ml_line_count + 1, 1);
|
||||||
|
|
||||||
|
// If the cursor was in that line, move it to the end of the last
|
||||||
|
// line.
|
||||||
|
if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) {
|
||||||
|
curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
|
||||||
|
coladvance(MAXCOL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
auto_format(false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// "o" and "O" commands.
|
/// "o" and "O" commands.
|
||||||
|
@@ -1785,10 +1785,12 @@ setmarks:
|
|||||||
/// Used for deletion.
|
/// Used for deletion.
|
||||||
static void mb_adjust_opend(oparg_T *oap)
|
static void mb_adjust_opend(oparg_T *oap)
|
||||||
{
|
{
|
||||||
if (oap->inclusive) {
|
if (!oap->inclusive) {
|
||||||
char *p = ml_get(oap->end.lnum);
|
return;
|
||||||
oap->end.col += utf_cp_tail_off(p, p + oap->end.col);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *p = ml_get(oap->end.lnum);
|
||||||
|
oap->end.col += utf_cp_tail_off(p, p + oap->end.col);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Put character 'c' at position 'lp'
|
/// Put character 'c' at position 'lp'
|
||||||
@@ -3711,20 +3713,23 @@ void adjust_cursor_eol(void)
|
|||||||
{
|
{
|
||||||
unsigned int cur_ve_flags = get_ve_flags();
|
unsigned int cur_ve_flags = get_ve_flags();
|
||||||
|
|
||||||
if (curwin->w_cursor.col > 0
|
const bool adj_cursor = (curwin->w_cursor.col > 0
|
||||||
&& gchar_cursor() == NUL
|
&& gchar_cursor() == NUL
|
||||||
&& (cur_ve_flags & VE_ONEMORE) == 0
|
&& (cur_ve_flags & VE_ONEMORE) == 0
|
||||||
&& !(restart_edit || (State & MODE_INSERT))) {
|
&& !(restart_edit || (State & MODE_INSERT)));
|
||||||
// Put the cursor on the last character in the line.
|
if (!adj_cursor) {
|
||||||
dec_cursor();
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (cur_ve_flags == VE_ALL) {
|
// Put the cursor on the last character in the line.
|
||||||
colnr_T scol, ecol;
|
dec_cursor();
|
||||||
|
|
||||||
// Coladd is set to the width of the last character.
|
if (cur_ve_flags == VE_ALL) {
|
||||||
getvcol(curwin, &curwin->w_cursor, &scol, NULL, &ecol);
|
colnr_T scol, ecol;
|
||||||
curwin->w_cursor.coladd = ecol - scol + 1;
|
|
||||||
}
|
// Coladd is set to the width of the last character.
|
||||||
|
getvcol(curwin, &curwin->w_cursor, &scol, NULL, &ecol);
|
||||||
|
curwin->w_cursor.coladd = ecol - scol + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4205,11 +4210,13 @@ static bool reset_lbr(void)
|
|||||||
/// Restore 'linebreak' and take care of side effects.
|
/// Restore 'linebreak' and take care of side effects.
|
||||||
static void restore_lbr(bool lbr_saved)
|
static void restore_lbr(bool lbr_saved)
|
||||||
{
|
{
|
||||||
if (!curwin->w_p_lbr && lbr_saved) {
|
if (curwin->w_p_lbr || !lbr_saved) {
|
||||||
// changing 'linebreak' may require w_virtcol to be updated
|
return;
|
||||||
curwin->w_p_lbr = true;
|
|
||||||
curwin->w_valid &= ~(VALID_WROW|VALID_WCOL|VALID_VIRTCOL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// changing 'linebreak' may require w_virtcol to be updated
|
||||||
|
curwin->w_p_lbr = true;
|
||||||
|
curwin->w_valid &= ~(VALID_WROW|VALID_WCOL|VALID_VIRTCOL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// prepare a few things for block mode yank/delete/tilde
|
/// prepare a few things for block mode yank/delete/tilde
|
||||||
|
@@ -674,23 +674,25 @@ void set_helplang_default(const char *lang)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int idx = findoption("hlg");
|
int idx = findoption("hlg");
|
||||||
if (idx >= 0 && !(options[idx].flags & P_WAS_SET)) {
|
if (idx < 0 || (options[idx].flags & P_WAS_SET)) {
|
||||||
if (options[idx].flags & P_ALLOCED) {
|
return;
|
||||||
free_string_option(p_hlg);
|
|
||||||
}
|
|
||||||
p_hlg = xmemdupz(lang, lang_len);
|
|
||||||
// zh_CN becomes "cn", zh_TW becomes "tw".
|
|
||||||
if (STRNICMP(p_hlg, "zh_", 3) == 0 && strlen(p_hlg) >= 5) {
|
|
||||||
p_hlg[0] = (char)TOLOWER_ASC(p_hlg[3]);
|
|
||||||
p_hlg[1] = (char)TOLOWER_ASC(p_hlg[4]);
|
|
||||||
} else if (strlen(p_hlg) >= 1 && *p_hlg == 'C') {
|
|
||||||
// any C like setting, such as C.UTF-8, becomes "en"
|
|
||||||
p_hlg[0] = 'e';
|
|
||||||
p_hlg[1] = 'n';
|
|
||||||
}
|
|
||||||
p_hlg[2] = NUL;
|
|
||||||
options[idx].flags |= P_ALLOCED;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options[idx].flags & P_ALLOCED) {
|
||||||
|
free_string_option(p_hlg);
|
||||||
|
}
|
||||||
|
p_hlg = xmemdupz(lang, lang_len);
|
||||||
|
// zh_CN becomes "cn", zh_TW becomes "tw".
|
||||||
|
if (STRNICMP(p_hlg, "zh_", 3) == 0 && strlen(p_hlg) >= 5) {
|
||||||
|
p_hlg[0] = (char)TOLOWER_ASC(p_hlg[3]);
|
||||||
|
p_hlg[1] = (char)TOLOWER_ASC(p_hlg[4]);
|
||||||
|
} else if (strlen(p_hlg) >= 1 && *p_hlg == 'C') {
|
||||||
|
// any C like setting, such as C.UTF-8, becomes "en"
|
||||||
|
p_hlg[0] = 'e';
|
||||||
|
p_hlg[1] = 'n';
|
||||||
|
}
|
||||||
|
p_hlg[2] = NUL;
|
||||||
|
options[idx].flags |= P_ALLOCED;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 'title' and 'icon' only default to true if they have not been set or reset
|
/// 'title' and 'icon' only default to true if they have not been set or reset
|
||||||
@@ -5035,10 +5037,11 @@ bool option_was_set(const char *name)
|
|||||||
void reset_option_was_set(const char *name)
|
void reset_option_was_set(const char *name)
|
||||||
{
|
{
|
||||||
const int idx = findoption(name);
|
const int idx = findoption(name);
|
||||||
|
if (idx < 0) {
|
||||||
if (idx >= 0) {
|
return;
|
||||||
options[idx].flags &= ~P_WAS_SET;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
options[idx].flags &= ~P_WAS_SET;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// fill_breakat_flags() -- called when 'breakat' changes value.
|
/// fill_breakat_flags() -- called when 'breakat' changes value.
|
||||||
|
@@ -167,36 +167,37 @@ void trigger_optionset_string(int opt_idx, int opt_flags, char *oldval, char *ol
|
|||||||
char *oldval_g, char *newval)
|
char *oldval_g, char *newval)
|
||||||
{
|
{
|
||||||
// Don't do this recursively.
|
// Don't do this recursively.
|
||||||
if (oldval != NULL
|
if (oldval == NULL || newval == NULL
|
||||||
&& newval != NULL
|
|| *get_vim_var_str(VV_OPTION_TYPE) != NUL) {
|
||||||
&& *get_vim_var_str(VV_OPTION_TYPE) == NUL) {
|
return;
|
||||||
char buf_type[7];
|
|
||||||
|
|
||||||
vim_snprintf(buf_type, ARRAY_SIZE(buf_type), "%s",
|
|
||||||
(opt_flags & OPT_LOCAL) ? "local" : "global");
|
|
||||||
set_vim_var_string(VV_OPTION_OLD, oldval, -1);
|
|
||||||
set_vim_var_string(VV_OPTION_NEW, newval, -1);
|
|
||||||
set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
|
|
||||||
if (opt_flags & OPT_LOCAL) {
|
|
||||||
set_vim_var_string(VV_OPTION_COMMAND, "setlocal", -1);
|
|
||||||
set_vim_var_string(VV_OPTION_OLDLOCAL, oldval, -1);
|
|
||||||
}
|
|
||||||
if (opt_flags & OPT_GLOBAL) {
|
|
||||||
set_vim_var_string(VV_OPTION_COMMAND, "setglobal", -1);
|
|
||||||
set_vim_var_string(VV_OPTION_OLDGLOBAL, oldval, -1);
|
|
||||||
}
|
|
||||||
if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) {
|
|
||||||
set_vim_var_string(VV_OPTION_COMMAND, "set", -1);
|
|
||||||
set_vim_var_string(VV_OPTION_OLDLOCAL, oldval_l, -1);
|
|
||||||
set_vim_var_string(VV_OPTION_OLDGLOBAL, oldval_g, -1);
|
|
||||||
}
|
|
||||||
if (opt_flags & OPT_MODELINE) {
|
|
||||||
set_vim_var_string(VV_OPTION_COMMAND, "modeline", -1);
|
|
||||||
set_vim_var_string(VV_OPTION_OLDLOCAL, oldval, -1);
|
|
||||||
}
|
|
||||||
apply_autocmds(EVENT_OPTIONSET, get_option(opt_idx)->fullname, NULL, false, NULL);
|
|
||||||
reset_v_option_vars();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char buf_type[7];
|
||||||
|
|
||||||
|
vim_snprintf(buf_type, ARRAY_SIZE(buf_type), "%s",
|
||||||
|
(opt_flags & OPT_LOCAL) ? "local" : "global");
|
||||||
|
set_vim_var_string(VV_OPTION_OLD, oldval, -1);
|
||||||
|
set_vim_var_string(VV_OPTION_NEW, newval, -1);
|
||||||
|
set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
|
||||||
|
if (opt_flags & OPT_LOCAL) {
|
||||||
|
set_vim_var_string(VV_OPTION_COMMAND, "setlocal", -1);
|
||||||
|
set_vim_var_string(VV_OPTION_OLDLOCAL, oldval, -1);
|
||||||
|
}
|
||||||
|
if (opt_flags & OPT_GLOBAL) {
|
||||||
|
set_vim_var_string(VV_OPTION_COMMAND, "setglobal", -1);
|
||||||
|
set_vim_var_string(VV_OPTION_OLDGLOBAL, oldval, -1);
|
||||||
|
}
|
||||||
|
if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) {
|
||||||
|
set_vim_var_string(VV_OPTION_COMMAND, "set", -1);
|
||||||
|
set_vim_var_string(VV_OPTION_OLDLOCAL, oldval_l, -1);
|
||||||
|
set_vim_var_string(VV_OPTION_OLDGLOBAL, oldval_g, -1);
|
||||||
|
}
|
||||||
|
if (opt_flags & OPT_MODELINE) {
|
||||||
|
set_vim_var_string(VV_OPTION_COMMAND, "modeline", -1);
|
||||||
|
set_vim_var_string(VV_OPTION_OLDLOCAL, oldval, -1);
|
||||||
|
}
|
||||||
|
apply_autocmds(EVENT_OPTIONSET, get_option(opt_idx)->fullname, NULL, false, NULL);
|
||||||
|
reset_v_option_vars();
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *illegal_char(char *errbuf, size_t errbuflen, int c)
|
static char *illegal_char(char *errbuf, size_t errbuflen, int c)
|
||||||
|
Reference in New Issue
Block a user