refactor: follow style guide

- reduce variable scope
- prefer initialization over declaration and assignment
- use bool to represent boolean values
This commit is contained in:
dundargoc
2023-11-12 15:54:54 +01:00
committed by dundargoc
parent 48bcc7b971
commit 28f4f3c484
42 changed files with 287 additions and 554 deletions

View File

@@ -101,7 +101,6 @@ void internal_format(int textwidth, int second_indent, int flags, bool format_on
int wantcol; // column at textwidth border
int foundcol; // column for start of spaces
int end_foundcol = 0; // column for start of word
colnr_T len;
colnr_T virtcol;
int orig_col = 0;
char *saved_text = NULL;
@@ -437,7 +436,7 @@ void internal_format(int textwidth, int second_indent, int flags, bool format_on
// Check if cursor is not past the NUL off the line, cindent
// may have added or removed indent.
curwin->w_cursor.col += startcol;
len = (colnr_T)strlen(get_cursor_line_ptr());
colnr_T len = (colnr_T)strlen(get_cursor_line_ptr());
if (curwin->w_cursor.col > len) {
curwin->w_cursor.col = len;
}
@@ -518,7 +517,6 @@ static bool same_leader(linenr_T lnum, int leader1_len, char *leader1_flags, int
char *leader2_flags)
{
int idx1 = 0, idx2 = 0;
char *p;
char *line1;
char *line2;
@@ -532,7 +530,7 @@ static bool same_leader(linenr_T lnum, int leader1_len, char *leader1_flags, int
// If first leader has 's' flag, the lines can only be joined if there is
// some text after it and the second line has the 'm' flag.
if (leader1_flags != NULL) {
for (p = leader1_flags; *p && *p != ':'; p++) {
for (char *p = leader1_flags; *p && *p != ':'; p++) {
if (*p == COM_FIRST) {
return leader2_len == 0;
}
@@ -629,9 +627,7 @@ static bool paragraph_start(linenr_T lnum)
/// @param prev_line may start in previous line
void auto_format(bool trailblank, bool prev_line)
{
colnr_T len;
char *linep, *plinep;
int cc;
char *linep;
if (!has_format_option(FO_AUTO)) {
return;
@@ -651,7 +647,7 @@ void auto_format(bool trailblank, bool prev_line)
int wasatend = (pos.col == (colnr_T)strlen(old));
if (*old != NUL && !trailblank && wasatend) {
dec_cursor();
cc = gchar_cursor();
int cc = gchar_cursor();
if (!WHITECHAR(cc) && curwin->w_cursor.col > 0
&& has_format_option(FO_ONE_LETTER)) {
dec_cursor();
@@ -702,9 +698,9 @@ void auto_format(bool trailblank, bool prev_line)
// formatted.
if (!wasatend && has_format_option(FO_WHITE_PAR)) {
linep = get_cursor_line_ptr();
len = (colnr_T)strlen(linep);
colnr_T len = (colnr_T)strlen(linep);
if (curwin->w_cursor.col == len) {
plinep = xstrnsave(linep, (size_t)len + 2);
char *plinep = xstrnsave(linep, (size_t)len + 2);
plinep[len] = ' ';
plinep[len + 1] = NUL;
ml_replace(curwin->w_cursor.lnum, plinep, false);