This commit was manufactured by cvs2svn to create branch 'XEmacs-21_4'.
[chise/xemacs-chise.git] / src / gutter.c
index ae568f7..3bde818 100644 (file)
@@ -50,6 +50,9 @@ Lisp_Object Qgutter_size;
 Lisp_Object Qgutter_visible;
 Lisp_Object Qdefault_gutter_position_changed_hook;
 
+static void
+update_gutter_geometry (struct frame *f, enum gutter_pos pos);
+
 #define SET_GUTTER_WAS_VISIBLE_FLAG(frame, pos, flag)  \
   do {                                                 \
     switch (pos)                                       \
@@ -85,6 +88,7 @@ static int gutter_was_visible (struct frame* frame, enum gutter_pos pos)
       return frame->right_gutter_was_visible;
     default:
       abort ();
+       return 0;       /* To keep the compiler happy */
     }
 }
 
@@ -179,7 +183,7 @@ get_gutter_coords (struct frame *f, enum gutter_pos pos, int *x, int *y,
     case TOP_GUTTER:
       *x = FRAME_LEFT_BORDER_END (f);
       *y = FRAME_TOP_BORDER_END (f);
-      *width = FRAME_RIGHT_BORDER_START (f) 
+      *width = FRAME_RIGHT_BORDER_START (f)
        - FRAME_LEFT_BORDER_END (f);
       *height = FRAME_TOP_GUTTER_BOUNDS (f);
       break;
@@ -187,7 +191,7 @@ get_gutter_coords (struct frame *f, enum gutter_pos pos, int *x, int *y,
     case BOTTOM_GUTTER:
       *x = FRAME_LEFT_BORDER_END (f);
       *y = WINDOW_BOTTOM (bot);
-      *width = FRAME_RIGHT_BORDER_START (f) 
+      *width = FRAME_RIGHT_BORDER_START (f)
        - FRAME_LEFT_BORDER_END (f);
       *height = FRAME_BOTTOM_GUTTER_BOUNDS (f);
       break;
@@ -199,7 +203,7 @@ get_gutter_coords (struct frame *f, enum gutter_pos pos, int *x, int *y,
       *height = WINDOW_BOTTOM (bot)
        - (FRAME_TOP_BORDER_END (f) + FRAME_TOP_GUTTER_BOUNDS (f));
       break;
-      
+
     case RIGHT_GUTTER:
       *x = FRAME_RIGHT_BORDER_START (f)
        - FRAME_RIGHT_GUTTER_BOUNDS (f);
@@ -216,20 +220,20 @@ get_gutter_coords (struct frame *f, enum gutter_pos pos, int *x, int *y,
 
 /* Convert the gutter specifier into something we can actually
    display. */
-static Lisp_Object construct_window_gutter_spec (struct window* w, 
+static Lisp_Object construct_window_gutter_spec (struct window* w,
                                                 enum gutter_pos pos)
 {
   Lisp_Object rest, *args;
   int nargs = 0;
   Lisp_Object gutter = RAW_WINDOW_GUTTER (w, pos);
-  
+
   if (STRINGP (gutter) || NILP (gutter))
     return gutter;
 
   GET_LIST_LENGTH (gutter, nargs);
   args = alloca_array (Lisp_Object, nargs >> 1);
   nargs = 0;
-  
+
   for (rest = gutter; !NILP (rest); rest = XCDR (XCDR (rest)))
     {
       /* We only put things in the real gutter that are declared to be
@@ -241,7 +245,7 @@ static Lisp_Object construct_window_gutter_spec (struct window* w,
          args [nargs++] = XCAR (XCDR (rest));
        }
     }
-  
+
   return Fconcat (nargs, args);
 }
 
@@ -256,7 +260,7 @@ output_gutter (struct frame *f, enum gutter_pos pos, int force)
   int line, border_width;
   face_index findex;
   display_line_dynarr* ddla, *cdla;
-  struct display_line *dl;
+  struct display_line *dl = 0;
   int cdla_len;
 
   if (!WINDOW_LIVE_P (w))
@@ -280,7 +284,7 @@ output_gutter (struct frame *f, enum gutter_pos pos, int force)
   /* generate some display lines */
   generate_displayable_area (w, WINDOW_GUTTER (w, pos),
                             x + border_width, y + border_width,
-                            width - 2 * border_width, 
+                            width - 2 * border_width,
                             height - 2 * border_width, ddla, 0, findex);
 
   /* We only output the gutter if we think something of significance
@@ -295,7 +299,7 @@ output_gutter (struct frame *f, enum gutter_pos pos, int force)
       (f->extents_changed && w->gutter_extent_modiff[pos]))
     {
 #ifdef DEBUG_GUTTERS
-      printf ("gutter redisplay triggered by %s\n", force ? "force" : 
+      printf ("gutter redisplay triggered by %s\n", force ? "force" :
              f->faces_changed ? "f->faces_changed" :
              f->frame_changed ? "f->frame_changed" :
              f->gutter_changed ? "f->gutter_changed" :
@@ -313,22 +317,50 @@ output_gutter (struct frame *f, enum gutter_pos pos, int force)
        {
          output_display_line (w, cdla, ddla, line, -1, -1);
        }
-      
+
       /* If the number of display lines has shrunk, adjust. */
       if (cdla_len > Dynarr_length (ddla))
        {
          Dynarr_length (cdla) = Dynarr_length (ddla);
        }
-      
+
       /* grab coordinates of last line and blank after it. */
-      dl = Dynarr_atp (ddla, Dynarr_length (ddla) - 1);
-      ypos = dl->ypos + dl->descent - dl->clip;
+      if (Dynarr_length (ddla) > 0)
+       {
+         dl = Dynarr_atp (ddla, Dynarr_length (ddla) - 1);
+         ypos = dl->ypos + dl->descent - dl->clip;
+       }
+      else
+       ypos = y;
+
       redisplay_clear_region (window, findex, x + border_width , ypos,
                              width - 2 * border_width, height - (ypos - y) - border_width);
+      /* If, for some reason, we have more to display than we have
+         room for, and we are allowed to resize the gutter, then make
+         sure this happens before the next time we try and
+         output. This can happen when face font sizes change. */
+      if (dl && dl->clip > 0 && EQ (w->gutter_size[pos], Qautodetect))
+       {
+         /* #### Ideally we would just mark the specifier as dirty
+         and everything else would "just work". Unfortunately we have
+         two problems with this. One is that the specifier cache
+         won't be recalculated unless the specifier code thinks the
+         cached value has actually changed, even though we have
+         marked the specifier as dirty. Additionally, although doing
+         this results in a gutter size change, we never seem to get
+         back into redisplay so that the frame size can be updated. I
+         think this is because we are already in redisplay and later
+         on the frame will be marked as clean. Thus we also have to
+         force a pending recalculation of the frame size.  */
+         w->gutter_size[pos] = Qnil;
+         Fset_specifier_dirty_flag (Vgutter_size[pos]);
+         update_gutter_geometry (f, pos);
+       }
+
       /* bevel the gutter area if so desired */
       if (border_width != 0)
        {
-         MAYBE_DEVMETH (d, bevel_area, 
+         MAYBE_DEVMETH (d, bevel_area,
                         (w, findex, x, y, width, height, border_width,
                          EDGE_ALL, EDGE_BEVEL_OUT));
        }
@@ -346,7 +378,7 @@ output_gutter (struct frame *f, enum gutter_pos pos, int force)
   w->gutter_extent_modiff [pos] = 0;
 }
 
-/* Sizing gutters is a pain so we try and help the user by detemining
+/* Sizing gutters is a pain so we try and help the user by determining
    what height will accommodate all lines. This is useless on left and
    right gutters as we always have a maximal number of lines. */
 static Lisp_Object
@@ -440,7 +472,7 @@ mark_gutters (struct frame* f)
 
 /* This is called by extent_changed_for_redisplay, so that redisplay
    knows exactly what extents have changed. */
-void 
+void
 gutter_extent_signal_changed_region_maybe (Lisp_Object obj,
                                           Bufpos start, Bufpos end)
 {
@@ -455,7 +487,7 @@ gutter_extent_signal_changed_region_maybe (Lisp_Object obj,
       enum gutter_pos pos;
       Lisp_Object window = FRAME_LAST_NONMINIBUF_WINDOW (f);
       struct window* w = XWINDOW (window);
-      
+
       GUTTER_POS_LOOP (pos)
        {
          if (EQ (WINDOW_GUTTER (w, pos), obj))
@@ -468,6 +500,25 @@ gutter_extent_signal_changed_region_maybe (Lisp_Object obj,
 
 /* We have to change the gutter geometry separately to the gutter
    update since it needs to occur outside of redisplay proper. */
+static void
+update_gutter_geometry (struct frame *f, enum gutter_pos pos)
+{
+  /* If the gutter geometry has changed then re-layout the
+     frame. If we are in display there is almost no point in doing
+     anything else since the frame size changes will be delayed
+     until we are out of redisplay proper. */
+  if (FRAME_GUTTER_BOUNDS (f, pos) != f->current_gutter_bounds[pos])
+    {
+      int width, height;
+      pixel_to_char_size (f, FRAME_PIXWIDTH (f), FRAME_PIXHEIGHT (f),
+                         &width, &height);
+      change_frame_size (f, height, width, 0);
+    }
+
+  /* Mark sizes as up-to-date. */
+  f->current_gutter_bounds[pos] = FRAME_GUTTER_BOUNDS (f, pos);
+}
+
 void
 update_frame_gutter_geometry (struct frame *f)
 {
@@ -481,20 +532,7 @@ update_frame_gutter_geometry (struct frame *f)
          until we are out of redisplay proper. */
       GUTTER_POS_LOOP (pos)
        {
-         if (FRAME_GUTTER_BOUNDS (f, pos) != f->current_gutter_bounds[pos])
-           {
-             int width, height;
-             pixel_to_char_size (f, FRAME_PIXWIDTH (f), FRAME_PIXHEIGHT (f),
-                                 &width, &height);
-             change_frame_size (f, height, width, 0);
-             break;
-           }
-       }
-
-      GUTTER_POS_LOOP (pos)
-       {
-         /* Mark sizes as up-to-date. */
-         f->current_gutter_bounds[pos] = FRAME_GUTTER_BOUNDS (f, pos);
+         update_gutter_geometry (f, pos);
        }
     }
 }
@@ -509,7 +547,7 @@ update_frame_gutters (struct frame *f)
       f->extents_changed)
     {
       enum gutter_pos pos;
-      
+
       /* We don't actually care about these when outputting the gutter
          so locally disable them. */
       int local_clip_changed = f->clip_changed;
@@ -557,6 +595,10 @@ redraw_exposed_gutter (struct frame *f, enum gutter_pos pos, int x, int y,
   if (((x + width) < g_x) || (x > (g_x + g_width)))
     return;
 
+#ifdef DEBUG_WIDGETS
+  printf ("redrawing gutter after expose %d+%d, %dx%d\n",
+         x, y, width, height);
+#endif
   /* #### optimize this - redrawing the whole gutter for every expose
      is very expensive. We reset the current display lines because if
      they're being exposed they are no longer current. */
@@ -573,11 +615,16 @@ redraw_exposed_gutters (struct frame *f, int x, int y, int width,
                        int height)
 {
   enum gutter_pos pos;
+
+  /* We have to be "in display" when we output the gutter - make it
+     so. */
+  hold_frame_size_changes ();
   GUTTER_POS_LOOP (pos)
     {
       if (FRAME_GUTTER_VISIBLE (f, pos))
        redraw_exposed_gutter (f, pos, x, y, width, height);
     }
+  unhold_one_frame_size_changes (f);
 }
 
 void
@@ -639,7 +686,7 @@ See `default-gutter-position'.
                              list1 (Fcons (Qnil, Qzero)));
       set_specifier_fallback (Vgutter_border_width[new],
                              Vdefault_gutter_border_width);
-      /* We don't realy want the left and right gutters to default to
+      /* We don't really want the left and right gutters to default to
          visible. */
       set_specifier_fallback (Vgutter_visible_p[cur],
                              cur == TOP_GUTTER || cur == BOTTOM_GUTTER ?
@@ -653,7 +700,7 @@ See `default-gutter-position'.
     }
 
   run_hook (Qdefault_gutter_position_changed_hook);
-  
+
   return position;
 }
 
@@ -722,7 +769,7 @@ gutter_validate (Lisp_Object instantiator)
 {
   if (NILP (instantiator))
     return;
-  
+
   /* Must be a string or a plist. */
   if (!STRINGP (instantiator) && NILP (Fvalid_plist_p (instantiator)))
       signal_simple_error ("Gutter spec must be string, plist or nil", instantiator);
@@ -730,7 +777,7 @@ gutter_validate (Lisp_Object instantiator)
   if (!STRINGP (instantiator))
     {
       Lisp_Object rest;
-      
+
       for (rest = instantiator; !NILP (rest); rest = XCDR (XCDR (rest)))
        {
          if (!SYMBOLP (XCAR (rest))
@@ -742,14 +789,9 @@ gutter_validate (Lisp_Object instantiator)
 
 DEFUN ("gutter-specifier-p", Fgutter_specifier_p, 1, 1, 0, /*
 Return non-nil if OBJECT is a gutter specifier.
-Gutter specifiers are used to specify the format of a gutter.
-The values of the variables `default-gutter', `top-gutter',
-`left-gutter', `right-gutter', and `bottom-gutter' are always
-gutter specifiers.
-
-Valid gutter instantiators are called "gutter descriptors" and are
-either strings or property-lists of strings.  See `default-gutter' for
-a description of the exact format.
+
+See `make-gutter-specifier' for a description of possible gutter
+instantiators.
 */
        (object))
 {
@@ -774,7 +816,7 @@ gutter_specs_changed (Lisp_Object specifier, struct window *w,
 {
   w->real_gutter[pos] = construct_window_gutter_spec (w, pos);
   w->real_gutter_size[pos] = w->gutter_size[pos];
-  
+
   if (EQ (w->real_gutter_size[pos], Qautodetect)
       && !NILP (w->gutter_visible_p[pos]))
     {
@@ -835,7 +877,7 @@ gutter_geometry_changed_in_window (Lisp_Object specifier, struct window *w,
          w->real_gutter_size [pos] = calculate_gutter_size (w, pos);
        }
     }
-  
+
   MARK_GUTTER_CHANGED;
   MARK_MODELINE_CHANGED;
   MARK_WINDOWS_CHANGED (w);
@@ -885,15 +927,8 @@ gutter_size_validate (Lisp_Object instantiator)
 DEFUN ("gutter-size-specifier-p", Fgutter_size_specifier_p, 1, 1, 0, /*
 Return non-nil if OBJECT is a gutter-size specifier.
 
-Gutter-size specifiers are used to specify the size of a gutter.  The
-values of the variables `default-gutter-size', `top-gutter-size',
-`left-gutter-size', `right-gutter-size', and `bottom-gutter-size' are
-always gutter-size specifiers.
-
-Valid gutter-size instantiators are either integers or the special
-symbol 'autodetect. If a gutter-size is set to 'autodetect them the
-size of the gutter will be adjusted to just accomodate the gutters
-contents. 'autodetect only works for top and bottom gutters.
+See `make-gutter-size-specifier' for a description of possible gutter-size
+instantiators.
 */
        (object))
 {
@@ -911,7 +946,7 @@ gutter_visible_validate (Lisp_Object instantiator)
     return;
 
   if (!NILP (instantiator) && !EQ (instantiator, Qt) && !CONSP (instantiator))
-    signal_simple_error ("Gutter visibility must be a boolean or list of symbols", 
+    signal_simple_error ("Gutter visibility must be a boolean or list of symbols",
                         instantiator);
 
   if (CONSP (instantiator))
@@ -921,7 +956,7 @@ gutter_visible_validate (Lisp_Object instantiator)
       EXTERNAL_LIST_LOOP (rest, instantiator)
        {
          if (!SYMBOLP (XCAR (rest)))
-             signal_simple_error ("Gutter visibility must be a boolean or list of symbols", 
+             signal_simple_error ("Gutter visibility must be a boolean or list of symbols",
                                   instantiator);
        }
     }
@@ -930,17 +965,8 @@ gutter_visible_validate (Lisp_Object instantiator)
 DEFUN ("gutter-visible-specifier-p", Fgutter_visible_specifier_p, 1, 1, 0, /*
 Return non-nil if OBJECT is a gutter-visible specifier.
 
-Gutter-visible specifiers are used to specify the visibility of a
-gutter.  The values of the variables `default-gutter-visible-p',
-`top-gutter-visible-p', `left-gutter-visible-p',
-`right-gutter-visible-p', and `bottom-gutter-visible-p' are always
-gutter-visible specifiers.
-
-Valid gutter-visible instantiators are t, nil or a list of symbols.
-If a gutter-visible instantiator is set to a list of symbols, and the
-correspondong gutter specification is a property-list strings, then
-elements of the gutter specification will only be visible if the
-corresponding symbol occurs in the gutter-visible instantiator.
+See `make-gutter-visible-specifier' for a description of possible
+gutter-visible instantiators.
 */
        (object))
 {
@@ -962,11 +988,13 @@ Ensure that all gutters are correctly showing their gutter specifier.
       DEVICE_FRAME_LOOP (frmcons, d)
        {
          struct frame *f = XFRAME (XCAR (frmcons));
-         
+
+         MAYBE_DEVMETH (d, frame_output_begin, (f));
+
          /* Sequence is quite important here. We not only want to
           redisplay the gutter area but we also want to flush any
           frame size changes out so that the gutter redisplay happens
-          in a kosha environment. 
+          in a kosha environment.
 
           This is not only so that things look right but so that
           glyph redisplay optimization kicks in, by default display
@@ -988,13 +1016,10 @@ Ensure that all gutters are correctly showing their gutter specifier.
              update_frame_gutters (f);
              unhold_one_frame_size_changes (f);
            }
-       }
-      /* We now call the output_end routine for tty frames.  We delay
-        doing so in order to avoid cursor flicker.  So much for 100%
-        encapsulation. */
-      if (DEVICE_TTY_P (d))
-       DEVMETH (d, output_end, (d));
-      
+
+         MAYBE_DEVMETH (d, frame_output_end, (f));
+      }
+
       d->gutter_changed = 0;
     }
 
@@ -1047,8 +1072,8 @@ syms_of_gutter (void)
 
   defsymbol (&Qgutter_size, "gutter-size");
   defsymbol (&Qgutter_visible, "gutter-visible");
-  defsymbol (&Qdefault_gutter_position_changed_hook, 
-            "default-gutter-position-changed");
+  defsymbol (&Qdefault_gutter_position_changed_hook,
+            "default-gutter-position-changed-hook");
 }
 
 void
@@ -1321,7 +1346,7 @@ See `default-gutter-height' for more information.
 #endif
 #ifdef HAVE_MS_WINDOWS
   fb = Fcons (Fcons (list1 (Qmsprinter), Qzero), fb);
-  fb = Fcons (Fcons (list1 (Qmswindows), 
+  fb = Fcons (Fcons (list1 (Qmswindows),
                     make_int (DEFAULT_GUTTER_WIDTH)), fb);
 #endif
   if (!NILP (fb))