Subject: bug#17281: 24.4.50; emacs hangs in next-line

From: Eli Zaretskii <[email-masked]>
Date: Thu, 17 Apr 2014 12:03:03 +0300

> Date: Thu, 17 Apr 2014 10:29:31 +0200
> From: "Stefan-W. Hahn" <[email-masked]>
> Cc: [email-masked]
> 
> Mail von Eli Zaretskii, Thu, 17 Apr 2014 at 11:00:05 +0300:
> > > Date: Thu, 17 Apr 2014 09:25:23 +0200
> > > From: "Stefan-W. Hahn" <[email-masked]>
> > > Cc: [email-masked]
> > > 
> > Then it's a different bug.  Are you sure it didn't happen before the
> > above commit?  I seem to be able to reproduce it as far back as Mar 15
> > (I have no easy way of trying older versions, due to changes in Lisp
> > files involved in this recipe).
> 
> I tried it back till 17. Dec 2013, but not all versions are compileable.
> All tried vesions have the same problem.
> 
> I even tried to debug it and I came to line-pixel-height (xdisp.c), which
> calls start-display(). I made a debug output in line-pixel-height before the
> call to start_display() and after. In the problematic case I never saw the
> debug output after start_display().

The infloop was indeed inside line-pixel-height.  Please try the patch
below, which I just committed to the emacs-24 branch.  It fixes your
recipe, so I hope the original use case with emacsclient will also be
fixed.

=== modified file 'src/xdisp.c'
--- src/xdisp.c	2014-04-12 11:21:47 +0000
+++ src/xdisp.c	2014-04-17 08:58:59 +0000
@@ -1262,12 +1262,23 @@ Value is the height in pixels of the lin
   struct it it;
   struct text_pos pt;
   struct window *w = XWINDOW (selected_window);
+  struct buffer *old_buffer = NULL;
+  Lisp_Object result;
 
+  if (XBUFFER (w->contents) != current_buffer)
+    {
+      old_buffer = current_buffer;
+      set_buffer_internal_1 (XBUFFER (w->contents));
+    }
   SET_TEXT_POS (pt, PT, PT_BYTE);
   start_display (&it, w, pt);
   it.vpos = it.current_y = 0;
   last_height = 0;
-  return make_number (line_bottom_y (&it));
+  result = make_number (line_bottom_y (&it));
+  if (old_buffer)
+    set_buffer_internal_1 (old_buffer);
+
+  return result;
 }
 
 /* Return the default pixel height of text lines in window W.  The