mirror of
https://github.com/neovim/neovim.git
synced 2025-09-29 06:28:35 +00:00
refactor: follow style guide
- reduce variable scope - prefer initialization over declaration and assignment
This commit is contained in:
@@ -358,11 +358,9 @@ static int nv_max_linear;
|
||||
/// through the index in nv_cmd_idx[].
|
||||
static int nv_compare(const void *s1, const void *s2)
|
||||
{
|
||||
int c1, c2;
|
||||
|
||||
// The commands are sorted on absolute value.
|
||||
c1 = nv_cmds[*(const int16_t *)s1].cmd_char;
|
||||
c2 = nv_cmds[*(const int16_t *)s2].cmd_char;
|
||||
int c1 = nv_cmds[*(const int16_t *)s1].cmd_char;
|
||||
int c2 = nv_cmds[*(const int16_t *)s2].cmd_char;
|
||||
if (c1 < 0) {
|
||||
c1 = -c1;
|
||||
}
|
||||
@@ -400,9 +398,6 @@ void init_normal_cmds(void)
|
||||
/// @return -1 for invalid command.
|
||||
static int find_command(int cmdchar)
|
||||
{
|
||||
int idx;
|
||||
int top, bot;
|
||||
|
||||
// A multi-byte character is never a command.
|
||||
if (cmdchar >= 0x100) {
|
||||
return -1;
|
||||
@@ -422,9 +417,9 @@ static int find_command(int cmdchar)
|
||||
}
|
||||
|
||||
// Perform a binary search.
|
||||
bot = nv_max_linear + 1;
|
||||
top = NV_CMDS_SIZE - 1;
|
||||
idx = -1;
|
||||
int bot = nv_max_linear + 1;
|
||||
int top = NV_CMDS_SIZE - 1;
|
||||
int idx = -1;
|
||||
while (bot <= top) {
|
||||
int i = (top + bot) / 2;
|
||||
int c = nv_cmds[nv_cmd_idx[i]].cmd_char;
|
||||
@@ -1994,13 +1989,11 @@ void add_to_showcmd_c(int c)
|
||||
/// Delete 'len' characters from the end of the shown command.
|
||||
static void del_from_showcmd(int len)
|
||||
{
|
||||
int old_len;
|
||||
|
||||
if (!p_sc) {
|
||||
return;
|
||||
}
|
||||
|
||||
old_len = (int)strlen(showcmd_buf);
|
||||
int old_len = (int)strlen(showcmd_buf);
|
||||
if (len > old_len) {
|
||||
len = old_len;
|
||||
}
|
||||
@@ -2140,8 +2133,6 @@ void do_check_scrollbind(bool check)
|
||||
/// (1998-11-02 16:21:01 R. Edward Ralston <eralston@computer.org>)
|
||||
void check_scrollbind(linenr_T topline_diff, int leftcol_diff)
|
||||
{
|
||||
bool want_ver;
|
||||
bool want_hor;
|
||||
win_T *old_curwin = curwin;
|
||||
buf_T *old_curbuf = curbuf;
|
||||
int old_VIsual_select = VIsual_select;
|
||||
@@ -2151,9 +2142,9 @@ void check_scrollbind(linenr_T topline_diff, int leftcol_diff)
|
||||
linenr_T y;
|
||||
|
||||
// check 'scrollopt' string for vertical and horizontal scroll options
|
||||
want_ver = (vim_strchr(p_sbo, 'v') && topline_diff != 0);
|
||||
bool want_ver = (vim_strchr(p_sbo, 'v') && topline_diff != 0);
|
||||
want_ver |= old_curwin->w_p_diff;
|
||||
want_hor = (vim_strchr(p_sbo, 'h') && (leftcol_diff || topline_diff != 0));
|
||||
bool want_hor = (vim_strchr(p_sbo, 'h') && (leftcol_diff || topline_diff != 0));
|
||||
|
||||
// loop through the scrollbound windows and scroll accordingly
|
||||
VIsual_select = VIsual_active = 0;
|
||||
@@ -2334,27 +2325,23 @@ static bool is_ident(const char *line, int offset)
|
||||
/// @return fail when not found.
|
||||
bool find_decl(char *ptr, size_t len, bool locally, bool thisblock, int flags_arg)
|
||||
{
|
||||
char *pat;
|
||||
pos_T old_pos;
|
||||
pos_T par_pos;
|
||||
pos_T found_pos;
|
||||
bool t;
|
||||
bool save_p_ws;
|
||||
bool save_p_scs;
|
||||
bool retval = true;
|
||||
bool incll;
|
||||
int searchflags = flags_arg;
|
||||
|
||||
size_t patlen = len + 7;
|
||||
pat = xmalloc(patlen);
|
||||
char *pat = xmalloc(patlen);
|
||||
|
||||
// Put "\V" before the pattern to avoid that the special meaning of "."
|
||||
// and "~" causes trouble.
|
||||
assert(patlen <= INT_MAX);
|
||||
snprintf(pat, patlen, vim_iswordp(ptr) ? "\\V\\<%.*s\\>" : "\\V%.*s", (int)len, ptr);
|
||||
old_pos = curwin->w_cursor;
|
||||
save_p_ws = p_ws;
|
||||
save_p_scs = p_scs;
|
||||
pos_T old_pos = curwin->w_cursor;
|
||||
bool save_p_ws = p_ws;
|
||||
bool 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
|
||||
|
||||
@@ -3902,14 +3889,13 @@ static void nv_down(cmdarg_T *cap)
|
||||
/// Grab the file name under the cursor and edit it.
|
||||
static void nv_gotofile(cmdarg_T *cap)
|
||||
{
|
||||
char *ptr;
|
||||
linenr_T lnum = -1;
|
||||
|
||||
if (check_text_or_curbuf_locked(cap->oap)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ptr = grab_file_name(cap->count1, &lnum);
|
||||
char *ptr = grab_file_name(cap->count1, &lnum);
|
||||
|
||||
if (ptr != NULL) {
|
||||
// do autowrite if necessary
|
||||
@@ -4206,13 +4192,12 @@ static void nv_bracket_block(cmdarg_T *cap, const pos_T *old_pos)
|
||||
/// cap->arg is BACKWARD for "[" and FORWARD for "]".
|
||||
static void nv_brackets(cmdarg_T *cap)
|
||||
{
|
||||
pos_T old_pos; // cursor position before command
|
||||
int flag;
|
||||
int n;
|
||||
|
||||
cap->oap->motion_type = kMTCharWise;
|
||||
cap->oap->inclusive = false;
|
||||
old_pos = curwin->w_cursor;
|
||||
pos_T old_pos = curwin->w_cursor; // cursor position before command
|
||||
curwin->w_cursor.coladd = 0; // TODO(Unknown): don't do this for an error.
|
||||
|
||||
// "[f" or "]f" : Edit file under the cursor (same as "gf")
|
||||
@@ -4478,7 +4463,6 @@ static void nv_kundo(cmdarg_T *cap)
|
||||
/// Handle the "r" command.
|
||||
static void nv_replace(cmdarg_T *cap)
|
||||
{
|
||||
char *ptr;
|
||||
int had_ctrl_v;
|
||||
|
||||
if (checkclearop(cap->oap)) {
|
||||
@@ -4541,7 +4525,7 @@ static void nv_replace(cmdarg_T *cap)
|
||||
}
|
||||
|
||||
// Abort if not enough characters to replace.
|
||||
ptr = get_cursor_pos_ptr();
|
||||
char *ptr = get_cursor_pos_ptr();
|
||||
if (strlen(ptr) < (unsigned)cap->count1
|
||||
|| (mb_charlen(ptr) < cap->count1)) {
|
||||
clearopbeep(cap->oap);
|
||||
@@ -4633,11 +4617,10 @@ static void nv_replace(cmdarg_T *cap)
|
||||
/// 'O': same, but in block mode exchange left and right corners.
|
||||
static void v_swap_corners(int cmdchar)
|
||||
{
|
||||
pos_T old_cursor;
|
||||
colnr_T left, right;
|
||||
|
||||
if (cmdchar == 'O' && VIsual_mode == Ctrl_V) {
|
||||
old_cursor = curwin->w_cursor;
|
||||
pos_T old_cursor = curwin->w_cursor;
|
||||
getvcols(curwin, &old_cursor, &VIsual, &left, &right);
|
||||
curwin->w_cursor.lnum = VIsual.lnum;
|
||||
coladvance(left);
|
||||
@@ -4667,7 +4650,7 @@ static void v_swap_corners(int cmdchar)
|
||||
curwin->w_curswant = left;
|
||||
}
|
||||
} else {
|
||||
old_cursor = curwin->w_cursor;
|
||||
pos_T old_cursor = curwin->w_cursor;
|
||||
curwin->w_cursor = VIsual;
|
||||
VIsual = old_cursor;
|
||||
curwin->w_set_curswant = true;
|
||||
@@ -4738,8 +4721,6 @@ static void nv_vreplace(cmdarg_T *cap)
|
||||
/// Swap case for "~" command, when it does not work like an operator.
|
||||
static void n_swapchar(cmdarg_T *cap)
|
||||
{
|
||||
int n;
|
||||
pos_T startpos;
|
||||
int did_change = 0;
|
||||
|
||||
if (checkclearopq(cap->oap)) {
|
||||
@@ -4757,8 +4738,8 @@ static void n_swapchar(cmdarg_T *cap)
|
||||
return;
|
||||
}
|
||||
|
||||
startpos = curwin->w_cursor;
|
||||
for (n = cap->count1; n > 0; n--) {
|
||||
pos_T startpos = curwin->w_cursor;
|
||||
for (int n = cap->count1; n > 0; n--) {
|
||||
did_change |= swapchar(cap->oap->op_type, &curwin->w_cursor);
|
||||
inc_cursor();
|
||||
if (gchar_cursor() == NUL) {
|
||||
@@ -5759,10 +5740,9 @@ static void nv_dot(cmdarg_T *cap)
|
||||
static void nv_redo_or_register(cmdarg_T *cap)
|
||||
{
|
||||
if (VIsual_select && VIsual_active) {
|
||||
int reg;
|
||||
// Get register name
|
||||
no_mapping++;
|
||||
reg = plain_vgetc();
|
||||
int reg = plain_vgetc();
|
||||
LANGMAP_ADJUST(reg, true);
|
||||
no_mapping--;
|
||||
|
||||
@@ -5822,9 +5802,7 @@ static void nv_tilde(cmdarg_T *cap)
|
||||
/// The actual work is done by do_pending_operator().
|
||||
static void nv_operator(cmdarg_T *cap)
|
||||
{
|
||||
int op_type;
|
||||
|
||||
op_type = get_op_type(cap->cmdchar, cap->nchar);
|
||||
int op_type = get_op_type(cap->cmdchar, cap->nchar);
|
||||
|
||||
if (bt_prompt(curbuf) && op_is_change(op_type)
|
||||
&& !prompt_curpos_editable()) {
|
||||
@@ -6130,12 +6108,10 @@ static void nv_normal(cmdarg_T *cap)
|
||||
/// Don't even beep if we are canceling a command.
|
||||
static void nv_esc(cmdarg_T *cap)
|
||||
{
|
||||
int no_reason;
|
||||
|
||||
no_reason = (cap->oap->op_type == OP_NOP
|
||||
&& cap->opcount == 0
|
||||
&& cap->count0 == 0
|
||||
&& cap->oap->regname == 0);
|
||||
int no_reason = (cap->oap->op_type == OP_NOP
|
||||
&& cap->opcount == 0
|
||||
&& cap->count0 == 0
|
||||
&& cap->oap->regname == 0);
|
||||
|
||||
if (cap->arg) { // true for CTRL-C
|
||||
if (restart_edit == 0 && cmdwin_type == 0 && !VIsual_active && no_reason) {
|
||||
@@ -6287,7 +6263,6 @@ static void nv_object(cmdarg_T *cap)
|
||||
{
|
||||
bool flag;
|
||||
bool include;
|
||||
char *mps_save;
|
||||
|
||||
if (cap->cmdchar == 'i') {
|
||||
include = false; // "ix" = inner object: exclude white space
|
||||
@@ -6295,7 +6270,7 @@ static void nv_object(cmdarg_T *cap)
|
||||
include = true; // "ax" = an object: include white space
|
||||
}
|
||||
// Make sure (), [], {} and <> are in 'matchpairs'
|
||||
mps_save = curbuf->b_p_mps;
|
||||
char *mps_save = curbuf->b_p_mps;
|
||||
curbuf->b_p_mps = "(:),{:},[:],<:>";
|
||||
|
||||
switch (cap->nchar) {
|
||||
|
Reference in New Issue
Block a user