* dispnew.c (init_display): Use Qx, Qw32, and Qns.
[bpt/emacs.git] / src / dispnew.c
index 0f8f174..5236d53 100644 (file)
@@ -1,7 +1,7 @@
 /* Updating of data structures for redisplay.
    Copyright (C) 1985, 1986, 1987, 1988, 1993, 1994, 1995,
                  1997, 1998, 1999, 2000, 2001, 2002, 2003,
-                 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+                 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -3954,11 +3954,12 @@ update_frame (f, force_p, inhibit_hairy_id_p)
       paused_p = update_frame_1 (f, force_p, inhibit_hairy_id_p);
       update_end (f);
 
-      if (FRAME_TERMCAP_P (f))
+      if (FRAME_TERMCAP_P (f) || FRAME_MSDOS_P (f))
         {
           if (FRAME_TTY (f)->termscript)
             fflush (FRAME_TTY (f)->termscript);
-          fflush (FRAME_TTY (f)->output);
+         if (FRAME_TERMCAP_P (f))
+           fflush (FRAME_TTY (f)->output);
         }
 
       /* Check window matrices for lost pointers.  */
@@ -4128,14 +4129,14 @@ redraw_overlapping_rows (w, yb)
 
       bottom_y = MATRIX_ROW_BOTTOM_Y (row);
 
-      if (row->overlapping_p && i > 0 && bottom_y < yb)
+      if (row->overlapping_p)
        {
          int overlaps = 0;
 
-         if (MATRIX_ROW_OVERLAPS_PRED_P (row)
+         if (MATRIX_ROW_OVERLAPS_PRED_P (row) && i > 0
              && !MATRIX_ROW (w->current_matrix, i - 1)->overlapped_p)
            overlaps |= OVERLAPS_PRED;
-         if (MATRIX_ROW_OVERLAPS_SUCC_P (row)
+         if (MATRIX_ROW_OVERLAPS_SUCC_P (row) && bottom_y < yb
              && !MATRIX_ROW (w->current_matrix, i + 1)->overlapped_p)
            overlaps |= OVERLAPS_SUCC;
 
@@ -4474,6 +4475,7 @@ update_text_area (w, vpos)
       struct glyph *desired_glyph = desired_row->glyphs[TEXT_AREA];
       int overlapping_glyphs_p = current_row->contains_overlapping_glyphs_p;
       int desired_stop_pos = desired_row->used[TEXT_AREA];
+      int abort_skipping = 0;
 
       /* If the desired row extends its face to the text area end, and
         unless the current row also does so at the same position,
@@ -4493,7 +4495,7 @@ update_text_area (w, vpos)
         in common.  */
       while (i < stop)
        {
-         int can_skip_p = 1;
+         int can_skip_p = !abort_skipping;
 
          /* Skip over glyphs that both rows have in common.  These
             don't have to be written.  We can't skip if the last
@@ -4510,11 +4512,13 @@ update_text_area (w, vpos)
 
              rif->get_glyph_overhangs (glyph, XFRAME (w->frame),
                                        &left, &right);
-             can_skip_p = right == 0;
+             can_skip_p = (right == 0 && !abort_skipping);
            }
 
          if (can_skip_p)
            {
+             int start_hpos = i;
+
              while (i < stop
                     && GLYPH_EQUAL_P (desired_glyph, current_glyph))
                {
@@ -4546,6 +4550,12 @@ update_text_area (w, vpos)
                      x -= desired_glyph->pixel_width;
                      left -= desired_glyph->pixel_width;
                    }
+
+                 /* Abort the skipping algorithm if we end up before
+                    our starting point, to avoid looping (bug#1070).
+                    This can happen when the lbearing is larger than
+                    the pixel width.  */
+                 abort_skipping = (i < start_hpos);
                }
            }
 
@@ -5923,7 +5933,7 @@ buffer_posn_from_coords (w, x, y, pos, object, dx, dy, width, height)
      int *width, *height;
 {
   struct it it;
-  struct buffer *old_current_buffer = current_buffer;
+  Lisp_Object old_current_buffer = Fcurrent_buffer ();
   struct text_pos startp;
   Lisp_Object string;
   struct glyph_row *row;
@@ -5932,7 +5942,9 @@ buffer_posn_from_coords (w, x, y, pos, object, dx, dy, width, height)
 #endif
   int x0, x1;
 
-  current_buffer = XBUFFER (w->buffer);
+  /* We used to set current_buffer directly here, but that does the
+     wrong thing with `face-remapping-alist' (bug#2044).  */
+  Fset_buffer (w->buffer);
   SET_TEXT_POS_FROM_MARKER (startp, w->start);
   CHARPOS (startp) = min (ZV, max (BEGV, CHARPOS (startp)));
   BYTEPOS (startp) = min (ZV_BYTE, max (BEGV_BYTE, BYTEPOS (startp)));
@@ -5942,7 +5954,7 @@ buffer_posn_from_coords (w, x, y, pos, object, dx, dy, width, height)
   move_it_to (&it, -1, x0 + it.first_visible_x, *y, -1,
              MOVE_TO_X | MOVE_TO_Y);
 
-  current_buffer = old_current_buffer;
+  Fset_buffer (old_current_buffer);
 
   *dx = x0 + it.first_visible_x - it.current_x;
   *dy = *y - it.current_y;
@@ -6206,6 +6218,11 @@ window_change_signal (signalnum) /* If we don't have an argument, */
     if (! tty->term_initted)
       continue;
 
+    /* Suspended tty frames have tty->input == NULL avoid trying to
+       use it.  */
+    if (!tty->input)
+      continue;
+
     get_tty_size (fileno (tty->input), &width, &height);
 
     if (width > 5 && height > 2) {
@@ -6356,7 +6373,9 @@ change_frame_size_1 (f, newheight, newwidth, pretend, delay, safe)
        set_window_height (FRAME_ROOT_WINDOW (f),
                           newheight - FRAME_TOP_MARGIN (f), 2);
 
-      if (FRAME_TERMCAP_P (f) && !pretend)
+      /* MSDOS frames cannot PRETEND, as they change frame size by
+        manipulating video hardware.  */
+      if ((FRAME_TERMCAP_P (f) && !pretend) || FRAME_MSDOS_P (f))
        FrameRows (FRAME_TTY (f)) = newheight;
     }
 
@@ -6366,7 +6385,9 @@ change_frame_size_1 (f, newheight, newwidth, pretend, delay, safe)
       if (FRAME_HAS_MINIBUF_P (f))
        set_window_width (FRAME_MINIBUF_WINDOW (f), new_frame_total_cols, 0);
 
-      if (FRAME_TERMCAP_P (f) && !pretend)
+      /* MSDOS frames cannot PRETEND, as they change frame size by
+        manipulating video hardware.  */
+      if ((FRAME_TERMCAP_P (f) && !pretend) || FRAME_MSDOS_P (f))
        FrameCols (FRAME_TTY (f)) = newwidth;
 
       if (WINDOWP (f->tool_bar_window))
@@ -6417,7 +6438,8 @@ FILE = nil means just close any termscript file currently open.  */)
 {
   struct tty_display_info *tty;
 
-  if (! FRAME_TERMCAP_P (SELECTED_FRAME ()))
+  if (! FRAME_TERMCAP_P (SELECTED_FRAME ())
+      && ! FRAME_MSDOS_P (SELECTED_FRAME ()))
     error ("Current frame is not on a tty device");
 
   tty = CURTTY ();
@@ -6447,7 +6469,7 @@ DEFUN ("send-string-to-terminal", Fsend_string_to_terminal,
 Control characters in STRING will have terminal-dependent effects.
 
 Optional parameter TERMINAL specifies the tty terminal device to use.
-It may be a terminal id, a frame, or nil for the terminal used by the
+It may be a terminal object, a frame, or nil for the terminal used by the
 currently selected frame.  */)
   (string, terminal)
      Lisp_Object string;
@@ -6465,6 +6487,9 @@ currently selected frame.  */)
 
   tty = t->display_info.tty;
 
+  if (! tty->output)
+    error ("Terminal is currently suspended");
+
   if (tty->termscript)
     {
       fwrite (SDATA (string), 1, SBYTES (string), tty->termscript);
@@ -6824,6 +6849,10 @@ init_display ()
     signal (SIGWINCH, window_change_signal);
 #endif /* SIGWINCH */
 
+  /* If running as a daemon, no need to initialize any frames/terminal. */
+  if (IS_DAEMON)
+      return;
+
   /* If the user wants to use a window system, we shouldn't bother
      initializing the terminal.  This is especially important when the
      terminal is so dumb that emacs gives up before and doesn't bother
@@ -6853,7 +6882,7 @@ init_display ()
 #endif
      )
     {
-      Vinitial_window_system = intern ("x");
+      Vinitial_window_system = Qx;
 #ifdef HAVE_X11
       Vwindow_system_version = make_number (11);
 #endif
@@ -6871,7 +6900,7 @@ init_display ()
 #ifdef HAVE_NTGUI
   if (!inhibit_window_system)
     {
-      Vinitial_window_system = intern ("w32");
+      Vinitial_window_system = Qw32;
       Vwindow_system_version = make_number (1);
       adjust_frame_glyphs_initially ();
       return;
@@ -6885,17 +6914,13 @@ init_display ()
 #endif
       )
     {
-      Vinitial_window_system = intern("ns");
+      Vinitial_window_system = Qns;
       Vwindow_system_version = make_number(10);
       adjust_frame_glyphs_initially ();
       return;
     }
 #endif
 
-  /* If running as a daemon, no need to initialize any frames/terminal. */
-  if (is_daemon)
-    return;
-
   /* If no window system has been specified, try to use the terminal.  */
   if (! isatty (0))
     {