rcfile: disallow extending a syntax that is defined in a main nanorc

The /etc/nanorc file should not define any syntax directly (and
preferably not include any either, to not slow startup down with
syntaxes the user is never going to use), and if the ~/.nanorc file
defines a syntax directly, there is no need to use 'extendsyntax':
the command can be added to the syntax itself -- it would be better
even: it keeps things together.
master
Benno Schulenberg 2019-06-03 15:32:05 +02:00
parent 3d6eca3f26
commit a1669e1bfd
1 changed files with 7 additions and 14 deletions

View File

@ -1038,8 +1038,14 @@ void parse_rcfile(FILE *rcstream, bool syntax_only, bool headers_only)
continue; continue;
} }
/* Disallow extending a syntax that is defined in a main nanorc. */
if (sint->filename == NULL) {
rcfile_error(N_("Only an 'include' syntax can be extended"));
opensyntax = FALSE;
continue;
}
/* When the syntax isn't loaded yet, store extendsyntax commands. */ /* When the syntax isn't loaded yet, store extendsyntax commands. */
if (sint->filename != NULL) {
augmentstruct *newitem = nmalloc(sizeof(augmentstruct));; augmentstruct *newitem = nmalloc(sizeof(augmentstruct));;
newitem->filename = strdup(nanorc); newitem->filename = strdup(nanorc);
@ -1059,19 +1065,6 @@ void parse_rcfile(FILE *rcstream, bool syntax_only, bool headers_only)
continue; continue;
} }
live_syntax = sint;
opensyntax = TRUE;
/* Refind the tail of the color list for this syntax. */
lastcolor = sint->color;
if (lastcolor != NULL)
while (lastcolor->next != NULL)
lastcolor = lastcolor->next;
keyword = ptr;
ptr = parse_next_word(ptr);
}
/* Try to parse the keyword. */ /* Try to parse the keyword. */
if (strcasecmp(keyword, "syntax") == 0) { if (strcasecmp(keyword, "syntax") == 0) {
if (headers_only || !syntax_only) { if (headers_only || !syntax_only) {