aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/textobject.c
diff options
context:
space:
mode:
authordundargoc <gocdundar@gmail.com>2023-11-13 23:40:37 +0100
committerdundargoc <33953936+dundargoc@users.noreply.github.com>2023-11-19 15:08:35 +0100
commitac1113ded5f8f09dd99a9894d7a7e795626fb728 (patch)
tree9cf615d03efafe2c44e539cb45f1b3df171b3e85 /src/nvim/textobject.c
parent1798a4b5e9f0ae56cd800095f79423fea5cae8ca (diff)
downloadrneovim-ac1113ded5f8f09dd99a9894d7a7e795626fb728.tar.gz
rneovim-ac1113ded5f8f09dd99a9894d7a7e795626fb728.tar.bz2
rneovim-ac1113ded5f8f09dd99a9894d7a7e795626fb728.zip
refactor: follow style guide
- reduce variable scope - prefer initialization over declaration and assignment
Diffstat (limited to 'src/nvim/textobject.c')
-rw-r--r--src/nvim/textobject.c61
1 files changed, 22 insertions, 39 deletions
diff --git a/src/nvim/textobject.c b/src/nvim/textobject.c
index 00038c7d6d..a0a33b17a3 100644
--- a/src/nvim/textobject.c
+++ b/src/nvim/textobject.c
@@ -38,12 +38,11 @@
/// text object.
int findsent(Direction dir, int count)
{
- pos_T pos, tpos;
int c;
int (*func)(pos_T *);
bool noskip = false; // do not skip blanks
- pos = curwin->w_cursor;
+ pos_T pos = curwin->w_cursor;
if (dir == FORWARD) {
func = incl;
} else {
@@ -80,7 +79,7 @@ int findsent(Direction dir, int count)
bool found_dot = false;
while (c = gchar_pos(&pos), ascii_iswhite(c)
|| vim_strchr(".!?)]\"'", c) != NULL) {
- tpos = pos;
+ pos_T tpos = pos;
if (decl(&tpos) == -1 || (LINEEMPTY(tpos.lnum) && dir == FORWARD)) {
break;
}
@@ -110,7 +109,7 @@ int findsent(Direction dir, int count)
break;
}
if (c == '.' || c == '!' || c == '?') {
- tpos = pos;
+ pos_T tpos = pos;
do {
if ((c = inc(&tpos)) == -1) {
break;
@@ -888,17 +887,14 @@ extend:
/// @param other ')', '}', etc.
int current_block(oparg_T *oap, int count, bool include, int what, int other)
{
- pos_T old_pos;
pos_T *pos = NULL;
pos_T start_pos;
pos_T *end_pos;
- pos_T old_start, old_end;
- char *save_cpo;
bool sol = false; // '{' at start of line
- old_pos = curwin->w_cursor;
- old_end = curwin->w_cursor; // remember where we started
- old_start = old_end;
+ pos_T old_pos = curwin->w_cursor;
+ pos_T old_end = curwin->w_cursor; // remember where we started
+ pos_T old_start = old_end;
// If we start on '(', '{', ')', '}', etc., use the whole block inclusive.
if (!VIsual_active || equalpos(VIsual, curwin->w_cursor)) {
@@ -925,7 +921,7 @@ int current_block(oparg_T *oap, int count, bool include, int what, int other)
// Put this position in start_pos.
// Ignore quotes here. Keep the "M" flag in 'cpo', as that is what the
// user wants.
- save_cpo = p_cpo;
+ char *save_cpo = p_cpo;
p_cpo = vim_strchr(p_cpo, CPO_MATCHBSL) != NULL ? "%M" : "%";
if ((pos = findmatch(NULL, what)) != NULL) {
while (count-- > 0) {
@@ -1080,13 +1076,7 @@ static bool in_html_tag(bool end_tag)
int current_tagblock(oparg_T *oap, int count_arg, bool include)
{
int count = count_arg;
- pos_T old_pos;
- pos_T start_pos;
- pos_T end_pos;
- pos_T old_start, old_end;
- char *p;
char *cp;
- int len;
bool do_include = include;
bool save_p_ws = p_ws;
int retval = FAIL;
@@ -1094,9 +1084,9 @@ int current_tagblock(oparg_T *oap, int count_arg, bool include)
p_ws = false;
- old_pos = curwin->w_cursor;
- old_end = curwin->w_cursor; // remember where we started
- old_start = old_end;
+ pos_T old_pos = curwin->w_cursor;
+ pos_T old_end = curwin->w_cursor; // remember where we started
+ pos_T old_start = old_end;
if (!VIsual_active || *p_sel == 'e') {
decl(&old_end); // old_end is inclusive
}
@@ -1148,15 +1138,15 @@ again:
goto theend;
}
}
- start_pos = curwin->w_cursor;
+ pos_T start_pos = curwin->w_cursor;
// Search for matching "</aaa>". First isolate the "aaa".
inc_cursor();
- p = get_cursor_pos_ptr();
+ char *p = get_cursor_pos_ptr();
for (cp = p;
*cp != NUL && *cp != '>' && !ascii_iswhite(*cp);
MB_PTR_ADV(cp)) {}
- len = (int)(cp - p);
+ int len = (int)(cp - p);
if (len == 0) {
curwin->w_cursor = old_pos;
goto theend;
@@ -1202,7 +1192,7 @@ again:
dec_cursor();
}
}
- end_pos = curwin->w_cursor;
+ pos_T end_pos = curwin->w_cursor;
if (!do_include) {
// Exclude the start tag.
@@ -1263,22 +1253,15 @@ theend:
/// @param type 'p' for paragraph, 'S' for section
int current_par(oparg_T *oap, int count, bool include, int type)
{
- linenr_T start_lnum;
- linenr_T end_lnum;
- int white_in_front;
int dir;
- int start_is_white;
- int prev_start_is_white;
int retval = OK;
int do_white = false;
- int t;
- int i;
if (type == 'S') { // not implemented yet
return FAIL;
}
- start_lnum = curwin->w_cursor.lnum;
+ linenr_T start_lnum = curwin->w_cursor.lnum;
// When visual area is more than one line: extend it.
if (VIsual_active && start_lnum != VIsual.lnum) {
@@ -1288,17 +1271,17 @@ extend:
} else {
dir = FORWARD;
}
- for (i = count; --i >= 0;) {
+ for (int i = count; --i >= 0;) {
if (start_lnum ==
(dir == BACKWARD ? 1 : curbuf->b_ml.ml_line_count)) {
retval = FAIL;
break;
}
- prev_start_is_white = -1;
- for (t = 0; t < 2; t++) {
+ int prev_start_is_white = -1;
+ for (int t = 0; t < 2; t++) {
start_lnum += dir;
- start_is_white = linewhite(start_lnum);
+ int start_is_white = linewhite(start_lnum);
if (prev_start_is_white == start_is_white) {
start_lnum -= dir;
break;
@@ -1332,7 +1315,7 @@ extend:
}
// First move back to the start_lnum of the paragraph or white lines
- white_in_front = linewhite(start_lnum);
+ int white_in_front = linewhite(start_lnum);
while (start_lnum > 1) {
if (white_in_front) { // stop at first white line
if (!linewhite(start_lnum - 1)) {
@@ -1347,13 +1330,13 @@ extend:
}
// Move past the end of any white lines.
- end_lnum = start_lnum;
+ linenr_T end_lnum = start_lnum;
while (end_lnum <= curbuf->b_ml.ml_line_count && linewhite(end_lnum)) {
end_lnum++;
}
end_lnum--;
- i = count;
+ int i = count;
if (!include && white_in_front) {
i--;
}