]> code.delx.au - gnu-emacs/blobdiff - src/fringe.c
(Version, mh-version): Update for release 8.0.
[gnu-emacs] / src / fringe.c
index a3e95c390e19d58d36331cab9b1f041dbb71ca55..48fb11810ed4e6f2e272339de07cfb23889397b2 100644 (file)
@@ -1,6 +1,7 @@
 /* Fringe handling (split from xdisp.c).
-   Copyright (C) 1985,86,87,88,93,94,95,97,98,99,2000,01,02,03,04
-   Free Software Foundation, Inc.
+   Copyright (C) 1985, 1986, 1987, 1988, 1993, 1994, 1995, 1997,
+                 1998, 1999, 2000, 2000, 2001, 2002, 2003, 2004,
+                 2005, 2006 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -16,8 +17,8 @@ GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with GNU Emacs; see the file COPYING.  If not, write to
-the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA.  */
+the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA.  */
 
 #include <config.h>
 #include <stdio.h>
@@ -48,31 +49,45 @@ Lisp_Object Voverflow_newline_into_fringe;
 
 Lisp_Object Vfringe_bitmaps;
 
-enum fringe_bitmap_type
-{
-  NO_FRINGE_BITMAP = 0,
-  UNDEF_FRINGE_BITMAP,
-  LEFT_TRUNCATION_BITMAP,
-  RIGHT_TRUNCATION_BITMAP,
-  UP_ARROW_BITMAP,
-  DOWN_ARROW_BITMAP,
-  CONTINUED_LINE_BITMAP,
-  CONTINUATION_LINE_BITMAP,
-  OVERLAY_ARROW_BITMAP,
-  TOP_LEFT_ANGLE_BITMAP,
-  TOP_RIGHT_ANGLE_BITMAP,
-  BOTTOM_LEFT_ANGLE_BITMAP,
-  BOTTOM_RIGHT_ANGLE_BITMAP,
-  LEFT_BRACKET_BITMAP,
-  RIGHT_BRACKET_BITMAP,
-  FILLED_BOX_CURSOR_BITMAP,
-  HOLLOW_BOX_CURSOR_BITMAP,
-  HOLLOW_SQUARE_BITMAP,
-  BAR_CURSOR_BITMAP,
-  HBAR_CURSOR_BITMAP,
-  ZV_LINE_BITMAP,
-  MAX_STANDARD_FRINGE_BITMAPS
-};
+/* Fringe bitmaps are represented in three different ways:
+
+   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,
+   e.g. 'bottom-left-angle', 'left-arrow', 'left-triangle', etc.
+   User defined bitmaps are physical bitmaps.
+
+   Internally, fringe bitmaps for a specific display row are
+   represented as a simple integer that is used as an index
+   into the table of all defined bitmaps.  This index is stored
+   in the `fringe' property of the physical bitmap symbol.
+
+   Logical bitmaps are mapped to physical bitmaps through the
+   buffer-local `fringe-indicator-alist' variable.
+
+   Each element of this alist is a cons (LOGICAL . PHYSICAL)
+   mapping a logical bitmap to a physical bitmap.
+   PHYSICAL is either a symbol to use in both left and right fringe,
+   or a cons of two symbols (LEFT . RIGHT) denoting different
+   bitmaps to use in left and right fringe.
+
+   LOGICAL is first looked up in the window's buffer's buffer-local
+   value of the fringe-indicator-alist variable, and if not present,
+   in the global value of fringe-indicator-alist.
+
+   If LOGICAL is not present in either alist, or the PHYSICAL value
+   found is nil, no bitmap is shown for the logical bitmap.
+
+   The `left-fringe' and `right-fringe' display properties
+   must specify physical bitmap symbols.
+*/
+
+extern Lisp_Object Qunknown;
+Lisp_Object Qtruncation, Qcontinuation, Qoverlay_arrow;
+Lisp_Object Qempty_line, Qtop_bottom;
+extern Lisp_Object Qbar, Qhbar, Qbox, Qhollow;
+Lisp_Object Qhollow_small;
 
 enum fringe_bitmap_align
 {
@@ -109,7 +124,7 @@ struct fringe_bitmap
   ...xx...
   ...xx...
 */
-static unsigned short unknown_bits[] = {
+static unsigned short question_mark_bits[] = {
   0x3c, 0x7e, 0x7e, 0x0c, 0x18, 0x18, 0x00, 0x18, 0x18};
 
 /* An arrow like this: `<-'.  */
@@ -171,20 +186,6 @@ static unsigned short up_arrow_bits[] = {
 static unsigned short down_arrow_bits[] = {
    0x18, 0x18, 0x18, 0x18, 0xff, 0x7e, 0x3c, 0x18};
 
-/* Marker for continued lines.  */
-/*
-  ..xxxx..
-  ..xxxxx.
-  ......xx
-  ..x..xxx
-  ..xxxxxx
-  ..xxxxx.
-  ..xxxx..
-  ..xxxxx.
-*/
-static unsigned short continued_bits[] = {
-   0x3c, 0x3e, 0x03, 0x27, 0x3f, 0x3e, 0x3c, 0x3e};
-
 /* Marker for continuation lines.  */
 /*
   ..xxxx..
@@ -196,24 +197,23 @@ static unsigned short continued_bits[] = {
   ..xxxx..
   .xxxxx..
 */
-static unsigned short continuation_bits[] = {
+static unsigned short left_curly_arrow_bits[] = {
    0x3c, 0x7c, 0xc0, 0xe4, 0xfc, 0x7c, 0x3c, 0x7c};
 
-/* Overlay arrow bitmap.  A triangular arrow.  */
+/* Marker for continued lines.  */
 /*
-  xx......
-  xxxx....
-  xxxxx...
-  xxxxxx..
-  xxxxxx..
-  xxxxx...
-  xxxx....
-  xx......
+  ..xxxx..
+  ..xxxxx.
+  ......xx
+  ..x..xxx
+  ..xxxxxx
+  ..xxxxx.
+  ..xxxx..
+  ..xxxxx.
 */
-static unsigned short ov_bits[] = {
-   0xc0, 0xf0, 0xf8, 0xfc, 0xfc, 0xf8, 0xf0, 0xc0};
+static unsigned short right_curly_arrow_bits[] = {
+   0x3c, 0x3e, 0x03, 0x27, 0x3f, 0x3e, 0x3c, 0x3e};
 
-#if 0
 /* Reverse Overlay arrow bitmap.  A triangular arrow.  */
 /*
   ......xx
@@ -225,9 +225,22 @@ static unsigned short ov_bits[] = {
   ....xxxx
   ......xx
 */
-static unsigned short rev_ov_bits[] = {
+static unsigned short left_triangle_bits[] = {
    0x03, 0x0f, 0x1f, 0x3f, 0x3f, 0x1f, 0x0f, 0x03};
-#endif
+
+/* Overlay arrow bitmap.  A triangular arrow.  */
+/*
+  xx......
+  xxxx....
+  xxxxx...
+  xxxxxx..
+  xxxxxx..
+  xxxxx...
+  xxxx....
+  xx......
+*/
+static unsigned short right_triangle_bits[] = {
+   0xc0, 0xf0, 0xf8, 0xfc, 0xfc, 0xf8, 0xf0, 0xc0};
 
 /* First line bitmap.  An top-left angle.  */
 /*
@@ -333,7 +346,7 @@ static unsigned short right_bracket_bits[] = {
   xxxxxxx.
   xxxxxxx.
 */
-static unsigned short filled_box_cursor_bits[] = {
+static unsigned short filled_rectangle_bits[] = {
    0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe};
 
 /* Hollow box cursor bitmap.  A hollow box; max 13 pixels high.  */
@@ -352,9 +365,33 @@ static unsigned short filled_box_cursor_bits[] = {
   x.....x.
   xxxxxxx.
 */
-static unsigned short hollow_box_cursor_bits[] = {
+static unsigned short hollow_rectangle_bits[] = {
    0xfe, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0xfe};
 
+/* Hollow square bitmap.  */
+/*
+  .xxxxxx.
+  .x....x.
+  .x....x.
+  .x....x.
+  .x....x.
+  .xxxxxx.
+*/
+static unsigned short hollow_square_bits[] = {
+   0x7e, 0x42, 0x42, 0x42, 0x42, 0x7e};
+
+/* Filled square bitmap.  */
+/*
+  .xxxxxx.
+  .xxxxxx.
+  .xxxxxx.
+  .xxxxxx.
+  .xxxxxx.
+  .xxxxxx.
+*/
+static unsigned short filled_square_bits[] = {
+   0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e};
+
 /* Bar cursor bitmap.  A vertical bar; max 13 pixels high.  */
 /*
   xx......
@@ -371,15 +408,15 @@ static unsigned short hollow_box_cursor_bits[] = {
   xx......
   xx......
 */
-static unsigned short bar_cursor_bits[] = {
+static unsigned short vertical_bar_bits[] = {
    0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0};
 
-/* HBar cursor bitmap.  A horisontal bar; 2 pixels high.  */
+/* HBar cursor bitmap.  A horizontal bar; 2 pixels high.  */
 /*
   xxxxxxx.
   xxxxxxx.
 */
-static unsigned short hbar_cursor_bits[] = {
+static unsigned short horizontal_bar_bits[] = {
   0xfe, 0xfe};
 
 
@@ -393,7 +430,7 @@ static unsigned short hbar_cursor_bits[] = {
   ..xxxx..
   ........
 */
-static unsigned short zv_bits[] = {
+static unsigned short empty_line_bits[] = {
   0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
   0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
   0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
@@ -403,50 +440,47 @@ static unsigned short zv_bits[] = {
   0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
   0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00};
 
-/* Hollow square bitmap.  */
-/*
-  .xxxxxx.
-  .x....x.
-  .x....x.
-  .x....x.
-  .x....x.
-  .xxxxxx.
-*/
-static unsigned short hollow_square_bits[] = {
-   0x7e, 0x42, 0x42, 0x42, 0x42, 0x7e};
-
 
 #define BYTES_PER_BITMAP_ROW  (sizeof (unsigned short))
 #define STANDARD_BITMAP_HEIGHT(bits) (sizeof (bits)/BYTES_PER_BITMAP_ROW)
 #define FRBITS(bits)  bits, STANDARD_BITMAP_HEIGHT (bits)
 
-struct fringe_bitmap standard_bitmaps[MAX_STANDARD_FRINGE_BITMAPS] =
+/* NOTE:  The order of these bitmaps must match the sequence
+   used in fringe.el to define the corresponding symbols.  */
+
+struct fringe_bitmap standard_bitmaps[] =
 {
   { NULL, 0, 0, 0, 0, 0 }, /* NO_FRINGE_BITMAP */
-  { FRBITS (unknown_bits),            8, 0, ALIGN_BITMAP_CENTER, 0 },
+  { FRBITS (question_mark_bits),      8, 0, ALIGN_BITMAP_CENTER, 0 },
   { FRBITS (left_arrow_bits),         8, 0, ALIGN_BITMAP_CENTER, 0 },
   { FRBITS (right_arrow_bits),        8, 0, ALIGN_BITMAP_CENTER, 0 },
   { FRBITS (up_arrow_bits),           8, 0, ALIGN_BITMAP_TOP,    0 },
   { FRBITS (down_arrow_bits),         8, 0, ALIGN_BITMAP_BOTTOM, 0 },
-  { FRBITS (continued_bits),          8, 0, ALIGN_BITMAP_CENTER, 0 },
-  { FRBITS (continuation_bits),       8, 0, ALIGN_BITMAP_CENTER, 0 },
-  { FRBITS (ov_bits),                 8, 0, ALIGN_BITMAP_CENTER, 0 },
+  { FRBITS (left_curly_arrow_bits),   8, 0, ALIGN_BITMAP_CENTER, 0 },
+  { FRBITS (right_curly_arrow_bits),  8, 0, ALIGN_BITMAP_CENTER, 0 },
+  { FRBITS (left_triangle_bits),      8, 0, ALIGN_BITMAP_CENTER, 0 },
+  { FRBITS (right_triangle_bits),     8, 0, ALIGN_BITMAP_CENTER, 0 },
   { FRBITS (top_left_angle_bits),     8, 0, ALIGN_BITMAP_TOP,    0 },
   { FRBITS (top_right_angle_bits),    8, 0, ALIGN_BITMAP_TOP,    0 },
   { FRBITS (bottom_left_angle_bits),  8, 0, ALIGN_BITMAP_BOTTOM, 0 },
   { FRBITS (bottom_right_angle_bits), 8, 0, ALIGN_BITMAP_BOTTOM, 0 },
   { FRBITS (left_bracket_bits),       8, 0, ALIGN_BITMAP_CENTER, 0 },
   { FRBITS (right_bracket_bits),      8, 0, ALIGN_BITMAP_CENTER, 0 },
-  { FRBITS (filled_box_cursor_bits),  8, 0, ALIGN_BITMAP_CENTER, 0 },
-  { FRBITS (hollow_box_cursor_bits),  8, 0, ALIGN_BITMAP_CENTER, 0 },
+  { FRBITS (filled_rectangle_bits),   8, 0, ALIGN_BITMAP_CENTER, 0 },
+  { FRBITS (hollow_rectangle_bits),   8, 0, ALIGN_BITMAP_CENTER, 0 },
+  { FRBITS (filled_square_bits),      8, 0, ALIGN_BITMAP_CENTER, 0 },
   { FRBITS (hollow_square_bits),      8, 0, ALIGN_BITMAP_CENTER, 0 },
-  { FRBITS (bar_cursor_bits),         8, 0, ALIGN_BITMAP_CENTER, 0 },
-  { FRBITS (hbar_cursor_bits),        8, 0, ALIGN_BITMAP_BOTTOM, 0 },
-  { FRBITS (zv_bits),                 8, 3, ALIGN_BITMAP_TOP,    0 },
+  { FRBITS (vertical_bar_bits),       8, 0, ALIGN_BITMAP_CENTER, 0 },
+  { FRBITS (horizontal_bar_bits),     8, 0, ALIGN_BITMAP_BOTTOM, 0 },
+  { FRBITS (empty_line_bits),         8, 3, ALIGN_BITMAP_TOP,    0 },
 };
 
+#define NO_FRINGE_BITMAP 0
+#define UNDEF_FRINGE_BITMAP 1
+#define MAX_STANDARD_FRINGE_BITMAPS (sizeof(standard_bitmaps)/sizeof(standard_bitmaps[0]))
+
 static struct fringe_bitmap **fringe_bitmaps;
-static unsigned *fringe_faces;
+static Lisp_Object *fringe_faces;
 static int max_fringe_bitmaps;
 
 static int max_used_fringe_bitmap = MAX_STANDARD_FRINGE_BITMAPS;
@@ -515,12 +549,12 @@ get_fringe_bitmap_name (bn)
    LEFT_P is 1 for left fringe, 0 for right fringe.
 */
 
-void
+static void
 draw_fringe_bitmap_1 (w, row, left_p, overlay, which)
      struct window *w;
      struct glyph_row *row;
      int left_p, overlay;
-     enum fringe_bitmap_type which;
+     int which;
 {
   struct frame *f = XFRAME (WINDOW_FRAME (w));
   struct draw_fringe_bitmap_params p;
@@ -547,7 +581,14 @@ draw_fringe_bitmap_1 (w, row, left_p, overlay, which)
     }
 
   if (face_id == DEFAULT_FACE_ID)
-    face_id = fringe_faces[which];
+    {
+      Lisp_Object face;
+
+      if ((face = fringe_faces[which], NILP (face))
+         || (face_id = lookup_derived_face (f, face, 'A', FRINGE_FACE_ID, 0),
+             face_id < 0))
+       face_id = FRINGE_FACE_ID;
+    }
 
   fb = fringe_bitmaps[which];
   if (fb == NULL)
@@ -574,7 +615,8 @@ draw_fringe_bitmap_1 (w, row, left_p, overlay, which)
 
   if (p.face == NULL)
     {
-      /* Why does this happen?  ++kfs */
+      /* This could happen after clearing face cache.
+        But it shouldn't happen anymore.  ++kfs */
       return;
     }
 
@@ -647,6 +689,134 @@ draw_fringe_bitmap_1 (w, row, left_p, overlay, which)
   rif->draw_fringe_bitmap (w, row, &p);
 }
 
+static int
+get_logical_cursor_bitmap (w, cursor)
+     struct window *w;
+     Lisp_Object cursor;
+{
+  Lisp_Object cmap, bm = Qnil;
+
+  if ((cmap = XBUFFER (w->buffer)->fringe_cursor_alist), !NILP (cmap))
+    {
+      bm = Fassq (cursor, cmap);
+      if (CONSP (bm))
+       {
+         if ((bm = XCDR (bm)), NILP (bm))
+           return NO_FRINGE_BITMAP;
+         return lookup_fringe_bitmap (bm);
+       }
+    }
+  if (EQ (cmap, buffer_defaults.fringe_cursor_alist))
+    return NO_FRINGE_BITMAP;
+  bm = Fassq (cursor, buffer_defaults.fringe_cursor_alist);
+  if (!CONSP (bm) || ((bm = XCDR (bm)), NILP (bm)))
+    return NO_FRINGE_BITMAP;
+  return lookup_fringe_bitmap (bm);
+}
+
+static int
+get_logical_fringe_bitmap (w, bitmap, right_p, partial_p)
+     struct window *w;
+     Lisp_Object bitmap;
+     int right_p, partial_p;
+{
+  Lisp_Object cmap, bm1 = Qnil, bm2 = Qnil, bm;
+  int ln1 = 0, ln2 = 0;
+  int ix1 = right_p;
+  int ix2 = ix1 + (partial_p ? 2 : 0);
+
+  /* Lookup in buffer-local fringe-indicator-alist before global alist.
+
+     Elements are:
+       BITMAP          -- use for all
+       (L R)           -- use for left right (whether partial or not)
+       (L R PL PR)     -- use for left rigth partial-left partial-right
+       If any value in local binding is not present or t, use global value.
+
+     If partial, lookup partial bitmap in default value if not found here.
+     If not partial, or no partial spec is present, use non-partial bitmap.  */
+
+  if ((cmap = XBUFFER (w->buffer)->fringe_indicator_alist), !NILP (cmap))
+    {
+      bm1 = Fassq (bitmap, cmap);
+      if (CONSP (bm1))
+       {
+         if ((bm1 = XCDR (bm1)), NILP (bm1))
+           return NO_FRINGE_BITMAP;
+         if (CONSP (bm1))
+           {
+             ln1 = XINT (Flength (bm1));
+             if (partial_p)
+               {
+                 if (ln1 > ix2)
+                   {
+                     bm = Fnth (make_number (ix2), bm1);
+                     if (!EQ (bm, Qt))
+                       goto found;
+                   }
+               }
+             else
+               {
+                 if (ln1 > ix1)
+                   {
+                     bm = Fnth (make_number (ix1), bm1);
+                     if (!EQ (bm, Qt))
+                       goto found;
+                   }
+               }
+           }
+         else if ((bm = bm1, !EQ (bm, Qt)))
+           goto found;
+       }
+    }
+
+  if (!EQ (cmap, buffer_defaults.fringe_indicator_alist)
+      && !NILP (buffer_defaults.fringe_indicator_alist))
+    {
+      bm2 = Fassq (bitmap, buffer_defaults.fringe_indicator_alist);
+      if (CONSP (bm2))
+       {
+         if ((bm2 = XCDR (bm2)), !NILP (bm2))
+           {
+             if (CONSP (bm2))
+               {
+                 ln2 = XINT (Flength (bm2));
+                 if (partial_p)
+                   {
+                     if (ln2 > ix2)
+                       {
+                         bm = Fnth (make_number (ix2), bm2);
+                         if (!EQ (bm, Qt))
+                           goto found;
+                       }
+                   }
+               }
+           }
+       }
+    }
+
+  if (ln1 > ix1)
+    {
+      bm = Fnth (make_number (ix1), bm1);
+      if (!EQ (bm, Qt))
+       goto found;
+    }
+
+  if (ln2 > ix1)
+    {
+      bm = Fnth (make_number (ix1), bm2);
+      if (!EQ (bm, Qt))
+       goto found;
+      return NO_FRINGE_BITMAP;
+    }
+  else if ((bm = bm2, NILP (bm)))
+    return NO_FRINGE_BITMAP;
+
+ found:
+  return lookup_fringe_bitmap (bm);
+}
+
+
 void
 draw_fringe_bitmap (w, row, left_p)
      struct window *w;
@@ -657,24 +827,24 @@ draw_fringe_bitmap (w, row, left_p)
 
   if (!left_p && row->cursor_in_fringe_p)
     {
-      int cursor = NO_FRINGE_BITMAP;
+      Lisp_Object cursor = Qnil;
 
       switch (w->phys_cursor_type)
        {
        case HOLLOW_BOX_CURSOR:
-         if (row->visible_height >= STANDARD_BITMAP_HEIGHT (hollow_box_cursor_bits))
-           cursor = HOLLOW_BOX_CURSOR_BITMAP;
+         if (row->visible_height >= STANDARD_BITMAP_HEIGHT (hollow_rectangle_bits))
+           cursor = Qhollow;
          else
-           cursor = HOLLOW_SQUARE_BITMAP;
+           cursor = Qhollow_small;
          break;
        case FILLED_BOX_CURSOR:
-         cursor = FILLED_BOX_CURSOR_BITMAP;
+         cursor = Qbox;
          break;
        case BAR_CURSOR:
-         cursor = BAR_CURSOR_BITMAP;
+         cursor = Qbar;
          break;
        case HBAR_CURSOR:
-         cursor = HBAR_CURSOR_BITMAP;
+         cursor = Qhbar;
          break;
        case NO_CURSOR:
        default:
@@ -682,20 +852,21 @@ draw_fringe_bitmap (w, row, left_p)
          row->cursor_in_fringe_p = 0;
          break;
        }
-      if (cursor != NO_FRINGE_BITMAP)
+      if (!NILP (cursor))
        {
-         draw_fringe_bitmap_1 (w, row, 0, 2, cursor);
-         overlay = cursor == FILLED_BOX_CURSOR_BITMAP ? 3 : 1;
+         int bm = get_logical_cursor_bitmap (w, cursor);
+         if (bm != NO_FRINGE_BITMAP)
+           {
+             draw_fringe_bitmap_1 (w, row, 0, 2, bm);
+             overlay = EQ (cursor, Qbox) ? 3 : 1;
+           }
        }
     }
 
   draw_fringe_bitmap_1 (w, row, left_p, overlay, NO_FRINGE_BITMAP);
 
-  if (left_p && row->overlay_arrow_p)
-    draw_fringe_bitmap_1 (w, row, 1, 1,
-                         (w->overlay_arrow_bitmap
-                          ? w->overlay_arrow_bitmap
-                          : OVERLAY_ARROW_BITMAP));
+  if (left_p && row->overlay_arrow_bitmap != NO_FRINGE_BITMAP)
+    draw_fringe_bitmap_1 (w, row, 1, 1, row->overlay_arrow_bitmap);
 }
 
 
@@ -768,13 +939,14 @@ draw_window_fringes (w, no_fringe)
 
 
 /* Recalculate the bitmaps to show in the fringes of window W.
-   If FORCE_P is 0, only mark rows with modified bitmaps for update in
-   redraw_fringe_bitmaps_p; else mark all rows for update.  */
+   Only mark rows with modified bitmaps for update in redraw_fringe_bitmaps_p.
+
+   If KEEP_CURRENT_P is 0, update current_matrix too.  */
 
 int
-update_window_fringes (w, force_p)
+update_window_fringes (w, keep_current_p)
      struct window *w;
-     int force_p;
+     int keep_current_p;
 {
   struct glyph_row *row, *cur = 0;
   int yb = window_text_bottom_y (w);
@@ -785,6 +957,8 @@ update_window_fringes (w, force_p)
   Lisp_Object arrow_top = Qnil, arrow_bot = Qnil;
   Lisp_Object empty_pos;
   Lisp_Object ind = Qnil;
+#define MAX_BITMAP_CACHE (8*4)
+  int bitmap_cache[MAX_BITMAP_CACHE];
 
   if (w->pseudo_window_p)
     return 0;
@@ -840,7 +1014,8 @@ update_window_fringes (w, force_p)
            {
              if (!done_top)
                {
-                 if (MATRIX_ROW_START_CHARPOS (row) <= BUF_BEGV (XBUFFER (w->buffer)))
+                 if (MATRIX_ROW_START_CHARPOS (row) <= BUF_BEGV (XBUFFER (w->buffer))
+                     && !MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w, row))
                    row->indicate_bob_p = !NILP (boundary_top);
                  else
                    row->indicate_top_line_p = !NILP (arrow_top);
@@ -849,7 +1024,8 @@ update_window_fringes (w, force_p)
 
              if (!done_bot)
                {
-                 if (MATRIX_ROW_END_CHARPOS (row) >= BUF_ZV (XBUFFER (w->buffer)))
+                 if (MATRIX_ROW_END_CHARPOS (row) >= BUF_ZV (XBUFFER (w->buffer))
+                     && !MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row))
                    row->indicate_eob_p = !NILP (boundary_bot), done_bot = 1;
                  else if (y + row->height >= yb)
                    row->indicate_bottom_line_p = !NILP (arrow_bot), done_bot = 1;
@@ -868,11 +1044,27 @@ update_window_fringes (w, force_p)
   if (!NILP (empty_pos) && !EQ (empty_pos, Qright))
     empty_pos = WINDOW_LEFT_FRINGE_WIDTH (w) == 0 ? Qright : Qleft;
 
+  for (y = 0; y < MAX_BITMAP_CACHE; y++)
+    bitmap_cache[y] = -1;
+
+#define LEFT_FRINGE(cache, which, partial_p)                   \
+  (bitmap_cache[cache*4+partial_p] >= 0                                \
+   ? bitmap_cache[cache*4+partial_p]                           \
+   : (bitmap_cache[cache*4+partial_p] =                                \
+      get_logical_fringe_bitmap (w, which, 0, partial_p)))
+
+#define RIGHT_FRINGE(cache, which, partial_p)                  \
+  (bitmap_cache[cache*4+2+partial_p] >= 0                      \
+   ? bitmap_cache[cache*4+2+partial_p]                         \
+   : (bitmap_cache[cache*4+2+partial_p] =                      \
+      get_logical_fringe_bitmap (w, which, 1, partial_p)))
+
+
   for (y = 0, rn = 0;
        y < yb && rn < nrows;
        y += row->height, rn++)
     {
-      enum fringe_bitmap_type left, right;
+      int left, right;
       unsigned left_face_id, right_face_id;
 
       row = w->desired_matrix->rows + rn;
@@ -890,21 +1082,22 @@ update_window_fringes (w, force_p)
          left = row->left_user_fringe_bitmap;
          left_face_id = row->left_user_fringe_face_id;
        }
+      else if (row->truncated_on_left_p)
+       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))
-               ? LEFT_BRACKET_BITMAP : TOP_LEFT_ANGLE_BITMAP);
+               ? LEFT_FRINGE (1, Qtop_bottom, row->ends_at_zv_p)
+               : LEFT_FRINGE (2, Qtop, 0));
       else if (row->indicate_eob_p && EQ (boundary_bot, Qleft))
-       left = BOTTOM_LEFT_ANGLE_BITMAP;
-      else if (row->truncated_on_left_p)
-       left = LEFT_TRUNCATION_BITMAP;
+       left = LEFT_FRINGE (3, Qbottom, row->ends_at_zv_p);
       else if (MATRIX_ROW_CONTINUATION_LINE_P (row))
-       left = CONTINUATION_LINE_BITMAP;
+       left = LEFT_FRINGE (4, Qcontinuation, 0);
       else if (row->indicate_empty_line_p && EQ (empty_pos, Qleft))
-       left = ZV_LINE_BITMAP;
+       left = LEFT_FRINGE (5, Qempty_line, 0);
       else if (row->indicate_top_line_p && EQ (arrow_top, Qleft))
-       left = UP_ARROW_BITMAP;
+       left = LEFT_FRINGE (6, Qup, 0);
       else if (row->indicate_bottom_line_p && EQ (arrow_bot, Qleft))
-       left = DOWN_ARROW_BITMAP;
+       left = LEFT_FRINGE (7, Qdown, 0);
       else
        left = NO_FRINGE_BITMAP;
 
@@ -916,26 +1109,26 @@ update_window_fringes (w, force_p)
          right = row->right_user_fringe_bitmap;
          right_face_id = row->right_user_fringe_face_id;
        }
+      else if (row->truncated_on_right_p)
+       right = RIGHT_FRINGE (0, Qtruncation, 0);
       else if (row->indicate_bob_p && EQ (boundary_top, Qright))
        right = ((row->indicate_eob_p && EQ (boundary_bot, Qright))
-                ? RIGHT_BRACKET_BITMAP : TOP_RIGHT_ANGLE_BITMAP);
+                ? RIGHT_FRINGE (1, Qtop_bottom, row->ends_at_zv_p)
+                : RIGHT_FRINGE (2, Qtop, 0));
       else if (row->indicate_eob_p && EQ (boundary_bot, Qright))
-       right = BOTTOM_RIGHT_ANGLE_BITMAP;
-      else if (row->truncated_on_right_p)
-       right = RIGHT_TRUNCATION_BITMAP;
+       right = RIGHT_FRINGE (3, Qbottom, row->ends_at_zv_p);
       else if (row->continued_p)
-       right = CONTINUED_LINE_BITMAP;
+       right = RIGHT_FRINGE (4, Qcontinuation, 0);
       else if (row->indicate_top_line_p && EQ (arrow_top, Qright))
-       right = UP_ARROW_BITMAP;
+       right = RIGHT_FRINGE (6, Qup, 0);
       else if (row->indicate_bottom_line_p && EQ (arrow_bot, Qright))
-       right = DOWN_ARROW_BITMAP;
+       right = RIGHT_FRINGE (7, Qdown, 0);
       else if (row->indicate_empty_line_p && EQ (empty_pos, Qright))
-       right = ZV_LINE_BITMAP;
+       right = RIGHT_FRINGE (5, Qempty_line, 0);
       else
        right = NO_FRINGE_BITMAP;
 
-      if (force_p
-         || row->y != cur->y
+      if (row->y != cur->y
          || row->visible_height != cur->visible_height
          || row->ends_at_zv_p != cur->ends_at_zv_p
          || left != cur->left_fringe_bitmap
@@ -944,17 +1137,24 @@ update_window_fringes (w, force_p)
          || right_face_id != cur->right_fringe_face_id
          || cur->redraw_fringe_bitmaps_p)
        {
-         redraw_p = row->redraw_fringe_bitmaps_p = cur->redraw_fringe_bitmaps_p = 1;
-         cur->left_fringe_bitmap = left;
-         cur->right_fringe_bitmap = right;
-         cur->left_fringe_face_id = left_face_id;
-         cur->right_fringe_face_id = right_face_id;
+         redraw_p = row->redraw_fringe_bitmaps_p = 1;
+         if (!keep_current_p)
+           {
+             cur->redraw_fringe_bitmaps_p = 1;
+             cur->left_fringe_bitmap = left;
+             cur->right_fringe_bitmap = right;
+             cur->left_fringe_face_id = left_face_id;
+             cur->right_fringe_face_id = right_face_id;
+           }
        }
 
-      if (row->overlay_arrow_p != cur->overlay_arrow_p)
+      if (row->overlay_arrow_bitmap < 0)
+       row->overlay_arrow_bitmap = get_logical_fringe_bitmap (w, Qoverlay_arrow, 0, 0);
+
+      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_p = row->overlay_arrow_p;
+         cur->overlay_arrow_bitmap = row->overlay_arrow_bitmap;
        }
 
       row->left_fringe_bitmap = left;
@@ -966,7 +1166,7 @@ update_window_fringes (w, force_p)
        row[-1].redraw_fringe_bitmaps_p = cur[-1].redraw_fringe_bitmaps_p = 1;
     }
 
-  return redraw_p;
+  return redraw_p && !keep_current_p;
 }
 
 
@@ -1073,7 +1273,7 @@ destroy_fringe_bitmap (n)
 {
   struct fringe_bitmap **fbp;
 
-  fringe_faces[n] = FRINGE_FACE_ID;
+  fringe_faces[n] = Qnil;
 
   fbp = &fringe_bitmaps[n];
   if (*fbp && (*fbp)->dynamic)
@@ -1129,7 +1329,7 @@ If BITMAP overrides a standard fringe bitmap, the original bitmap is restored.
 
 void
 init_fringe_bitmap (which, fb, once_p)
-     enum fringe_bitmap_type which;
+     int which;
      struct fringe_bitmap *fb;
      int once_p;
 {
@@ -1294,12 +1494,12 @@ If BITMAP already exists, the existing definition is replaced.  */)
                = ((struct fringe_bitmap **)
                   xrealloc (fringe_bitmaps, max_fringe_bitmaps * sizeof (struct fringe_bitmap *)));
              fringe_faces
-               = (unsigned *) xrealloc (fringe_faces, max_fringe_bitmaps * sizeof (unsigned));
+               = (Lisp_Object *) xrealloc (fringe_faces, max_fringe_bitmaps * sizeof (Lisp_Object));
 
              for (; i < max_fringe_bitmaps; i++)
                {
                  fringe_bitmaps[i] = NULL;
-                 fringe_faces[i] = FRINGE_FACE_ID;
+                 fringe_faces[i] = Qnil;
                }
            }
        }
@@ -1353,14 +1553,13 @@ If FACE is nil, reset face to default fringe face.  */)
 
   if (!NILP (face))
     {
-      face_id = lookup_named_face (SELECTED_FRAME (), face, 'A', 1);
+      face_id = lookup_derived_face (SELECTED_FRAME (), face,
+                                    'A', FRINGE_FACE_ID, 1);
       if (face_id < 0)
        error ("No such face");
     }
-  else
-    face_id = FRINGE_FACE_ID;
 
-  fringe_faces[n] = face_id;
+  fringe_faces[n] = face;
 
   return Qnil;
 }
@@ -1401,7 +1600,9 @@ Return nil if POS is not visible in WINDOW.  */)
   if (row)
     return list3 (get_fringe_bitmap_name (row->left_fringe_bitmap),
                  get_fringe_bitmap_name (row->right_fringe_bitmap),
-                 (row->overlay_arrow_p ? Qt : Qnil));
+                 (row->overlay_arrow_bitmap == 0 ? Qnil
+                  : row->overlay_arrow_bitmap < 0 ? Qt
+                  : get_fringe_bitmap_name (row->overlay_arrow_bitmap)));
   else
     return Qnil;
 }
@@ -1414,6 +1615,19 @@ Return nil if POS is not visible in WINDOW.  */)
 void
 syms_of_fringe ()
 {
+  Qtruncation = intern ("truncation");
+  staticpro (&Qtruncation);
+  Qcontinuation = intern ("continuation");
+  staticpro (&Qcontinuation);
+  Qoverlay_arrow = intern ("overlay-arrow");
+  staticpro (&Qoverlay_arrow);
+  Qempty_line = intern ("empty-line");
+  staticpro (&Qempty_line);
+  Qtop_bottom = intern ("top-bottom");
+  staticpro (&Qtop_bottom);
+  Qhollow_small = intern ("hollow-small");
+  staticpro (&Qhollow_small);
+
   defsubr (&Sdestroy_fringe_bitmap);
   defsubr (&Sdefine_fringe_bitmap);
   defsubr (&Sfringe_bitmaps_at_pos);
@@ -1429,17 +1643,28 @@ If nil, also continue lines which are exactly as wide as the window.  */);
   Voverflow_newline_into_fringe = Qt;
 
   DEFVAR_LISP ("fringe-bitmaps", &Vfringe_bitmaps,
-    doc: /* List of fringe bitmap symbols.
-You must (require 'fringe) to use fringe bitmap symbols in your programs." */);
+    doc: /* List of fringe bitmap symbols.  */);
   Vfringe_bitmaps = Qnil;
 }
 
+/* Garbage collection hook */
+
+void
+mark_fringe_data ()
+{
+  int i;
+
+  for (i = 0; i < max_fringe_bitmaps; i++)
+    if (!NILP (fringe_faces[i]))
+      mark_object (fringe_faces[i]);
+}
+
 /* Initialize this module when Emacs starts.  */
 
 void
 init_fringe_once ()
 {
-  enum fringe_bitmap_type bt;
+  int bt;
 
   for (bt = NO_FRINGE_BITMAP + 1; bt < MAX_STANDARD_FRINGE_BITMAPS; bt++)
     init_fringe_bitmap(bt, &standard_bitmaps[bt], 1);
@@ -1455,21 +1680,25 @@ init_fringe ()
   fringe_bitmaps
     = (struct fringe_bitmap **) xmalloc (max_fringe_bitmaps * sizeof (struct fringe_bitmap *));
   fringe_faces
-    = (unsigned *) xmalloc (max_fringe_bitmaps * sizeof (unsigned));
+    = (Lisp_Object *) xmalloc (max_fringe_bitmaps * sizeof (Lisp_Object));
 
   for (i = 0; i < max_fringe_bitmaps; i++)
     {
       fringe_bitmaps[i] = NULL;
-      fringe_faces[i] = FRINGE_FACE_ID;
+      fringe_faces[i] = Qnil;
     }
 }
 
-#ifdef HAVE_NTGUI
+#if defined (HAVE_NTGUI) || defined (MAC_OS)
 
 void
+#ifdef HAVE_NTGUI
 w32_init_fringe ()
+#else  /* MAC_OS */
+mac_init_fringe ()
+#endif
 {
-  enum fringe_bitmap_type bt;
+  int bt;
 
   if (!rif)
     return;
@@ -1480,7 +1709,9 @@ w32_init_fringe ()
       rif->define_fringe_bitmap (bt, fb->bits, fb->height, fb->width);
     }
 }
+#endif
 
+#ifdef HAVE_NTGUI
 void
 w32_reset_fringes ()
 {