]> code.delx.au - gnu-emacs/blobdiff - src/xdisp.c
(mark_byte_stack): Use XMARKBIT and XMARK.
[gnu-emacs] / src / xdisp.c
index 5ad0cef63dbb227b5669e67d20a96534c55618da..484474c2ab64ad52b2b76b1734e2975b0aacb310 100644 (file)
@@ -169,9 +169,6 @@ Boston, MA 02111-1307, USA.  */
 
 #include <config.h>
 #include <stdio.h>
-#ifdef STDC_HEADERS
-#include <stdlib.h>
-#endif
 #include "lisp.h"
 #include "frame.h"
 #include "window.h"
@@ -258,6 +255,7 @@ extern Lisp_Object Qface, Qinvisible, Qimage;
 
 Lisp_Object Qspace, QCalign_to, QCrelative_width, QCrelative_height;
 Lisp_Object Qleft_margin, Qright_margin, Qspace_width, Qheight, Qraise;
+Lisp_Object Qmargin;
 
 /* Non-nil means highlight trailing whitespace.  */
 
@@ -605,7 +603,7 @@ static Lisp_Object eval_form P_ ((Lisp_Object));
 static void insert_left_trunc_glyphs P_ ((struct it *));
 static struct glyph_row *get_overlay_arrow_glyph_row P_ ((struct window *));
 static void extend_face_to_end_of_line P_ ((struct it *));
-static void append_space P_ ((struct it *, int));
+static int append_space P_ ((struct it *, int));
 static void make_cursor_line_fully_visible P_ ((struct window *));
 static int try_scrolling P_ ((Lisp_Object, int, int, int, int));
 static int trailing_whitespace_p P_ ((int));
@@ -627,7 +625,7 @@ static void display_mode_lines P_ ((struct window *));
 static void display_mode_line P_ ((struct window *, enum face_id,
                                   Lisp_Object));
 static int display_mode_element P_ ((struct it *, int, int, int, Lisp_Object));
-static char *decode_mode_spec P_ ((struct window *, char, int, int));
+static char *decode_mode_spec P_ ((struct window *, int, int, int));
 static void display_menu_bar P_ ((struct window *));
 static int display_count_lines P_ ((int, int, int, int, int *));
 static int display_string P_ ((unsigned char *, Lisp_Object, Lisp_Object,
@@ -1783,6 +1781,7 @@ handle_fontified_prop (it)
 {
   Lisp_Object prop, pos;
   enum prop_handled handled = HANDLED_NORMALLY;
+  struct gcpro gcpro1;
 
   /* Get the value of the `fontified' property at IT's current buffer
      position.  (The `fontified' property doesn't have a special
@@ -1797,6 +1796,7 @@ handle_fontified_prop (it)
     {
       Lisp_Object args[2];
 
+      GCPRO1 (pos);
       /* Run the hook functions.  */
       args[0] = Qfontification_functions;
       args[1] = pos;
@@ -1807,6 +1807,7 @@ handle_fontified_prop (it)
         fontify the text for which reason ever.  */
       if (!NILP (Fget_char_property (pos, Qfontified, Qnil)))
        handled = HANDLED_RECOMPUTE_PROPS;
+      UNGCPRO;
     }
 
   return handled;
@@ -2212,8 +2213,11 @@ handle_display_prop (it)
     return HANDLED_NORMALLY;
 
   space_or_image_found_p = 0;
-  if (CONSP (prop) && CONSP (XCAR (prop)))
+  if (CONSP (prop)
+      && CONSP (XCAR (prop))
+      && !EQ (Qmargin, XCAR (XCAR (prop))))
     {
+      /* A list of sub-properties.  */
       while (CONSP (prop))
        {
          if (handle_single_display_prop (it, XCAR (prop), object, position))
@@ -2239,7 +2243,7 @@ handle_display_prop (it)
 }
 
 
-/* Value is the position of the end of the `display' property stating
+/* Value is the position of the end of the `display' property starting
    at START_POS in OBJECT.  */
 
 static struct text_pos
@@ -2250,27 +2254,14 @@ display_prop_end (it, object, start_pos)
 {
   Lisp_Object end;
   struct text_pos end_pos;
-  
-  /* Characters having this form of property are not displayed, so
-     we have to find the end of the property.  */
-  end = Fnext_single_property_change (make_number (start_pos.charpos),
-                                     Qdisplay, object, Qnil);
-  if (NILP (end))
-    {
-      /* A nil value of `end' means there are no changes of the
-        property to the end of the buffer or string.  */
-      if (it->current.overlay_string_index >= 0)
-       end_pos.charpos = XSTRING (it->string)->size;
-      else
-       end_pos.charpos = it->end_charpos;
-    }
-  else
-    end_pos.charpos = XFASTINT (end);
 
-  if (STRINGP (it->string))
+  end = next_single_char_property_change (make_number (CHARPOS (start_pos)),
+                                         Qdisplay, object, Qnil);
+  CHARPOS (end_pos) = XFASTINT (end);
+  if (STRINGP (object))
     compute_string_pos (&end_pos, start_pos, it->string);
   else
-    end_pos.bytepos = CHAR_TO_BYTE (end_pos.charpos);
+    BYTEPOS (end_pos) = CHAR_TO_BYTE (XFASTINT (end));
 
   return end_pos;
 }
@@ -2431,8 +2422,8 @@ handle_single_display_prop (it, prop, object, position)
     }
   else if (!it->string_from_display_prop_p)
     {
-      /* `(left-margin VALUE)' or `(right-margin VALUE)
-        or `(nil VALUE)' or VALUE.  */
+      /* `((margin left-margin) VALUE)' or `((margin right-margin)
+        VALUE) or `((margin nil) VALUE)' or VALUE. */
       Lisp_Object location, value;
       struct text_pos start_pos;
       int valid_p;
@@ -2447,14 +2438,26 @@ handle_single_display_prop (it, prop, object, position)
         text properties change there.  */
       it->stop_charpos = position->charpos;
 
-      if (CONSP (prop)
-         && !EQ (XCAR (prop), Qspace)
-         && !EQ (XCAR (prop), Qimage))
+      location = Qunbound;
+      if (CONSP (prop) && CONSP (XCAR (prop)))
        {
-         location = XCAR (prop);
+         Lisp_Object tem;
+         
          value = XCDR (prop);
+         if (CONSP (value))
+           value = XCAR (value);
+
+         tem = XCAR (prop);
+         if (EQ (XCAR (tem), Qmargin)
+             && (tem = XCDR (tem),
+                 tem = CONSP (tem) ? XCAR (tem) : Qnil,
+                 (NILP (tem)
+                  || EQ (tem, Qleft_margin)
+                  || EQ (tem, Qright_margin))))
+           location = tem;
        }
-      else
+
+      if (EQ (location, Qunbound))
        {
          location = Qnil;
          value = prop;
@@ -2973,7 +2976,6 @@ back_to_previous_visible_line_start (it)
          && indented_beyond_p (IT_CHARPOS (*it), IT_BYTEPOS (*it),
                                it->selective))
        visible_p = 0;
-#ifdef USE_TEXT_PROPERTIES
       else 
        {
          Lisp_Object prop;
@@ -2982,7 +2984,6 @@ back_to_previous_visible_line_start (it)
          if (TEXT_PROP_MEANS_INVISIBLE (prop))
            visible_p = 0;
        }
-#endif /* USE_TEXT_PROPERTIES  */
 
       /* Back one more newline if the current one is invisible.  */
       if (!visible_p)
@@ -4401,7 +4402,6 @@ invisible_text_between_p (it, start_charpos, end_charpos)
      struct it *it;
      int start_charpos, end_charpos;
 {
-#ifdef USE_TEXT_PROPERTIES
   Lisp_Object prop, limit;
   int invisible_found_p;
   
@@ -4414,18 +4414,13 @@ invisible_text_between_p (it, start_charpos, end_charpos)
     invisible_found_p = 1;
   else
     {
-      limit = Fnext_single_property_change (make_number (start_charpos),
-                                           Qinvisible,
-                                           Fcurrent_buffer (),
-                                           make_number (end_charpos));
+      limit = next_single_char_property_change (make_number (start_charpos),
+                                               Qinvisible, Qnil,
+                                               make_number (end_charpos));
       invisible_found_p = XFASTINT (limit) < end_charpos;
     }
 
   return invisible_found_p;
-  
-#else /* not USE_TEXT_PROPERTIES */
-  return 0;
-#endif /* not USE_TEXT_PROPERTIES */
 }
 
 
@@ -4569,6 +4564,37 @@ move_it_by_lines (it, dvpos, need_y_p)
  ***********************************************************************/
 
 
+/* Add a message with format string FORMAT and arguments ARG1 and ARG2
+   to *Messages*.  */
+
+void
+add_to_log (format, arg1, arg2)
+     char *format;
+     Lisp_Object arg1, arg2;
+{
+  Lisp_Object args[3];
+  Lisp_Object msg, fmt;
+  char *buffer;
+  int len;
+  struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
+
+  fmt = msg = Qnil;
+  GCPRO4 (fmt, msg, arg1, arg2);
+  
+  args[0] = fmt = build_string (format);
+  args[1] = arg1;
+  args[2] = arg2;
+  msg = Fformat (make_number (3), args);
+
+  len = STRING_BYTES (XSTRING (msg)) + 1;
+  buffer = (char *) alloca (len);
+  strcpy (buffer, XSTRING (msg)->data);
+  
+  message_dolog (buffer, len, 1, 0);
+  UNGCPRO;
+}
+
+
 /* Output a newline in the *Messages* buffer if "needs" one.  */
 
 void
@@ -5457,7 +5483,8 @@ resize_mini_window (w, exact_p)
   xassert (MINI_WINDOW_P (w));
 
   /* Nil means don't try to resize.  */
-  if (NILP (Vmax_mini_window_height))
+  if (NILP (Vmax_mini_window_height)
+      || (FRAME_X_P (f) && f->output_data.x == NULL))
     return 0;
   
   if (!FRAME_MINIBUF_ONLY_P (f))
@@ -5484,9 +5511,13 @@ resize_mini_window (w, exact_p)
       max_height = min (total_height, max_height);
       
       /* Find out the height of the text in the window.  */
+      last_height = 0;
       move_it_to (&it, ZV, -1, -1, -1, MOVE_TO_POS);
-      height = (unit - 1 + it.current_y + last_height) / unit;
-      height = max (1, height);
+      if (it.max_ascent == 0 && it.max_descent == 0)
+       height = it.current_y + last_height;
+      else
+       height = it.current_y + it.max_ascent + it.max_descent;
+      height = (height + unit - 1) / unit;
       
       /* Compute a suitable window start.  */
       if (height > max_height)
@@ -5502,18 +5533,20 @@ resize_mini_window (w, exact_p)
 
       /* Let it grow only, until we display an empty message, in which
         case the window shrinks again.  */
-      if (height > XFASTINT (w->height)
-         || exact_p
-         || BEGV == ZV)
+      if (height > XFASTINT (w->height))
        {
-         Lisp_Object old_selected_window;
-             
-         freeze_window_starts (f, height > XFASTINT (w->height));
-         old_selected_window = selected_window;
-         XSETWINDOW (selected_window, w);
-         change_window_height (height - XFASTINT (w->height), 0);
-         selected_window = old_selected_window;
-         window_height_changed_p = 1;
+         int old_height = XFASTINT (w->height);
+         freeze_window_starts (f, 1);
+         grow_mini_window (w, height - XFASTINT (w->height));
+         window_height_changed_p = XFASTINT (w->height) != old_height;
+       }
+      else if (height < XFASTINT (w->height)
+              && (exact_p || BEGV == ZV))
+       {
+         int old_height = XFASTINT (w->height);
+         freeze_window_starts (f, 0);
+         shrink_mini_window (w);
+         window_height_changed_p = XFASTINT (w->height) != old_height;
        }
     }
 
@@ -5821,13 +5854,14 @@ echo_area_display (update_frame_p)
   if (!FRAME_VISIBLE_P (f) || !f->glyphs_initialized_p)
     return 0;
 
+#ifdef HAVE_X_WINDOWS
   /* When Emacs starts, selected_frame may be a visible terminal
      frame, even if we run under a window system.  If we let this
      through, a message would be displayed on the terminal.  */
-#ifdef HAVE_WINDOW_SYSTEM
-  if (!inhibit_window_system && !FRAME_WINDOW_P (sf))
+  if (EQ (selected_frame, Vterminal_frame) 
+      && !NILP (Vwindow_system))
     return 0;
-#endif /* HAVE_WINDOW_SYSTEM */
+#endif /* HAVE_X_WINDOWS */
 
   /* Redraw garbaged frames.  */
   if (frame_garbaged)
@@ -8185,6 +8219,12 @@ compute_window_start_on_continuation_line (w)
     {
       struct it it;
       struct glyph_row *row;
+
+      /* Handle the case that the window start is out of range.  */
+      if (CHARPOS (start_pos) < BEGV)
+       SET_TEXT_POS (start_pos, BEGV, BEGV_BYTE);
+      else if (CHARPOS (start_pos) > ZV)
+       SET_TEXT_POS (start_pos, ZV, ZV_BYTE);
       
       /* Find the start of the continued line.  This should be fast
         because scan_buffer is fast (newline cache).  */
@@ -9673,8 +9713,15 @@ sync_frame_with_window_matrix_rows (w)
   while (window_row < window_row_end)
     {
       int area;
+      
       for (area = LEFT_MARGIN_AREA; area <= LAST_AREA; ++area)
        frame_row->glyphs[area] = window_row->glyphs[area];
+
+      /* Disable frame rows whose corresponding window rows have
+        been disabled in try_window_id.  */
+      if (!window_row->enabled_p)
+       frame_row->enabled_p = 0;
+      
       ++window_row, ++frame_row;
     }
 }
@@ -10673,7 +10720,7 @@ compute_line_metrics (it)
 /* Append one space to the glyph row of iterator IT if doing a
    window-based redisplay.  DEFAULT_FACE_P non-zero means let the
    space have the default face, otherwise let it have the same face as
-   IT->face_id.
+   IT->face_id.  Value is non-zero if a space was added.
 
    This function is called to make sure that there is always one glyph
    at the end of a glyph row that the cursor can be set on under
@@ -10683,7 +10730,7 @@ compute_line_metrics (it)
    At the same time this space let's a nicely handle clearing to the
    end of the line if the row ends in italic text.  */
 
-static void
+static int
 append_space (it, default_face_p)
      struct it *it;
      int default_face_p;
@@ -10728,8 +10775,11 @@ append_space (it, default_face_p)
          it->what = saved_what;
          it->face_id = saved_face_id;
          it->charset = saved_charset;
+         return 1;
        }
     }
+
+  return 0;
 }
 
 
@@ -10955,13 +11005,11 @@ display_line (it)
       if (!get_next_display_element (it))
        {
          /* Maybe add a space at the end of this line that is used to
-            display the cursor there under X.  */
-         append_space (it, 1);
-
-         /* The position -1 below indicates a blank line not
-            corresponding to any text, as opposed to an empty line
-            corresponding to a line end.  */
-         if (row->used[TEXT_AREA] <= 1)
+            display the cursor there under X.  Set the charpos of the
+            first glyph of blank lines not corresponding to any text
+            to -1.  */
+         if ((append_space (it, 1) && row->used[TEXT_AREA] == 1)
+             || row->used[TEXT_AREA] == 0)
            {
              row->glyphs[TEXT_AREA]->charpos = -1;
              row->displays_text_p = 0;
@@ -11275,7 +11323,7 @@ display_menu_bar (w)
 
 #ifdef USE_X_TOOLKIT
   xassert (!FRAME_WINDOW_P (f));
-  init_iterator (&it, w, -1, -1, f->desired_matrix->rows, MODE_LINE_FACE_ID);
+  init_iterator (&it, w, -1, -1, f->desired_matrix->rows, MENU_FACE_ID);
   it.first_visible_x = 0;
   it.last_visible_x = FRAME_WINDOW_WIDTH (f) * CANON_X_UNIT (f);
 #else /* not USE_X_TOOLKIT */
@@ -11287,7 +11335,7 @@ display_menu_bar (w)
       xassert (WINDOWP (f->menu_bar_window));
       menu_w = XWINDOW (f->menu_bar_window);
       init_iterator (&it, menu_w, -1, -1, menu_w->desired_matrix->rows,
-                    MODE_LINE_FACE_ID);
+                    MENU_FACE_ID);
       it.first_visible_x = 0;
       it.last_visible_x = FRAME_WINDOW_WIDTH (f) * CANON_X_UNIT (f);
     }
@@ -11296,7 +11344,7 @@ display_menu_bar (w)
       /* This is a TTY frame, i.e. character hpos/vpos are used as
         pixel x/y.  */
       init_iterator (&it, w, -1, -1, f->desired_matrix->rows,
-                    MODE_LINE_FACE_ID);
+                    MENU_FACE_ID);
       it.first_visible_x = 0;
       it.last_visible_x = FRAME_WIDTH (f);
     }
@@ -11826,7 +11874,7 @@ static char lots_of_dashes[] = "------------------------------------------------
 static char *
 decode_mode_spec (w, c, field_width, precision)
      struct window *w;
-     register char c;
+     register int c;
      int field_width, precision;
 {
   Lisp_Object obj;
@@ -12322,6 +12370,8 @@ display_string (string, lisp_string, face_string, face_string_pos,
                start, it, field_width, precision, max_x, multibyte)
      unsigned char *string;
      Lisp_Object lisp_string;
+     Lisp_Object face_string;
+     int face_string_pos;
      int start;
      struct it *it;
      int field_width, precision, max_x;
@@ -12593,9 +12643,8 @@ syms_of_xdisp ()
   staticpro (&Qinhibit_point_motion_hooks);
   Qinhibit_point_motion_hooks = intern ("inhibit-point-motion-hooks");
 
-  staticpro (&Qdisplay);
   Qdisplay = intern ("display");
-  staticpro (&Qleft_margin);
+  staticpro (&Qdisplay);
   Qspace_width = intern ("space-width");
   staticpro (&Qspace_width);
   Qheight = intern ("height");
@@ -12604,9 +12653,12 @@ syms_of_xdisp ()
   staticpro (&Qraise);
   Qspace = intern ("space");
   staticpro (&Qspace);
+  Qmargin = intern ("margin");
+  staticpro (&Qmargin);
   Qleft_margin = intern ("left-margin");
-  staticpro (&Qright_margin);
+  staticpro (&Qleft_margin);
   Qright_margin = intern ("right-margin");
+  staticpro (&Qright_margin);
   Qalign_to = intern ("align-to");
   staticpro (&Qalign_to);
   QCalign_to = intern (":align-to");
@@ -12622,9 +12674,9 @@ syms_of_xdisp ()
   QCeval = intern (":eval");
   staticpro (&QCeval);
   Qwhen = intern ("when");
+  staticpro (&Qwhen);
   QCfile = intern (":file");
   staticpro (&QCfile);
-  staticpro (&Qwhen);
   Qfontified = intern ("fontified");
   staticpro (&Qfontified);
   Qfontification_functions = intern ("fontification-functions");
@@ -12634,10 +12686,10 @@ syms_of_xdisp ()
   Qimage = intern ("image");
   staticpro (&Qimage);
 
-  staticpro (&last_arrow_position);
-  staticpro (&last_arrow_string);
   last_arrow_position = Qnil;
   last_arrow_string = Qnil;
+  staticpro (&last_arrow_position);
+  staticpro (&last_arrow_string);
   
   echo_buffer[0] = echo_buffer[1] = Qnil;
   staticpro (&echo_buffer[0]);