commit 0e72c0d372fabffb4aca2c1d8b1753f316eefa97
parent 88c8da143fe0609ad8f7373e1c7dcb103bcd0dec
Author: Benno Schulenberg <bensberg@telfort.nl>
Date: Thu, 25 Jan 2024 16:28:14 +0100
chars: add a helper function for stripping leading blanks from a string
And apply this function to the formatter and linter command strings,
to complement the bug fixes in the previous two commits.
Diffstat:
4 files changed, 18 insertions(+), 6 deletions(-)
diff --git a/src/chars.c b/src/chars.c
@@ -654,3 +654,12 @@ bool white_string(const char *string)
return !*string;
}
+
+#if defined(ENABLE_SPELLER) || defined(ENABLE_COLOR)
+/* Remove leading whitespace from the given string. */
+void strip_leading_blanks_from(char *string)
+{
+ while (string && (*string == ' ' || *string == '\t'))
+ memmove(string, string + 1, strlen(string));
+}
+#endif
diff --git a/src/nano.c b/src/nano.c
@@ -2208,9 +2208,7 @@ int main(int argc, char **argv)
free(alt_speller);
alt_speller = alt_speller_cmdline;
}
- /* Strip leading whitespace from the speller command, if any. */
- while (alt_speller && (*alt_speller == ' ' || *alt_speller == '\t'))
- memmove(alt_speller, alt_speller + 1, strlen(alt_speller));
+ strip_leading_blanks_from(alt_speller);
#endif
/* If an rcfile undid the default setting, copy it to the new flag. */
diff --git a/src/prototypes.h b/src/prototypes.h
@@ -238,6 +238,9 @@ char *mbrevstrpbrk(const char *head, const char *accept, const char *pointer);
bool has_blank_char(const char *string);
#endif
bool white_string(const char *string);
+#if defined(ENABLE_SPELLER) || defined(ENABLE_COLOR)
+void strip_leading_blanks_from(char *string);
+#endif
/* Most functions in color.c. */
#ifdef ENABLE_COLOR
diff --git a/src/rcfile.c b/src/rcfile.c
@@ -1332,11 +1332,13 @@ bool parse_syntax_commands(char *keyword, char *ptr)
#endif
} else if (strcmp(keyword, "tabgives") == 0) {
pick_up_name("tabgives", ptr, &live_syntax->tabstring);
- } else if (strcmp(keyword, "linter") == 0)
+ } else if (strcmp(keyword, "linter") == 0) {
pick_up_name("linter", ptr, &live_syntax->linter);
- else if (strcmp(keyword, "formatter") == 0)
+ strip_leading_blanks_from(live_syntax->linter);
+ } else if (strcmp(keyword, "formatter") == 0) {
pick_up_name("formatter", ptr, &live_syntax->formatter);
- else
+ strip_leading_blanks_from(live_syntax->formatter);
+ } else
return FALSE;
return TRUE;