files: recompute the multidata only when the applicable syntax changed

master
Benno Schulenberg 2016-06-08 14:17:30 +02:00
parent ca2c808f69
commit 5aa1df37d1
1 changed files with 19 additions and 15 deletions

View File

@ -2122,26 +2122,30 @@ bool write_file(const char *name, FILE *f_open, bool tmp, append_type
} }
if (!tmp && append == OVERWRITE) { if (!tmp && append == OVERWRITE) {
if (!nonamechange) { /* If we must set the filename, and it changed, adjust things. */
filestruct *line; if (!nonamechange && strcmp(openfile->filename, realname) != 0) {
openfile->filename = mallocstrcpy(openfile->filename,
realname);
#ifndef DISABLE_COLOR #ifndef DISABLE_COLOR
/* Discard all the now (possibly) obsolete multidata. */ char *syntaxname = openfile->syntax ? openfile->syntax->name : "";
for (line = openfile->fileage; line != NULL; line = line->next) { filestruct *line = openfile->fileage;
free(line->multidata); #endif
line->multidata = NULL; openfile->filename = mallocstrcpy(openfile->filename, realname);
}
/* We might have changed the filename, so update the colors #ifndef DISABLE_COLOR
* to account for it, and then make sure we're using them. */ /* See if the applicable syntax has changed. */
color_update(); color_update();
color_init(); color_init();
precalc_multicolorinfo();
/* If color syntaxes are available and turned on, we need to /* If the syntax changed, discard and recompute the multidata. */
* call edit_refresh(). */ if (openfile->syntax &&
strcmp(syntaxname, openfile->syntax->name) != 0) {
for (; line != NULL; line = line->next) {
free(line->multidata);
line->multidata = NULL;
}
precalc_multicolorinfo();
}
/* If color syntaxes are available and turned on, refresh. */
if (openfile->colorstrings != NULL && !ISSET(NO_COLOR_SYNTAX)) if (openfile->colorstrings != NULL && !ISSET(NO_COLOR_SYNTAX))
edit_refresh(); edit_refresh();
#endif #endif