refactor: reduce scope of locals as per the style guide 3 (#22221)

refactor: reduce scope of locals as per the style guide
This commit is contained in:
dundargoc
2023-02-12 18:48:49 +01:00
committed by GitHub
parent 2b1c07a1d4
commit 5f72ab77bf
21 changed files with 147 additions and 275 deletions

View File

@@ -633,19 +633,16 @@ static bool paragraph_start(linenr_T lnum)
/// @param prev_line may start in previous line
void auto_format(bool trailblank, bool prev_line)
{
pos_T pos;
colnr_T len;
char *old;
char *new, *pnew;
int wasatend;
int cc;
if (!has_format_option(FO_AUTO)) {
return;
}
pos = curwin->w_cursor;
old = get_cursor_line_ptr();
pos_T pos = curwin->w_cursor;
char *old = get_cursor_line_ptr();
// may remove added space
check_auto_format(false);
@@ -655,7 +652,7 @@ void auto_format(bool trailblank, bool prev_line)
// in 'formatoptions' and there is a single character before the cursor.
// Otherwise the line would be broken and when typing another non-white
// next they are not joined back together.
wasatend = (pos.col == (colnr_T)strlen(old));
int wasatend = (pos.col == (colnr_T)strlen(old));
if (*old != NUL && !trailblank && wasatend) {
dec_cursor();
cc = gchar_cursor();
@@ -733,18 +730,16 @@ void auto_format(bool trailblank, bool prev_line)
/// @param end_insert true when ending Insert mode
void check_auto_format(bool end_insert)
{
int c = ' ';
int cc;
if (!did_add_space) {
return;
}
cc = gchar_cursor();
int cc = gchar_cursor();
if (!WHITECHAR(cc)) {
// Somehow the space was removed already.
did_add_space = false;
} else {
int c = ' ';
if (!end_insert) {
inc_cursor();
c = gchar_cursor();
@@ -886,7 +881,6 @@ void op_formatexpr(oparg_T *oap)
int fex_format(linenr_T lnum, long count, int c)
{
int use_sandbox = was_set_insecurely(curwin, "formatexpr", OPT_LOCAL);
int r;
// Set v:lnum to the first line number and v:count to the number of lines.
// Set v:char to the character to be inserted (can be NUL).
@@ -900,7 +894,7 @@ int fex_format(linenr_T lnum, long count, int c)
if (use_sandbox) {
sandbox++;
}
r = (int)eval_to_number(fex);
int r = (int)eval_to_number(fex);
if (use_sandbox) {
sandbox--;
}