Add TAGS-LISP
[bpt/emacs.git] / src / dispnew.c
index ee3fbc3..54facf4 100644 (file)
@@ -235,9 +235,9 @@ Lisp_Object Qdisplay_table;
 
 \f
 /* The currently selected frame.  In a single-frame version, this
-   variable always holds the address of the_only_frame.  */
+   variable always equals the_only_frame.  */
 
-struct frame *selected_frame;
+Lisp_Object selected_frame;
 
 /* A frame which is not just a mini-buffer, or 0 if there are no such
    frames.  This is usually the most recent such frame that was
@@ -1902,24 +1902,24 @@ adjust_glyphs (f)
 static void
 adjust_frame_glyphs_initially ()
 {
-  struct window *root = XWINDOW (selected_frame->root_window);
+  struct frame *sf = SELECTED_FRAME ();
+  struct window *root = XWINDOW (sf->root_window);
   struct window *mini = XWINDOW (root->next);
-  int frame_height = FRAME_HEIGHT (selected_frame);
-  int frame_width = FRAME_WIDTH (selected_frame);
-  int top_margin = FRAME_TOP_MARGIN (selected_frame);
+  int frame_height = FRAME_HEIGHT (sf);
+  int frame_width = FRAME_WIDTH (sf);
+  int top_margin = FRAME_TOP_MARGIN (sf);
 
   /* Do it for the root window.  */
   XSETFASTINT (root->top, top_margin);
   XSETFASTINT (root->width, frame_width);
-  set_window_height (selected_frame->root_window,
-                    frame_height - 1 - top_margin, 0);
+  set_window_height (sf->root_window, frame_height - 1 - top_margin, 0);
 
   /* Do it for the mini-buffer window.  */
   XSETFASTINT (mini->top, frame_height - 1);
   XSETFASTINT (mini->width, frame_width);
   set_window_height (root->next, 1, 0);
 
-  adjust_frame_glyphs (selected_frame);
+  adjust_frame_glyphs (sf);
   glyphs_initialized_initially_p = 1;
 }
   
@@ -2992,7 +2992,7 @@ int
 direct_output_for_insert (g)
      int g;
 {
-  register struct frame *f = selected_frame;
+  register struct frame *f = SELECTED_FRAME ();
   struct window *w = XWINDOW (selected_window);
   struct it it, it2;
   struct glyph_row *glyph_row;
@@ -3140,7 +3140,8 @@ direct_output_for_insert (g)
 
   /* Make room for new glyphs, then insert them.  */
   xassert (end - glyphs - n >= 0);
-  safe_bcopy (glyphs, glyphs + n, (end - glyphs - n) * sizeof (*end));
+  safe_bcopy ((char *) glyphs, (char *) (glyphs + n),
+             (end - glyphs - n) * sizeof (*end));
   bcopy (it.glyph_row->glyphs[TEXT_AREA], glyphs, n * sizeof *glyphs);
   glyph_row->used[TEXT_AREA] = min (glyph_row->used[TEXT_AREA] + n,
                                    end - glyph_row->glyphs[TEXT_AREA]);
@@ -3253,7 +3254,7 @@ int
 direct_output_forward_char (n)
      int n;
 {
-  struct frame *f = selected_frame;
+  struct frame *f = SELECTED_FRAME ();
   struct window *w = XWINDOW (selected_window);
   struct glyph_row *row;
 
@@ -3278,6 +3279,15 @@ direct_output_forward_char (n)
   if (!NILP (Vshow_trailing_whitespace))
     return 0;
 
+  /* Give up if we are showing a message or just cleared the message
+     because we might need to resize the echo area window.  */
+  if (!NILP (echo_area_buffer[0]) || !NILP (echo_area_buffer[1]))
+    return 0;
+
+  /* Give up if we don't know where the cursor is.  */
+  if (w->cursor.vpos < 0)
+    return 0;
+
   row = MATRIX_ROW (w->current_matrix, w->cursor.vpos);
 
   if (PT <= MATRIX_ROW_START_BYTEPOS (row)
@@ -4781,31 +4791,31 @@ update_frame_line (frame, vpos)
   else
     reassert_line_highlight (desired_row->inverse_p, vpos);
 
+  /* Current row not enabled means it has unknown contents.  We must
+     write the whole desired line in that case.  */
   must_write_whole_line_p = !current_row->enabled_p;
   if (must_write_whole_line_p)
     {
-      /* A line that is not enabled is empty.  */
       obody = 0;
       olen = 0;
     }
   else
     {
-      /* A line not empty in the current matrix.  */
       obody = MATRIX_ROW_GLYPH_START (current_matrix, vpos);
       olen = current_row->used[TEXT_AREA];
       
       if (! current_row->inverse_p)
        {
-         /* Ignore trailing spaces.  */
+         /* Ignore trailing spaces, if we can.  */
          if (!must_write_spaces)
            while (olen > 0 && CHAR_GLYPH_SPACE_P (obody[olen-1]))
              olen--;
        }
       else
        {
-         /* For an inverse-video line, remember we gave it spaces all
-            the way to the frame edge so that the reverse video
-            extends all the way across.  */
+         /* For an inverse-video line, make sure it's filled with
+            spaces all the way to the frame edge so that the reverse
+            video extends all the way across.  */
          while (olen < FRAME_WIDTH (frame) - 1)
            obody[olen++] = space_glyph;
        }
@@ -4829,15 +4839,27 @@ update_frame_line (frame, vpos)
   /* If display line has unknown contents, write the whole line.  */
   if (must_write_whole_line_p)
     {
+      /* Ignore spaces at the end, if we can.  */
       if (!must_write_spaces)
        while (nlen > 0 && CHAR_GLYPH_SPACE_P (nbody[nlen - 1]))
          --nlen;
 
-      cursor_to (vpos, 0);
+      /* Write the contents of the desired line.  */
       if (nlen)
-       write_glyphs (nbody, nlen);
+       {
+          cursor_to (vpos, 0);
+         write_glyphs (nbody, nlen);
+       }
       
-      clear_end_of_line (FRAME_WINDOW_WIDTH (frame));
+      /* Don't call clear_end_of_line if we already wrote the whole
+        line.  The cursor will not be at the right margin in that
+        case but in the line below.  */
+      if (nlen < FRAME_WINDOW_WIDTH (frame))
+       {
+         cursor_to (vpos, nlen);
+          clear_end_of_line (FRAME_WINDOW_WIDTH (frame));
+       }
+
       make_current (desired_matrix, current_matrix, vpos);
       return;
     }
@@ -5852,8 +5874,9 @@ For types not defined in VMS, use  define emacs_term \"TYPE\".\n\
   term_init (terminal_type);
   
   {
-    int width = FRAME_WINDOW_WIDTH (selected_frame);
-    int height = FRAME_HEIGHT (selected_frame);
+    struct frame *sf = SELECTED_FRAME ();
+    int width = FRAME_WINDOW_WIDTH (sf);
+    int height = FRAME_HEIGHT (sf);
 
     unsigned int total_glyphs = height * (width + 2) * sizeof (struct glyph);
 
@@ -5864,7 +5887,7 @@ For types not defined in VMS, use  define emacs_term \"TYPE\".\n\
   }
 
   adjust_frame_glyphs_initially ();
-  calculate_costs (selected_frame);
+  calculate_costs (XFRAME (selected_frame));
 
 #ifdef SIGWINCH
 #ifndef CANNOT_DUMP