Merge from trunk.
[bpt/emacs.git] / src / fringe.c
index 75c65bb..edc254f 100644 (file)
@@ -35,7 +35,7 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
    Logical bitmaps are used internally to denote things like
    'end-of-buffer', 'left-truncation', 'overlay-arrow', etc.
 
-   Physical bitmaps specify the visual appearence of the bitmap,
+   Physical bitmaps specify the visual appearance of the bitmap,
    e.g. 'bottom-left-angle', 'left-arrow', 'left-triangle', etc.
    User defined bitmaps are physical bitmaps.
 
@@ -456,7 +456,7 @@ static struct fringe_bitmap standard_bitmaps[] =
 
 #define NO_FRINGE_BITMAP 0
 #define UNDEF_FRINGE_BITMAP 1
-#define MAX_STANDARD_FRINGE_BITMAPS (sizeof(standard_bitmaps)/sizeof(standard_bitmaps[0]))
+#define MAX_STANDARD_FRINGE_BITMAPS (sizeof (standard_bitmaps)/sizeof (standard_bitmaps[0]))
 
 static struct fringe_bitmap **fringe_bitmaps;
 static Lisp_Object *fringe_faces;
@@ -474,7 +474,7 @@ int max_used_fringe_bitmap = MAX_STANDARD_FRINGE_BITMAPS;
 int
 lookup_fringe_bitmap (Lisp_Object bitmap)
 {
-  int bn;
+  EMACS_INT bn;
 
   bitmap = Fget (bitmap, Qfringe);
   if (!INTEGERP (bitmap))
@@ -696,7 +696,7 @@ static int
 get_logical_fringe_bitmap (struct window *w, Lisp_Object bitmap, int right_p, int partial_p)
 {
   Lisp_Object cmap, bm1 = Qnil, bm2 = Qnil, bm;
-  int ln1 = 0, ln2 = 0;
+  EMACS_INT ln1 = 0, ln2 = 0;
   int ix1 = right_p;
   int ix2 = ix1 + (partial_p ? 2 : 0);
 
@@ -928,7 +928,7 @@ update_window_fringes (struct window *w, int keep_current_p)
   int top_ind_rn, bot_ind_rn;
   int top_ind_min_y, bot_ind_max_y;
 
-  /* top_ind_rn is set to a nonnegative value whenver
+  /* top_ind_rn is set to a nonnegative value whenever
      row->indicate_bob_p is set, so it's OK that top_row_ends_at_zv_p
      is not initialized here.  Similarly for bot_ind_rn,
      row->indicate_eob_p and bot_row_ends_at_zv_p.  */
@@ -1165,7 +1165,7 @@ update_window_fringes (struct window *w, int keep_current_p)
        }
       else if ((!row->reversed_p && row->truncated_on_left_p)
               || (row->reversed_p && row->truncated_on_right_p))
-       left = LEFT_FRINGE(0, Qtruncation, 0);
+       left = LEFT_FRINGE (0, Qtruncation, 0);
       else if (row->indicate_bob_p && EQ (boundary_top, Qleft))
        {
          left = ((row->indicate_eob_p && EQ (boundary_bot, Qleft))
@@ -1279,8 +1279,12 @@ update_window_fringes (struct window *w, int keep_current_p)
 
       if (row->overlay_arrow_bitmap != cur->overlay_arrow_bitmap)
        {
-         redraw_p = row->redraw_fringe_bitmaps_p = cur->redraw_fringe_bitmaps_p = 1;
-         cur->overlay_arrow_bitmap = row->overlay_arrow_bitmap;
+         redraw_p = row->redraw_fringe_bitmaps_p = 1;
+         if (!keep_current_p)
+           {
+             cur->redraw_fringe_bitmaps_p = 1;
+             cur->overlay_arrow_bitmap = row->overlay_arrow_bitmap;
+           }
        }
 
       row->left_fringe_bitmap = left;
@@ -1551,7 +1555,7 @@ If BITMAP already exists, the existing definition is replaced.  */)
   else
     {
       CHECK_NUMBER (height);
-      fb.height = min (XINT (height), 255);
+      fb.height = max (0, min (XINT (height), 255));
       if (fb.height > h)
        {
          fill1 = (fb.height - h) / 2;
@@ -1564,7 +1568,7 @@ If BITMAP already exists, the existing definition is replaced.  */)
   else
     {
       CHECK_NUMBER (width);
-      fb.width = min (XINT (width), 255);
+      fb.width = max (0, min (XINT (width), 255));
     }
 
   fb.period = 0;
@@ -1606,22 +1610,25 @@ If BITMAP already exists, the existing definition is replaced.  */)
 
          if (n == max_fringe_bitmaps)
            {
-             if ((max_fringe_bitmaps + 20) > MAX_FRINGE_BITMAPS)
+             int bitmaps = max_fringe_bitmaps + 20;
+             if (MAX_FRINGE_BITMAPS < bitmaps)
                error ("No free fringe bitmap slots");
 
              i = max_fringe_bitmaps;
-             max_fringe_bitmaps += 20;
              fringe_bitmaps
                = ((struct fringe_bitmap **)
-                  xrealloc (fringe_bitmaps, max_fringe_bitmaps * sizeof (struct fringe_bitmap *)));
+                  xrealloc (fringe_bitmaps, bitmaps * sizeof *fringe_bitmaps));
              fringe_faces
-               = (Lisp_Object *) xrealloc (fringe_faces, max_fringe_bitmaps * sizeof (Lisp_Object));
+               = (Lisp_Object *) xrealloc (fringe_faces,
+                                           bitmaps * sizeof *fringe_faces);
 
-             for (; i < max_fringe_bitmaps; i++)
+             for (i = max_fringe_bitmaps; i < bitmaps; i++)
                {
                  fringe_bitmaps[i] = NULL;
                  fringe_faces[i] = Qnil;
                }
+
+             max_fringe_bitmaps = bitmaps;
            }
        }
 
@@ -1697,7 +1704,7 @@ Return nil if POS is not visible in WINDOW.  */)
 {
   struct window *w;
   struct glyph_row *row;
-  int textpos;
+  ptrdiff_t textpos;
 
   if (NILP (window))
     window = selected_window;
@@ -1707,6 +1714,8 @@ Return nil if POS is not visible in WINDOW.  */)
   if (!NILP (pos))
     {
       CHECK_NUMBER_COERCE_MARKER (pos);
+      if (! (BEGV <= XINT (pos) && XINT (pos) <= ZV))
+       args_out_of_range (window, pos);
       textpos = XINT (pos);
     }
   else if (w == XWINDOW (selected_window))
@@ -1734,18 +1743,12 @@ Return nil if POS is not visible in WINDOW.  */)
 void
 syms_of_fringe (void)
 {
-  Qtruncation = intern_c_string ("truncation");
-  staticpro (&Qtruncation);
-  Qcontinuation = intern_c_string ("continuation");
-  staticpro (&Qcontinuation);
-  Qoverlay_arrow = intern_c_string ("overlay-arrow");
-  staticpro (&Qoverlay_arrow);
-  Qempty_line = intern_c_string ("empty-line");
-  staticpro (&Qempty_line);
-  Qtop_bottom = intern_c_string ("top-bottom");
-  staticpro (&Qtop_bottom);
-  Qhollow_small = intern_c_string ("hollow-small");
-  staticpro (&Qhollow_small);
+  DEFSYM (Qtruncation, "truncation");
+  DEFSYM (Qcontinuation, "continuation");
+  DEFSYM (Qoverlay_arrow, "overlay-arrow");
+  DEFSYM (Qempty_line, "empty-line");
+  DEFSYM (Qtop_bottom, "top-bottom");
+  DEFSYM (Qhollow_small, "hollow-small");
 
   defsubr (&Sdestroy_fringe_bitmap);
   defsubr (&Sdefine_fringe_bitmap);
@@ -1786,7 +1789,7 @@ init_fringe_once (void)
   int bt;
 
   for (bt = NO_FRINGE_BITMAP + 1; bt < MAX_STANDARD_FRINGE_BITMAPS; bt++)
-    init_fringe_bitmap(bt, &standard_bitmaps[bt], 1);
+    init_fringe_bitmap (bt, &standard_bitmaps[bt], 1);
 }
 
 void