Subject: Re: bug#17279: 24.4.50; dired buffer slightly scrambled

From: Eli Zaretskii <[email-masked]>
Date: Thu, 17 Apr 2014 10:32:28 +0300

> Date: Thu, 17 Apr 2014 08:49:25 +0300
> From: Eli Zaretskii <[email-masked]>
> Cc: [email-masked]
> 
> > Date: Wed, 16 Apr 2014 22:41:14 -0700
> > From: Ushnish Basu <[email-masked]>
> > CC: [email-masked]
> > 
> > Yes, it does - thanks for the tip.
> 
> Then I guess it's another duplicate of 17269.

Please try the patch below, which I've just committed to the emacs-24
branch:

=== modified file 'src/insdel.c'
--- src/insdel.c	2014-04-14 15:32:27 +0000
+++ src/insdel.c	2014-04-17 07:24:40 +0000
@@ -1857,14 +1857,9 @@ invalidate_buffer_caches (struct buffer 
      need to consider the caches of their base buffer.  */
   if (buf->base_buffer)
     buf = buf->base_buffer;
-  if (buf->newline_cache)
-    invalidate_region_cache (buf,
-                             buf->newline_cache,
-                             start - BUF_BEG (buf), BUF_Z (buf) - end);
-  if (buf->width_run_cache)
-    invalidate_region_cache (buf,
-                             buf->width_run_cache,
-                             start - BUF_BEG (buf), BUF_Z (buf) - end);
+  /* The bidi_paragraph_cache must be invalidated first, because doing
+     so might need to use the newline_cache (via find_newline_no_quit,
+     see below).  */
   if (buf->bidi_paragraph_cache)
     {
       if (start != end
@@ -1888,13 +1883,20 @@ invalidate_buffer_caches (struct buffer 
 					       &start_byte);
 	      set_buffer_internal (old);
 	    }
-	  if (line_beg > BUF_BEG (buf))
-	    start = line_beg - 1;
+	  start = line_beg - (line_beg > BUF_BEG (buf));
 	}
       invalidate_region_cache (buf,
 			       buf->bidi_paragraph_cache,
 			       start - BUF_BEG (buf), BUF_Z (buf) - end);
     }
+  if (buf->newline_cache)
+    invalidate_region_cache (buf,
+                             buf->newline_cache,
+                             start - BUF_BEG (buf), BUF_Z (buf) - end);
+  if (buf->width_run_cache)
+    invalidate_region_cache (buf,
+                             buf->width_run_cache,
+                             start - BUF_BEG (buf), BUF_Z (buf) - end);
 }
 
 /* These macros work with an argument named `preserve_ptr'