commit 5aa1df37d1b8ba4cba8f7b1838c8409fdff59e37
parent ca2c808f6987a44dcca8f79862ee8ff477179f66
Author: Benno Schulenberg <bensberg@justemail.net>
Date: Wed, 8 Jun 2016 14:17:30 +0200
files: recompute the multidata only when the applicable syntax changed
Diffstat:
1 file changed, 19 insertions(+), 15 deletions(-)
diff --git a/src/files.c b/src/files.c
@@ -2122,26 +2122,30 @@ bool write_file(const char *name, FILE *f_open, bool tmp, append_type
}
if (!tmp && append == OVERWRITE) {
- if (!nonamechange) {
- filestruct *line;
-
- openfile->filename = mallocstrcpy(openfile->filename,
- realname);
+ /* If we must set the filename, and it changed, adjust things. */
+ if (!nonamechange && strcmp(openfile->filename, realname) != 0) {
#ifndef DISABLE_COLOR
- /* Discard all the now (possibly) obsolete multidata. */
- for (line = openfile->fileage; line != NULL; line = line->next) {
- free(line->multidata);
- line->multidata = NULL;
- }
+ char *syntaxname = openfile->syntax ? openfile->syntax->name : "";
+ filestruct *line = openfile->fileage;
+#endif
+ openfile->filename = mallocstrcpy(openfile->filename, realname);
- /* We might have changed the filename, so update the colors
- * to account for it, and then make sure we're using them. */
+#ifndef DISABLE_COLOR
+ /* See if the applicable syntax has changed. */
color_update();
color_init();
- precalc_multicolorinfo();
- /* If color syntaxes are available and turned on, we need to
- * call edit_refresh(). */
+ /* If the syntax changed, discard and recompute the multidata. */
+ 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))
edit_refresh();
#endif