summaryrefslogtreecommitdiffstats
path: root/src/normal.c
diff options
context:
space:
mode:
authorYegappan Lakshmanan <yegappan@yahoo.com>2023-01-16 18:19:05 +0000
committerBram Moolenaar <Bram@vim.org>2023-01-16 18:19:05 +0000
commita41e221935edab62672a15123af48f4f14ac1c7d (patch)
tree318664da494793bc3edfd6ffafc9d9ed53971dd5 /src/normal.c
parent450c7a97d1a28f715acaf562298112b9b932adc3 (diff)
patch 9.0.1208: code is indented more than necessaryv9.0.1208
Problem: Code is indented more than necessary. Solution: Use an early return where it makes sense. (Yegappan Lakshmanan, closes #11819)
Diffstat (limited to 'src/normal.c')
-rw-r--r--src/normal.c804
1 files changed, 409 insertions, 395 deletions
diff --git a/src/normal.c b/src/normal.c
index 3d9f74dec5..0bd6655f2d 100644
--- a/src/normal.c
+++ b/src/normal.c
@@ -186,14 +186,13 @@ find_command(int cmdchar)
static int
check_text_locked(oparg_T *oap)
{
- if (text_locked())
- {
- if (oap != NULL)
- clearopbeep(oap);
- text_locked_msg();
- return TRUE;
- }
- return FALSE;
+ if (!text_locked())
+ return FALSE;
+
+ if (oap != NULL)
+ clearopbeep(oap);
+ text_locked_msg();
+ return TRUE;
}
/*
@@ -206,13 +205,13 @@ check_text_or_curbuf_locked(oparg_T *oap)
{
if (check_text_locked(oap))
return TRUE;
- if (curbuf_locked())
- {
- if (oap != NULL)
- clearop(oap);
- return TRUE;
- }
- return FALSE;
+
+ if (!curbuf_locked())
+ return FALSE;
+
+ if (oap != NULL)
+ clearop(oap);
+ return TRUE;
}
/*
@@ -2030,19 +2029,19 @@ nv_addsub(cmdarg_T *cap)
static void
nv_page(cmdarg_T *cap)
{
- if (!checkclearop(cap->oap))
+ if (checkclearop(cap->oap))
+ return;
+
+ if (mod_mask & MOD_MASK_CTRL)
{
- if (mod_mask & MOD_MASK_CTRL)
- {
- // <C-PageUp>: tab page back; <C-PageDown>: tab page forward
- if (cap->arg == BACKWARD)
- goto_tabpage(-(int)cap->count1);
- else
- goto_tabpage((int)cap->count0);
- }
+ // <C-PageUp>: tab page back; <C-PageDown>: tab page forward
+ if (cap->arg == BACKWARD)
+ goto_tabpage(-(int)cap->count1);
else
- (void)onepage(cap->arg, cap->count1);
+ goto_tabpage((int)cap->count0);
}
+ else
+ (void)onepage(cap->arg, cap->count1);
}
/*
@@ -2062,17 +2061,16 @@ nv_gd(
== FAIL)
{
clearopbeep(oap);
+ return;
}
- else
- {
+
#ifdef FEAT_FOLDING
- if ((fdo_flags & FDO_SEARCH) && KeyTyped && oap->op_type == OP_NOP)
- foldOpenCursor();
+ if ((fdo_flags & FDO_SEARCH) && KeyTyped && oap->op_type == OP_NOP)
+ foldOpenCursor();
#endif
- // clear any search statistics
- if (messaging() && !msg_silent && !shortmess(SHM_SEARCHCOUNT))
- clear_cmdline = TRUE;
- }
+ // clear any search statistics
+ if (messaging() && !msg_silent && !shortmess(SHM_SEARCHCOUNT))
+ clear_cmdline = TRUE;
}
/*
@@ -3157,60 +3155,61 @@ nv_colon(cmdarg_T *cap)
int flags;
if (VIsual_active && !is_cmdkey)
+ {
nv_operator(cap);
- else
+ return;
+ }
+
+ if (cap->oap->op_type != OP_NOP)
{
- if (cap->oap->op_type != OP_NOP)
+ // Using ":" as a movement is characterwise exclusive.
+ cap->oap->motion_type = MCHAR;
+ cap->oap->inclusive = FALSE;
+ }
+ else if (cap->count0 && !is_cmdkey)
+ {
+ // translate "count:" into ":.,.+(count - 1)"
+ stuffcharReadbuff('.');
+ if (cap->count0 > 1)
{
- // Using ":" as a movement is characterwise exclusive.
- cap->oap->motion_type = MCHAR;
- cap->oap->inclusive = FALSE;
+ stuffReadbuff((char_u *)",.+");
+ stuffnumReadbuff((long)cap->count0 - 1L);
}
- else if (cap->count0 && !is_cmdkey)
- {
- // translate "count:" into ":.,.+(count - 1)"
- stuffcharReadbuff('.');
- if (cap->count0 > 1)
- {
- stuffReadbuff((char_u *)",.+");
- stuffnumReadbuff((long)cap->count0 - 1L);
- }
- }
-
- // When typing, don't type below an old message
- if (KeyTyped)
- compute_cmdrow();
+ }
- old_p_im = p_im;
+ // When typing, don't type below an old message
+ if (KeyTyped)
+ compute_cmdrow();
- // get a command line and execute it
- flags = cap->oap->op_type != OP_NOP ? DOCMD_KEEPLINE : 0;
- if (is_cmdkey)
- cmd_result = do_cmdkey_command(cap->cmdchar, flags);
- else
- cmd_result = do_cmdline(NULL, getexline, NULL, flags);
+ old_p_im = p_im;
- // If 'insertmode' changed, enter or exit Insert mode
- if (p_im != old_p_im)
- {
- if (p_im)
- restart_edit = 'i';
- else
- restart_edit = 0;
- }
+ // get a command line and execute it
+ flags = cap->oap->op_type != OP_NOP ? DOCMD_KEEPLINE : 0;
+ if (is_cmdkey)
+ cmd_result = do_cmdkey_command(cap->cmdchar, flags);
+ else
+ cmd_result = do_cmdline(NULL, getexline, NULL, flags);
- if (cmd_result == FAIL)
- // 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);
+ // If 'insertmode' changed, enter or exit Insert mode
+ if (p_im != old_p_im)
+ {
+ if (p_im)
+ restart_edit = 'i';
+ else
+ restart_edit = 0;
}
+
+ if (cmd_result == FAIL)
+ // 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);
}
/*
@@ -3251,28 +3250,28 @@ nv_ctrlh(cmdarg_T *cap)
static void
nv_clear(cmdarg_T *cap)
{
- if (!checkclearop(cap->oap))
- {
+ if (checkclearop(cap->oap))
+ return;
+
#ifdef FEAT_SYN_HL
- // Clear all syntax states to force resyncing.
- syn_stack_free_all(curwin->w_s);
+ // Clear all syntax states to force resyncing.
+ syn_stack_free_all(curwin->w_s);
# ifdef FEAT_RELTIME
- {
- win_T *wp;
+ {
+ win_T *wp;
- FOR_ALL_WINDOWS(wp)
- wp->w_s->b_syn_slow = FALSE;
- }
+ FOR_ALL_WINDOWS(wp)
+ wp->w_s->b_syn_slow = FALSE;
+ }
# endif
#endif
- redraw_later(UPD_CLEAR);
+ redraw_later(UPD_CLEAR);
#if defined(MSWIN) && (!defined(FEAT_GUI_MSWIN) || defined(VIMDLL))
# ifdef VIMDLL
- if (!gui.in_use)
+ if (!gui.in_use)
# endif
- resize_console_buf();
+ resize_console_buf();
#endif
- }
}
/*
@@ -3314,20 +3313,20 @@ nv_hat(cmdarg_T *cap)
static void
nv_Zet(cmdarg_T *cap)
{
- if (!checkclearopq(cap->oap))
+ if (checkclearopq(cap->oap))
+ return;
+
+ switch (cap->nchar)
{
- switch (cap->nchar)
- {
- // "ZZ": equivalent to ":x".
- case 'Z': do_cmdline_cmd((char_u *)"x");
+ // "ZZ": equivalent to ":x".
+ case 'Z': do_cmdline_cmd((char_u *)"x");
break;
// "ZQ": equivalent to ":q!" (Elvis compatible).
- case 'Q': do_cmdline_cmd((char_u *)"q!");
+ case 'Q': do_cmdline_cmd((char_u *)"q!");
break;
- default: clearopbeep(cap->oap);
- }
+ default: clearopbeep(cap->oap);
}
}
@@ -3982,15 +3981,14 @@ nv_up(cmdarg_T *cap)
// <S-Up> is page up
cap->arg = BACKWARD;
nv_page(cap);
+ return;
}
- else
- {
- cap->oap->motion_type = MLINE;
- if (cursor_up(cap->count1, cap->oap->op_type == OP_NOP) == FAIL)
- clearopbeep(cap->oap);
- else if (cap->arg)
- beginline(BL_WHITE | BL_FIX);
- }
+
+ cap->oap->motion_type = MLINE;
+ if (cursor_up(cap->count1, cap->oap->op_type == OP_NOP) == FAIL)
+ clearopbeep(cap->oap);
+ else if (cap->arg)
+ beginline(BL_WHITE | BL_FIX);
}
/*
@@ -4249,27 +4247,28 @@ nv_csearch(cmdarg_T *cap)
cap->oap->motion_type = MCHAR;
if (IS_SPECIAL(cap->nchar) || searchc(cap, t_cmd) == FAIL)
+ {
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))
{
- 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;
+ colnr_T scol, ecol;
- getvcol(curwin, &curwin->w_cursor, &scol, NULL, &ecol);
- curwin->w_cursor.coladd = ecol - scol;
- }
- else
- curwin->w_cursor.coladd = 0;
- adjust_for_sel(cap);
+ getvcol(curwin, &curwin->w_cursor, &scol, NULL, &ecol);
+ curwin->w_cursor.coladd = ecol - scol;
+ }
+ else
+ curwin->w_cursor.coladd = 0;
+ adjust_for_sel(cap);
#ifdef FEAT_FOLDING
- if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP)
- foldOpenCursor();
+ if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP)
+ foldOpenCursor();
#endif
- }
}
/*
@@ -4654,17 +4653,18 @@ nv_brace(cmdarg_T *cap)
curwin->w_set_curswant = TRUE;
if (findsent(cap->arg, cap->count1) == FAIL)
- clearopbeep(cap->oap);
- else
{
- // Don't leave the cursor on the NUL past end of line.
- adjust_cursor(cap->oap);
- curwin->w_cursor.coladd = 0;
+ clearopbeep(cap->oap);
+ return;
+ }
+
+ // Don't leave the cursor on the NUL past end of line.
+ adjust_cursor(cap->oap);
+ curwin->w_cursor.coladd = 0;
#ifdef FEAT_FOLDING
- if ((fdo_flags & FDO_BLOCK) && KeyTyped && cap->oap->op_type == OP_NOP)
- foldOpenCursor();
+ if ((fdo_flags & FDO_BLOCK) && KeyTyped && cap->oap->op_type == OP_NOP)
+ foldOpenCursor();
#endif
- }
}
/*
@@ -4673,11 +4673,11 @@ nv_brace(cmdarg_T *cap)
static void
nv_mark(cmdarg_T *cap)
{
- if (!checkclearop(cap->oap))
- {
- if (setmark(cap->nchar) == FAIL)
- clearopbeep(cap->oap);
- }
+ if (checkclearop(cap->oap))
+ return;
+
+ if (setmark(cap->nchar) == FAIL)
+ clearopbeep(cap->oap);
}
/*
@@ -4692,15 +4692,16 @@ nv_findpar(cmdarg_T *cap)
cap->oap->use_reg_one = TRUE;
curwin->w_set_curswant = TRUE;
if (!findpar(&cap->oap->inclusive, cap->arg, cap->count1, NUL, FALSE))
- clearopbeep(cap->oap);
- else
{
- curwin->w_cursor.coladd = 0;
+ clearopbeep(cap->oap);
+ return;
+ }
+
+ curwin->w_cursor.coladd = 0;
#ifdef FEAT_FOLDING
- if ((fdo_flags & FDO_BLOCK) && KeyTyped && cap->oap->op_type == OP_NOP)
- foldOpenCursor();
+ if ((fdo_flags & FDO_BLOCK) && KeyTyped && cap->oap->op_type == OP_NOP)
+ foldOpenCursor();
#endif
- }
}
/*
@@ -4726,18 +4727,18 @@ nv_undo(cmdarg_T *cap)
static void
nv_kundo(cmdarg_T *cap)
{
- if (!checkclearopq(cap->oap))
- {
+ if (checkclearopq(cap->oap))
+ return;
+
#ifdef FEAT_JOB_CHANNEL
- if (bt_prompt(curbuf))
- {
- clearopbeep(cap->oap);
- return;
- }
-#endif
- u_undo((int)cap->count1);
- curwin->w_set_curswant = TRUE;
+ if (bt_prompt(curbuf))
+ {
+ clearopbeep(cap->oap);
+ return;
}
+#endif
+ u_undo((int)cap->count1);
+ curwin->w_set_curswant = TRUE;
}
/*
@@ -5008,17 +5009,19 @@ nv_Replace(cmdarg_T *cap)
VIsual_mode_orig = VIsual_mode; // remember original area for gv
VIsual_mode = 'V';
nv_operator(cap);
+ return;
}
- else if (!checkclearopq(cap->oap))
+
+ if (checkclearopq(cap->oap))
+ return;
+
+ if (!curbuf->b_p_ma)
+ emsg(_(e_cannot_make_changes_modifiable_is_off));
+ else
{
- if (!curbuf->b_p_ma)
- emsg(_(e_cannot_make_changes_modifiable_is_off));
- else
- {
- if (virtual_active())
- coladvance(getviscol());
- invoke_edit(cap, FALSE, cap->arg ? 'V' : 'R', FALSE);
- }
+ if (virtual_active())
+ coladvance(getviscol());
+ invoke_edit(cap, FALSE, cap->arg ? 'V' : 'R', FALSE);
}
}
@@ -5033,21 +5036,23 @@ nv_vreplace(cmdarg_T *cap)
cap->cmdchar = 'r';
cap->nchar = cap->extra_char;
nv_replace(cap); // Do same as "r" in Visual mode for now
+ return;
}
- else if (!checkclearopq(cap->oap))
+
+ if (checkclearopq(cap->oap))
+ return;
+
+ if (!curbuf->b_p_ma)
+ emsg(_(e_cannot_make_changes_modifiable_is_off));
+ else
{
- if (!curbuf->b_p_ma)
- emsg(_(e_cannot_make_changes_modifiable_is_off));
- else
- {
- if (cap->extra_char == Ctrl_V) // get another character
- cap->extra_char = get_literal(FALSE);
- stuffcharReadbuff(cap->extra_char);
- stuffcharReadbuff(ESC);
- if (virtual_active())
- coladvance(getviscol());
- invoke_edit(cap, TRUE, 'v', FALSE);
- }
+ if (cap->extra_char == Ctrl_V) // get another character
+ cap->extra_char = get_literal(FALSE);
+ stuffcharReadbuff(cap->extra_char);
+ stuffcharReadbuff(ESC);
+ if (virtual_active())
+ coladvance(getviscol());
+ invoke_edit(cap, TRUE, 'v', FALSE);
}
}
@@ -5345,44 +5350,44 @@ nv_pcmark(cmdarg_T *cap)
int old_KeyTyped = KeyTyped; // getting file may reset it
#endif
- if (!checkclearopq(cap->oap))
+ if (checkclearopq(cap->oap))
+ return;
+
+ if (cap->cmdchar == TAB && mod_mask == MOD_MASK_CTRL)
{
- if (cap->cmdchar == TAB && mod_mask == MOD_MASK_CTRL)
- {
- if (goto_tabpage_lastused() == FAIL)
- clearopbeep(cap->oap);
- return;
- }
- if (cap->cmdchar == 'g')
- pos = movechangelist((int)cap->count1);
- else
- pos = movemark((int)cap->count1);
- if (pos == (pos_T *)-1) // jump to other file
- {
- curwin->w_set_curswant = TRUE;
- check_cursor();
- }
- else if (pos != NULL) // can jump
- nv_cursormark(cap, FALSE, pos);
- else if (cap->cmdchar == 'g')
- {
- if (curbuf->b_changelistlen == 0)
- emsg(_(e_changelist_is_empty));
- else if (cap->count1 < 0)
- emsg(_(e_at_start_of_changelist));
- else
- emsg(_(e_at_end_of_changelist));
- }
- else
+ if (goto_tabpage_lastused() == FAIL)
clearopbeep(cap->oap);
+ return;
+ }
+ if (cap->cmdchar == 'g')
+ pos = movechangelist((int)cap->count1);
+ else
+ pos = movemark((int)cap->count1);
+ if (pos == (pos_T *)-1) // jump to other file
+ {
+ curwin->w_set_curswant = TRUE;
+ check_cursor();
+ }
+ else if (pos != NULL) // can jump
+ nv_cursormark(cap, FALSE, pos);
+ else if (cap->cmdchar == 'g')
+ {
+ if (curbuf->b_changelistlen == 0)
+ emsg(_(e_changelist_is_empty));
+ else if (cap->count1 < 0)
+ emsg(_(e_at_start_of_changelist));
+ else
+ emsg(_(e_at_end_of_changelist));
+ }
+ else
+ clearopbeep(cap->oap);
# ifdef FEAT_FOLDING
- if (cap->oap->op_type == OP_NOP
- && (pos == (pos_T *)-1 || lnum != curwin->w_cursor.lnum)
- && (fdo_flags & FDO_MARK)
- && old_KeyTyped)
- foldOpenCursor();
+ if (cap->oap->op_type == OP_NOP
+ && (pos == (pos_T *)-1 || lnum != curwin->w_cursor.lnum)
+ && (fdo_flags & FDO_MARK)
+ && old_KeyTyped)
+ foldOpenCursor();
# endif
- }
}
/*
@@ -6237,41 +6242,41 @@ n_opencmd(cmdarg_T *cap)
linenr_T oldline = curwin->w_cursor.lnum;
#endif
- if (!checkclearopq(cap->oap))
- {
+ if (checkclearopq(cap->oap))
+ return;
+
#ifdef FEAT_FOLDING
- if (cap->cmdchar == 'O')
- // Open above the first line of a folded sequence of lines
- (void)hasFolding(curwin->w_cursor.lnum,
- &curwin->w_cursor.lnum, NULL);
- else
- // Open below the last line of a folded sequence of lines
- (void)hasFolding(curwin->w_cursor.lnum,
- NULL, &curwin->w_cursor.lnum);
-#endif
- if (u_save((linenr_T)(curwin->w_cursor.lnum -
- (cap->cmdchar == 'O' ? 1 : 0)),
- (linenr_T)(curwin->w_cursor.lnum +
- (cap->cmdchar == 'o' ? 1 : 0))
- ) == OK
- && open_line(cap->cmdchar == 'O' ? BACKWARD : FORWARD,
- has_format_option(FO_OPEN_COMS) ? OPENLINE_DO_COM : 0,
- 0, NULL) == OK)
- {
+ if (cap->cmdchar == 'O')
+ // Open above the first line of a folded sequence of lines
+ (void)hasFolding(curwin->w_cursor.lnum,
+ &curwin->w_cursor.lnum, NULL);
+ else
+ // Open below the last line of a folded sequence of lines
+ (void)hasFolding(curwin->w_cursor.lnum,
+ NULL, &curwin->w_cursor.lnum);
+#endif
+ if (u_save((linenr_T)(curwin->w_cursor.lnum -
+ (cap->cmdchar == 'O' ? 1 : 0)),
+ (linenr_T)(curwin->w_cursor.lnum +
+ (cap->cmdchar == 'o' ? 1 : 0))
+ ) == OK
+ && open_line(cap->cmdchar == 'O' ? BACKWARD : FORWARD,
+ has_format_option(FO_OPEN_COMS) ? OPENLINE_DO_COM : 0,
+ 0, NULL) == OK)
+ {
#ifdef FEAT_CONCEAL
- if (curwin->w_p_cole > 0 && oldline != curwin->w_cursor.lnum)
- redrawWinline(curwin, oldline);
+ if (curwin->w_p_cole > 0 && oldline != curwin->w_cursor.lnum)
+ redrawWinline(curwin, oldline);
#endif
#ifdef FEAT_SYN_HL
- if (curwin->w_p_cul)
- // force redraw of cursorline
- curwin->w_valid &= ~VALID_CROW;
-#endif
- // When '#' is in 'cpoptions' ignore the count.
- if (vim_strchr(p_cpo, CPO_HASH) != NULL)
- cap->count1 = 1;
- invoke_edit(cap, FALSE, cap->cmdchar, TRUE);
- }
+ if (curwin->w_p_cul)
+ // force redraw of cursorline
+ curwin->w_valid &= ~VALID_CROW;
+#endif
+ // When '#' is in 'cpoptions' ignore the count.
+ if (vim_strchr(p_cpo, CPO_HASH) != NULL)
+ cap->count1 = 1;
+ invoke_edit(cap, FALSE, cap->cmdchar, TRUE);
}
}
@@ -6281,14 +6286,14 @@ n_opencmd(cmdarg_T *cap)
static void
nv_dot(cmdarg_T *cap)
{
- if (!checkclearopq(cap->oap))
- {
- // If "restart_edit" is TRUE, the last but one command is repeated
- // 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) == FAIL)
- clearopbeep(cap->oap);
- }
+ if (checkclearopq(cap->oap))
+ return;
+
+ // If "restart_edit" is TRUE, the last but one command is repeated
+ // 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) == FAIL)
+ clearopbeep(cap->oap);
}
/*
@@ -6316,11 +6321,11 @@ nv_redo_or_register(cmdarg_T *cap)
return;
}
- if (!checkclearopq(cap->oap))
- {
- u_redo((int)cap->count1);
- curwin->w_set_curswant = TRUE;
- }
+ if (checkclearopq(cap->oap))
+ return;
+
+ u_redo((int)cap->count1);
+ curwin->w_set_curswant = TRUE;
}
/*
@@ -6336,12 +6341,14 @@ nv_Undo(cmdarg_T *cap)
cap->cmdchar = 'g';
cap->nchar = 'U';
nv_operator(cap);
+ return;
}
- else if (!checkclearopq(cap->oap))
- {
- u_undoline();
- curwin->w_set_curswant = TRUE;
- }
+
+ if (checkclearopq(cap->oap))
+ return;
+
+ u_undoline();
+ curwin->w_set_curswant = TRUE;
}
/*
@@ -7146,25 +7153,27 @@ nv_record(cmdarg_T *cap)
cap->cmdchar = 'g';
cap->nchar = 'q';
nv_operator(cap);
+ return;
}
- else if (!checkclearop(cap->oap))
+
+ if (checkclearop(cap->oap))
+ return;
+
+ if (cap->nchar == ':' || cap->nchar == '/' || cap->nchar == '?')
{
- if (cap->nchar == ':' || cap->nchar == '/' || cap->nchar == '?')
+ if (cmdwin_type != 0)
{
- if (cmdwin_type != 0)
- {
- emsg(_(e_cmdline_window_already_open));
- return;
- }
- stuffcharReadbuff(cap->nchar);
- stuffcharReadbuff(K_CMDWIN);
+ emsg(_(e_cmdline_window_already_open));
+ return;
}
- else
- // (stop) recording into a named register, unless executing a
- // register
- if (reg_executing == 0 && do_record(cap->nchar) == FAIL)
- 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);
}
/*
@@ -7214,28 +7223,32 @@ nv_halfpage(cmdarg_T *cap)
nv_join(cmdarg_T *cap)
{
if (VIsual_active) // join the visual lines
+ {
nv_operator(cap);
- else if (!checkclearop(cap->oap))
+ return;
+ }
+
+ 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)
{
- 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)
{
- // 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;
+ clearopbeep(cap->oap);
+ return;
}
-
- prep_redo(cap->oap->regname, cap->count0,
- NUL, cap->cmdchar, NUL, NUL, cap->nchar);
- (void)do_join(cap->count0, cap->nchar == NUL, TRUE, TRUE, TRUE);
+ 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);
+ (void)do_join(cap->count0, cap->nchar == NUL, TRUE, TRUE, TRUE);
}
/*
@@ -7273,132 +7286,133 @@ nv_put_opt(cmdarg_T *cap, int fix_indent)
}
else
#endif
- clearopbeep(cap->oap);
+ clearopbeep(cap->oap);
+ return;
}
+
#ifdef FEAT_JOB_CHANNEL
- else if (bt_prompt(curbuf) && !prompt_curpos_editable())
+ if (bt_prompt(curbuf) && !prompt_curpos_editable())
{
clearopbeep(cap->oap);
+ return;
}
#endif
- else
+
+ if (fix_indent)
{
- 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;
+ 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;
- keep_registers = cap->cmdchar == 'P';
+ 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;
+ keep_registers = cap->cmdchar == 'P';
#ifdef FEAT_CLIPBOARD
- adjust_clip_reg(&regname);
+ adjust_clip_reg(&regname);
#endif
- if (regname == 0 || regname == '"'
- || VIM_ISDIGIT(regname) || regname == '-'
+ if (regname == 0 || regname == '"'
+ || VIM_ISDIGIT(regname) || regname == '-'
#ifdef FEAT_CLIPBOARD
- || (clip_unnamed && (regname == '*' || regname == '+'))
+ || (clip_unnamed && (regname == '*' || regname == '+'))
#endif
- )
- {
- // The delete is going to overwrite the register we want to
- // put, save it first.
- reg1 = get_register(regname, TRUE);
- }
-
- // 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;
-
- if (reg1 != NULL)
- {
- // Delete probably changed the register we want to put, save
- // it first. Then put back what was there before the delete.
- reg2 = get_register(regname, FALSE);
- put_register(regname, reg1);
- }
-
- // When deleted a linewise Visual area, put the register as
- // lines to avoid it joined with the next line. When deletion was
- // characterwise, 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, NULL, dir, cap->count1, flags);
-
- // If a register was saved, put it back now.
- if (reg2 != NULL)
- put_register(regname, reg2);
-
- // 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);
+ // The delete is going to overwrite the register we want to
+ // put, save it first.
+ reg1 = get_register(regname, TRUE);
}
- // 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)
+ // 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;
+
+ if (reg1 != NULL)
+ {
+ // Delete probably changed the register we want to put, save
+ // it first. Then put back what was there before the delete.
+ reg2 = get_register(regname, FALSE);
+ put_register(regname, reg1);
+ }
+
+ // When deleted a linewise Visual area, put the register as
+ // lines to avoid it joined with the next line. When deletion was
+ // characterwise, 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, NULL, dir, cap->count1, flags);
+
+ // If a register was saved, put it back now.
+ if (reg2 != NULL)
+ put_register(regname, reg2);
+
+ // 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_flags(curbuf->b_ml.ml_line_count, ML_DEL_MESSAGE);
+ 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)
{
- ml_delete_flags(curbuf->b_ml.ml_line_count, ML_DEL_MESSAGE);
- 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((colnr_T)MAXCOL);
- }
+ curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
+ coladvance((colnr_T)MAXCOL);
}
- auto_format(FALSE, TRUE);
}
+ auto_format(FALSE, TRUE);
}
/*