aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/normal.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/normal.c')
-rw-r--r--src/nvim/normal.c2353
1 files changed, 1297 insertions, 1056 deletions
diff --git a/src/nvim/normal.c b/src/nvim/normal.c
index 4c3d7d58de..85897bac12 100644
--- a/src/nvim/normal.c
+++ b/src/nvim/normal.c
@@ -9,14 +9,12 @@
#include <assert.h>
#include <inttypes.h>
-#include <string.h>
#include <stdbool.h>
#include <stdlib.h>
+#include <string.h>
-#include "nvim/log.h"
-#include "nvim/vim.h"
+#include "nvim/api/private/helpers.h"
#include "nvim/ascii.h"
-#include "nvim/normal.h"
#include "nvim/buffer.h"
#include "nvim/change.h"
#include "nvim/charset.h"
@@ -25,6 +23,7 @@
#include "nvim/digraph.h"
#include "nvim/edit.h"
#include "nvim/eval/userfunc.h"
+#include "nvim/event/loop.h"
#include "nvim/ex_cmds.h"
#include "nvim/ex_cmds2.h"
#include "nvim/ex_docmd.h"
@@ -34,35 +33,35 @@
#include "nvim/getchar.h"
#include "nvim/indent.h"
#include "nvim/indent_c.h"
+#include "nvim/keymap.h"
+#include "nvim/log.h"
#include "nvim/main.h"
#include "nvim/mark.h"
#include "nvim/memline.h"
#include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/misc1.h"
-#include "nvim/keymap.h"
-#include "nvim/move.h"
#include "nvim/mouse.h"
+#include "nvim/move.h"
+#include "nvim/normal.h"
#include "nvim/ops.h"
#include "nvim/option.h"
+#include "nvim/os/input.h"
+#include "nvim/os/time.h"
#include "nvim/plines.h"
#include "nvim/quickfix.h"
#include "nvim/screen.h"
#include "nvim/search.h"
#include "nvim/spell.h"
#include "nvim/spellfile.h"
+#include "nvim/state.h"
#include "nvim/strings.h"
#include "nvim/syntax.h"
#include "nvim/tag.h"
#include "nvim/ui.h"
-#include "nvim/mouse.h"
#include "nvim/undo.h"
+#include "nvim/vim.h"
#include "nvim/window.h"
-#include "nvim/state.h"
-#include "nvim/event/loop.h"
-#include "nvim/os/time.h"
-#include "nvim/os/input.h"
-#include "nvim/api/private/helpers.h"
typedef struct normal_state {
VimState state;
@@ -88,10 +87,10 @@ typedef struct normal_state {
/*
* The Visual area is remembered for reselection.
*/
-static int resel_VIsual_mode = NUL; /* 'v', 'V', or Ctrl-V */
-static linenr_T resel_VIsual_line_count; /* number of lines */
-static colnr_T resel_VIsual_vcol; /* nr of cols or end col */
-static int VIsual_mode_orig = NUL; /* saved Visual mode */
+static int resel_VIsual_mode = NUL; // 'v', 'V', or Ctrl-V
+static linenr_T resel_VIsual_line_count; // number of lines
+static colnr_T resel_VIsual_vcol; // nr of cols or end col
+static int VIsual_mode_orig = NUL; // saved Visual mode
#ifdef INCLUDE_GENERATED_DECLARATIONS
@@ -119,18 +118,18 @@ static char *e_noident = N_("E349: No identifier under cursor");
*/
typedef void (*nv_func_T)(cmdarg_T *cap);
-/* Values for cmd_flags. */
-#define NV_NCH 0x01 /* may need to get a second char */
-#define NV_NCH_NOP (0x02|NV_NCH) /* get second char when no operator pending */
-#define NV_NCH_ALW (0x04|NV_NCH) /* always get a second char */
-#define NV_LANG 0x08 /* second char needs language adjustment */
+// Values for cmd_flags.
+#define NV_NCH 0x01 // may need to get a second char
+#define NV_NCH_NOP (0x02|NV_NCH) // get second char when no operator pending
+#define NV_NCH_ALW (0x04|NV_NCH) // always get a second char
+#define NV_LANG 0x08 // second char needs language adjustment
-#define NV_SS 0x10 /* may start selection */
-#define NV_SSS 0x20 /* may start selection with shift modifier */
-#define NV_STS 0x40 /* may stop selection without shift modif. */
-#define NV_RL 0x80 /* 'rightleft' modifies command */
-#define NV_KEEPREG 0x100 /* don't clear regname */
-#define NV_NCW 0x200 /* not allowed in command-line window */
+#define NV_SS 0x10 // may start selection
+#define NV_SSS 0x20 // may start selection with shift modifier
+#define NV_STS 0x40 // may stop selection without shift modif.
+#define NV_RL 0x80 // 'rightleft' modifies command
+#define NV_KEEPREG 0x100 // don't clear regname
+#define NV_NCW 0x200 // not allowed in command-line window
/*
* Generally speaking, every Normal mode command should either clear any
@@ -148,10 +147,10 @@ typedef void (*nv_func_T)(cmdarg_T *cap);
* It is faster when all keys from zero to '~' are present.
*/
static const struct nv_cmd {
- int cmd_char; /* (first) command character */
- nv_func_T cmd_func; /* function for this command */
- uint16_t cmd_flags; /* NV_ flags */
- short cmd_arg; /* value for ca.arg */
+ int cmd_char; // (first) command character
+ nv_func_T cmd_func; // function for this command
+ uint16_t cmd_flags; // NV_ flags
+ short cmd_arg; // value for ca.arg
} nv_cmds[] =
{
{ NUL, nv_error, 0, 0 },
@@ -344,10 +343,10 @@ static const struct nv_cmd {
{ K_COMMAND, nv_colon, 0, 0 },
};
-/* Number of commands in nv_cmds[]. */
+// Number of commands in nv_cmds[].
#define NV_CMDS_SIZE ARRAY_SIZE(nv_cmds)
-/* Sorted index of commands in nv_cmds[]. */
+// Sorted index of commands in nv_cmds[].
static short nv_cmd_idx[NV_CMDS_SIZE];
/* The highest index for which
@@ -362,13 +361,15 @@ static int nv_compare(const void *s1, const void *s2)
{
int c1, c2;
- /* The commands are sorted on absolute value. */
+ // The commands are sorted on absolute value.
c1 = nv_cmds[*(const short *)s1].cmd_char;
c2 = nv_cmds[*(const short *)s2].cmd_char;
- if (c1 < 0)
+ if (c1 < 0) {
c1 = -c1;
- if (c2 < 0)
+ }
+ if (c2 < 0) {
c2 = -c2;
+ }
return c1 - c2;
}
@@ -379,15 +380,15 @@ void init_normal_cmds(void)
{
assert(NV_CMDS_SIZE <= SHRT_MAX);
- /* Fill the index table with a one to one relation. */
+ // Fill the index table with a one to one relation.
for (short int i = 0; i < (short int)NV_CMDS_SIZE; ++i) {
nv_cmd_idx[i] = i;
}
- /* Sort the commands by the command character. */
+ // Sort the commands by the command character.
qsort(&nv_cmd_idx, NV_CMDS_SIZE, sizeof(short), nv_compare);
- /* Find the first entry that can't be indexed by the command character. */
+ // Find the first entry that can't be indexed by the command character.
short int i;
for (i = 0; i < (short int)NV_CMDS_SIZE; ++i) {
if (i != nv_cmds[nv_cmd_idx[i]].cmd_char) {
@@ -408,38 +409,43 @@ static int find_command(int cmdchar)
int top, bot;
int c;
- /* A multi-byte character is never a command. */
- if (cmdchar >= 0x100)
+ // A multi-byte character is never a command.
+ if (cmdchar >= 0x100) {
return -1;
+ }
/* We use the absolute value of the character. Special keys have a
* negative value, but are sorted on their absolute value. */
- if (cmdchar < 0)
+ if (cmdchar < 0) {
cmdchar = -cmdchar;
+ }
/* If the character is in the first part: The character is the index into
* nv_cmd_idx[]. */
assert(nv_max_linear < (int)NV_CMDS_SIZE);
- if (cmdchar <= nv_max_linear)
+ if (cmdchar <= nv_max_linear) {
return nv_cmd_idx[cmdchar];
+ }
- /* Perform a binary search. */
+ // Perform a binary search.
bot = nv_max_linear + 1;
top = NV_CMDS_SIZE - 1;
idx = -1;
while (bot <= top) {
i = (top + bot) / 2;
c = nv_cmds[nv_cmd_idx[i]].cmd_char;
- if (c < 0)
+ if (c < 0) {
c = -c;
+ }
if (cmdchar == c) {
idx = nv_cmd_idx[i];
break;
}
- if (cmdchar > c)
+ if (cmdchar > c) {
bot = i + 1;
- else
+ } else {
top = i - 1;
+ }
}
return idx;
}
@@ -544,59 +550,60 @@ static bool normal_need_additional_char(NormalState *s)
int cmdchar = s->ca.cmdchar;
// without NV_NCH we never need to check for an additional char
return flags & NV_NCH && (
- // NV_NCH_NOP is set and no operator is pending, get a second char
- ((flags & NV_NCH_NOP) == NV_NCH_NOP && !pending_op)
- // NV_NCH_ALW is set, always get a second char
- || (flags & NV_NCH_ALW) == NV_NCH_ALW
- // 'q' without a pending operator, recording or executing a register,
- // needs to be followed by a second char, examples:
- // - qc => record using register c
- // - q: => open command-line window
- || (cmdchar == 'q'
- && !pending_op
- && reg_recording == 0
- && reg_executing == 0)
- // 'a' or 'i' after an operator is a text object, examples:
- // - ciw => change inside word
- // - da( => delete parenthesis and everything inside.
- // Also, don't do anything when these keys are received in visual mode
- // so just get another char.
- //
- // TODO(tarruda): Visual state needs to be refactored into a
- // separate state that "inherits" from normal state.
- || ((cmdchar == 'a' || cmdchar == 'i') && (pending_op || VIsual_active)));
+ // NV_NCH_NOP is set and no operator is pending, get a second char
+ ((flags & NV_NCH_NOP) == NV_NCH_NOP && !pending_op)
+ // NV_NCH_ALW is set, always get a second char
+ || (flags & NV_NCH_ALW) == NV_NCH_ALW
+ // 'q' without a pending operator, recording or executing a register,
+ // needs to be followed by a second char, examples:
+ // - qc => record using register c
+ // - q: => open command-line window
+ || (cmdchar == 'q'
+ && !pending_op
+ && reg_recording == 0
+ && reg_executing == 0)
+ // 'a' or 'i' after an operator is a text object, examples:
+ // - ciw => change inside word
+ // - da( => delete parenthesis and everything inside.
+ // Also, don't do anything when these keys are received in visual mode
+ // so just get another char.
+ //
+ // TODO(tarruda): Visual state needs to be refactored into a
+ // separate state that "inherits" from normal state.
+ || ((cmdchar == 'a' || cmdchar == 'i') &&
+ (pending_op || VIsual_active)));
}
static bool normal_need_redraw_mode_message(NormalState *s)
{
return (
- // 'showmode' is set and messages can be printed
- ((p_smd && msg_silent == 0
- // must restart insert mode(ctrl+o or ctrl+l) or we just entered visual
- // mode
- && (restart_edit != 0 || (VIsual_active
- && s->old_pos.lnum == curwin->w_cursor.lnum
- && s->old_pos.col == curwin->w_cursor.col))
- // command-line must be cleared or redrawn
- && (clear_cmdline || redraw_cmdline)
- // some message was printed or scrolled
- && (msg_didout || (msg_didany && msg_scroll))
- // it is fine to remove the current message
- && !msg_nowait
- // the command was the result of direct user input and not a mapping
- && KeyTyped)
- // must restart insert mode, not in visual mode and error message is
- // being shown
- || (restart_edit != 0 && !VIsual_active && msg_scroll
- && emsg_on_display))
- // no register was used
- && s->oa.regname == 0
- && !(s->ca.retval & CA_COMMAND_BUSY)
- && stuff_empty()
- && typebuf_typed()
- && emsg_silent == 0
- && !did_wait_return
- && s->oa.op_type == OP_NOP);
+ // 'showmode' is set and messages can be printed
+ ((p_smd && msg_silent == 0
+ // must restart insert mode(ctrl+o or ctrl+l) or we just entered visual
+ // mode
+ && (restart_edit != 0 || (VIsual_active
+ && s->old_pos.lnum == curwin->w_cursor.lnum
+ && s->old_pos.col == curwin->w_cursor.col))
+ // command-line must be cleared or redrawn
+ && (clear_cmdline || redraw_cmdline)
+ // some message was printed or scrolled
+ && (msg_didout || (msg_didany && msg_scroll))
+ // it is fine to remove the current message
+ && !msg_nowait
+ // the command was the result of direct user input and not a mapping
+ && KeyTyped)
+ // must restart insert mode, not in visual mode and error message is
+ // being shown
+ || (restart_edit != 0 && !VIsual_active && msg_scroll
+ && emsg_on_display))
+ // no register was used
+ && s->oa.regname == 0
+ && !(s->ca.retval & CA_COMMAND_BUSY)
+ && stuff_empty()
+ && typebuf_typed()
+ && emsg_silent == 0
+ && !did_wait_return
+ && s->oa.op_type == OP_NOP);
}
static void normal_redraw_mode_message(NormalState *s)
@@ -707,7 +714,7 @@ static void normal_get_additional_char(NormalState *s)
if (!lit) {
// Typing CTRL-K gets a digraph.
if (*cp == Ctrl_K && ((nv_cmds[s->idx].cmd_flags & NV_LANG)
- || cp == &s->ca.extra_char)
+ || cp == &s->ca.extra_char)
&& vim_strchr(p_cpo, CPO_DIGRAPH) == NULL) {
s->c = get_digraph(false);
if (s->c > 0) {
@@ -735,7 +742,7 @@ static void normal_get_additional_char(NormalState *s)
s->ca.nchar = s->ca.extra_char;
s->idx = find_command(s->ca.cmdchar);
} else if ((s->ca.nchar == 'n' || s->ca.nchar == 'N')
- && s->ca.cmdchar == 'g') {
+ && s->ca.cmdchar == 'g') {
s->ca.oap->op_type = get_op_type(*cp, NUL);
} else if (*cp == Ctrl_BSL) {
long towait = (p_ttm >= 0 ? p_ttm : p_tm);
@@ -769,7 +776,7 @@ static void normal_get_additional_char(NormalState *s)
&& (s->c >= 0x100 || MB_BYTE2LEN(vpeekc()) > 1)) {
s->c = plain_vgetc();
if (!utf_iscomposing(s->c)) {
- vungetc(s->c); /* it wasn't, put it back */
+ vungetc(s->c); // it wasn't, put it back
break;
} else if (s->ca.ncharC1 == 0) {
s->ca.ncharC1 = s->c;
@@ -785,16 +792,26 @@ static void normal_get_additional_char(NormalState *s)
static void normal_invert_horizontal(NormalState *s)
{
switch (s->ca.cmdchar) {
- case 'l': s->ca.cmdchar = 'h'; break;
- case K_RIGHT: s->ca.cmdchar = K_LEFT; break;
- case K_S_RIGHT: s->ca.cmdchar = K_S_LEFT; break;
- case K_C_RIGHT: s->ca.cmdchar = K_C_LEFT; break;
- case 'h': s->ca.cmdchar = 'l'; break;
- case K_LEFT: s->ca.cmdchar = K_RIGHT; break;
- case K_S_LEFT: s->ca.cmdchar = K_S_RIGHT; break;
- case K_C_LEFT: s->ca.cmdchar = K_C_RIGHT; break;
- case '>': s->ca.cmdchar = '<'; break;
- case '<': s->ca.cmdchar = '>'; break;
+ case 'l':
+ s->ca.cmdchar = 'h'; break;
+ case K_RIGHT:
+ s->ca.cmdchar = K_LEFT; break;
+ case K_S_RIGHT:
+ s->ca.cmdchar = K_S_LEFT; break;
+ case K_C_RIGHT:
+ s->ca.cmdchar = K_C_LEFT; break;
+ case 'h':
+ s->ca.cmdchar = 'l'; break;
+ case K_LEFT:
+ s->ca.cmdchar = K_RIGHT; break;
+ case K_S_LEFT:
+ s->ca.cmdchar = K_S_RIGHT; break;
+ case K_C_LEFT:
+ s->ca.cmdchar = K_C_RIGHT; break;
+ case '>':
+ s->ca.cmdchar = '<'; break;
+ case '<':
+ s->ca.cmdchar = '>'; break;
}
s->idx = find_command(s->ca.cmdchar);
}
@@ -808,7 +825,7 @@ static bool normal_get_command_count(NormalState *s)
// Note that '0' is a command and not the start of a count, but it's
// part of a count after other digits.
while ((s->c >= '1' && s->c <= '9') || (s->ca.count0 != 0
- && (s->c == K_DEL || s->c == K_KDEL || s->c == '0'))) {
+ && (s->c == K_DEL || s->c == K_KDEL || s->c == '0'))) {
if (s->c == K_DEL || s->c == K_KDEL) {
s->ca.count0 /= 10;
del_from_showcmd(4); // delete the digit and ~@%
@@ -941,11 +958,11 @@ normal_end:
// if still inside a mapping that started in Visual mode).
// May switch from Visual to Select mode after CTRL-O command.
if (s->oa.op_type == OP_NOP
- && ((restart_edit != 0 && !VIsual_active && s->old_mapped_len == 0)
- || restart_VIsual_select == 1)
- && !(s->ca.retval & CA_COMMAND_BUSY)
- && stuff_empty()
- && s->oa.regname == 0) {
+ && ((restart_edit != 0 && !VIsual_active && s->old_mapped_len == 0)
+ || restart_VIsual_select == 1)
+ && !(s->ca.retval & CA_COMMAND_BUSY)
+ && stuff_empty()
+ && s->oa.regname == 0) {
if (restart_VIsual_select == 1) {
VIsual_select = true;
showmode();
@@ -968,7 +985,7 @@ static int normal_execute(VimState *state, int key)
{
NormalState *s = (NormalState *)state;
s->command_finished = false;
- s->ctrl_w = false; /* got CTRL-W command */
+ s->ctrl_w = false; // got CTRL-W command
s->old_col = curwin->w_curswant;
s->c = key;
@@ -980,7 +997,7 @@ static int normal_execute(VimState *state, int key)
if (restart_edit == 0) {
s->old_mapped_len = 0;
} else if (s->old_mapped_len || (VIsual_active && s->mapped_len == 0
- && typebuf_maplen() > 0)) {
+ && typebuf_maplen() > 0)) {
s->old_mapped_len = typebuf_maplen();
}
@@ -990,7 +1007,7 @@ static int normal_execute(VimState *state, int key)
// In Select mode, typed text replaces the selection.
if (VIsual_active && VIsual_select && (vim_isprintc(s->c)
- || s->c == NL || s->c == CAR || s->c == K_KENTER)) {
+ || s->c == NL || s->c == CAR || s->c == K_KENTER)) {
// Fake a "c"hange command. When "restart_edit" is set (e.g., because
// 'insertmode' is set) fake a "d"elete command, Insert mode will
// restart automatically.
@@ -1008,14 +1025,14 @@ static int normal_execute(VimState *state, int key)
s->need_flushbuf = add_to_showcmd(s->c);
- while (normal_get_command_count(s)) continue;
+ while (normal_get_command_count(s)) { continue; }
if (s->c == K_EVENT) {
// Save the count values so that ca.opcount and ca.count0 are exactly
// the same when coming back here after handling K_EVENT.
s->oa.prev_opcount = s->ca.opcount;
s->oa.prev_count0 = s->ca.count0;
- } else if (s->ca.opcount != 0) {
+ } else if (s->ca.opcount != 0) {
// If we're in the middle of an operator (including after entering a
// yank buffer with '"') AND we had a count before the operator, then
// that count overrides the current value of ca.count0.
@@ -1427,11 +1444,12 @@ static void set_vcount_ca(cmdarg_T *cap, bool *set_prevcount)
{
long count = cap->count0;
- /* multiply with cap->opcount the same way as above */
- if (cap->opcount != 0)
+ // multiply with cap->opcount the same way as above
+ if (cap->opcount != 0) {
count = cap->opcount * (count == 0 ? 1 : count);
+ }
set_vcount(count, count == 0 ? 1 : count, *set_prevcount);
- *set_prevcount = false; /* only set v:prevcount once */
+ *set_prevcount = false; // only set v:prevcount once
}
// Handle an operator after Visual mode or when the movement is finished.
@@ -1508,12 +1526,11 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
&& oap->op_type != OP_FOLDCLOSE
&& oap->op_type != OP_FOLDCLOSEREC
&& oap->op_type != OP_FOLDDEL
- && oap->op_type != OP_FOLDDELREC
- ) {
+ && oap->op_type != OP_FOLDDELREC) {
prep_redo(oap->regname, cap->count0,
- get_op_char(oap->op_type), get_extra_op_char(oap->op_type),
- oap->motion_force, cap->cmdchar, cap->nchar);
- if (cap->cmdchar == '/' || cap->cmdchar == '?') { /* was a search */
+ get_op_char(oap->op_type), get_extra_op_char(oap->op_type),
+ oap->motion_force, cap->cmdchar, cap->nchar);
+ if (cap->cmdchar == '/' || cap->cmdchar == '?') { // was a search
/*
* If 'cpoptions' does not contain 'r', insert the search
* pattern to really repeat the same command.
@@ -1541,8 +1558,9 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
* redo_VIsual_line_count and redo_VIsual_vcol. */
oap->start = curwin->w_cursor;
curwin->w_cursor.lnum += redo_VIsual_line_count - 1;
- if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count)
+ if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) {
curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
+ }
VIsual_mode = redo_VIsual_mode;
if (redo_VIsual_vcol == MAXCOL || VIsual_mode == 'v') {
if (VIsual_mode == 'v') {
@@ -1550,8 +1568,9 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
validate_virtcol();
curwin->w_curswant =
curwin->w_virtcol + redo_VIsual_vcol - 1;
- } else
+ } else {
curwin->w_curswant = redo_VIsual_vcol;
+ }
} else {
curwin->w_curswant = MAXCOL;
}
@@ -1561,7 +1580,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
cap->count1 = (cap->count0 == 0 ? 1 : cap->count0);
} else if (VIsual_active) {
if (!gui_yank) {
- /* Save the current VIsual area for '< and '> marks, and "gv" */
+ // Save the current VIsual area for '< and '> marks, and "gv"
curbuf->b_visual.vi_start = VIsual;
curbuf->b_visual.vi_end = curwin->w_cursor;
curbuf->b_visual.vi_mode = VIsual_mode;
@@ -1607,10 +1626,11 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
* to the end of the operated text. w_cursor is equal to oap->start.
*/
if (lt(oap->start, curwin->w_cursor)) {
- /* Include folded lines completely. */
+ // Include folded lines completely.
if (!VIsual_active) {
- if (hasFolding(oap->start.lnum, &oap->start.lnum, NULL))
+ if (hasFolding(oap->start.lnum, &oap->start.lnum, NULL)) {
oap->start.col = 0;
+ }
if ((curwin->w_cursor.col > 0
|| oap->inclusive
|| oap->motion_type == kMTLineWise)
@@ -1645,7 +1665,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
check_pos(curwin->w_buffer, &oap->end);
oap->line_count = oap->end.lnum - oap->start.lnum + 1;
- /* Set "virtual_op" before resetting VIsual_active. */
+ // Set "virtual_op" before resetting VIsual_active.
virtual_op = virtual_active();
if (VIsual_active || redo_VIsual_busy) {
@@ -1657,19 +1677,22 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
* size of the Visual text
*/
resel_VIsual_mode = VIsual_mode;
- if (curwin->w_curswant == MAXCOL)
+ if (curwin->w_curswant == MAXCOL) {
resel_VIsual_vcol = MAXCOL;
- else {
- if (VIsual_mode != Ctrl_V)
+ } else {
+ if (VIsual_mode != Ctrl_V) {
getvvcol(curwin, &(oap->end),
- NULL, NULL, &oap->end_vcol);
+ NULL, NULL, &oap->end_vcol);
+ }
if (VIsual_mode == Ctrl_V || oap->line_count <= 1) {
- if (VIsual_mode != Ctrl_V)
+ if (VIsual_mode != Ctrl_V) {
getvvcol(curwin, &(oap->start),
- &oap->start_vcol, NULL, NULL);
+ &oap->start_vcol, NULL, NULL);
+ }
resel_VIsual_vcol = oap->end_vcol - oap->start_vcol + 1;
- } else
+ } else {
resel_VIsual_vcol = oap->end_vcol;
+ }
}
resel_VIsual_line_count = oap->line_count;
}
@@ -1684,8 +1707,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
&& oap->op_type != OP_FOLDCLOSEREC
&& oap->op_type != OP_FOLDDEL
&& oap->op_type != OP_FOLDDELREC
- && oap->motion_force == NUL
- ) {
+ && oap->motion_force == NUL) {
/* Prepare for redoing. Only use the nchar field for "r",
* otherwise it might be the second char of the operator. */
if (cap->cmdchar == 'g' && (cap->nchar == 'n'
@@ -1725,8 +1747,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
} else if (VIsual_mode == 'v') {
oap->motion_type = kMTCharWise;
if (*ml_get_pos(&(oap->end)) == NUL
- && (include_line_break || !virtual_op)
- ) {
+ && (include_line_break || !virtual_op)) {
oap->inclusive = false;
// Try to include the newline, unless it's an operator
// that works on lines only.
@@ -1828,22 +1849,24 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
oap->inclusive = true;
}
}
- } else
+ } else {
oap->end_adjusted = false;
+ }
switch (oap->op_type) {
case OP_LSHIFT:
case OP_RSHIFT:
op_shift(oap, true,
- oap->is_VIsual ? (int)cap->count1 :
- 1);
+ oap->is_VIsual ? (int)cap->count1 :
+ 1);
auto_format(false, true);
break;
case OP_JOIN_NS:
case OP_JOIN:
- if (oap->line_count < 2)
+ if (oap->line_count < 2) {
oap->line_count = 2;
+ }
if (curwin->w_cursor.lnum + oap->line_count - 1 >
curbuf->b_ml.ml_line_count) {
beep_flush();
@@ -1855,7 +1878,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
break;
case OP_DELETE:
- VIsual_reselect = false; /* don't reselect now */
+ VIsual_reselect = false; // don't reselect now
if (empty_region_error) {
vim_beep(BO_OPER);
CancelRedo();
@@ -1885,7 +1908,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
break;
case OP_CHANGE:
- VIsual_reselect = false; /* don't reselect now */
+ VIsual_reselect = false; // don't reselect now
if (empty_region_error) {
vim_beep(BO_OPER);
CancelRedo();
@@ -1894,10 +1917,11 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
* remember it to make 'insertmode' work with mappings for
* Visual mode. But do this only once and not when typed and
* 'insertmode' isn't set. */
- if (p_im || !KeyTyped)
+ if (p_im || !KeyTyped) {
restart_edit_save = restart_edit;
- else
+ } else {
restart_edit_save = 0;
+ }
restart_edit = 0;
// Restore linebreak, so that when the user edits it looks as before.
@@ -1905,10 +1929,12 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
// Reset finish_op now, don't want it set inside edit().
finish_op = false;
- if (op_change(oap)) /* will call edit() */
+ if (op_change(oap)) { // will call edit()
cap->retval |= CA_COMMAND_BUSY;
- if (restart_edit == 0)
+ }
+ if (restart_edit == 0) {
restart_edit = restart_edit_save;
+ }
}
break;
@@ -1932,8 +1958,8 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
break;
}
op_reindent(oap,
- *curbuf->b_p_inde != NUL ? get_expr_indent :
- get_c_indent);
+ *curbuf->b_p_inde != NUL ? get_expr_indent :
+ get_c_indent);
break;
}
@@ -1947,8 +1973,9 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
if (empty_region_error) {
vim_beep(BO_OPER);
CancelRedo();
- } else
+ } else {
op_tilde(oap);
+ }
check_cursor_col();
break;
@@ -1965,7 +1992,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
break;
case OP_FORMAT2:
- op_format(oap, true); /* use internal function */
+ op_format(oap, true); // use internal function
break;
case OP_FUNCTION:
@@ -1977,7 +2004,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
case OP_INSERT:
case OP_APPEND:
- VIsual_reselect = false; /* don't reselect now */
+ VIsual_reselect = false; // don't reselect now
if (empty_region_error) {
vim_beep(BO_OPER);
CancelRedo();
@@ -2009,7 +2036,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
break;
case OP_REPLACE:
- VIsual_reselect = false; /* don't reselect now */
+ VIsual_reselect = false; // don't reselect now
if (empty_region_error) {
vim_beep(BO_OPER);
CancelRedo();
@@ -2141,10 +2168,10 @@ static void op_function(const oparg_T *oap)
{
const TriState save_virtual_op = virtual_op;
- if (*p_opfunc == NUL)
+ if (*p_opfunc == NUL) {
EMSG(_("E774: 'operatorfunc' is empty"));
- else {
- /* Set '[ and '] marks to text to be operated on. */
+ } else {
+ // Set '[ and '] marks to text to be operated on.
curbuf->b_op_start = oap->start;
curbuf->b_op_end = oap->end;
if (oap->motion_type != kMTLineWise && !oap->inclusive) {
@@ -2157,10 +2184,10 @@ static void op_function(const oparg_T *oap)
argv[1].v_type = VAR_UNKNOWN;
argv[0].vval.v_string =
(char_u *)(((const char *const[]) {
- [kMTBlockWise] = "block",
- [kMTLineWise] = "line",
- [kMTCharWise] = "char",
- })[oap->motion_type]);
+ [kMTBlockWise] = "block",
+ [kMTLineWise] = "line",
+ [kMTCharWise] = "char",
+ })[oap->motion_type]);
// Reset virtual_op so that 'virtualedit' can be changed in the
// function.
@@ -2178,70 +2205,66 @@ static void move_tab_to_mouse(void)
{
int tabnr = tab_page_click_defs[mouse_col].tabnr;
if (tabnr <= 0) {
- tabpage_move(9999);
+ tabpage_move(9999);
} else if (tabnr < tabpage_index(curtab)) {
- tabpage_move(tabnr - 1);
+ tabpage_move(tabnr - 1);
} else {
- tabpage_move(tabnr);
- }
-}
-
-/*
- * Do the appropriate action for the current mouse click in the current mode.
- * Not used for Command-line mode.
- *
- * Normal Mode:
- * event modi- position visual change action
- * fier cursor window
- * left press - yes end yes
- * left press C yes end yes "^]" (2)
- * left press S yes end yes "*" (2)
- * left drag - yes start if moved no
- * left relse - yes start if moved no
- * middle press - yes if not active no put register
- * middle press - yes if active no yank and put
- * right press - yes start or extend yes
- * right press S yes no change yes "#" (2)
- * right drag - yes extend no
- * right relse - yes extend no
- *
- * Insert or Replace Mode:
- * event modi- position visual change action
- * fier cursor window
- * left press - yes (cannot be active) yes
- * left press C yes (cannot be active) yes "CTRL-O^]" (2)
- * left press S yes (cannot be active) yes "CTRL-O*" (2)
- * left drag - yes start or extend (1) no CTRL-O (1)
- * left relse - yes start or extend (1) no CTRL-O (1)
- * middle press - no (cannot be active) no put register
- * right press - yes start or extend yes CTRL-O
- * right press S yes (cannot be active) yes "CTRL-O#" (2)
- *
- * (1) only if mouse pointer moved since press
- * (2) only if click is in same buffer
- *
- * Return true if start_arrow() should be called for edit mode.
- */
-bool
-do_mouse (
- oparg_T *oap, /* operator argument, can be NULL */
- int c, /* K_LEFTMOUSE, etc */
- int dir, /* Direction to 'put' if necessary */
- long count,
- bool fixindent /* PUT_FIXINDENT if fixing indent necessary */
-)
-{
- static bool got_click = false; /* got a click some time back */
-
- int which_button; /* MOUSE_LEFT, _MIDDLE or _RIGHT */
- bool is_click; /* If false it's a drag or release event */
- bool is_drag; /* If true it's a drag event */
- int jump_flags = 0; /* flags for jump_to_mouse() */
+ tabpage_move(tabnr);
+ }
+}
+
+/// Do the appropriate action for the current mouse click in the current mode.
+/// Not used for Command-line mode.
+///
+/// Normal Mode:
+/// event modi- position visual change action
+/// fier cursor window
+/// left press - yes end yes
+/// left press C yes end yes "^]" (2)
+/// left press S yes end yes "*" (2)
+/// left drag - yes start if moved no
+/// left relse - yes start if moved no
+/// middle press - yes if not active no put register
+/// middle press - yes if active no yank and put
+/// right press - yes start or extend yes
+/// right press S yes no change yes "#" (2)
+/// right drag - yes extend no
+/// right relse - yes extend no
+///
+/// Insert or Replace Mode:
+/// event modi- position visual change action
+/// fier cursor window
+/// left press - yes (cannot be active) yes
+/// left press C yes (cannot be active) yes "CTRL-O^]" (2)
+/// left press S yes (cannot be active) yes "CTRL-O*" (2)
+/// left drag - yes start or extend (1) no CTRL-O (1)
+/// left relse - yes start or extend (1) no CTRL-O (1)
+/// middle press - no (cannot be active) no put register
+/// right press - yes start or extend yes CTRL-O
+/// right press S yes (cannot be active) yes "CTRL-O#" (2)
+///
+/// (1) only if mouse pointer moved since press
+/// (2) only if click is in same buffer
+///
+/// @param oap operator argument, can be NULL
+/// @param c K_LEFTMOUSE, etc
+/// @param dir Direction to 'put' if necessary
+/// @param fixindent PUT_FIXINDENT if fixing indent necessary
+///
+/// @return true if start_arrow() should be called for edit mode.
+bool do_mouse(oparg_T *oap, int c, int dir, long count, bool fixindent)
+{
+ static bool got_click = false; // got a click some time back
+
+ int which_button; // MOUSE_LEFT, _MIDDLE or _RIGHT
+ bool is_click; // If false it's a drag or release event
+ bool is_drag; // If true it's a drag event
+ int jump_flags = 0; // flags for jump_to_mouse()
pos_T start_visual;
- bool moved; /* Has cursor moved? */
- bool in_status_line; /* mouse in status line */
- static bool in_tab_line = false; /* mouse clicked in tab line */
- bool in_sep_line; /* mouse in vertical separator line */
+ bool moved; // Has cursor moved?
+ bool in_status_line; // mouse in status line
+ static bool in_tab_line = false; // mouse clicked in tab line
+ bool in_sep_line; // mouse in vertical separator line
int c1, c2;
pos_T save_cursor;
win_T *old_curwin = curwin;
@@ -2269,8 +2292,9 @@ do_mouse (
/* Need to get the character, peeking doesn't get the actual
* one. */
nc = safe_vgetc();
- if (c == nc)
+ if (c == nc) {
continue;
+ }
vungetc(nc);
mouse_grid = save_mouse_grid;
mouse_row = save_mouse_row;
@@ -2288,12 +2312,13 @@ do_mouse (
/*
* Ignore drag and release events if we didn't get a click.
*/
- if (is_click)
+ if (is_click) {
got_click = true;
- else {
- if (!got_click) /* didn't get click, ignore */
+ } else {
+ if (!got_click) { // didn't get click, ignore
return false;
- if (!is_drag) { /* release, reset got_click */
+ }
+ if (!is_drag) { // release, reset got_click
got_click = false;
if (in_tab_line) {
in_tab_line = false;
@@ -2307,20 +2332,23 @@ do_mouse (
* CTRL right mouse button does CTRL-T
*/
if (is_click && (mod_mask & MOD_MASK_CTRL) && which_button == MOUSE_RIGHT) {
- if (State & INSERT)
+ if (State & INSERT) {
stuffcharReadbuff(Ctrl_O);
- if (count > 1)
+ }
+ if (count > 1) {
stuffnumReadbuff(count);
+ }
stuffcharReadbuff(Ctrl_T);
- got_click = false; /* ignore drag&release now */
+ got_click = false; // ignore drag&release now
return false;
}
/*
* CTRL only works with left mouse button
*/
- if ((mod_mask & MOD_MASK_CTRL) && which_button != MOUSE_LEFT)
+ if ((mod_mask & MOD_MASK_CTRL) && which_button != MOUSE_LEFT) {
return false;
+ }
/*
* When a modifier is down, ignore drag and release events, as well as
@@ -2337,22 +2365,24 @@ do_mouse (
&& which_button == MOUSE_LEFT)
&& !((mod_mask & MOD_MASK_ALT)
&& !mouse_model_popup()
- && which_button == MOUSE_RIGHT)
- )
+ && which_button == MOUSE_RIGHT)) {
return false;
+ }
/*
* If the button press was used as the movement command for an operator
* (eg "d<MOUSE>"), or it is the middle button that is held down, ignore
* drag/release events.
*/
- if (!is_click && which_button == MOUSE_MIDDLE)
+ if (!is_click && which_button == MOUSE_MIDDLE) {
return false;
+ }
- if (oap != NULL)
+ if (oap != NULL) {
regname = oap->regname;
- else
+ } else {
regname = 0;
+ }
/*
* Middle mouse button does a 'put' of the selected text
@@ -2386,8 +2416,9 @@ do_mouse (
/*
* The rest is below jump_to_mouse()
*/
- } else if ((State & INSERT) == 0)
+ } else if ((State & INSERT) == 0) {
return false;
+ }
/*
* Middle click in insert mode doesn't move the mouse, just insert the
@@ -2409,7 +2440,7 @@ do_mouse (
do_put(regname, NULL, BACKWARD, 1L,
(fixindent ? PUT_FIXINDENT : 0) | PUT_CURSEND);
- /* Repeat it with CTRL-R CTRL-O r or CTRL-R CTRL-P r */
+ // Repeat it with CTRL-R CTRL-O r or CTRL-R CTRL-P r
AppendCharToRedobuff(Ctrl_R);
AppendCharToRedobuff(fixindent ? Ctrl_P : Ctrl_O);
AppendCharToRedobuff(regname == 0 ? '"' : regname);
@@ -2419,9 +2450,10 @@ do_mouse (
}
}
- /* When dragging or button-up stay in the same window. */
- if (!is_click)
+ // When dragging or button-up stay in the same window.
+ if (!is_click) {
jump_flags |= MOUSE_FOCUS | MOUSE_DID_MOVE;
+ }
start_visual.lnum = 0;
@@ -2434,17 +2466,17 @@ do_mouse (
return false;
}
- /* click in a tab selects that tab page */
+ // click in a tab selects that tab page
if (is_click
&& cmdwin_type == 0
&& mouse_col < Columns) {
in_tab_line = true;
c1 = tab_page_click_defs[mouse_col].tabnr;
switch (tab_page_click_defs[mouse_col].type) {
- case kStlClickDisabled: {
+ case kStlClickDisabled: {
break;
}
- case kStlClickTabClose: {
+ case kStlClickTabClose: {
tabpage_T *tp;
// Close the current or specified tab page.
@@ -2462,7 +2494,7 @@ do_mouse (
}
break;
}
- case kStlClickTabSwitch: {
+ case kStlClickTabSwitch: {
if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK) {
// double click opens new page
end_visual_mode();
@@ -2480,13 +2512,13 @@ do_mouse (
}
break;
}
- case kStlClickFuncRun: {
+ case kStlClickFuncRun: {
typval_T argv[] = {
{
.v_lock = VAR_FIXED,
.v_type = VAR_NUMBER,
.vval = {
- .v_number = (varnumber_T) tab_page_click_defs[mouse_col].tabnr
+ .v_number = (varnumber_T)tab_page_click_defs[mouse_col].tabnr
},
},
{
@@ -2508,7 +2540,7 @@ do_mouse (
{
.v_lock = VAR_FIXED,
.v_type = VAR_STRING,
- .vval = { .v_string = (char_u *) (which_button == MOUSE_LEFT
+ .vval = { .v_string = (char_u *)(which_button == MOUSE_LEFT
? "l"
: which_button == MOUSE_RIGHT
? "r"
@@ -2521,10 +2553,10 @@ do_mouse (
.v_type = VAR_STRING,
.vval = {
.v_string = (char_u[]) {
- (char_u) (mod_mask & MOD_MASK_SHIFT ? 's' : ' '),
- (char_u) (mod_mask & MOD_MASK_CTRL ? 'c' : ' '),
- (char_u) (mod_mask & MOD_MASK_ALT ? 'a' : ' '),
- (char_u) (mod_mask & MOD_MASK_META ? 'm' : ' '),
+ (char_u)(mod_mask & MOD_MASK_SHIFT ? 's' : ' '),
+ (char_u)(mod_mask & MOD_MASK_CTRL ? 'c' : ' '),
+ (char_u)(mod_mask & MOD_MASK_ALT ? 'a' : ' '),
+ (char_u)(mod_mask & MOD_MASK_META ? 'm' : ' '),
NUL
}
},
@@ -2577,8 +2609,9 @@ do_mouse (
if (is_click) {
/* stop Visual mode for a left click in a window, but not when
* on a status line */
- if (VIsual_active)
+ if (VIsual_active) {
jump_flags |= MOUSE_MAY_STOP_VIS;
+ }
} else {
jump_flags |= MOUSE_MAY_VIS;
}
@@ -2610,9 +2643,10 @@ do_mouse (
oap->motion_type = kMTCharWise;
}
- /* When releasing the button let jump_to_mouse() know. */
- if (!is_click && !is_drag)
+ // When releasing the button let jump_to_mouse() know.
+ if (!is_click && !is_drag) {
jump_flags |= MOUSE_RELEASED;
+ }
/*
* JUMP!
@@ -2628,8 +2662,9 @@ do_mouse (
/* When jumping to another window, clear a pending operator. That's a bit
* friendlier than beeping and not jumping to that window. */
- if (curwin != old_curwin && oap != NULL && oap->op_type != OP_NOP)
+ if (curwin != old_curwin && oap != NULL && oap->op_type != OP_NOP) {
clearop(oap);
+ }
if (mod_mask == 0
&& !is_drag
@@ -2659,16 +2694,17 @@ do_mouse (
}
}
- /* When dragging the mouse above the window, scroll down. */
+ // When dragging the mouse above the window, scroll down.
if (is_drag && mouse_row < 0 && !in_status_line) {
scroll_redraw(false, 1L);
mouse_row = 0;
}
- if (start_visual.lnum) { /* right click in visual mode */
- /* When ALT is pressed make Visual mode blockwise. */
- if (mod_mask & MOD_MASK_ALT)
+ if (start_visual.lnum) { // right click in visual mode
+ // When ALT is pressed make Visual mode blockwise.
+ if (mod_mask & MOD_MASK_ALT) {
VIsual_mode = Ctrl_V;
+ }
/*
* In Visual-block mode, divide the area in four, pick up the corner
@@ -2676,55 +2712,58 @@ do_mouse (
*/
if (VIsual_mode == Ctrl_V) {
getvcols(curwin, &start_visual, &end_visual, &leftcol, &rightcol);
- if (curwin->w_curswant > (leftcol + rightcol) / 2)
+ if (curwin->w_curswant > (leftcol + rightcol) / 2) {
end_visual.col = leftcol;
- else
+ } else {
end_visual.col = rightcol;
+ }
if (curwin->w_cursor.lnum >=
(start_visual.lnum + end_visual.lnum) / 2) {
end_visual.lnum = start_visual.lnum;
}
- /* move VIsual to the right column */
- start_visual = curwin->w_cursor; /* save the cursor pos */
+ // move VIsual to the right column
+ start_visual = curwin->w_cursor; // save the cursor pos
curwin->w_cursor = end_visual;
coladvance(end_visual.col);
VIsual = curwin->w_cursor;
- curwin->w_cursor = start_visual; /* restore the cursor */
+ curwin->w_cursor = start_visual; // restore the cursor
} else {
/*
* If the click is before the start of visual, change the start.
* If the click is after the end of visual, change the end. If
* the click is inside the visual, change the closest side.
*/
- if (lt(curwin->w_cursor, start_visual))
+ if (lt(curwin->w_cursor, start_visual)) {
VIsual = end_visual;
- else if (lt(end_visual, curwin->w_cursor))
+ } else if (lt(end_visual, curwin->w_cursor)) {
VIsual = start_visual;
- else {
- /* In the same line, compare column number */
+ } else {
+ // In the same line, compare column number
if (end_visual.lnum == start_visual.lnum) {
if (curwin->w_cursor.col - start_visual.col >
- end_visual.col - curwin->w_cursor.col)
+ end_visual.col - curwin->w_cursor.col) {
VIsual = start_visual;
- else
+ } else {
VIsual = end_visual;
+ }
}
- /* In different lines, compare line number */
+ // In different lines, compare line number
else {
diff = (curwin->w_cursor.lnum - start_visual.lnum) -
(end_visual.lnum - curwin->w_cursor.lnum);
- if (diff > 0) /* closest to end */
+ if (diff > 0) { // closest to end
VIsual = start_visual;
- else if (diff < 0) /* closest to start */
+ } else if (diff < 0) { // closest to start
VIsual = end_visual;
- else { /* in the middle line */
+ } else { // in the middle line
if (curwin->w_cursor.col <
- (start_visual.col + end_visual.col) / 2)
+ (start_visual.col + end_visual.col) / 2) {
VIsual = end_visual;
- else
+ } else {
VIsual = start_visual;
+ }
}
}
}
@@ -2733,8 +2772,9 @@ do_mouse (
/*
* If Visual mode started in insert mode, execute "CTRL-O"
*/
- else if ((State & INSERT) && VIsual_active)
+ else if ((State & INSERT) && VIsual_active) {
stuffcharReadbuff(Ctrl_O);
+ }
/*
* Middle mouse click: Put text before cursor.
@@ -2744,10 +2784,12 @@ do_mouse (
regname = '*';
}
if (yank_register_mline(regname)) {
- if (mouse_past_bottom)
+ if (mouse_past_bottom) {
dir = FORWARD;
- } else if (mouse_past_eol)
+ }
+ } else if (mouse_past_eol) {
dir = FORWARD;
+ }
if (fixindent) {
c1 = (dir == BACKWARD) ? '[' : ']';
@@ -2762,8 +2804,9 @@ do_mouse (
* Remember where the paste started, so in edit() Insstart can be set
* to this position
*/
- if (restart_edit != 0)
+ if (restart_edit != 0) {
where_paste_started = curwin->w_cursor;
+ }
do_put(regname, NULL, dir, count,
(fixindent ? PUT_FIXINDENT : 0)| PUT_CURSEND);
}
@@ -2789,10 +2832,11 @@ do_mouse (
&& (mod_mask &
MOD_MASK_MULTI_CLICK) ==
MOD_MASK_2CLICK)) {
- if (State & INSERT)
+ if (State & INSERT) {
stuffcharReadbuff(Ctrl_O);
+ }
stuffcharReadbuff(Ctrl_RSB);
- got_click = false; /* ignore drag&release now */
+ got_click = false; // ignore drag&release now
}
/*
* Shift-Mouse click searches for the next occurrence of the word under
@@ -2800,15 +2844,16 @@ do_mouse (
*/
else if ((mod_mask & MOD_MASK_SHIFT)) {
if (State & INSERT
- || (VIsual_active && VIsual_select)
- )
+ || (VIsual_active && VIsual_select)) {
stuffcharReadbuff(Ctrl_O);
- if (which_button == MOUSE_LEFT)
+ }
+ if (which_button == MOUSE_LEFT) {
stuffcharReadbuff('*');
- else /* MOUSE_RIGHT */
+ } else { // MOUSE_RIGHT
stuffcharReadbuff('#');
+ }
}
- /* Handle double clicks, unless on status line */
+ // Handle double clicks, unless on status line
else if (in_status_line) {
} else if (in_sep_line) {
} else if ((mod_mask & MOD_MASK_MULTI_CLICK) && (State & (NORMAL | INSERT))) {
@@ -2820,20 +2865,22 @@ do_mouse (
orig_cursor = VIsual;
VIsual_active = true;
VIsual_reselect = true;
- /* start Select mode if 'selectmode' contains "mouse" */
+ // start Select mode if 'selectmode' contains "mouse"
may_start_select('o');
setmouse();
}
if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK) {
- /* Double click with ALT pressed makes it blockwise. */
- if (mod_mask & MOD_MASK_ALT)
+ // Double click with ALT pressed makes it blockwise.
+ if (mod_mask & MOD_MASK_ALT) {
VIsual_mode = Ctrl_V;
- else
+ } else {
VIsual_mode = 'v';
- } else if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_3CLICK)
+ }
+ } else if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_3CLICK) {
VIsual_mode = 'V';
- else if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_4CLICK)
+ } else if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_4CLICK) {
VIsual_mode = Ctrl_V;
+ }
}
/*
* A double click selects a word or a block.
@@ -2847,8 +2894,9 @@ do_mouse (
* not a word character, try finding a match and select a (),
* {}, [], #if/#endif, etc. block. */
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);
+ }
if (oap != NULL) {
oap->motion_type = kMTCharWise;
}
@@ -2878,28 +2926,32 @@ do_mouse (
find_end_of_word(&VIsual);
} else {
find_start_of_word(&VIsual);
- if (*p_sel == 'e' && *get_cursor_pos_ptr() != NUL)
+ if (*p_sel == 'e' && *get_cursor_pos_ptr() != NUL) {
curwin->w_cursor.col +=
(*mb_ptr2len)(get_cursor_pos_ptr());
+ }
find_end_of_word(&curwin->w_cursor);
}
}
curwin->w_set_curswant = true;
}
- if (is_click)
- redraw_curbuf_later(INVERTED); /* update the inversion */
+ if (is_click) {
+ redraw_curbuf_later(INVERTED); // update the inversion
+ }
} else if (VIsual_active && !old_active) {
- if (mod_mask & MOD_MASK_ALT)
+ if (mod_mask & MOD_MASK_ALT) {
VIsual_mode = Ctrl_V;
- else
+ } else {
VIsual_mode = 'v';
+ }
}
- /* If Visual mode changed show it later. */
+ // If Visual mode changed show it later.
if ((!VIsual_active && old_active && mode_displayed)
|| (VIsual_active && p_smd && msg_silent == 0
- && (!old_active || VIsual_mode != old_mode)))
+ && (!old_active || VIsual_mode != old_mode))) {
redraw_cmdline = true;
+ }
return moved;
}
@@ -2945,8 +2997,9 @@ static void find_end_of_word(pos_T *pos)
while (line[pos->col] != NUL) {
col = pos->col + (*mb_ptr2len)(line + pos->col);
if (get_mouse_class(line + col) != cclass) {
- if (*p_sel == 'e')
+ if (*p_sel == 'e') {
pos->col = col;
+ }
break;
}
pos->col = col;
@@ -2980,8 +3033,9 @@ static int get_mouse_class(char_u *p)
* "->", "/ *", "*=", "+=", "&=", "<=", ">=", "!=" etc. Otherwise, each
* character is in its own class.
*/
- if (c != NUL && vim_strchr((char_u *)"-+*/%<>&|^!=", c) != NULL)
+ if (c != NUL && vim_strchr((char_u *)"-+*/%<>&|^!=", c) != NULL) {
return 1;
+ }
return c;
}
@@ -2992,19 +3046,19 @@ static int get_mouse_class(char_u *p)
*/
void end_visual_mode(void)
{
-
VIsual_active = false;
setmouse();
mouse_dragging = 0;
- /* Save the current VIsual area for '< and '> marks, and "gv" */
+ // Save the current VIsual area for '< and '> marks, and "gv"
curbuf->b_visual.vi_mode = VIsual_mode;
curbuf->b_visual.vi_start = VIsual;
curbuf->b_visual.vi_end = curwin->w_cursor;
curbuf->b_visual.vi_curswant = curwin->w_curswant;
curbuf->b_visual_mode_eval = VIsual_mode;
- if (!virtual_active())
+ if (!virtual_active()) {
curwin->w_cursor.coladd = 0;
+ }
may_clear_cmdline();
@@ -3018,7 +3072,7 @@ void reset_VIsual_and_resel(void)
{
if (VIsual_active) {
end_visual_mode();
- redraw_curbuf_later(INVERTED); /* delete the inversion later */
+ redraw_curbuf_later(INVERTED); // delete the inversion later
}
VIsual_reselect = false;
}
@@ -3030,7 +3084,7 @@ void reset_VIsual(void)
{
if (VIsual_active) {
end_visual_mode();
- redraw_curbuf_later(INVERTED); /* delete the inversion later */
+ redraw_curbuf_later(INVERTED); // delete the inversion later
VIsual_reselect = false;
}
}
@@ -3041,11 +3095,8 @@ void reset_VIsual(void)
// "dir" is FORWARD or BACKWARD, the direction of searching.
// "*colp" is in/decremented if "ptr[-dir]" should also be included.
// "bnp" points to a counter for square brackets.
-static bool find_is_eval_item(
- const char_u *const ptr,
- int *const colp,
- int *const bnp,
- const int dir)
+static bool find_is_eval_item(const char_u *const ptr, int *const colp, int *const bnp,
+ const int dir)
{
// Accept everything inside [].
if ((*ptr == ']' && dir == BACKWARD) || (*ptr == '[' && dir == FORWARD)) {
@@ -3098,17 +3149,12 @@ size_t find_ident_under_cursor(char_u **text, int find_type)
curwin->w_cursor.col, text, NULL, find_type);
}
-/*
- * Like find_ident_under_cursor(), but for any window and any position.
- * However: Uses 'iskeyword' from the current window!.
- */
-size_t find_ident_at_pos(
- win_T *wp,
- linenr_T lnum,
- colnr_T startcol,
- char_u **text,
- int *textcol, // column where "text" starts, can be NULL
- int find_type)
+/// Like find_ident_under_cursor(), but for any window and any position.
+/// However: Uses 'iskeyword' from the current window!.
+///
+/// @param textcol column where "text" starts, can be NULL
+size_t find_ident_at_pos(win_T *wp, linenr_T lnum, colnr_T startcol, char_u **text, int *textcol,
+ int find_type)
FUNC_ATTR_NONNULL_ARG(1, 4)
{
int col = 0; // init to shut up GCC
@@ -3214,7 +3260,7 @@ size_t find_ident_at_pos(
static void prep_redo_cmd(cmdarg_T *cap)
{
prep_redo(cap->oap->regname, cap->count0,
- NUL, cap->cmdchar, NUL, NUL, cap->nchar);
+ NUL, cap->cmdchar, NUL, NUL, cap->nchar);
}
/*
@@ -3224,23 +3270,29 @@ static void prep_redo_cmd(cmdarg_T *cap)
static void prep_redo(int regname, long num, int cmd1, int cmd2, int cmd3, int cmd4, int cmd5)
{
ResetRedobuff();
- if (regname != 0) { /* yank from specified buffer */
+ if (regname != 0) { // yank from specified buffer
AppendCharToRedobuff('"');
AppendCharToRedobuff(regname);
}
- if (num)
+ if (num) {
AppendNumberToRedobuff(num);
+ }
- if (cmd1 != NUL)
+ if (cmd1 != NUL) {
AppendCharToRedobuff(cmd1);
- if (cmd2 != NUL)
+ }
+ if (cmd2 != NUL) {
AppendCharToRedobuff(cmd2);
- if (cmd3 != NUL)
+ }
+ if (cmd3 != NUL) {
AppendCharToRedobuff(cmd3);
- if (cmd4 != NUL)
+ }
+ if (cmd4 != NUL) {
AppendCharToRedobuff(cmd4);
- if (cmd5 != NUL)
+ }
+ if (cmd5 != NUL) {
AppendCharToRedobuff(cmd5);
+ }
}
/*
@@ -3250,8 +3302,9 @@ static void prep_redo(int regname, long num, int cmd1, int cmd2, int cmd3, int c
*/
static bool checkclearop(oparg_T *oap)
{
- if (oap->op_type == OP_NOP)
+ if (oap->op_type == OP_NOP) {
return false;
+ }
clearopbeep(oap);
return true;
}
@@ -3264,9 +3317,9 @@ static bool checkclearop(oparg_T *oap)
static bool checkclearopq(oparg_T *oap)
{
if (oap->op_type == OP_NOP
- && !VIsual_active
- )
+ && !VIsual_active) {
return false;
+ }
clearopbeep(oap);
return true;
}
@@ -3292,12 +3345,18 @@ static void clearopbeep(oparg_T *oap)
static void unshift_special(cmdarg_T *cap)
{
switch (cap->cmdchar) {
- case K_S_RIGHT: cap->cmdchar = K_RIGHT; break;
- case K_S_LEFT: cap->cmdchar = K_LEFT; break;
- case K_S_UP: cap->cmdchar = K_UP; break;
- case K_S_DOWN: cap->cmdchar = K_DOWN; break;
- case K_S_HOME: cap->cmdchar = K_HOME; break;
- case K_S_END: cap->cmdchar = K_END; break;
+ case K_S_RIGHT:
+ cap->cmdchar = K_RIGHT; break;
+ case K_S_LEFT:
+ cap->cmdchar = K_LEFT; break;
+ case K_S_UP:
+ cap->cmdchar = K_UP; break;
+ case K_S_DOWN:
+ cap->cmdchar = K_DOWN; break;
+ case K_S_HOME:
+ cap->cmdchar = K_HOME; break;
+ case K_S_END:
+ cap->cmdchar = K_END; break;
}
cap->cmdchar = simplify_key(cap->cmdchar, &mod_mask);
}
@@ -3317,15 +3376,16 @@ static void may_clear_cmdline(void)
// Routines for displaying a partly typed command
# define SHOWCMD_BUFLEN SHOWCMD_COLS + 1 + 30
static char_u showcmd_buf[SHOWCMD_BUFLEN];
-static char_u old_showcmd_buf[SHOWCMD_BUFLEN]; /* For push_showcmd() */
+static char_u old_showcmd_buf[SHOWCMD_BUFLEN]; // For push_showcmd()
static bool showcmd_is_clear = true;
static bool showcmd_visual = false;
void clear_showcmd(void)
{
- if (!p_sc)
+ if (!p_sc) {
return;
+ }
if (VIsual_active && !char_avail()) {
int cursor_bot = lt(VIsual, curwin->w_cursor);
@@ -3333,7 +3393,7 @@ void clear_showcmd(void)
colnr_T leftcol, rightcol;
linenr_T top, bot;
- /* Show the size of the Visual area. */
+ // Show the size of the Visual area.
if (cursor_bot) {
top = VIsual.lnum;
bot = curwin->w_cursor.lnum;
@@ -3349,7 +3409,7 @@ void clear_showcmd(void)
if (VIsual_mode == Ctrl_V) {
char_u *saved_sbr = p_sbr;
- /* 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;
getvcols(curwin, &curwin->w_cursor, &VIsual, &leftcol, &rightcol);
p_sbr = saved_sbr;
@@ -3375,16 +3435,17 @@ void clear_showcmd(void)
if (l == 0) {
++bytes;
++chars;
- break; /* end of line */
+ break; // end of line
}
bytes += l;
++chars;
s += l;
}
- if (bytes == chars)
+ if (bytes == chars) {
sprintf((char *)showcmd_buf, "%d", chars);
- else
+ } else {
sprintf((char *)showcmd_buf, "%d-%d", chars, bytes);
+ }
}
int limit = ui_has(kUIMessages) ? SHOWCMD_BUFLEN-1 : SHOWCMD_COLS;
showcmd_buf[limit] = NUL; // truncate
@@ -3393,9 +3454,10 @@ void clear_showcmd(void)
showcmd_buf[0] = NUL;
showcmd_visual = false;
- /* Don't actually display something if there is nothing to clear. */
- if (showcmd_is_clear)
+ // Don't actually display something if there is nothing to clear.
+ if (showcmd_is_clear) {
return;
+ }
}
display_showcmd();
@@ -3421,23 +3483,28 @@ bool add_to_showcmd(int c)
0
};
- if (!p_sc || msg_silent != 0)
+ if (!p_sc || msg_silent != 0) {
return false;
+ }
if (showcmd_visual) {
showcmd_buf[0] = NUL;
showcmd_visual = false;
}
- /* Ignore keys that are scrollbar updates and mouse clicks */
- if (IS_SPECIAL(c))
- for (i = 0; ignore[i] != 0; ++i)
- if (ignore[i] == c)
+ // Ignore keys that are scrollbar updates and mouse clicks
+ if (IS_SPECIAL(c)) {
+ for (i = 0; ignore[i] != 0; ++i) {
+ if (ignore[i] == c) {
return false;
+ }
+ }
+ }
p = transchar(c);
- if (*p == ' ')
+ if (*p == ' ') {
STRCPY(p, "<20>");
+ }
size_t old_len = STRLEN(showcmd_buf);
size_t extra_len = STRLEN(p);
size_t limit = ui_has(kUIMessages) ? SHOWCMD_BUFLEN-1 : SHOWCMD_COLS;
@@ -3447,8 +3514,9 @@ bool add_to_showcmd(int c)
}
STRCAT(showcmd_buf, p);
- if (char_avail())
+ if (char_avail()) {
return false;
+ }
display_showcmd();
@@ -3468,16 +3536,19 @@ static void del_from_showcmd(int len)
{
int old_len;
- if (!p_sc)
+ if (!p_sc) {
return;
+ }
old_len = (int)STRLEN(showcmd_buf);
- if (len > old_len)
+ if (len > old_len) {
len = old_len;
+ }
showcmd_buf[old_len - len] = NUL;
- if (!char_avail())
+ if (!char_avail()) {
display_showcmd();
+ }
}
/*
@@ -3486,14 +3557,16 @@ static void del_from_showcmd(int len)
*/
void push_showcmd(void)
{
- if (p_sc)
+ if (p_sc) {
STRCPY(old_showcmd_buf, showcmd_buf);
+ }
}
void pop_showcmd(void)
{
- if (!p_sc)
+ if (!p_sc) {
return;
+ }
STRCPY(showcmd_buf, old_showcmd_buf);
@@ -3551,9 +3624,9 @@ void do_check_scrollbind(bool check)
if (check && curwin->w_p_scb) {
/* If a ":syncbind" command was just used, don't scroll, only reset
* the values. */
- if (did_syncbind)
+ if (did_syncbind) {
did_syncbind = false;
- else if (curwin == old_curwin) {
+ } else if (curwin == old_curwin) {
/*
* Synchronize other windows, as necessary according to
* 'scrollbind'. Don't do this after an ":edit" command, except
@@ -3566,9 +3639,9 @@ void do_check_scrollbind(bool check)
|| curwin->w_topfill != old_topfill
|| curwin->w_leftcol != old_leftcol)) {
check_scrollbind(curwin->w_topline - old_topline,
- (long)(curwin->w_leftcol - old_leftcol));
+ (long)(curwin->w_leftcol - old_leftcol));
}
- } else if (vim_strchr(p_sbo, 'j')) { /* jump flag set in 'scrollopt' */
+ } else if (vim_strchr(p_sbo, 'j')) { // jump flag set in 'scrollopt'
/*
* When switching between windows, make sure that the relative
* vertical offset is valid for the new window. The relative
@@ -3622,7 +3695,7 @@ void check_scrollbind(linenr_T topline_diff, long leftcol_diff)
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
curwin = wp;
curbuf = curwin->w_buffer;
- /* skip original window and windows with 'noscrollbind' */
+ // skip original window and windows with 'noscrollbind'
if (curwin == old_curwin || !curwin->w_p_scb) {
continue;
}
@@ -3635,16 +3708,19 @@ void check_scrollbind(linenr_T topline_diff, long leftcol_diff)
} else {
curwin->w_scbind_pos += topline_diff;
topline = curwin->w_scbind_pos;
- if (topline > curbuf->b_ml.ml_line_count)
+ if (topline > curbuf->b_ml.ml_line_count) {
topline = curbuf->b_ml.ml_line_count;
- if (topline < 1)
+ }
+ if (topline < 1) {
topline = 1;
+ }
y = topline - curwin->w_topline;
- if (y > 0)
+ if (y > 0) {
scrollup(y, false);
- else
+ } else {
scrolldown(-y, false);
+ }
}
redraw_later(curwin, VALID);
@@ -3677,7 +3753,7 @@ void check_scrollbind(linenr_T topline_diff, long leftcol_diff)
*/
static void nv_ignore(cmdarg_T *cap)
{
- cap->retval |= CA_COMMAND_BUSY; /* don't call edit() now */
+ cap->retval |= CA_COMMAND_BUSY; // don't call edit() now
}
/*
@@ -3701,8 +3777,9 @@ static void nv_error(cmdarg_T *cap)
*/
static void nv_help(cmdarg_T *cap)
{
- if (!checkclearopq(cap->oap))
+ if (!checkclearopq(cap->oap)) {
ex_help(NULL);
+ }
}
/*
@@ -3731,25 +3808,22 @@ static void nv_page(cmdarg_T *cap)
{
if (!checkclearop(cap->oap)) {
if (mod_mask & MOD_MASK_CTRL) {
- /* <C-PageUp>: tab page back; <C-PageDown>: tab page forward */
- if (cap->arg == BACKWARD)
+ // <C-PageUp>: tab page back; <C-PageDown>: tab page forward
+ if (cap->arg == BACKWARD) {
goto_tabpage(-(int)cap->count1);
- else
+ } else {
goto_tabpage((int)cap->count0);
- } else
+ }
+ } else {
(void)onepage(cap->arg, cap->count1);
+ }
}
}
-/*
- * Implementation of "gd" and "gD" command.
- */
-static void
-nv_gd (
- oparg_T *oap,
- int nchar,
- int thisblock /* 1 for "1gd" and "1gD" */
-)
+/// Implementation of "gd" and "gD" command.
+///
+/// @param thisblock 1 for "1gd" and "1gD"
+static void nv_gd(oparg_T *oap, int nchar, int thisblock)
{
size_t len;
char_u *ptr;
@@ -3794,21 +3868,15 @@ static bool is_ident(char_u *line, int offset)
return incomment == false && instring == 0;
}
-/*
- * Search for variable declaration of "ptr[len]".
- * When "locally" is true in the current function ("gd"), otherwise in the
- * current file ("gD").
- * When "thisblock" is true check the {} block scope.
- * Return fail when not found.
- */
-bool
-find_decl (
- char_u *ptr,
- size_t len,
- bool locally,
- bool thisblock,
- int flags_arg // flags passed to searchit()
-)
+/// Search for variable declaration of "ptr[len]".
+/// When "locally" is true in the current function ("gd"), otherwise in the
+/// current file ("gD").
+///
+/// @param thisblock when true check the {} block scope.
+/// @param flags_arg flags passed to searchit()
+///
+/// @return fail when not found.
+bool find_decl(char_u *ptr, size_t len, bool locally, bool thisblock, int flags_arg)
{
char_u *pat;
pos_T old_pos;
@@ -3831,8 +3899,8 @@ find_decl (
old_pos = curwin->w_cursor;
save_p_ws = p_ws;
save_p_scs = p_scs;
- p_ws = false; /* don't wrap around end of file now */
- p_scs = false; /* don't switch ignorecase off now */
+ p_ws = false; // don't wrap around end of file now
+ p_scs = false; // don't switch ignorecase off now
/*
* With "gD" go to line 1.
@@ -3840,18 +3908,19 @@ find_decl (
* back until a blank line. If this fails go to line 1.
*/
if (!locally || !findpar(&incll, BACKWARD, 1L, '{', false)) {
- setpcmark(); /* Set in findpar() otherwise */
+ setpcmark(); // Set in findpar() otherwise
curwin->w_cursor.lnum = 1;
par_pos = curwin->w_cursor;
} else {
par_pos = curwin->w_cursor;
while (curwin->w_cursor.lnum > 1
- && *skipwhite(get_cursor_line_ptr()) != NUL)
+ && *skipwhite(get_cursor_line_ptr()) != NUL) {
--curwin->w_cursor.lnum;
+ }
}
curwin->w_cursor.col = 0;
- /* Search forward for the identifier, ignore comment lines. */
+ // Search forward for the identifier, ignore comment lines.
clearpos(&found_pos);
for (;; ) {
t = searchit(curwin, curbuf, &curwin->w_cursor, NULL, FORWARD,
@@ -3875,7 +3944,7 @@ find_decl (
}
if (t == false) {
- /* If we previously found a valid position, use it. */
+ // If we previously found a valid position, use it.
if (found_pos.lnum != 0) {
curwin->w_cursor = found_pos;
t = true;
@@ -3883,7 +3952,7 @@ find_decl (
break;
}
if (get_leader_len(get_cursor_line_ptr(), NULL, false, true) > 0) {
- /* Ignore this line, continue at start of next line. */
+ // Ignore this line, continue at start of next line.
++curwin->w_cursor.lnum;
curwin->w_cursor.col = 0;
continue;
@@ -3925,7 +3994,7 @@ find_decl (
curwin->w_cursor = old_pos;
} else {
curwin->w_set_curswant = true;
- /* "n" searches forward now */
+ // "n" searches forward now
reset_search_dir();
}
@@ -3949,10 +4018,10 @@ static bool nv_screengo(oparg_T *oap, int dir, long dist)
bool retval = true;
bool atend = false;
int n;
- int col_off1; /* margin offset for first screen line */
- int col_off2; /* margin offset for wrapped screen line */
- int width1; /* text width for first screen line */
- int width2; /* test width for wrapped screen line */
+ int col_off1; // margin offset for first screen line
+ int col_off2; // margin offset for wrapped screen line
+ int width1; // text width for first screen line
+ int width2; // test width for wrapped screen line
oap->motion_type = kMTCharWise;
oap->inclusive = (curwin->w_curswant == MAXCOL);
@@ -3972,20 +4041,22 @@ static bool nv_screengo(oparg_T *oap, int dir, long dist)
if (curwin->w_curswant == MAXCOL) {
atend = true;
validate_virtcol();
- if (width1 <= 0)
+ if (width1 <= 0) {
curwin->w_curswant = 0;
- else {
+ } else {
curwin->w_curswant = width1 - 1;
- if (curwin->w_virtcol > curwin->w_curswant)
+ if (curwin->w_virtcol > curwin->w_curswant) {
curwin->w_curswant += ((curwin->w_virtcol
- curwin->w_curswant -
1) / width2 + 1) * width2;
+ }
}
} else {
- if (linelen > width1)
+ if (linelen > width1) {
n = ((linelen - width1 - 1) / width2 + 1) * width2 + width1;
- else
+ } else {
n = width1;
+ }
if (curwin->w_curswant >= n) {
curwin->w_curswant = n - 1;
}
@@ -4021,11 +4092,12 @@ static bool nv_screengo(oparg_T *oap, int dir, long dist)
curwin->w_curswant += w;
}
}
- } else { /* dir == FORWARD */
- if (linelen > width1)
+ } else { // dir == FORWARD
+ if (linelen > width1) {
n = ((linelen - width1 - 1) / width2 + 1) * width2 + width1;
- else
+ } else {
n = width1;
+ }
if (curwin->w_curswant + width2 < (colnr_T)n
&& !hasFolding(curwin->w_cursor.lnum, NULL, NULL)) {
// move forward within line
@@ -4055,10 +4127,11 @@ static bool nv_screengo(oparg_T *oap, int dir, long dist)
}
}
- if (virtual_active() && atend)
+ if (virtual_active() && atend) {
coladvance(MAXCOL);
- else
+ } else {
coladvance(curwin->w_curswant);
+ }
if (curwin->w_cursor.col > 0 && curwin->w_p_wrap) {
/*
@@ -4068,20 +4141,22 @@ static bool nv_screengo(oparg_T *oap, int dir, long dist)
*/
validate_virtcol();
colnr_T virtcol = curwin->w_virtcol;
- if (virtcol > (colnr_T)width1 && *p_sbr != NUL)
- virtcol -= vim_strsize(p_sbr);
+ if (virtcol > (colnr_T)width1 && *p_sbr != NUL) {
+ virtcol -= vim_strsize(p_sbr);
+ }
if (virtcol > curwin->w_curswant
&& (curwin->w_curswant < (colnr_T)width1
? (curwin->w_curswant > (colnr_T)width1 / 2)
: ((curwin->w_curswant - width1) % width2
- > (colnr_T)width2 / 2)))
+ > (colnr_T)width2 / 2))) {
--curwin->w_cursor.col;
+ }
}
- if (atend)
- curwin->w_curswant = MAXCOL; /* stick in the last column */
-
+ if (atend) {
+ curwin->w_curswant = MAXCOL; // stick in the last column
+ }
return retval;
}
@@ -4146,8 +4221,9 @@ static void nv_mouse(cmdarg_T *cap)
*/
static void nv_scroll_line(cmdarg_T *cap)
{
- if (!checkclearop(cap->oap))
+ if (!checkclearop(cap->oap)) {
scroll_redraw(cap->arg, cap->count1);
+ }
}
/*
@@ -4160,8 +4236,8 @@ void scroll_redraw(int up, long count)
linenr_T prev_lnum = curwin->w_cursor.lnum;
bool moved = up ?
- scrollup(count, true) :
- scrolldown(count, true);
+ scrollup(count, true) :
+ scrolldown(count, true);
if (get_scrolloff_value(curwin)) {
// Adjust the cursor position for 'scrolloff'. Mark w_topline as
@@ -4174,17 +4250,18 @@ void scroll_redraw(int up, long count)
* we get stuck at one position. Don't move the cursor up if the
* first line of the buffer is already on the screen */
while (curwin->w_topline == prev_topline
- && curwin->w_topfill == prev_topfill
- ) {
+ && curwin->w_topfill == prev_topfill) {
if (up) {
if (curwin->w_cursor.lnum > prev_lnum
- || cursor_down(1L, false) == false)
+ || cursor_down(1L, false) == false) {
break;
+ }
} else {
if (curwin->w_cursor.lnum < prev_lnum
|| prev_topline == 1L
- || cursor_up(1L, false) == false)
+ || cursor_up(1L, false) == false) {
break;
+ }
}
/* Mark w_topline as valid, otherwise the screen jumps back at the
* end of the file. */
@@ -4220,8 +4297,9 @@ static void nv_zet(cmdarg_T *cap)
/*
* "z123{nchar}": edit the count before obtaining {nchar}
*/
- if (checkclearop(cap->oap))
+ if (checkclearop(cap->oap)) {
return;
+ }
n = nchar - '0';
for (;; ) {
no_mapping++;
@@ -4229,11 +4307,11 @@ static void nv_zet(cmdarg_T *cap)
LANGMAP_ADJUST(nchar, true);
no_mapping--;
(void)add_to_showcmd(nchar);
- if (nchar == K_DEL || nchar == K_KDEL)
+ if (nchar == K_DEL || nchar == K_KDEL) {
n /= 10;
- else if (ascii_isdigit(nchar))
+ } else if (ascii_isdigit(nchar)) {
n = n * 10 + (nchar - '0');
- else if (nchar == CAR) {
+ } else if (nchar == CAR) {
win_setheight(n);
break;
} else if (nchar == 'l'
@@ -4270,15 +4348,16 @@ dozet:
&& cap->count0
&& cap->count0 != curwin->w_cursor.lnum) {
setpcmark();
- if (cap->count0 > curbuf->b_ml.ml_line_count)
+ if (cap->count0 > curbuf->b_ml.ml_line_count) {
curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
- else
+ } else {
curwin->w_cursor.lnum = cap->count0;
+ }
check_cursor_col();
}
switch (nchar) {
- /* "z+", "z<CR>" and "zt": put cursor at top of screen */
+ // "z+", "z<CR>" and "zt": put cursor at top of screen
case '+':
if (cap->count0 == 0) {
// No count given: put cursor at the line below screen
@@ -4296,16 +4375,19 @@ dozet:
beginline(BL_WHITE | BL_FIX);
FALLTHROUGH;
- case 't': scroll_cursor_top(0, true);
+ case 't':
+ scroll_cursor_top(0, true);
redraw_later(curwin, VALID);
set_fraction(curwin);
break;
- /* "z." and "zz": put cursor in middle of screen */
- case '.': beginline(BL_WHITE | BL_FIX);
- FALLTHROUGH;
+ // "z." and "zz": put cursor in middle of screen
+ case '.':
+ beginline(BL_WHITE | BL_FIX);
+ FALLTHROUGH;
- case 'z': scroll_cursor_halfway(true);
+ case 'z':
+ scroll_cursor_halfway(true);
redraw_later(curwin, VALID);
set_fraction(curwin);
break;
@@ -4317,74 +4399,83 @@ dozet:
if (cap->count0 != 0) {
scroll_cursor_bot(0, true);
curwin->w_cursor.lnum = curwin->w_topline;
- } else if (curwin->w_topline == 1)
+ } else if (curwin->w_topline == 1) {
curwin->w_cursor.lnum = 1;
- else
+ } else {
curwin->w_cursor.lnum = curwin->w_topline - 1;
+ }
FALLTHROUGH;
case '-':
beginline(BL_WHITE | BL_FIX);
FALLTHROUGH;
- case 'b': scroll_cursor_bot(0, true);
+ case 'b':
+ scroll_cursor_bot(0, true);
redraw_later(curwin, VALID);
set_fraction(curwin);
break;
- /* "zH" - scroll screen right half-page */
+ // "zH" - scroll screen right half-page
case 'H':
cap->count1 *= curwin->w_width_inner / 2;
FALLTHROUGH;
- /* "zh" - scroll screen to the right */
+ // "zh" - scroll screen to the right
case 'h':
case K_LEFT:
if (!curwin->w_p_wrap) {
- if ((colnr_T)cap->count1 > curwin->w_leftcol)
+ if ((colnr_T)cap->count1 > curwin->w_leftcol) {
curwin->w_leftcol = 0;
- else
+ } else {
curwin->w_leftcol -= (colnr_T)cap->count1;
+ }
leftcol_changed();
}
break;
// "zL" - scroll screen left half-page
- case 'L': cap->count1 *= curwin->w_width_inner / 2;
+ case 'L':
+ cap->count1 *= curwin->w_width_inner / 2;
FALLTHROUGH;
- /* "zl" - scroll screen to the left */
+ // "zl" - scroll screen to the left
case 'l':
case K_RIGHT:
if (!curwin->w_p_wrap) {
- /* scroll the window left */
+ // scroll the window left
curwin->w_leftcol += (colnr_T)cap->count1;
leftcol_changed();
}
break;
- /* "zs" - scroll screen, cursor at the start */
- case 's': if (!curwin->w_p_wrap) {
- if (hasFolding(curwin->w_cursor.lnum, NULL, NULL))
- col = 0; /* like the cursor is in col 0 */
- else
+ // "zs" - scroll screen, cursor at the start
+ case 's':
+ if (!curwin->w_p_wrap) {
+ if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) {
+ col = 0; // like the cursor is in col 0
+ } else {
getvcol(curwin, &curwin->w_cursor, &col, NULL, NULL);
- if (col > l_p_siso)
+ }
+ if (col > l_p_siso) {
col -= l_p_siso;
- else
+ } else {
col = 0;
+ }
if (curwin->w_leftcol != col) {
curwin->w_leftcol = col;
redraw_later(curwin, NOT_VALID);
}
- }
+ }
break;
- /* "ze" - scroll screen, cursor at the end */
- case 'e': if (!curwin->w_p_wrap) {
- if (hasFolding(curwin->w_cursor.lnum, NULL, NULL))
- col = 0; /* like the cursor is in col 0 */
- else
+ // "ze" - scroll screen, cursor at the end
+ case 'e':
+ if (!curwin->w_p_wrap) {
+ if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) {
+ col = 0; // like the cursor is in col 0
+ } else {
getvcol(curwin, &curwin->w_cursor, NULL, NULL, &col);
+ }
n = curwin->w_width_inner - curwin_col_off();
if (col + l_p_siso < n) {
col = 0;
@@ -4395,7 +4486,7 @@ dozet:
curwin->w_leftcol = col;
redraw_later(curwin, NOT_VALID);
}
- }
+ }
break;
// "zp", "zP" in block mode put without addind trailing spaces
@@ -4404,41 +4495,46 @@ dozet:
nv_put(cap);
break;
// "zy" Yank without trailing spaces
- case 'y': nv_operator(cap);
- break;
+ case 'y':
+ nv_operator(cap);
+ break;
- /* "zF": create fold command */
- /* "zf": create fold operator */
+ // "zF": create fold command
+ // "zf": create fold operator
case 'F':
- case 'f': if (foldManualAllowed(true)) {
+ case 'f':
+ if (foldManualAllowed(true)) {
cap->nchar = 'f';
nv_operator(cap);
curwin->w_p_fen = true;
- /* "zF" is like "zfzf" */
+ // "zF" is like "zfzf"
if (nchar == 'F' && cap->oap->op_type == OP_FOLD) {
nv_operator(cap);
finish_op = true;
}
- } else
+ } else {
clearopbeep(cap->oap);
+ }
break;
- /* "zd": delete fold at cursor */
- /* "zD": delete fold at cursor recursively */
+ // "zd": delete fold at cursor
+ // "zD": delete fold at cursor recursively
case 'd':
- case 'D': if (foldManualAllowed(false)) {
+ case 'D':
+ if (foldManualAllowed(false)) {
if (VIsual_active) {
nv_operator(cap);
} else {
deleteFold(curwin, curwin->w_cursor.lnum,
curwin->w_cursor.lnum, nchar == 'D', false);
}
- }
+ }
break;
- /* "zE": erase all folds */
- case 'E': if (foldmethodIsManual(curwin)) {
+ // "zE": erase all folds
+ case 'E':
+ if (foldmethodIsManual(curwin)) {
clearFolding(curwin);
changed_window_setting();
} else if (foldmethodIsMarker(curwin)) {
@@ -4448,20 +4544,24 @@ dozet:
}
break;
- /* "zn": fold none: reset 'foldenable' */
- case 'n': curwin->w_p_fen = false;
+ // "zn": fold none: reset 'foldenable'
+ case 'n':
+ curwin->w_p_fen = false;
break;
- /* "zN": fold Normal: set 'foldenable' */
- case 'N': curwin->w_p_fen = true;
+ // "zN": fold Normal: set 'foldenable'
+ case 'N':
+ curwin->w_p_fen = true;
break;
- /* "zi": invert folding: toggle 'foldenable' */
- case 'i': curwin->w_p_fen = !curwin->w_p_fen;
+ // "zi": invert folding: toggle 'foldenable'
+ case 'i':
+ curwin->w_p_fen = !curwin->w_p_fen;
break;
// "za": open closed fold or close open fold at cursor
- case 'a': if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) {
+ case 'a':
+ if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) {
openFold(curwin->w_cursor, cap->count1);
} else {
closeFold(curwin->w_cursor, cap->count1);
@@ -4470,7 +4570,8 @@ dozet:
break;
// "zA": open fold at cursor recursively
- case 'A': if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) {
+ case 'A':
+ if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) {
openFoldRecurse(curwin->w_cursor);
} else {
closeFoldRecurse(curwin->w_cursor);
@@ -4479,7 +4580,8 @@ dozet:
break;
// "zo": open fold at cursor or Visual area
- case 'o': if (VIsual_active) {
+ case 'o':
+ if (VIsual_active) {
nv_operator(cap);
} else {
openFold(curwin->w_cursor, cap->count1);
@@ -4487,7 +4589,8 @@ dozet:
break;
// "zO": open fold recursively
- case 'O': if (VIsual_active) {
+ case 'O':
+ if (VIsual_active) {
nv_operator(cap);
} else {
openFoldRecurse(curwin->w_cursor);
@@ -4495,16 +4598,18 @@ dozet:
break;
// "zc": close fold at cursor or Visual area
- case 'c': if (VIsual_active) {
+ case 'c':
+ if (VIsual_active) {
nv_operator(cap);
- } else {
+ } else {
closeFold(curwin->w_cursor, cap->count1);
}
curwin->w_p_fen = true;
break;
// "zC": close fold recursively
- case 'C': if (VIsual_active) {
+ case 'C':
+ if (VIsual_active) {
nv_operator(cap);
} else {
closeFoldRecurse(curwin->w_cursor);
@@ -4512,24 +4617,27 @@ dozet:
curwin->w_p_fen = true;
break;
- /* "zv": open folds at the cursor */
- case 'v': foldOpenCursor();
+ // "zv": open folds at the cursor
+ case 'v':
+ foldOpenCursor();
break;
- /* "zx": re-apply 'foldlevel' and open folds at the cursor */
- case 'x': curwin->w_p_fen = true;
- curwin->w_foldinvalid = true; /* recompute folds */
- newFoldLevel(); /* update right now */
+ // "zx": re-apply 'foldlevel' and open folds at the cursor
+ case 'x':
+ curwin->w_p_fen = true;
+ curwin->w_foldinvalid = true; // recompute folds
+ newFoldLevel(); // update right now
foldOpenCursor();
break;
- /* "zX": undo manual opens/closes, re-apply 'foldlevel' */
- case 'X': curwin->w_p_fen = true;
- curwin->w_foldinvalid = true; /* recompute folds */
- old_fdl = -1; /* force an update */
+ // "zX": undo manual opens/closes, re-apply 'foldlevel'
+ case 'X':
+ curwin->w_p_fen = true;
+ curwin->w_foldinvalid = true; // recompute folds
+ old_fdl = -1; // force an update
break;
- /* "zm": fold more */
+ // "zm": fold more
case 'm':
if (curwin->w_p_fdl > 0) {
curwin->w_p_fdl -= cap->count1;
@@ -4537,17 +4645,18 @@ dozet:
curwin->w_p_fdl = 0;
}
}
- old_fdl = -1; /* force an update */
+ old_fdl = -1; // force an update
curwin->w_p_fen = true;
break;
- /* "zM": close all folds */
- case 'M': curwin->w_p_fdl = 0;
- old_fdl = -1; /* force an update */
+ // "zM": close all folds
+ case 'M':
+ curwin->w_p_fdl = 0;
+ old_fdl = -1; // force an update
curwin->w_p_fen = true;
break;
- /* "zr": reduce folding */
+ // "zr": reduce folding
case 'r':
curwin->w_p_fdl += cap->count1;
{
@@ -4563,11 +4672,12 @@ dozet:
old_fdl = -1; // force an update
break;
- case 'j': /* "zj" move to next fold downwards */
- case 'k': /* "zk" move to next fold upwards */
+ case 'j': // "zj" move to next fold downwards
+ case 'k': // "zk" move to next fold upwards
if (foldMoveTo(true, nchar == 'j' ? FORWARD : BACKWARD,
- cap->count1) == false)
+ cap->count1) == false) {
clearopbeep(cap->oap);
+ }
break;
@@ -4584,55 +4694,61 @@ dozet:
undo = true;
FALLTHROUGH;
- case 'g': /* "zg": add good word to word list */
- case 'w': /* "zw": add wrong word to word list */
- case 'G': /* "zG": add good word to temp word list */
- case 'W': /* "zW": add wrong word to temp word list */
- {
- char_u *ptr = NULL;
- size_t len;
-
- if (checkclearop(cap->oap))
- break;
- if (VIsual_active && !get_visual_text(cap, &ptr, &len))
- return;
- if (ptr == NULL) {
- pos_T pos = curwin->w_cursor;
+ case 'g': // "zg": add good word to word list
+ case 'w': // "zw": add wrong word to word list
+ case 'G': // "zG": add good word to temp word list
+ case 'W': // "zW": add wrong word to temp word list
+ {
+ char_u *ptr = NULL;
+ size_t len;
- /* Find bad word under the cursor. When 'spell' is
- * off this fails and find_ident_under_cursor() is
- * used below. */
- emsg_off++;
- len = spell_move_to(curwin, FORWARD, true, true, NULL);
- emsg_off--;
- if (len != 0 && curwin->w_cursor.col <= pos.col)
- ptr = ml_get_pos(&curwin->w_cursor);
- curwin->w_cursor = pos;
- }
+ if (checkclearop(cap->oap)) {
+ break;
+ }
+ if (VIsual_active && !get_visual_text(cap, &ptr, &len)) {
+ return;
+ }
+ if (ptr == NULL) {
+ pos_T pos = curwin->w_cursor;
+
+ /* Find bad word under the cursor. When 'spell' is
+ * off this fails and find_ident_under_cursor() is
+ * used below. */
+ emsg_off++;
+ len = spell_move_to(curwin, FORWARD, true, true, NULL);
+ emsg_off--;
+ if (len != 0 && curwin->w_cursor.col <= pos.col) {
+ ptr = ml_get_pos(&curwin->w_cursor);
+ }
+ curwin->w_cursor = pos;
+ }
- if (ptr == NULL && (len = find_ident_under_cursor(&ptr, FIND_IDENT)) == 0)
- return;
- assert(len <= INT_MAX);
- spell_add_word(ptr, (int)len,
- nchar == 'w' || nchar == 'W'
+ if (ptr == NULL && (len = find_ident_under_cursor(&ptr, FIND_IDENT)) == 0) {
+ return;
+ }
+ assert(len <= INT_MAX);
+ spell_add_word(ptr, (int)len,
+ nchar == 'w' || nchar == 'W'
? SPELL_ADD_BAD : SPELL_ADD_GOOD,
- (nchar == 'G' || nchar == 'W') ? 0 : (int)cap->count1,
- undo);
- }
- break;
+ (nchar == 'G' || nchar == 'W') ? 0 : (int)cap->count1,
+ undo);
+ }
+ break;
- case '=': /* "z=": suggestions for a badly spelled word */
- if (!checkclearop(cap->oap))
+ case '=': // "z=": suggestions for a badly spelled word
+ if (!checkclearop(cap->oap)) {
spell_suggest((int)cap->count0);
+ }
break;
- default: clearopbeep(cap->oap);
+ default:
+ clearopbeep(cap->oap);
}
- /* Redraw when 'foldenable' changed */
+ // Redraw when 'foldenable' changed
if (old_fen != curwin->w_p_fen) {
if (foldmethodIsDiff(curwin) && curwin->w_p_scb) {
- /* Adjust 'foldenable' in diff-synced windows. */
+ // Adjust 'foldenable' in diff-synced windows.
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
if (wp != curwin && foldmethodIsDiff(wp) && wp->w_p_scb) {
wp->w_p_fen = curwin->w_p_fen;
@@ -4643,9 +4759,10 @@ dozet:
changed_window_setting();
}
- /* Redraw when 'foldlevel' changed. */
- if (old_fdl != curwin->w_p_fdl)
+ // Redraw when 'foldlevel' changed.
+ if (old_fdl != curwin->w_p_fdl) {
newFoldLevel();
+ }
}
@@ -4688,9 +4805,10 @@ static void nv_colon(cmdarg_T *cap)
}
}
- /* When typing, don't type below an old message */
- if (KeyTyped)
+ // When typing, don't type below an old message
+ if (KeyTyped) {
compute_cmdrow();
+ }
old_p_im = p_im;
@@ -4698,26 +4816,28 @@ static void nv_colon(cmdarg_T *cap)
cmd_result = do_cmdline(NULL, is_cmdkey ? getcmdkeycmd : getexline, NULL,
cap->oap->op_type != OP_NOP ? DOCMD_KEEPLINE : 0);
- /* If 'insertmode' changed, enter or exit Insert mode */
+ // If 'insertmode' changed, enter or exit Insert mode
if (p_im != old_p_im) {
- if (p_im)
+ if (p_im) {
restart_edit = 'i';
- else
+ } else {
restart_edit = 0;
+ }
}
- if (cmd_result == false)
- /* The Ex command failed, do not execute the operator. */
+ 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
- ))
+ } 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);
+ }
}
}
@@ -4726,12 +4846,13 @@ static void nv_colon(cmdarg_T *cap)
*/
static void nv_ctrlg(cmdarg_T *cap)
{
- if (VIsual_active) { /* toggle Selection/Visual mode */
+ if (VIsual_active) { // toggle Selection/Visual mode
VIsual_select = !VIsual_select;
showmode();
- } else if (!checkclearop(cap->oap))
- /* print full name if count given or :cd used */
+ } else if (!checkclearop(cap->oap)) {
+ // print full name if count given or :cd used
fileinfo((int)cap->count0, false, true);
+ }
}
/*
@@ -4740,10 +4861,11 @@ static void nv_ctrlg(cmdarg_T *cap)
static void nv_ctrlh(cmdarg_T *cap)
{
if (VIsual_active && VIsual_select) {
- cap->cmdchar = 'x'; /* BS key behaves like 'x' in Select mode */
+ cap->cmdchar = 'x'; // BS key behaves like 'x' in Select mode
v_visop(cap);
- } else
+ } else {
nv_left(cap);
+ }
}
/*
@@ -4752,7 +4874,7 @@ static void nv_ctrlh(cmdarg_T *cap)
static void nv_clear(cmdarg_T *cap)
{
if (!checkclearop(cap->oap)) {
- /* Clear all syntax states to force resyncing. */
+ // 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;
@@ -4770,7 +4892,7 @@ static void nv_ctrlo(cmdarg_T *cap)
if (VIsual_active && VIsual_select) {
VIsual_select = false;
showmode();
- restart_VIsual_select = 2; /* restart Select mode later */
+ restart_VIsual_select = 2; // restart Select mode later
} else {
cap->count1 = -cap->count1;
nv_pcmark(cap);
@@ -4781,9 +4903,10 @@ static void nv_ctrlo(cmdarg_T *cap)
// not named.
static void nv_hat(cmdarg_T *cap)
{
- if (!checkclearopq(cap->oap))
+ if (!checkclearopq(cap->oap)) {
(void)buflist_getfile((int)cap->count0, (linenr_T)0,
- GETF_SETMARK|GETF_ALT, false);
+ GETF_SETMARK|GETF_ALT, false);
+ }
}
/*
@@ -4793,15 +4916,18 @@ static void nv_Zet(cmdarg_T *cap)
{
if (!checkclearopq(cap->oap)) {
switch (cap->nchar) {
- /* "ZZ": equivalent to ":x". */
- case 'Z': do_cmdline_cmd("x");
+ // "ZZ": equivalent to ":x".
+ case 'Z':
+ do_cmdline_cmd("x");
break;
- /* "ZQ": equivalent to ":q!" (Elvis compatible). */
- case 'Q': do_cmdline_cmd("q!");
+ // "ZQ": equivalent to ":q!" (Elvis compatible).
+ case 'Q':
+ do_cmdline_cmd("q!");
break;
- default: clearopbeep(cap->oap);
+ default:
+ clearopbeep(cap->oap);
}
}
}
@@ -4824,23 +4950,23 @@ void do_nv_ident(int c1, int c2)
/*
* Handle the commands that use the word under the cursor.
- * [g] CTRL-] :ta to current identifier
- * [g] 'K' run program for current identifier
- * [g] '*' / to current identifier or string
- * [g] '#' ? to current identifier or string
- * g ']' :tselect for current identifier
+ * [g] CTRL-] :ta to current identifier
+ * [g] 'K' run program for current identifier
+ * [g] '*' / to current identifier or string
+ * [g] '#' ? to current identifier or string
+ * g ']' :tselect for current identifier
*/
static void nv_ident(cmdarg_T *cap)
{
char_u *ptr = NULL;
char_u *p;
- size_t n = 0; /* init for GCC */
+ size_t n = 0; // init for GCC
int cmdchar;
- bool g_cmd; /* "g" command */
+ bool g_cmd; // "g" command
bool tag_cmd = false;
char_u *aux_ptr;
- if (cap->cmdchar == 'g') { /* "g*", "g#", "g]" and "gCTRL-]" */
+ if (cap->cmdchar == 'g') { // "g*", "g#", "g]" and "gCTRL-]"
cmdchar = cap->nchar;
g_cmd = true;
} else {
@@ -4848,17 +4974,20 @@ static void nv_ident(cmdarg_T *cap)
g_cmd = false;
}
- if (cmdchar == POUND) /* the pound sign, '#' for English keyboards */
+ if (cmdchar == POUND) { // the pound sign, '#' for English keyboards
cmdchar = '#';
+ }
/*
* The "]", "CTRL-]" and "K" commands accept an argument in Visual mode.
*/
if (cmdchar == ']' || cmdchar == Ctrl_RSB || cmdchar == 'K') {
- if (VIsual_active && get_visual_text(cap, &ptr, &n) == false)
+ if (VIsual_active && get_visual_text(cap, &ptr, &n) == false) {
return;
- if (checkclearopq(cap->oap))
+ }
+ if (checkclearopq(cap->oap)) {
return;
+ }
}
if (ptr == NULL && (n = find_ident_under_cursor(&ptr,
@@ -4895,11 +5024,12 @@ static void nv_ident(cmdarg_T *cap)
* it was.
*/
setpcmark();
- curwin->w_cursor.col = (colnr_T) (ptr - get_cursor_line_ptr());
+ curwin->w_cursor.col = (colnr_T)(ptr - get_cursor_line_ptr());
- if (!g_cmd && vim_iswordp(ptr))
+ if (!g_cmd && vim_iswordp(ptr)) {
STRCPY(buf, "\\<");
- no_smartcase = true; /* don't use 'smartcase' now */
+ }
+ no_smartcase = true; // don't use 'smartcase' now
break;
case 'K':
@@ -4919,7 +5049,7 @@ static void nv_ident(cmdarg_T *cap)
--n;
}
if (n == 0) {
- EMSG(_(e_noident)); /* found dashes only */
+ EMSG(_(e_noident)); // found dashes only
xfree(buf);
return;
}
@@ -4942,7 +5072,7 @@ static void nv_ident(cmdarg_T *cap)
STRCAT(buf, " ");
if (cap->count0 != 0 && (isman || isman_s)) {
snprintf(buf + STRLEN(buf), buf_size - STRLEN(buf), "%" PRId64,
- (int64_t)cap->count0);
+ (int64_t)cap->count0);
STRCAT(buf, " ");
}
}
@@ -4950,21 +5080,23 @@ static void nv_ident(cmdarg_T *cap)
case ']':
tag_cmd = true;
- if (p_cst)
+ if (p_cst) {
STRCPY(buf, "cstag ");
- else
+ } else {
STRCPY(buf, "ts ");
+ }
break;
default:
tag_cmd = true;
- if (curbuf->b_help)
+ if (curbuf->b_help) {
STRCPY(buf, "he! ");
- else {
- if (g_cmd)
+ } else {
+ if (g_cmd) {
STRCPY(buf, "tj ");
- else
+ } else {
snprintf(buf, buf_size, "%" PRId64 "ta ", (int64_t)cap->count0);
+ }
}
}
@@ -4984,24 +5116,27 @@ static void nv_ident(cmdarg_T *cap)
STRCAT(buf, p);
xfree(p);
} else {
- if (cmdchar == '*')
+ if (cmdchar == '*') {
aux_ptr = (char_u *)(p_magic ? "/.*~[^$\\" : "/^$\\");
- else if (cmdchar == '#')
+ } else if (cmdchar == '#') {
aux_ptr = (char_u *)(p_magic ? "/?.*~[^$\\" : "/?^$\\");
- else if (tag_cmd) {
- if (curbuf->b_help)
- /* ":help" handles unescaped argument */
+ } else if (tag_cmd) {
+ if (curbuf->b_help) {
+ // ":help" handles unescaped argument
aux_ptr = (char_u *)"";
- else
+ } else {
aux_ptr = (char_u *)"\\|\"\n[";
- } else
+ }
+ } else {
aux_ptr = (char_u *)"\\|\"\n*?[";
+ }
p = (char_u *)buf + STRLEN(buf);
while (n-- > 0) {
- /* put a backslash before \ and some others */
- if (vim_strchr(aux_ptr, *ptr) != NULL)
+ // put a backslash before \ and some others
+ if (vim_strchr(aux_ptr, *ptr) != NULL) {
*p++ = '\\';
+ }
/* When current byte is a part of multibyte character, copy all
* bytes of that character. */
const size_t len = (size_t)(utfc_ptr2len(ptr) - 1);
@@ -5046,22 +5181,21 @@ static void nv_ident(cmdarg_T *cap)
xfree(buf);
}
-/*
- * Get visually selected text, within one line only.
- * Returns false if more than one line selected.
- */
-bool
-get_visual_text (
- cmdarg_T *cap,
- char_u **pp, /* return: start of selected text */
- size_t *lenp /* return: length of selected text */
-)
-{
- if (VIsual_mode != 'V')
+/// Get visually selected text, within one line only.
+///
+/// @param pp return: start of selected text
+/// @param lenp return: length of selected text
+///
+/// @return false if more than one line selected.
+bool get_visual_text(cmdarg_T *cap, char_u **pp, size_t *lenp)
+{
+ if (VIsual_mode != 'V') {
unadjust_for_sel();
+ }
if (VIsual.lnum != curwin->w_cursor.lnum) {
- if (cap != NULL)
+ if (cap != NULL) {
clearopbeep(cap->oap);
+ }
return false;
}
if (VIsual_mode == 'V') {
@@ -5087,8 +5221,9 @@ get_visual_text (
*/
static void nv_tagpop(cmdarg_T *cap)
{
- if (!checkclearopq(cap->oap))
+ if (!checkclearopq(cap->oap)) {
do_tag((char_u *)"", DT_POP, (int)cap->count1, false, true);
+ }
}
/*
@@ -5107,23 +5242,24 @@ static void nv_scroll(cmdarg_T *cap)
if (cap->cmdchar == 'L') {
validate_botline(curwin); // make sure curwin->w_botline is valid
curwin->w_cursor.lnum = curwin->w_botline - 1;
- if (cap->count1 - 1 >= curwin->w_cursor.lnum)
+ if (cap->count1 - 1 >= curwin->w_cursor.lnum) {
curwin->w_cursor.lnum = 1;
- else {
+ } else {
if (hasAnyFolding(curwin)) {
- /* Count a fold for one screen line. */
+ // Count a fold for one screen line.
for (n = cap->count1 - 1; n > 0
&& curwin->w_cursor.lnum > curwin->w_topline; --n) {
(void)hasFolding(curwin->w_cursor.lnum,
- &curwin->w_cursor.lnum, NULL);
+ &curwin->w_cursor.lnum, NULL);
--curwin->w_cursor.lnum;
}
- } else
+ } else {
curwin->w_cursor.lnum -= cap->count1 - 1;
+ }
}
} else {
if (cap->cmdchar == 'M') {
- /* Don't count filler lines above the window. */
+ // Don't count filler lines above the window.
used -= diff_check_fill(curwin, curwin->w_topline)
- curwin->w_topfill;
validate_botline(curwin); // make sure w_empty_rows is valid
@@ -5132,7 +5268,7 @@ static void nv_scroll(cmdarg_T *cap)
// Count half he number of filler lines to be "below this
// line" and half to be "above the next line".
if (n > 0 && used + diff_check_fill(curwin, curwin->w_topline
- + n) / 2 >= half) {
+ + n) / 2 >= half) {
--n;
break;
}
@@ -5150,7 +5286,7 @@ static void nv_scroll(cmdarg_T *cap)
} else { // (cap->cmdchar == 'H')
n = cap->count1 - 1;
if (hasAnyFolding(curwin)) {
- /* Count a fold for one screen line. */
+ // Count a fold for one screen line.
lnum = curwin->w_topline;
while (n-- > 0 && lnum < curwin->w_botline - 1) {
(void)hasFolding(lnum, NULL, &lnum);
@@ -5160,8 +5296,9 @@ static void nv_scroll(cmdarg_T *cap)
}
}
curwin->w_cursor.lnum = curwin->w_topline + n;
- if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count)
+ if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) {
curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
+ }
}
// Correct for 'so', except when an operator is pending.
@@ -5180,9 +5317,10 @@ static void nv_right(cmdarg_T *cap)
int PAST_LINE;
if (mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL)) {
- /* <C-Right> and <S-Right> move a word or WORD right */
- if (mod_mask & MOD_MASK_CTRL)
+ // <C-Right> and <S-Right> move a word or WORD right
+ if (mod_mask & MOD_MASK_CTRL) {
cap->arg = true;
+ }
nv_wordcmd(cap);
return;
}
@@ -5195,13 +5333,14 @@ static void nv_right(cmdarg_T *cap)
* In virtual mode, there's no such thing as "PAST_LINE", as lines are
* (theoretically) infinitely long.
*/
- if (virtual_active())
+ if (virtual_active()) {
PAST_LINE = 0;
+ }
for (n = cap->count1; n > 0; --n) {
if ((!PAST_LINE && oneright() == false)
- || (PAST_LINE && *get_cursor_pos_ptr() == NUL)
- ) {
+ || (PAST_LINE &&
+ *get_cursor_pos_ptr() == NUL)) {
// <Space> wraps to next line if 'whichwrap' has 's'.
// 'l' wraps to next line if 'whichwrap' has 'l'.
// CURS_RIGHT wraps to next line if 'whichwrap' has '>'.
@@ -5246,8 +5385,9 @@ static void nv_right(cmdarg_T *cap)
}
}
if (n != cap->count1 && (fdo_flags & FDO_HOR) && KeyTyped
- && cap->oap->op_type == OP_NOP)
+ && cap->oap->op_type == OP_NOP) {
foldOpenCursor();
+ }
}
/*
@@ -5260,9 +5400,10 @@ static void nv_left(cmdarg_T *cap)
long n;
if (mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL)) {
- /* <C-Left> and <S-Left> move a word or WORD left */
- if (mod_mask & MOD_MASK_CTRL)
+ // <C-Left> and <S-Left> move a word or WORD left
+ if (mod_mask & MOD_MASK_CTRL) {
cap->arg = 1;
+ }
nv_bck_word(cap);
return;
}
@@ -5272,8 +5413,8 @@ static void nv_left(cmdarg_T *cap)
for (n = cap->count1; n > 0; --n) {
if (oneleft() == false) {
/* <BS> and <Del> wrap to previous line if 'whichwrap' has 'b'.
- * 'h' wraps to previous line if 'whichwrap' has 'h'.
- * CURS_LEFT wraps to previous line if 'whichwrap' has '<'.
+ * 'h' wraps to previous line if 'whichwrap' has 'h'.
+ * CURS_LEFT wraps to previous line if 'whichwrap' has '<'.
*/
if ((((cap->cmdchar == K_BS || cap->cmdchar == Ctrl_H)
&& vim_strchr(p_ww, 'b') != NULL)
@@ -5299,15 +5440,17 @@ static void nv_left(cmdarg_T *cap)
}
continue;
}
- /* Only beep and flush if not moved at all */
- else if (cap->oap->op_type == OP_NOP && n == cap->count1)
+ // Only beep and flush if not moved at all
+ else if (cap->oap->op_type == OP_NOP && n == cap->count1) {
beep_flush();
+ }
break;
}
}
if (n != cap->count1 && (fdo_flags & FDO_HOR) && KeyTyped
- && cap->oap->op_type == OP_NOP)
+ && cap->oap->op_type == OP_NOP) {
foldOpenCursor();
+ }
}
/*
@@ -5317,7 +5460,7 @@ static void nv_left(cmdarg_T *cap)
static void nv_up(cmdarg_T *cap)
{
if (mod_mask & MOD_MASK_SHIFT) {
- /* <S-Up> is page up */
+ // <S-Up> is page up
cap->arg = BACKWARD;
nv_page(cap);
} else {
@@ -5337,7 +5480,7 @@ static void nv_up(cmdarg_T *cap)
static void nv_down(cmdarg_T *cap)
{
if (mod_mask & MOD_MASK_SHIFT) {
- /* <S-Down> is page down */
+ // <S-Down> is page down
cap->arg = FORWARD;
nv_page(cap);
} else if (bt_quickfix(curbuf) && cap->cmdchar == CAR) {
@@ -5399,8 +5542,9 @@ static void nv_gotofile(cmdarg_T *cap)
beginline(BL_SOL | BL_FIX);
}
xfree(ptr);
- } else
+ } else {
clearop(cap->oap);
+ }
}
/*
@@ -5408,10 +5552,10 @@ static void nv_gotofile(cmdarg_T *cap)
*/
static void nv_end(cmdarg_T *cap)
{
- if (cap->arg || (mod_mask & MOD_MASK_CTRL)) { /* CTRL-END = goto last line */
+ if (cap->arg || (mod_mask & MOD_MASK_CTRL)) { // CTRL-END = goto last line
cap->arg = true;
nv_goto(cap);
- cap->count1 = 1; /* to end of current line */
+ cap->count1 = 1; // to end of current line
}
nv_dollar(cap);
}
@@ -5427,13 +5571,15 @@ static void nv_dollar(cmdarg_T *cap)
* is pending (whew!) keep the cursor where it is.
* Otherwise, send it to the end of the line. */
if (!virtual_active() || gchar_cursor() != NUL
- || cap->oap->op_type == OP_NOP)
- curwin->w_curswant = MAXCOL; /* so we stay at the end */
+ || cap->oap->op_type == OP_NOP) {
+ curwin->w_curswant = MAXCOL; // so we stay at the end
+ }
if (cursor_down(cap->count1 - 1,
- cap->oap->op_type == OP_NOP) == false)
+ cap->oap->op_type == OP_NOP) == false) {
clearopbeep(cap->oap);
- else if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP)
+ } else if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) {
foldOpenCursor();
+ }
}
/*
@@ -5446,7 +5592,7 @@ static void nv_search(cmdarg_T *cap)
pos_T save_cursor = curwin->w_cursor;
if (cap->cmdchar == '?' && cap->oap->op_type == OP_ROT13) {
- /* Translate "g??" to "g?g?" */
+ // Translate "g??" to "g?g?"
cap->cmdchar = 'g';
cap->nchar = '?';
nv_operator(cap);
@@ -5487,18 +5633,13 @@ static void nv_next(cmdarg_T *cap)
}
}
-/*
- * Search for "pat" in direction "dir" ('/' or '?', 0 for repeat).
- * Uses only cap->count1 and cap->oap from "cap".
- * Return 0 for failure, 1 for found, 2 for found and line offset added.
- */
-static int normal_search(
- cmdarg_T *cap,
- int dir,
- char_u *pat,
- int opt, // extra flags for do_search()
- int *wrapped
-)
+/// Search for "pat" in direction "dir" ('/' or '?', 0 for repeat).
+/// Uses only cap->count1 and cap->oap from "cap".
+///
+/// @param opt extra flags for do_search()
+///
+/// @return 0 for failure, 1 for found, 2 for found and line offset added.
+static int normal_search(cmdarg_T *cap, int dir, char_u *pat, int opt, int *wrapped)
{
int i;
searchit_arg_T sia;
@@ -5521,8 +5662,9 @@ static int normal_search(
cap->oap->motion_type = kMTLineWise;
}
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();
+ }
}
/* "/$" will put the cursor after the end of the line, may need to
@@ -5541,28 +5683,31 @@ static void nv_csearch(cmdarg_T *cap)
{
bool t_cmd;
- if (cap->cmdchar == 't' || cap->cmdchar == 'T')
+ if (cap->cmdchar == 't' || cap->cmdchar == 'T') {
t_cmd = true;
- else
+ } else {
t_cmd = false;
+ }
cap->oap->motion_type = kMTCharWise;
if (IS_SPECIAL(cap->nchar) || searchc(cap, t_cmd) == false) {
clearopbeep(cap->oap);
} else {
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
&& (t_cmd || cap->oap->op_type != OP_NOP)) {
colnr_T scol, ecol;
getvcol(curwin, &curwin->w_cursor, &scol, NULL, &ecol);
curwin->w_cursor.coladd = ecol - scol;
- } else
+ } else {
curwin->w_cursor.coladd = 0;
+ }
adjust_for_sel(cap);
- if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP)
+ if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) {
foldOpenCursor();
+ }
}
}
@@ -5574,8 +5719,8 @@ static void nv_brackets(cmdarg_T *cap)
{
pos_T new_pos = { 0, 0, 0 };
pos_T prev_pos;
- pos_T *pos = NULL; /* init for GCC */
- pos_T old_pos; /* cursor position before command */
+ pos_T *pos = NULL; // init for GCC
+ pos_T old_pos; // cursor position before command
int flag;
long n;
int findc;
@@ -5584,32 +5729,32 @@ static void nv_brackets(cmdarg_T *cap)
cap->oap->motion_type = kMTCharWise;
cap->oap->inclusive = false;
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.
/*
* "[f" or "]f" : Edit file under the cursor (same as "gf")
*/
- if (cap->nchar == 'f')
+ if (cap->nchar == 'f') {
nv_gotofile(cap);
- else
+ } else
/*
* Find the occurrence(s) of the identifier or define under cursor
* in current and included files or jump to the first occurrence.
*
- * search list jump
- * fwd bwd fwd bwd fwd bwd
- * identifier "]i" "[i" "]I" "[I" "]^I" "[^I"
- * define "]d" "[d" "]D" "[D" "]^D" "[^D"
+ * search list jump
+ * fwd bwd fwd bwd fwd bwd
+ * identifier "]i" "[i" "]I" "[I" "]^I" "[^I"
+ * define "]d" "[d" "]D" "[D" "]^D" "[^D"
*/
if (vim_strchr((char_u *)
- "iI\011dD\004",
- cap->nchar) != NULL) {
+ "iI\011dD\004",
+ cap->nchar) != NULL) {
char_u *ptr;
size_t len;
- if ((len = find_ident_under_cursor(&ptr, FIND_IDENT)) == 0)
+ if ((len = find_ident_under_cursor(&ptr, FIND_IDENT)) == 0) {
clearop(cap->oap);
- else {
+ } else {
find_pattern_in_path(ptr, 0, len, true,
cap->count0 == 0 ? !isupper(cap->nchar) : false,
(((cap->nchar & 0xf) == ('d' & 0xf))
@@ -5637,14 +5782,16 @@ static void nv_brackets(cmdarg_T *cap)
&& vim_strchr((char_u *)"{(*/#mM", cap->nchar) != NULL)
|| (cap->cmdchar == ']'
&& vim_strchr((char_u *)"})*/#mM", cap->nchar) != NULL)) {
- if (cap->nchar == '*')
+ if (cap->nchar == '*') {
cap->nchar = '/';
+ }
prev_pos.lnum = 0;
if (cap->nchar == 'm' || cap->nchar == 'M') {
- if (cap->cmdchar == '[')
+ if (cap->cmdchar == '[') {
findc = '{';
- else
+ } else {
findc = '}';
+ }
n = 9999;
} else {
findc = cap->nchar;
@@ -5652,12 +5799,14 @@ static void nv_brackets(cmdarg_T *cap)
}
for (; n > 0; --n) {
if ((pos = findmatchlimit(cap->oap, findc,
- (cap->cmdchar == '[') ? FM_BACKWARD : FM_FORWARD, 0)) == NULL) {
- if (new_pos.lnum == 0) { /* nothing found */
- if (cap->nchar != 'm' && cap->nchar != 'M')
+ (cap->cmdchar == '[') ? FM_BACKWARD : FM_FORWARD, 0)) == NULL) {
+ if (new_pos.lnum == 0) { // nothing found
+ if (cap->nchar != 'm' && cap->nchar != 'M') {
clearopbeep(cap->oap);
- } else
- pos = &new_pos; /* use last one found */
+ }
+ } else {
+ pos = &new_pos; // use last one found
+ }
break;
}
prev_pos = new_pos;
@@ -5673,24 +5822,27 @@ static void nv_brackets(cmdarg_T *cap)
* Also repeat for the given count.
*/
if (cap->nchar == 'm' || cap->nchar == 'M') {
- /* norm is true for "]M" and "[m" */
+ // norm is true for "]M" and "[m"
int norm = ((findc == '{') == (cap->nchar == 'm'));
n = cap->count1;
- /* found a match: we were inside a method */
+ // found a match: we were inside a method
if (prev_pos.lnum != 0) {
pos = &prev_pos;
curwin->w_cursor = prev_pos;
- if (norm)
+ if (norm) {
--n;
- } else
+ }
+ } else {
pos = NULL;
+ }
while (n > 0) {
for (;; ) {
if ((findc == '{' ? dec_cursor() : inc_cursor()) < 0) {
- /* if not found anything, that's an error */
- if (pos == NULL)
+ // if not found anything, that's an error
+ if (pos == NULL) {
clearopbeep(cap->oap);
+ }
n = 0;
break;
}
@@ -5709,54 +5861,59 @@ static void nv_brackets(cmdarg_T *cap)
new_pos = curwin->w_cursor;
pos = &new_pos;
}
- /* found start/end of other method: go to match */
+ // found start/end of other method: go to match
else if ((pos = findmatchlimit(cap->oap, findc,
- (cap->cmdchar == '[') ? FM_BACKWARD : FM_FORWARD,
- 0)) == NULL)
+ (cap->cmdchar == '[') ? FM_BACKWARD : FM_FORWARD,
+ 0)) == NULL) {
n = 0;
- else
+ } else {
curwin->w_cursor = *pos;
+ }
break;
}
}
--n;
}
curwin->w_cursor = old_pos;
- if (pos == NULL && new_pos.lnum != 0)
+ if (pos == NULL && new_pos.lnum != 0) {
clearopbeep(cap->oap);
+ }
}
if (pos != NULL) {
setpcmark();
curwin->w_cursor = *pos;
curwin->w_set_curswant = true;
if ((fdo_flags & FDO_BLOCK) && KeyTyped
- && cap->oap->op_type == OP_NOP)
+ && cap->oap->op_type == OP_NOP) {
foldOpenCursor();
+ }
}
}
/*
* "[[", "[]", "]]" and "][": move to start or end of function
*/
else if (cap->nchar == '[' || cap->nchar == ']') {
- if (cap->nchar == cap->cmdchar) /* "]]" or "[[" */
+ if (cap->nchar == cap->cmdchar) { // "]]" or "[["
flag = '{';
- else
- flag = '}'; /* "][" or "[]" */
-
+ } else {
+ flag = '}'; // "][" or "[]"
+ }
curwin->w_set_curswant = true;
/*
* Imitate strange Vi behaviour: When using "]]" with an operator
* we also stop at '}'.
*/
if (!findpar(&cap->oap->inclusive, cap->arg, cap->count1, flag,
- (cap->oap->op_type != OP_NOP
- && cap->arg == FORWARD && flag == '{')))
+ (cap->oap->op_type != OP_NOP
+ && cap->arg == FORWARD && flag == '{'))) {
clearopbeep(cap->oap);
- else {
- if (cap->oap->op_type == OP_NOP)
+ } else {
+ if (cap->oap->op_type == OP_NOP) {
beginline(BL_WHITE | BL_FIX);
- if ((fdo_flags & FDO_BLOCK) && KeyTyped && cap->oap->op_type == OP_NOP)
+ }
+ if ((fdo_flags & FDO_BLOCK) && KeyTyped && cap->oap->op_type == OP_NOP) {
foldOpenCursor();
+ }
}
} else if (cap->nchar == 'p' || cap->nchar == 'P') {
// "[p", "[P", "]P" and "]p": put with indent adjustment
@@ -5770,12 +5927,14 @@ static void nv_brackets(cmdarg_T *cap)
for (n = cap->count1; n > 0; --n) {
prev_pos = *pos;
pos = getnextmark(pos, cap->cmdchar == '[' ? BACKWARD : FORWARD,
- cap->nchar == '\'');
- if (pos == NULL)
+ cap->nchar == '\'');
+ if (pos == NULL) {
break;
+ }
}
- if (pos == NULL)
+ if (pos == NULL) {
pos = &prev_pos;
+ }
nv_cursormark(cap, cap->nchar == '\'', pos);
}
/*
@@ -5784,31 +5943,33 @@ static void nv_brackets(cmdarg_T *cap)
*/
else if (cap->nchar >= K_RIGHTRELEASE && cap->nchar <= K_LEFTMOUSE) {
(void)do_mouse(cap->oap, cap->nchar,
- (cap->cmdchar == ']') ? FORWARD : BACKWARD,
- cap->count1, PUT_FIXINDENT);
+ (cap->cmdchar == ']') ? FORWARD : BACKWARD,
+ cap->count1, PUT_FIXINDENT);
}
/*
* "[z" and "]z": move to start or end of open fold.
*/
else if (cap->nchar == 'z') {
if (foldMoveTo(false, cap->cmdchar == ']' ? FORWARD : BACKWARD,
- cap->count1) == false)
+ cap->count1) == false) {
clearopbeep(cap->oap);
+ }
}
/*
* "[c" and "]c": move to next or previous diff-change.
*/
else if (cap->nchar == 'c') {
if (diff_move_to(cap->cmdchar == ']' ? FORWARD : BACKWARD,
- cap->count1) == false)
+ cap->count1) == false) {
clearopbeep(cap->oap);
+ }
}
/*
* "[s", "[S", "]s" and "]S": move to next spell error.
*/
else if (cap->nchar == 's' || cap->nchar == 'S') {
setpcmark();
- for (n = 0; n < cap->count1; ++n)
+ for (n = 0; n < cap->count1; ++n) {
if (spell_move_to(curwin, cap->cmdchar == ']' ? FORWARD : BACKWARD,
cap->nchar == 's', false, NULL) == 0) {
clearopbeep(cap->oap);
@@ -5816,12 +5977,15 @@ static void nv_brackets(cmdarg_T *cap)
} else {
curwin->w_set_curswant = true;
}
- 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();
+ }
}
- /* Not a valid cap->nchar. */
- else
+ // Not a valid cap->nchar.
+ else {
clearopbeep(cap->oap);
+ }
}
/*
@@ -5861,9 +6025,9 @@ static void nv_percent(cmdarg_T *cap)
} else { // "%" : go to matching paren
cap->oap->motion_type = kMTCharWise;
cap->oap->use_reg_one = true;
- if ((pos = findmatch(cap->oap, NUL)) == NULL)
+ if ((pos = findmatch(cap->oap, NUL)) == NULL) {
clearopbeep(cap->oap);
- else {
+ } else {
setpcmark();
curwin->w_cursor = *pos;
curwin->w_set_curswant = true;
@@ -5874,8 +6038,9 @@ static void nv_percent(cmdarg_T *cap)
if (cap->oap->op_type == OP_NOP
&& lnum != curwin->w_cursor.lnum
&& (fdo_flags & FDO_PERCENT)
- && KeyTyped)
+ && KeyTyped) {
foldOpenCursor();
+ }
}
/*
@@ -5886,18 +6051,19 @@ static void nv_brace(cmdarg_T *cap)
{
cap->oap->motion_type = kMTCharWise;
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;
curwin->w_set_curswant = true;
- if (findsent(cap->arg, cap->count1) == false)
+ if (findsent(cap->arg, cap->count1) == false) {
clearopbeep(cap->oap);
- else {
- /* Don't leave the cursor on the NUL past end of line. */
+ } else {
+ // Don't leave the cursor on the NUL past end of line.
adjust_cursor(cap->oap);
curwin->w_cursor.coladd = 0;
- if ((fdo_flags & FDO_BLOCK) && KeyTyped && cap->oap->op_type == OP_NOP)
+ if ((fdo_flags & FDO_BLOCK) && KeyTyped && cap->oap->op_type == OP_NOP) {
foldOpenCursor();
+ }
}
}
@@ -5907,8 +6073,9 @@ static void nv_brace(cmdarg_T *cap)
static void nv_mark(cmdarg_T *cap)
{
if (!checkclearop(cap->oap)) {
- if (setmark(cap->nchar) == false)
+ if (setmark(cap->nchar) == false) {
clearopbeep(cap->oap);
+ }
}
}
@@ -5922,12 +6089,13 @@ static void nv_findpar(cmdarg_T *cap)
cap->oap->inclusive = false;
cap->oap->use_reg_one = 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);
- else {
+ } else {
curwin->w_cursor.coladd = 0;
- if ((fdo_flags & FDO_BLOCK) && KeyTyped && cap->oap->op_type == OP_NOP)
+ if ((fdo_flags & FDO_BLOCK) && KeyTyped && cap->oap->op_type == OP_NOP) {
foldOpenCursor();
+ }
}
}
@@ -5937,14 +6105,14 @@ static void nv_findpar(cmdarg_T *cap)
static void nv_undo(cmdarg_T *cap)
{
if (cap->oap->op_type == OP_LOWER
- || VIsual_active
- ) {
- /* translate "<Visual>u" to "<Visual>gu" and "guu" to "gugu" */
+ || VIsual_active) {
+ // translate "<Visual>u" to "<Visual>gu" and "guu" to "gugu"
cap->cmdchar = 'g';
cap->nchar = 'u';
nv_operator(cap);
- } else
+ } else {
nv_kundo(cap);
+ }
}
/*
@@ -5978,26 +6146,29 @@ static void nv_replace(cmdarg_T *cap)
return;
}
- /* get another character */
+ // get another character
if (cap->nchar == Ctrl_V) {
had_ctrl_v = Ctrl_V;
cap->nchar = get_literal();
- /* Don't redo a multibyte character with CTRL-V. */
- if (cap->nchar > DEL)
+ // Don't redo a multibyte character with CTRL-V.
+ if (cap->nchar > DEL) {
had_ctrl_v = NUL;
- } else
+ }
+ } else {
had_ctrl_v = NUL;
+ }
- /* Abort if the character is a special key. */
+ // Abort if the character is a special key.
if (IS_SPECIAL(cap->nchar)) {
clearopbeep(cap->oap);
return;
}
- /* Visual mode "r" */
+ // Visual mode "r"
if (VIsual_active) {
- if (got_int)
+ if (got_int) {
reset_VIsual();
+ }
if (had_ctrl_v) {
// Use a special (negative) number to make a difference between a
// literal CR or NL and a line break.
@@ -6011,24 +6182,25 @@ static void nv_replace(cmdarg_T *cap)
return;
}
- /* Break tabs, etc. */
+ // Break tabs, etc.
if (virtual_active()) {
- if (u_save_cursor() == false)
+ if (u_save_cursor() == false) {
return;
+ }
if (gchar_cursor() == NUL) {
- /* Add extra space and put the cursor on the first one. */
+ // Add extra space and put the cursor on the first one.
coladvance_force((colnr_T)(getviscol() + cap->count1));
assert(cap->count1 <= INT_MAX);
curwin->w_cursor.col -= (colnr_T)cap->count1;
- } else if (gchar_cursor() == TAB)
+ } else if (gchar_cursor() == TAB) {
coladvance_force(getviscol());
+ }
}
- /* Abort if not enough characters to replace. */
+ // Abort if not enough characters to replace.
ptr = get_cursor_pos_ptr();
if (STRLEN(ptr) < (unsigned)cap->count1
- || (mb_charlen(ptr) < cap->count1)
- ) {
+ || (mb_charlen(ptr) < cap->count1)) {
clearopbeep(cap->oap);
return;
}
@@ -6045,9 +6217,10 @@ static void nv_replace(cmdarg_T *cap)
return;
}
- /* save line for undo */
- if (u_save_cursor() == false)
+ // save line for undo
+ if (u_save_cursor() == false) {
return;
+ }
if (had_ctrl_v != Ctrl_V && (cap->nchar == '\r' || cap->nchar == '\n')) {
/*
@@ -6055,18 +6228,18 @@ static void nv_replace(cmdarg_T *cap)
* Strange vi behaviour: Only one newline is inserted.
* Delete the characters here.
* Insert the newline with an insert command, takes care of
- * autoindent. The insert command depends on being on the last
+ * autoindent. The insert command depends on being on the last
* character of a line or not.
*/
- (void)del_chars(cap->count1, false); /* delete the characters */
+ (void)del_chars(cap->count1, false); // delete the characters
stuffcharReadbuff('\r');
stuffcharReadbuff(ESC);
- /* Give 'r' to edit(), to get the redo command right. */
+ // Give 'r' to edit(), to get the redo command right.
invoke_edit(cap, true, 'r', false);
} else {
prep_redo(cap->oap->regname, cap->count1,
- NUL, 'r', NUL, had_ctrl_v, cap->nchar);
+ NUL, 'r', NUL, had_ctrl_v, cap->nchar);
curbuf->b_op_start = curwin->w_cursor;
const int old_State = State;
@@ -6103,7 +6276,7 @@ static void nv_replace(cmdarg_T *cap)
ins_char(cap->ncharC2);
}
}
- --curwin->w_cursor.col; /* cursor on the last replaced char */
+ --curwin->w_cursor.col; // cursor on the last replaced char
/* if the character on the left of the current cursor is a multi-byte
* character, move two characters left */
mb_adjust_cursor();
@@ -6135,16 +6308,18 @@ static void v_swap_corners(int cmdchar)
curwin->w_curswant = right;
/* 'selection "exclusive" and cursor at right-bottom corner: move it
* right one column */
- if (old_cursor.lnum >= VIsual.lnum && *p_sel == 'e')
+ if (old_cursor.lnum >= VIsual.lnum && *p_sel == 'e') {
++curwin->w_curswant;
+ }
coladvance(curwin->w_curswant);
if (curwin->w_cursor.col == old_cursor.col
&& (!virtual_active()
- || curwin->w_cursor.coladd == old_cursor.coladd)
- ) {
+ || curwin->w_cursor.coladd ==
+ old_cursor.coladd)) {
curwin->w_cursor.lnum = VIsual.lnum;
- if (old_cursor.lnum <= VIsual.lnum && *p_sel == 'e')
+ if (old_cursor.lnum <= VIsual.lnum && *p_sel == 'e') {
++right;
+ }
coladvance(right);
VIsual = curwin->w_cursor;
@@ -6165,18 +6340,19 @@ static void v_swap_corners(int cmdchar)
*/
static void nv_Replace(cmdarg_T *cap)
{
- if (VIsual_active) { /* "R" is replace lines */
+ if (VIsual_active) { // "R" is replace lines
cap->cmdchar = 'c';
cap->nchar = NUL;
- VIsual_mode_orig = VIsual_mode; /* remember original area for gv */
+ VIsual_mode_orig = VIsual_mode; // remember original area for gv
VIsual_mode = 'V';
nv_operator(cap);
} else if (!checkclearopq(cap->oap)) {
if (!MODIFIABLE(curbuf)) {
EMSG(_(e_modifiable));
} else {
- if (virtual_active())
+ if (virtual_active()) {
coladvance(getviscol());
+ }
invoke_edit(cap, false, cap->arg ? 'V' : 'R', false);
}
}
@@ -6190,17 +6366,19 @@ static void nv_vreplace(cmdarg_T *cap)
if (VIsual_active) {
cap->cmdchar = 'r';
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)) {
if (!MODIFIABLE(curbuf)) {
EMSG(_(e_modifiable));
} else {
- if (cap->extra_char == Ctrl_V) /* get another character */
+ if (cap->extra_char == Ctrl_V) { // get another character
cap->extra_char = get_literal();
+ }
stuffcharReadbuff(cap->extra_char);
stuffcharReadbuff(ESC);
- if (virtual_active())
+ if (virtual_active()) {
coladvance(getviscol());
+ }
invoke_edit(cap, true, 'v', false);
}
}
@@ -6226,8 +6404,9 @@ static void n_swapchar(cmdarg_T *cap)
prep_redo_cmd(cap);
- if (u_save_cursor() == false)
+ if (u_save_cursor() == false) {
return;
+ }
startpos = curwin->w_cursor;
for (n = cap->count1; n > 0; --n) {
@@ -6239,12 +6418,14 @@ static void n_swapchar(cmdarg_T *cap)
++curwin->w_cursor.lnum;
curwin->w_cursor.col = 0;
if (n > 1) {
- if (u_savesub(curwin->w_cursor.lnum) == false)
+ if (u_savesub(curwin->w_cursor.lnum) == false) {
break;
+ }
u_clearline();
}
- } else
+ } else {
break;
+ }
}
}
@@ -6256,8 +6437,9 @@ static void n_swapchar(cmdarg_T *cap)
0L, true);
curbuf->b_op_start = startpos;
curbuf->b_op_end = curwin->w_cursor;
- if (curbuf->b_op_end.col > 0)
+ if (curbuf->b_op_end.col > 0) {
--curbuf->b_op_end.col;
+ }
}
}
@@ -6266,19 +6448,21 @@ static void n_swapchar(cmdarg_T *cap)
*/
static void nv_cursormark(cmdarg_T *cap, int flag, pos_T *pos)
{
- if (check_mark(pos) == false)
+ if (check_mark(pos) == false) {
clearop(cap->oap);
- else {
+ } else {
if (cap->cmdchar == '\''
|| cap->cmdchar == '`'
|| cap->cmdchar == '['
- || cap->cmdchar == ']')
+ || cap->cmdchar == ']') {
setpcmark();
+ }
curwin->w_cursor = *pos;
- if (flag)
+ if (flag) {
beginline(BL_WHITE | BL_FIX);
- else
+ } else {
check_cursor();
+ }
}
cap->oap->motion_type = flag ? kMTLineWise : kMTCharWise;
if (cap->cmdchar == '`') {
@@ -6301,8 +6485,9 @@ static void v_visop(cmdarg_T *cap)
if (VIsual_mode != Ctrl_V) {
VIsual_mode_orig = VIsual_mode;
VIsual_mode = 'V';
- } else if (cap->cmdchar == 'C' || cap->cmdchar == 'D')
+ } else if (cap->cmdchar == 'C' || cap->cmdchar == 'D') {
curwin->w_curswant = MAXCOL;
+ }
}
cap->cmdchar = *(vim_strchr(trans, cap->cmdchar) + 1);
nv_operator(cap);
@@ -6324,8 +6509,9 @@ static void nv_subst(cmdarg_T *cap)
}
cap->cmdchar = 'c';
nv_operator(cap);
- } else
+ } else {
nv_optrans(cap);
+ }
}
/*
@@ -6333,14 +6519,15 @@ static void nv_subst(cmdarg_T *cap)
*/
static void nv_abbrev(cmdarg_T *cap)
{
- if (cap->cmdchar == K_DEL || cap->cmdchar == K_KDEL)
- cap->cmdchar = 'x'; /* DEL key behaves like 'x' */
-
- /* in Visual mode these commands are operators */
- if (VIsual_active)
+ if (cap->cmdchar == K_DEL || cap->cmdchar == K_KDEL) {
+ cap->cmdchar = 'x'; // DEL key behaves like 'x'
+ }
+ // in Visual mode these commands are operators
+ if (VIsual_active) {
v_visop(cap);
- else
+ } else {
nv_optrans(cap);
+ }
}
/*
@@ -6372,19 +6559,22 @@ static void nv_gomark(cmdarg_T *cap)
pos_T old_cursor = curwin->w_cursor;
const bool old_KeyTyped = KeyTyped; // getting file may reset it
- if (cap->cmdchar == 'g')
+ if (cap->cmdchar == 'g') {
c = cap->extra_char;
- else
+ } else {
c = cap->nchar;
+ }
pos = getmark(c, (cap->oap->op_type == OP_NOP));
- if (pos == (pos_T *)-1) { /* jumped to other file */
+ if (pos == (pos_T *)-1) { // jumped to other file
if (cap->arg) {
check_cursor_lnum();
beginline(BL_WHITE | BL_FIX);
- } else
+ } else {
check_cursor();
- } else
+ }
+ } else {
nv_cursormark(cap, cap->arg, pos);
+ }
// May need to clear the coladd that a mark includes.
if (!virtual_active()) {
@@ -6420,22 +6610,25 @@ static void nv_pcmark(cmdarg_T *cap)
if (pos == (pos_T *)-1) { // jump to other file
curwin->w_set_curswant = true;
check_cursor();
- } else if (pos != NULL) /* can jump */
+ } else if (pos != NULL) { // can jump
nv_cursormark(cap, false, pos);
- else if (cap->cmdchar == 'g') {
- if (curbuf->b_changelistlen == 0)
+ } else if (cap->cmdchar == 'g') {
+ if (curbuf->b_changelistlen == 0) {
EMSG(_("E664: changelist is empty"));
- else if (cap->count1 < 0)
+ } else if (cap->count1 < 0) {
EMSG(_("E662: At start of changelist"));
- else
+ } else {
EMSG(_("E663: At end of changelist"));
- } else
+ }
+ } else {
clearopbeep(cap->oap);
+ }
if (cap->oap->op_type == OP_NOP
&& (pos == (pos_T *)-1 || lnum != curwin->w_cursor.lnum)
&& (fdo_flags & FDO_MARK)
- && old_KeyTyped)
+ && old_KeyTyped) {
foldOpenCursor();
+ }
}
}
@@ -6444,16 +6637,19 @@ static void nv_pcmark(cmdarg_T *cap)
*/
static void nv_regname(cmdarg_T *cap)
{
- if (checkclearop(cap->oap))
+ if (checkclearop(cap->oap)) {
return;
- if (cap->nchar == '=')
+ }
+ if (cap->nchar == '=') {
cap->nchar = get_expr_register();
+ }
if (cap->nchar != NUL && valid_yank_reg(cap->nchar, false)) {
cap->oap->regname = cap->nchar;
- cap->opcount = cap->count0; /* remember count before '"' */
+ cap->opcount = cap->count0; // remember count before '"'
set_reg_var(cap->oap->regname);
- } else
+ } else {
clearopbeep(cap->oap);
+ }
}
/*
@@ -6464,8 +6660,9 @@ static void nv_regname(cmdarg_T *cap)
*/
static void nv_visual(cmdarg_T *cap)
{
- if (cap->cmdchar == Ctrl_Q)
+ if (cap->cmdchar == Ctrl_Q) {
cap->cmdchar = Ctrl_V;
+ }
// 'v', 'V' and CTRL-V can be used while an operator is pending to make it
// charwise, linewise, or blockwise.
@@ -6476,28 +6673,30 @@ static void nv_visual(cmdarg_T *cap)
}
VIsual_select = cap->arg;
- if (VIsual_active) { /* change Visual mode */
- if (VIsual_mode == cap->cmdchar) /* stop visual mode */
+ if (VIsual_active) { // change Visual mode
+ if (VIsual_mode == cap->cmdchar) { // stop visual mode
end_visual_mode();
- else { /* toggle char/block mode */
- /* or char/line mode */
+ } else { // toggle char/block mode
+ // or char/line mode
VIsual_mode = cap->cmdchar;
showmode();
}
redraw_curbuf_later(INVERTED); // update the inversion
} else { // start Visual mode
if (cap->count0 > 0 && resel_VIsual_mode != NUL) {
- /* use previously selected part */
+ // use previously selected part
VIsual = curwin->w_cursor;
VIsual_active = true;
VIsual_reselect = true;
- if (!cap->arg)
- /* start Select mode when 'selectmode' contains "cmd" */
+ if (!cap->arg) {
+ // start Select mode when 'selectmode' contains "cmd"
may_start_select('c');
+ }
setmouse();
- if (p_smd && msg_silent == 0)
- redraw_cmdline = true; /* show visual mode later */
+ if (p_smd && msg_silent == 0) {
+ redraw_cmdline = true; // show visual mode later
+ }
/*
* For V and ^V, we multiply the number of lines even if there
* was only one -- webb
@@ -6505,8 +6704,9 @@ static void nv_visual(cmdarg_T *cap)
if (resel_VIsual_mode != 'v' || resel_VIsual_line_count > 1) {
curwin->w_cursor.lnum +=
resel_VIsual_line_count * cap->count0 - 1;
- if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count)
+ if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) {
curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
+ }
}
VIsual_mode = resel_VIsual_mode;
if (VIsual_mode == 'v') {
@@ -6515,8 +6715,9 @@ static void nv_visual(cmdarg_T *cap)
assert(cap->count0 >= INT_MIN && cap->count0 <= INT_MAX);
curwin->w_curswant = (curwin->w_virtcol
+ resel_VIsual_vcol * (int)cap->count0 - 1);
- } else
+ } else {
curwin->w_curswant = resel_VIsual_vcol;
+ }
coladvance(curwin->w_curswant);
}
if (resel_VIsual_vcol == MAXCOL) {
@@ -6528,22 +6729,26 @@ static void nv_visual(cmdarg_T *cap)
curwin->w_curswant = (curwin->w_virtcol
+ resel_VIsual_vcol * (int)cap->count0 - 1);
coladvance(curwin->w_curswant);
- } else
+ } else {
curwin->w_set_curswant = true;
- redraw_curbuf_later(INVERTED); /* show the inversion */
+ }
+ redraw_curbuf_later(INVERTED); // show the inversion
} else {
- if (!cap->arg)
- /* start Select mode when 'selectmode' contains "cmd" */
+ if (!cap->arg) {
+ // start Select mode when 'selectmode' contains "cmd"
may_start_select('c');
+ }
n_start_visual_mode(cap->cmdchar);
- if (VIsual_mode != 'V' && *p_sel == 'e')
- ++cap->count1; /* include one more char */
+ if (VIsual_mode != 'V' && *p_sel == 'e') {
+ ++cap->count1; // include one more char
+ }
if (cap->count0 > 0 && --cap->count1 > 0) {
- /* With a count select that many characters or lines. */
- if (VIsual_mode == 'v' || VIsual_mode == Ctrl_V)
+ // With a count select that many characters or lines.
+ if (VIsual_mode == 'v' || VIsual_mode == Ctrl_V) {
nv_right(cap);
- else if (VIsual_mode == 'V')
+ } else if (VIsual_mode == 'V') {
nv_down(cap);
+ }
}
}
}
@@ -6554,7 +6759,7 @@ static void nv_visual(cmdarg_T *cap)
*/
void start_selection(void)
{
- /* if 'selectmode' contains "key", start Select mode */
+ // if 'selectmode' contains "key", start Select mode
may_start_select('k');
n_start_visual_mode('v');
}
@@ -6592,9 +6797,9 @@ static void n_start_visual_mode(int c)
// Check for redraw after changing the state.
conceal_check_cursor_line();
- if (p_smd && msg_silent == 0)
- redraw_cmdline = true; /* show visual mode later */
-
+ if (p_smd && msg_silent == 0) {
+ redraw_cmdline = true; // show visual mode later
+ }
/* Only need to redraw this line, unless still need to redraw an old
* Visual area (when 'lazyredraw' is set). */
if (curwin->w_redr_type < INVERTED) {
@@ -6625,8 +6830,9 @@ static void nv_window(cmdarg_T *cap)
static void nv_suspend(cmdarg_T *cap)
{
clearop(cap->oap);
- if (VIsual_active)
- end_visual_mode(); /* stop Visual mode */
+ if (VIsual_active) {
+ end_visual_mode(); // stop Visual mode
+ }
do_cmdline_cmd("st");
}
@@ -6670,18 +6876,19 @@ static void nv_g_cmd(cmdarg_T *cap)
/*
* "gv": Reselect the previous Visual area. If Visual already active,
- * exchange previous and current Visual area.
+ * exchange previous and current Visual area.
*/
case 'v':
- if (checkclearop(oap))
+ if (checkclearop(oap)) {
break;
+ }
- if ( curbuf->b_visual.vi_start.lnum == 0
- || curbuf->b_visual.vi_start.lnum > curbuf->b_ml.ml_line_count
- || curbuf->b_visual.vi_end.lnum == 0)
+ if (curbuf->b_visual.vi_start.lnum == 0
+ || curbuf->b_visual.vi_start.lnum > curbuf->b_ml.ml_line_count
+ || curbuf->b_visual.vi_end.lnum == 0) {
beep_flush();
- else {
- /* set w_cursor to the start of the Visual area, tpos to the end */
+ } else {
+ // set w_cursor to the start of the Visual area, tpos to the end
if (VIsual_active) {
i = VIsual_mode;
VIsual_mode = curbuf->b_visual.vi_mode;
@@ -6727,7 +6934,7 @@ static void nv_g_cmd(cmdarg_T *cap)
break;
/*
* "gV": Don't reselect the previous Visual area after a Select mode
- * mapping of menu.
+ * mapping of menu.
*/
case 'V':
VIsual_reselect = false;
@@ -6755,8 +6962,9 @@ static void nv_g_cmd(cmdarg_T *cap)
*/
case 'N':
case 'n':
- if (!current_search(cap->count1, cap->nchar == 'n'))
+ if (!current_search(cap->count1, cap->nchar == 'n')) {
clearopbeep(oap);
+ }
break;
/*
@@ -6769,10 +6977,12 @@ static void nv_g_cmd(cmdarg_T *cap)
if (!curwin->w_p_wrap) {
oap->motion_type = kMTLineWise;
i = cursor_down(cap->count1, oap->op_type == OP_NOP);
- } else
+ } else {
i = nv_screengo(oap, FORWARD, cap->count1);
- if (!i)
+ }
+ if (!i) {
clearopbeep(oap);
+ }
break;
case 'k':
@@ -6781,10 +6991,12 @@ static void nv_g_cmd(cmdarg_T *cap)
if (!curwin->w_p_wrap) {
oap->motion_type = kMTLineWise;
i = cursor_up(cap->count1, oap->op_type == OP_NOP);
- } else
+ } else {
i = nv_screengo(oap, BACKWARD, cap->count1);
- if (!i)
+ }
+ if (!i) {
clearopbeep(oap);
+ }
break;
/*
@@ -6809,17 +7021,18 @@ static void nv_g_cmd(cmdarg_T *cap)
oap->motion_type = kMTCharWise;
oap->inclusive = false;
if (curwin->w_p_wrap
- && curwin->w_width_inner != 0
- ) {
+ && curwin->w_width_inner != 0) {
int width1 = curwin->w_width_inner - curwin_col_off();
int width2 = width1 + curwin_col_off2();
validate_virtcol();
i = 0;
- if (curwin->w_virtcol >= (colnr_T)width1 && width2 > 0)
+ if (curwin->w_virtcol >= (colnr_T)width1 && width2 > 0) {
i = (curwin->w_virtcol - width1) / width2 * width2 + width1;
- } else
+ }
+ } else {
i = curwin->w_leftcol;
+ }
/* Go to the middle of the screen line. When 'number' or
* 'relativenumber' is on and lines are wrapping the middle can be more
* to the left. */
@@ -6838,8 +7051,7 @@ static void nv_g_cmd(cmdarg_T *cap)
curwin->w_set_curswant = true;
break;
- case 'M':
- {
+ case 'M': {
const char_u *const ptr = get_cursor_line_ptr();
oap->motion_type = kMTCharWise;
@@ -6861,19 +7073,21 @@ static void nv_g_cmd(cmdarg_T *cap)
cap->oap->inclusive = true;
curwin->w_curswant = MAXCOL;
if (cursor_down(cap->count1 - 1,
- cap->oap->op_type == OP_NOP) == false)
+ cap->oap->op_type == OP_NOP) == false) {
clearopbeep(cap->oap);
- else {
+ } else {
char_u *ptr = get_cursor_line_ptr();
- /* In Visual mode we may end up after the line. */
- if (curwin->w_cursor.col > 0 && ptr[curwin->w_cursor.col] == NUL)
+ // In Visual mode we may end up after the line.
+ if (curwin->w_cursor.col > 0 && ptr[curwin->w_cursor.col] == NUL) {
--curwin->w_cursor.col;
+ }
- /* Decrease the cursor column until it's on a non-blank. */
+ // Decrease the cursor column until it's on a non-blank.
while (curwin->w_cursor.col > 0
- && ascii_iswhite(ptr[curwin->w_cursor.col]))
+ && ascii_iswhite(ptr[curwin->w_cursor.col])) {
--curwin->w_cursor.col;
+ }
curwin->w_set_curswant = true;
adjust_for_sel(cap);
}
@@ -6881,57 +7095,58 @@ static void nv_g_cmd(cmdarg_T *cap)
case '$':
case K_END:
- case K_KEND:
- {
- int col_off = curwin_col_off();
+ case K_KEND: {
+ int col_off = curwin_col_off();
- oap->motion_type = kMTCharWise;
- oap->inclusive = true;
- if (curwin->w_p_wrap
- && curwin->w_width_inner != 0
- ) {
- curwin->w_curswant = MAXCOL; /* so we stay at the end */
- if (cap->count1 == 1) {
- int width1 = curwin->w_width_inner - col_off;
- int width2 = width1 + curwin_col_off2();
+ oap->motion_type = kMTCharWise;
+ oap->inclusive = true;
+ if (curwin->w_p_wrap
+ && curwin->w_width_inner != 0) {
+ curwin->w_curswant = MAXCOL; // so we stay at the end
+ if (cap->count1 == 1) {
+ int width1 = curwin->w_width_inner - col_off;
+ int width2 = width1 + curwin_col_off2();
- validate_virtcol();
- i = width1 - 1;
- if (curwin->w_virtcol >= (colnr_T)width1)
- i += ((curwin->w_virtcol - width1) / width2 + 1)
- * width2;
+ validate_virtcol();
+ i = width1 - 1;
+ if (curwin->w_virtcol >= (colnr_T)width1) {
+ i += ((curwin->w_virtcol - width1) / width2 + 1)
+ * width2;
+ }
+ coladvance((colnr_T)i);
+
+ // Make sure we stick in this column.
+ validate_virtcol();
+ curwin->w_curswant = curwin->w_virtcol;
+ curwin->w_set_curswant = false;
+ if (curwin->w_cursor.col > 0 && curwin->w_p_wrap) {
+ /*
+ * Check for landing on a character that got split at
+ * the end of the line. We do not want to advance to
+ * the next screen line.
+ */
+ if (curwin->w_virtcol > (colnr_T)i) {
+ --curwin->w_cursor.col;
+ }
+ }
+ } else if (nv_screengo(oap, FORWARD, cap->count1 - 1) == false) {
+ clearopbeep(oap);
+ }
+ } else {
+ if (cap->count1 > 1) {
+ // if it fails, let the cursor still move to the last char
+ (void)cursor_down(cap->count1 - 1, false);
+ }
+ i = curwin->w_leftcol + curwin->w_width_inner - col_off - 1;
coladvance((colnr_T)i);
- /* Make sure we stick in this column. */
+ // Make sure we stick in this column.
validate_virtcol();
curwin->w_curswant = curwin->w_virtcol;
curwin->w_set_curswant = false;
- if (curwin->w_cursor.col > 0 && curwin->w_p_wrap) {
- /*
- * Check for landing on a character that got split at
- * the end of the line. We do not want to advance to
- * the next screen line.
- */
- if (curwin->w_virtcol > (colnr_T)i)
- --curwin->w_cursor.col;
- }
- } else if (nv_screengo(oap, FORWARD, cap->count1 - 1) == false)
- clearopbeep(oap);
- } else {
- if (cap->count1 > 1) {
- // if it fails, let the cursor still move to the last char
- (void)cursor_down(cap->count1 - 1, false);
}
- i = curwin->w_leftcol + curwin->w_width_inner - col_off - 1;
- coladvance((colnr_T)i);
-
- // Make sure we stick in this column.
- validate_virtcol();
- curwin->w_curswant = curwin->w_virtcol;
- curwin->w_set_curswant = false;
}
- }
- break;
+ break;
/*
* "g*" and "g#", like "*" and "#" but without using "\<" and "\>"
@@ -6939,10 +7154,10 @@ static void nv_g_cmd(cmdarg_T *cap)
case '*':
case '#':
#if POUND != '#'
- case POUND: /* pound sign (sometimes equal to '#') */
+ case POUND: // pound sign (sometimes equal to '#')
#endif
- case Ctrl_RSB: /* :tag or :tselect for current identifier */
- case ']': /* :tselect for current identifier */
+ case Ctrl_RSB: // :tag or :tselect for current identifier
+ case ']': // :tselect for current identifier
nv_ident(cap);
break;
@@ -6954,8 +7169,9 @@ static void nv_g_cmd(cmdarg_T *cap)
oap->motion_type = kMTCharWise;
curwin->w_set_curswant = true;
oap->inclusive = true;
- if (bckend_word(cap->count1, cap->nchar == 'E', false) == false)
+ if (bckend_word(cap->count1, cap->nchar == 'E', false) == false) {
clearopbeep(oap);
+ }
break;
// "g CTRL-G": display info about cursor position
@@ -6970,8 +7186,9 @@ static void nv_g_cmd(cmdarg_T *cap)
check_cursor_lnum();
i = (int)STRLEN(get_cursor_line_ptr());
if (curwin->w_cursor.col > (colnr_T)i) {
- if (virtual_active())
+ if (virtual_active()) {
curwin->w_cursor.coladd += curwin->w_cursor.col - i;
+ }
curwin->w_cursor.col = i;
}
}
@@ -6984,8 +7201,9 @@ static void nv_g_cmd(cmdarg_T *cap)
*/
case 'I':
beginline(0);
- if (!checkclearopq(oap))
+ if (!checkclearopq(oap)) {
invoke_edit(cap, false, 'g', false);
+ }
break;
/*
@@ -6997,7 +7215,7 @@ static void nv_g_cmd(cmdarg_T *cap)
nv_gotofile(cap);
break;
- /* "g'm" and "g`m": jump to mark without setting pcmark */
+ // "g'm" and "g`m": jump to mark without setting pcmark
case '\'':
cap->arg = true;
FALLTHROUGH;
@@ -7014,7 +7232,7 @@ static void nv_g_cmd(cmdarg_T *cap)
/*
* "ga": Display the ascii value of the character under the
- * cursor. It is displayed in decimal, hex, and octal. -- webb
+ * cursor. It is displayed in decimal, hex, and octal. -- webb
*/
case 'a':
do_ascii(NULL);
@@ -7022,14 +7240,15 @@ static void nv_g_cmd(cmdarg_T *cap)
/*
* "g8": Display the bytes used for the UTF-8 character under the
- * cursor. It is displayed in hex.
+ * cursor. It is displayed in hex.
* "8g8" finds illegal byte sequence.
*/
case '8':
- if (cap->count0 == 8)
+ if (cap->count0 == 8) {
utf_find_illegal();
- else
+ } else {
show_utf8();
+ }
break;
// "g<": show scrollback text
case '<':
@@ -7046,14 +7265,14 @@ static void nv_g_cmd(cmdarg_T *cap)
break;
/*
- * Two-character operators:
- * "gq" Format text
- * "gw" Format text and keep cursor position
- * "g~" Toggle the case of the text.
- * "gu" Change text to lower case.
- * "gU" Change text to upper case.
- * "g?" rot13 encoding
- * "g@" call 'operatorfunc'
+ * Two-character operators:
+ * "gq" Format text
+ * "gw" Format text and keep cursor position
+ * "g~" Toggle the case of the text.
+ * "gu" Change text to lower case.
+ * "gU" Change text to upper case.
+ * "g?" rot13 encoding
+ * "g@" call 'operatorfunc'
*/
case 'q':
case 'w':
@@ -7069,7 +7288,7 @@ static void nv_g_cmd(cmdarg_T *cap)
/*
* "gd": Find first occurrence of pattern under the cursor in the
- * current function
+ * current function
* "gD": idem, but in the current file.
*/
case 'd':
@@ -7111,12 +7330,12 @@ static void nv_g_cmd(cmdarg_T *cap)
nv_put(cap);
break;
- /* "go": goto byte count from start of buffer */
+ // "go": goto byte count from start of buffer
case 'o':
goto_byte(cap->count0);
break;
- /* "gQ": improved Ex mode */
+ // "gQ": improved Ex mode
case 'Q':
if (text_locked()) {
clearopbeep(cap->oap);
@@ -7139,12 +7358,14 @@ static void nv_g_cmd(cmdarg_T *cap)
break;
case 't':
- if (!checkclearop(oap))
+ if (!checkclearop(oap)) {
goto_tabpage((int)cap->count0);
+ }
break;
case 'T':
- if (!checkclearop(oap))
+ if (!checkclearop(oap)) {
goto_tabpage(-(int)cap->count1);
+ }
break;
case TAB:
if (!checkclearop(oap)) {
@@ -7153,10 +7374,11 @@ static void nv_g_cmd(cmdarg_T *cap)
break;
case '+':
- case '-': /* "g+" and "g-": undo or redo along the timeline */
- if (!checkclearopq(oap))
+ case '-': // "g+" and "g-": undo or redo along the timeline
+ if (!checkclearopq(oap)) {
undo_time(cap->nchar == '-' ? -cap->count1 : cap->count1,
- false, false, false);
+ false, false, false);
+ }
break;
default:
@@ -7171,19 +7393,20 @@ static void nv_g_cmd(cmdarg_T *cap)
static void n_opencmd(cmdarg_T *cap)
{
if (!checkclearopq(cap->oap)) {
- if (cap->cmdchar == 'O')
- /* Open above the first line of a folded sequence of lines */
+ 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 */
+ &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);
+ NULL, &curwin->w_cursor.lnum);
+ }
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))
- )
+ (linenr_T)(curwin->w_cursor.lnum +
+ (cap->cmdchar == 'o' ? 1 : 0))
+ )
&& open_line(cap->cmdchar == 'O' ? BACKWARD : FORWARD,
has_format_option(FO_OPEN_COMS)
? OPENLINE_DO_COM : 0,
@@ -7208,8 +7431,9 @@ static void nv_dot(cmdarg_T *cap)
* 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 (start_redo(cap->count0, restart_edit != 0 && !arrow_used) == false) {
clearopbeep(cap->oap);
+ }
}
}
@@ -7229,11 +7453,10 @@ static void nv_redo(cmdarg_T *cap)
*/
static void nv_Undo(cmdarg_T *cap)
{
- /* In Visual mode and typing "gUU" triggers an operator */
+ // In Visual mode and typing "gUU" triggers an operator
if (cap->oap->op_type == OP_UPPER
- || VIsual_active
- ) {
- /* translate "gUU" to "gUgU" */
+ || VIsual_active) {
+ // translate "gUU" to "gUgU"
cap->cmdchar = 'g';
cap->nchar = 'U';
nv_operator(cap);
@@ -7278,9 +7501,9 @@ static void nv_operator(cmdarg_T *cap)
return;
}
- if (op_type == cap->oap->op_type) /* double operator works on lines */
+ if (op_type == cap->oap->op_type) { // double operator works on lines
nv_lineop(cap);
- else if (!checkclearop(cap->oap)) {
+ } else if (!checkclearop(cap->oap)) {
cap->oap->start = curwin->w_cursor;
cap->oap->op_type = op_type;
set_op_var(op_type);
@@ -7298,11 +7521,11 @@ static void set_op_var(int optype)
char opchars[3];
int opchar0 = get_op_char(optype);
assert(opchar0 >= 0 && opchar0 <= UCHAR_MAX);
- opchars[0] = (char) opchar0;
+ opchars[0] = (char)opchar0;
int opchar1 = get_extra_op_char(optype);
assert(opchar1 >= 0 && opchar1 <= UCHAR_MAX);
- opchars[1] = (char) opchar1;
+ opchars[1] = (char)opchar1;
opchars[2] = NUL;
set_vim_var_string(VV_OP, opchars, -1);
@@ -7340,10 +7563,10 @@ static void nv_lineop(cmdarg_T *cap)
*/
static void nv_home(cmdarg_T *cap)
{
- /* CTRL-HOME is like "gg" */
- if (mod_mask & MOD_MASK_CTRL)
+ // CTRL-HOME is like "gg"
+ if (mod_mask & MOD_MASK_CTRL) {
nv_goto(cap);
- else {
+ } else {
cap->count0 = 1;
nv_pipe(cap);
}
@@ -7362,8 +7585,9 @@ static void nv_pipe(cmdarg_T *cap)
if (cap->count0 > 0) {
coladvance((colnr_T)(cap->count0 - 1));
curwin->w_curswant = (colnr_T)(cap->count0 - 1);
- } else
+ } else {
curwin->w_curswant = 0;
+ }
/* keep curswant at the column where we wanted to go, not where
* we ended; differs if line is too short */
curwin->w_set_curswant = false;
@@ -7378,10 +7602,11 @@ static void nv_bck_word(cmdarg_T *cap)
cap->oap->motion_type = kMTCharWise;
cap->oap->inclusive = false;
curwin->w_set_curswant = true;
- if (bck_word(cap->count1, cap->arg, false) == false)
+ if (bck_word(cap->count1, cap->arg, false) == false) {
clearopbeep(cap->oap);
- else if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP)
+ } else if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) {
foldOpenCursor();
+ }
}
/*
@@ -7398,10 +7623,11 @@ static void nv_wordcmd(cmdarg_T *cap)
/*
* Set inclusive for the "E" and "e" command.
*/
- if (cap->cmdchar == 'e' || cap->cmdchar == 'E')
+ if (cap->cmdchar == 'e' || cap->cmdchar == 'E') {
word_end = true;
- else
+ } else {
word_end = false;
+ }
cap->oap->inclusive = word_end;
/*
@@ -7428,22 +7654,25 @@ static void nv_wordcmd(cmdarg_T *cap)
cap->oap->motion_type = kMTCharWise;
curwin->w_set_curswant = true;
- if (word_end)
+ if (word_end) {
n = end_word(cap->count1, cap->arg, flag, false);
- else
+ } else {
n = fwd_word(cap->count1, cap->arg, cap->oap->op_type != OP_NOP);
+ }
/* Don't leave the cursor on the NUL past the end of line. Unless we
* didn't move it forward. */
- if (lt(startpos, curwin->w_cursor))
+ if (lt(startpos, curwin->w_cursor)) {
adjust_cursor(cap->oap);
+ }
- if (n == false && cap->oap->op_type == OP_NOP)
+ if (n == false && cap->oap->op_type == OP_NOP) {
clearopbeep(cap->oap);
- else {
+ } else {
adjust_for_sel(cap);
- if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP)
+ if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) {
foldOpenCursor();
+ }
}
}
@@ -7461,8 +7690,8 @@ static void adjust_cursor(oparg_T *oap)
*/
if (curwin->w_cursor.col > 0 && gchar_cursor() == NUL
&& (!VIsual_active || *p_sel == 'o')
- && !virtual_active() && (ve_flags & VE_ONEMORE) == 0
- ) {
+ && !virtual_active() &&
+ (ve_flags & VE_ONEMORE) == 0) {
curwin->w_cursor.col--;
// prevent cursor from moving on the trail byte
mb_adjust_cursor();
@@ -7479,8 +7708,9 @@ static void nv_beginline(cmdarg_T *cap)
cap->oap->motion_type = kMTCharWise;
cap->oap->inclusive = false;
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) {
foldOpenCursor();
+ }
ins_at_eol = false; /* Don't move cursor past eol (only necessary in a
one-character line). */
}
@@ -7507,10 +7737,11 @@ static bool unadjust_for_sel(void)
pos_T *pp;
if (*p_sel == 'e' && !equalpos(VIsual, curwin->w_cursor)) {
- if (lt(VIsual, curwin->w_cursor))
+ if (lt(VIsual, curwin->w_cursor)) {
pp = &curwin->w_cursor;
- else
+ } else {
pp = &VIsual;
+ }
if (pp->coladd > 0) {
pp->coladd--;
} else if (pp->col > 0) {
@@ -7530,10 +7761,10 @@ static bool unadjust_for_sel(void)
*/
static void nv_select(cmdarg_T *cap)
{
- if (VIsual_active)
+ if (VIsual_active) {
VIsual_select = true;
- else if (VIsual_reselect) {
- cap->nchar = 'v'; /* fake "gv" command */
+ } else if (VIsual_reselect) {
+ cap->nchar = 'v'; // fake "gv" command
cap->arg = true;
nv_g_cmd(cap);
}
@@ -7548,24 +7779,28 @@ static void nv_goto(cmdarg_T *cap)
{
linenr_T lnum;
- if (cap->arg)
+ if (cap->arg) {
lnum = curbuf->b_ml.ml_line_count;
- else
+ } else {
lnum = 1L;
+ }
cap->oap->motion_type = kMTLineWise;
setpcmark();
- /* When a count is given, use it instead of the default lnum */
- if (cap->count0 != 0)
+ // When a count is given, use it instead of the default lnum
+ if (cap->count0 != 0) {
lnum = cap->count0;
- if (lnum < 1L)
+ }
+ if (lnum < 1L) {
lnum = 1L;
- else if (lnum > curbuf->b_ml.ml_line_count)
+ } else if (lnum > curbuf->b_ml.ml_line_count) {
lnum = curbuf->b_ml.ml_line_count;
+ }
curwin->w_cursor.lnum = lnum;
beginline(BL_SOL | BL_FIX);
- if ((fdo_flags & FDO_JUMP) && KeyTyped && cap->oap->op_type == OP_NOP)
+ if ((fdo_flags & FDO_JUMP) && KeyTyped && cap->oap->op_type == OP_NOP) {
foldOpenCursor();
+ }
}
/*
@@ -7575,20 +7810,24 @@ static void nv_normal(cmdarg_T *cap)
{
if (cap->nchar == Ctrl_N || cap->nchar == Ctrl_G) {
clearop(cap->oap);
- if (restart_edit != 0 && mode_displayed)
- clear_cmdline = true; /* unshow mode later */
+ if (restart_edit != 0 && mode_displayed) {
+ clear_cmdline = true; // unshow mode later
+ }
restart_edit = 0;
- if (cmdwin_type != 0)
+ if (cmdwin_type != 0) {
cmdwin_result = Ctrl_C;
+ }
if (VIsual_active) {
- end_visual_mode(); /* stop Visual */
+ end_visual_mode(); // stop Visual
redraw_curbuf_later(INVERTED);
}
- /* CTRL-\ CTRL-G restarts Insert mode when 'insertmode' is set. */
- if (cap->nchar == Ctrl_G && p_im)
+ // CTRL-\ CTRL-G restarts Insert mode when 'insertmode' is set.
+ if (cap->nchar == Ctrl_G && p_im) {
restart_edit = 'a';
- } else
+ }
+ } else {
clearopbeep(cap->oap);
+ }
}
/*
@@ -7605,7 +7844,7 @@ static void nv_esc(cmdarg_T *cap)
&& cap->oap->regname == 0
&& !p_im);
- if (cap->arg) { /* true for CTRL-C */
+ if (cap->arg) { // true for CTRL-C
if (restart_edit == 0
&& cmdwin_type == 0
&& !VIsual_active
@@ -7620,11 +7859,12 @@ static void nv_esc(cmdarg_T *cap)
/* Don't reset "restart_edit" when 'insertmode' is set, it won't be
* set again below when halfway through a mapping. */
- if (!p_im)
+ if (!p_im) {
restart_edit = 0;
+ }
if (cmdwin_type != 0) {
cmdwin_result = K_IGNORE;
- got_int = false; /* don't stop executing autocommands et al. */
+ got_int = false; // don't stop executing autocommands et al.
return;
}
} else if (cmdwin_type != 0 && ex_normal_busy) {
@@ -7636,8 +7876,8 @@ static void nv_esc(cmdarg_T *cap)
}
if (VIsual_active) {
- end_visual_mode(); /* stop Visual */
- check_cursor_col(); /* make sure cursor is not beyond EOL */
+ end_visual_mode(); // stop Visual
+ check_cursor_col(); // make sure cursor is not beyond EOL
curwin->w_set_curswant = true;
redraw_curbuf_later(INVERTED);
} else if (no_reason) {
@@ -7648,9 +7888,9 @@ static void nv_esc(cmdarg_T *cap)
/* A CTRL-C is often used at the start of a menu. When 'insertmode' is
* set return to Insert mode afterwards. */
if (restart_edit == 0 && goto_im()
- && ex_normal_busy == 0
- )
+ && ex_normal_busy == 0) {
restart_edit = 'a';
+ }
}
// Move the cursor for the "A" command.
@@ -7681,7 +7921,7 @@ static void nv_edit(cmdarg_T *cap)
// in Visual mode "A" and "I" are an operator
if (VIsual_active && (cap->cmdchar == 'A' || cap->cmdchar == 'I')) {
v_visop(cap);
- // in Visual mode and after an operator "a" and "i" are for text objects
+ // in Visual mode and after an operator "a" and "i" are for text objects
} else if ((cap->cmdchar == 'a' || cap->cmdchar == 'i')
&& (cap->oap->op_type != OP_NOP || VIsual_active)) {
nv_object(cap);
@@ -7695,20 +7935,21 @@ static void nv_edit(cmdarg_T *cap)
set_cursor_for_append_to_line();
break;
- case 'I': /* "I"nsert before the first non-blank */
+ case 'I': // "I"nsert before the first non-blank
beginline(BL_WHITE);
break;
- case 'a': /* "a"ppend is like "i"nsert on the next character. */
+ case 'a': // "a"ppend is like "i"nsert on the next character.
/* increment coladd when in virtual space, increment the
* column otherwise, also to append after an unprintable char */
if (virtual_active()
&& (curwin->w_cursor.coladd > 0
|| *get_cursor_pos_ptr() == NUL
- || *get_cursor_pos_ptr() == TAB))
+ || *get_cursor_pos_ptr() == TAB)) {
curwin->w_cursor.coladd++;
- else if (*get_cursor_pos_ptr() != NUL)
+ } else if (*get_cursor_pos_ptr() != NUL) {
inc_cursor();
+ }
break;
}
@@ -7726,35 +7967,32 @@ static void nv_edit(cmdarg_T *cap)
}
}
-/*
- * Invoke edit() and take care of "restart_edit" and the return value.
- */
-static void
-invoke_edit (
- cmdarg_T *cap,
- int repl, /* "r" or "gr" command */
- int cmd,
- int startln
-)
+/// Invoke edit() and take care of "restart_edit" and the return value.
+///
+/// @param repl "r" or "gr" command
+static void invoke_edit(cmdarg_T *cap, int repl, int cmd, int startln)
{
int restart_edit_save = 0;
/* Complicated: When the user types "a<C-O>a" we don't want to do Insert
* mode recursively. But when doing "a<C-O>." or "a<C-O>rx" we do allow
* it. */
- if (repl || !stuff_empty())
+ if (repl || !stuff_empty()) {
restart_edit_save = restart_edit;
- else
+ } else {
restart_edit_save = 0;
+ }
- /* Always reset "restart_edit", this is not a restarted edit. */
+ // Always reset "restart_edit", this is not a restarted edit.
restart_edit = 0;
- if (edit(cmd, startln, cap->count1))
+ if (edit(cmd, startln, cap->count1)) {
cap->retval |= CA_COMMAND_BUSY;
+ }
- if (restart_edit == 0)
+ if (restart_edit == 0) {
restart_edit = restart_edit_save;
+ }
}
/*
@@ -7766,41 +8004,41 @@ static void nv_object(cmdarg_T *cap)
bool include;
char_u *mps_save;
- if (cap->cmdchar == 'i')
- include = false; /* "ix" = inner object: exclude white space */
- else
- include = true; /* "ax" = an object: include white space */
-
- /* Make sure (), [], {} and <> are in 'matchpairs' */
+ if (cap->cmdchar == 'i') {
+ include = false; // "ix" = inner object: exclude white space
+ } else {
+ include = true; // "ax" = an object: include white space
+ }
+ // Make sure (), [], {} and <> are in 'matchpairs'
mps_save = curbuf->b_p_mps;
curbuf->b_p_mps = (char_u *)"(:),{:},[:],<:>";
switch (cap->nchar) {
- case 'w': /* "aw" = a word */
+ case 'w': // "aw" = a word
flag = current_word(cap->oap, cap->count1, include, false);
break;
- case 'W': /* "aW" = a WORD */
+ case 'W': // "aW" = a WORD
flag = current_word(cap->oap, cap->count1, include, true);
break;
- case 'b': /* "ab" = a braces block */
+ case 'b': // "ab" = a braces block
case '(':
case ')':
flag = current_block(cap->oap, cap->count1, include, '(', ')');
break;
- case 'B': /* "aB" = a Brackets block */
+ case 'B': // "aB" = a Brackets block
case '{':
case '}':
flag = current_block(cap->oap, cap->count1, include, '{', '}');
break;
- case '[': /* "a[" = a [] block */
+ case '[': // "a[" = a [] block
case ']':
flag = current_block(cap->oap, cap->count1, include, '[', ']');
break;
- case '<': /* "a<" = a <> block */
+ case '<': // "a<" = a <> block
case '>':
flag = current_block(cap->oap, cap->count1, include, '<', '>');
break;
- case 't': /* "at" = a tag block (xml and html) */
+ case 't': // "at" = a tag block (xml and html)
// Do not adjust oap->end in do_pending_operator()
// otherwise there are different results for 'dit'
// (note leading whitespace in last line):
@@ -7810,17 +8048,17 @@ static void nv_object(cmdarg_T *cap)
cap->retval |= CA_NO_ADJ_OP_END;
flag = current_tagblock(cap->oap, cap->count1, include);
break;
- case 'p': /* "ap" = a paragraph */
+ case 'p': // "ap" = a paragraph
flag = current_par(cap->oap, cap->count1, include, 'p');
break;
- case 's': /* "as" = a sentence */
+ case 's': // "as" = a sentence
flag = current_sent(cap->oap, cap->count1, include);
break;
- case '"': /* "a"" = a double quoted string */
- case '\'': /* "a'" = a single quoted string */
- case '`': /* "a`" = a backtick quoted string */
+ case '"': // "a"" = a double quoted string
+ case '\'': // "a'" = a single quoted string
+ case '`': // "a`" = a backtick quoted string
flag = current_quote(cap->oap, cap->count1, include,
- cap->nchar);
+ cap->nchar);
break;
default:
flag = false;
@@ -7828,8 +8066,9 @@ static void nv_object(cmdarg_T *cap)
}
curbuf->b_p_mps = mps_save;
- if (!flag)
+ if (!flag) {
clearopbeep(cap->oap);
+ }
adjust_cursor_col();
curwin->w_set_curswant = true;
}
@@ -7841,7 +8080,7 @@ static void nv_object(cmdarg_T *cap)
static void nv_record(cmdarg_T *cap)
{
if (cap->oap->op_type == OP_FORMAT) {
- /* "gqq" is the same as "gqgq": format line */
+ // "gqq" is the same as "gqgq": format line
cap->cmdchar = 'g';
cap->nchar = 'q';
nv_operator(cap);
@@ -7864,11 +8103,13 @@ static void nv_record(cmdarg_T *cap)
*/
static void nv_at(cmdarg_T *cap)
{
- if (checkclearop(cap->oap))
+ if (checkclearop(cap->oap)) {
return;
+ }
if (cap->nchar == '=') {
- if (get_expr_register() == NUL)
+ if (get_expr_register() == NUL) {
return;
+ }
}
while (cap->count1-- && !got_int) {
if (do_execreg(cap->nchar, false, false, false) == false) {
@@ -7886,10 +8127,11 @@ static void nv_halfpage(cmdarg_T *cap)
{
if ((cap->cmdchar == Ctrl_U && curwin->w_cursor.lnum == 1)
|| (cap->cmdchar == Ctrl_D
- && curwin->w_cursor.lnum == curbuf->b_ml.ml_line_count))
+ && curwin->w_cursor.lnum == curbuf->b_ml.ml_line_count)) {
clearopbeep(cap->oap);
- else if (!checkclearop(cap->oap))
+ } else if (!checkclearop(cap->oap)) {
halfpage(cap->cmdchar == Ctrl_D, cap->count0);
+ }
}
/*
@@ -7939,7 +8181,7 @@ static void nv_put_opt(cmdarg_T *cap, bool fix_indent)
int flags = 0;
if (cap->oap->op_type != OP_NOP) {
- /* "dp" is ":diffput" */
+ // "dp" is ":diffput"
if (cap->oap->op_type == OP_DELETE && cap->cmdchar == 'p') {
clearop(cap->oap);
assert(cap->opcount >= 0);
@@ -7976,7 +8218,7 @@ static void nv_put_opt(cmdarg_T *cap, bool fix_indent)
regname = cap->oap->regname;
// '+' and '*' could be the same selection
bool clipoverwrite = (regname == '+' || regname == '*')
- && (cb_flags & CB_UNNAMEDMASK);
+ && (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
@@ -8017,11 +8259,12 @@ static void nv_put_opt(cmdarg_T *cap, bool fix_indent)
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))
+ && 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(). */
+ }
+ // May have been reset in do_put().
VIsual_active = true;
}
do_put(cap->oap->regname, savereg, dir, cap->count1, flags);
@@ -8065,7 +8308,7 @@ static void nv_put_opt(cmdarg_T *cap, bool fix_indent)
*/
static void nv_open(cmdarg_T *cap)
{
- /* "do" is ":diffget" */
+ // "do" is ":diffget"
if (cap->oap->op_type == OP_DELETE && cap->cmdchar == 'o') {
clearop(cap->oap);
assert(cap->opcount >= 0);
@@ -8080,12 +8323,10 @@ static void nv_open(cmdarg_T *cap)
}
}
-// Calculate start/end virtual columns for operating in block mode.
-static void get_op_vcol(
- oparg_T *oap,
- colnr_T redo_VIsual_vcol,
- bool initial // when true: adjust position for 'selectmode'
-)
+/// Calculate start/end virtual columns for operating in block mode.
+///
+/// @param initial when true: adjust position for 'selectmode'
+static void get_op_vcol(oparg_T *oap, colnr_T redo_VIsual_vcol, bool initial)
{
colnr_T start;
colnr_T end;