diff --git a/ChangeLog b/ChangeLog
index 144188e4c8bac3a38974c97ce404dda98f58767b..7fd524102b9f32bd7756093b65cd32ba30e9b2fb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2015-12-20  Benno Schulenberg  <bensberg@justemail.net>
+	* src/files.c (display_buffer), src/nano.c (main): Precalculate the
+	multiline-regex cache data for each buffer, not just for the first.
+	This fixes Savannah bug #46511.
+
 2015-12-18  Benno Schulenberg  <bensberg@justemail.net>
 	* src/color.c (color_init): Use less #ifdefs, and adjust indentation.
 	* src/color.c (set_colorpairs): Improve comments and rename vars.
diff --git a/src/files.c b/src/files.c
index 53e1b97e8a42a87858ebe4a55ab705199cf01e84..db41c6009ee02057c055edb2b646b30e6cbc13a7 100644
--- a/src/files.c
+++ b/src/files.c
@@ -456,9 +456,14 @@ void display_buffer(void)
     titlebar(NULL);
 
 #ifndef DISABLE_COLOR
-    /* Make sure we're using the buffer's associated colors, if
-     * applicable. */
+    /* Make sure we're using the buffer's associated colors. */
     color_init();
+
+    /* If there are multiline coloring regexes, and there is no
+     * multiline cache data yet, precalculate it now. */
+    if (openfile->syntax && openfile->syntax->nmultis > 0 &&
+		openfile->fileage->multidata == NULL)
+	precalc_multicolorinfo();
 #endif
 
     /* Update the edit window. */
diff --git a/src/nano.c b/src/nano.c
index 18302e708476d0b550aaa83537aab7c2cf92158c..c92a89a6c999b243146fe1646a147ff6a4731793 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -2799,12 +2799,6 @@ int main(int argc, char **argv)
     fprintf(stderr, "Main: top and bottom win\n");
 #endif
 
-#ifndef DISABLE_COLOR
-    if (openfile->syntax)
-	if (openfile->syntax->nmultis > 0)
-	    precalc_multicolorinfo();
-#endif
-
     /* If a starting position was given on the command line, go there. */
     if (startline > 0 || startcol > 0)
 	do_gotolinecolumn(startline, startcol, FALSE, FALSE, FALSE, FALSE);
diff --git a/src/proto.h b/src/proto.h
index 2baa86880d2a429fc983fdde71eea291bda0da5f..c5118e666c4a725746cfe2731df555cdc90a8c97 100644
--- a/src/proto.h
+++ b/src/proto.h
@@ -506,6 +506,7 @@ int do_input(bool allow_funcs);
 int do_mouse(void);
 #endif
 void do_output(char *output, size_t output_len, bool allow_cntrls);
+void precalc_multicolorinfo(void);
 
 /* All functions in prompt.c. */
 int do_statusbar_input(bool *ran_func, bool *finished,