/[emacs]/emacs/src/buffer.c
ViewVC logotype

Diff of /emacs/src/buffer.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.430 by monnier, Tue Jul 8 22:09:23 2003 UTC revision 1.431 by monnier, Wed Jul 9 15:09:12 2003 UTC
# Line 183  Lisp_Object Qinsert_behind_hooks; Line 183  Lisp_Object Qinsert_behind_hooks;
183    
184  static void alloc_buffer_text P_ ((struct buffer *, size_t));  static void alloc_buffer_text P_ ((struct buffer *, size_t));
185  static void free_buffer_text P_ ((struct buffer *b));  static void free_buffer_text P_ ((struct buffer *b));
186  static Lisp_Object copy_overlays P_ ((struct buffer *, Lisp_Object));  static struct Lisp_Overlay * copy_overlays P_ ((struct buffer *, struct Lisp_Overlay *));
187  static void modify_overlay P_ ((struct buffer *, int, int));  static void modify_overlay P_ ((struct buffer *, int, int));
188    
189    
# Line 434  The value is never nil.  */) Line 434  The value is never nil.  */)
434  /* Return a list of overlays which is a copy of the overlay list  /* Return a list of overlays which is a copy of the overlay list
435     LIST, but for buffer B.  */     LIST, but for buffer B.  */
436    
437  static Lisp_Object  static struct Lisp_Overlay *
438  copy_overlays (b, list)  copy_overlays (b, list)
439       struct buffer *b;       struct buffer *b;
440       Lisp_Object list;       struct Lisp_Overlay *list;
441  {  {
442    Lisp_Object result, buffer;    Lisp_Object buffer;
443      struct Lisp_Overlay *result = NULL, *tail = NULL;
444    
445    XSETBUFFER (buffer, b);    XSETBUFFER (buffer, b);
446    
447    for (result = Qnil; CONSP (list); list = XCDR (list))    for (; list; list = list->next)
448      {      {
449        Lisp_Object overlay, start, end, old_overlay;        Lisp_Object overlay, start, end, old_overlay;
450        int charpos;        int charpos;
451    
452        old_overlay = XCAR (list);        XSETMISC (old_overlay, list);
453        charpos = marker_position (OVERLAY_START (old_overlay));        charpos = marker_position (OVERLAY_START (old_overlay));
454        start = Fmake_marker ();        start = Fmake_marker ();
455        Fset_marker (start, make_number (charpos), buffer);        Fset_marker (start, make_number (charpos), buffer);
# Line 466  copy_overlays (b, list) Line 467  copy_overlays (b, list)
467        OVERLAY_START (overlay) = start;        OVERLAY_START (overlay) = start;
468        OVERLAY_END (overlay) = end;        OVERLAY_END (overlay) = end;
469        OVERLAY_PLIST (overlay) = Fcopy_sequence (OVERLAY_PLIST (old_overlay));        OVERLAY_PLIST (overlay) = Fcopy_sequence (OVERLAY_PLIST (old_overlay));
470          XOVERLAY (overlay)->next = NULL;
471    
472        result = Fcons (overlay, result);        if (tail)
473            tail = tail->next = XOVERLAY (overlay);
474          else
475            result = tail = XOVERLAY (overlay);
476      }      }
477    
478    return Fnreverse (result);    return result;
479  }  }
480    
481    
# Line 646  reset_buffer (b) Line 651  reset_buffer (b)
651    b->auto_save_failure_time = -1;    b->auto_save_failure_time = -1;
652    b->auto_save_file_name = Qnil;    b->auto_save_file_name = Qnil;
653    b->read_only = Qnil;    b->read_only = Qnil;
654    b->overlays_before = Qnil;    b->overlays_before = NULL;
655    b->overlays_after = Qnil;    b->overlays_after = NULL;
656    b->overlay_center = BEG;    b->overlay_center = BEG;
657    b->mark_active = Qnil;    b->mark_active = Qnil;
658    b->point_before_scroll = Qnil;    b->point_before_scroll = Qnil;
# Line 2428  overlays_at (pos, extend, vec_ptr, len_p Line 2433  overlays_at (pos, extend, vec_ptr, len_p
2433       int *prev_ptr;       int *prev_ptr;
2434       int change_req;       int change_req;
2435  {  {
2436    Lisp_Object tail, overlay, start, end;    Lisp_Object overlay, start, end;
2437      struct Lisp_Overlay *tail;
2438    int idx = 0;    int idx = 0;
2439    int len = *len_ptr;    int len = *len_ptr;
2440    Lisp_Object *vec = *vec_ptr;    Lisp_Object *vec = *vec_ptr;
# Line 2436  overlays_at (pos, extend, vec_ptr, len_p Line 2442  overlays_at (pos, extend, vec_ptr, len_p
2442    int prev = BEGV;    int prev = BEGV;
2443    int inhibit_storing = 0;    int inhibit_storing = 0;
2444    
2445    for (tail = current_buffer->overlays_before;    for (tail = current_buffer->overlays_before; tail; tail = tail->next)
        GC_CONSP (tail);  
        tail = XCDR (tail))  
2446      {      {
2447        int startpos, endpos;        int startpos, endpos;
2448    
2449        overlay = XCAR (tail);        XSETMISC (overlay, tail);
2450    
2451        start = OVERLAY_START (overlay);        start = OVERLAY_START (overlay);
2452        end = OVERLAY_END (overlay);        end = OVERLAY_END (overlay);
# Line 2489  overlays_at (pos, extend, vec_ptr, len_p Line 2493  overlays_at (pos, extend, vec_ptr, len_p
2493          next = startpos;          next = startpos;
2494      }      }
2495    
2496    for (tail = current_buffer->overlays_after;    for (tail = current_buffer->overlays_after; tail; tail = tail->next)
        GC_CONSP (tail);  
        tail = XCDR (tail))  
2497      {      {
2498        int startpos, endpos;        int startpos, endpos;
2499    
2500        overlay = XCAR (tail);        XSETMISC (overlay, tail);
2501    
2502        start = OVERLAY_START (overlay);        start = OVERLAY_START (overlay);
2503        end = OVERLAY_END (overlay);        end = OVERLAY_END (overlay);
# Line 2574  overlays_in (beg, end, extend, vec_ptr, Line 2576  overlays_in (beg, end, extend, vec_ptr,
2576       int *next_ptr;       int *next_ptr;
2577       int *prev_ptr;       int *prev_ptr;
2578  {  {
2579    Lisp_Object tail, overlay, ostart, oend;    Lisp_Object overlay, ostart, oend;
2580      struct Lisp_Overlay *tail;
2581    int idx = 0;    int idx = 0;
2582    int len = *len_ptr;    int len = *len_ptr;
2583    Lisp_Object *vec = *vec_ptr;    Lisp_Object *vec = *vec_ptr;
# Line 2582  overlays_in (beg, end, extend, vec_ptr, Line 2585  overlays_in (beg, end, extend, vec_ptr,
2585    int prev = BEGV;    int prev = BEGV;
2586    int inhibit_storing = 0;    int inhibit_storing = 0;
2587    
2588    for (tail = current_buffer->overlays_before;    for (tail = current_buffer->overlays_before; tail; tail = tail->next)
        GC_CONSP (tail);  
        tail = XCDR (tail))  
2589      {      {
2590        int startpos, endpos;        int startpos, endpos;
2591    
2592        overlay = XCAR (tail);        XSETMISC (overlay, tail);
2593    
2594        ostart = OVERLAY_START (overlay);        ostart = OVERLAY_START (overlay);
2595        oend = OVERLAY_END (overlay);        oend = OVERLAY_END (overlay);
# Line 2632  overlays_in (beg, end, extend, vec_ptr, Line 2633  overlays_in (beg, end, extend, vec_ptr,
2633          next = startpos;          next = startpos;
2634      }      }
2635    
2636    for (tail = current_buffer->overlays_after;    for (tail = current_buffer->overlays_after; tail; tail = tail->next)
        GC_CONSP (tail);  
        tail = XCDR (tail))  
2637      {      {
2638        int startpos, endpos;        int startpos, endpos;
2639    
2640        overlay = XCAR (tail);        XSETMISC (overlay, tail);
2641    
2642        ostart = OVERLAY_START (overlay);        ostart = OVERLAY_START (overlay);
2643        oend = OVERLAY_END (overlay);        oend = OVERLAY_END (overlay);
# Line 2724  int Line 2723  int
2723  overlay_touches_p (pos)  overlay_touches_p (pos)
2724       int pos;       int pos;
2725  {  {
2726    Lisp_Object tail, overlay;    Lisp_Object overlay;
2727      struct Lisp_Overlay *tail;
2728    
2729    for (tail = current_buffer->overlays_before; GC_CONSP (tail);    for (tail = current_buffer->overlays_before; tail; tail = tail->next)
        tail = XCDR (tail))  
2730      {      {
2731        int endpos;        int endpos;
2732    
2733        overlay = XCAR (tail);        XSETMISC (overlay ,tail);
2734        if (!GC_OVERLAYP (overlay))        if (!GC_OVERLAYP (overlay))
2735          abort ();          abort ();
2736    
# Line 2742  overlay_touches_p (pos) Line 2741  overlay_touches_p (pos)
2741          return 1;          return 1;
2742      }      }
2743    
2744    for (tail = current_buffer->overlays_after; GC_CONSP (tail);    for (tail = current_buffer->overlays_after; tail; tail = tail->next)
        tail = XCDR (tail))  
2745      {      {
2746        int startpos;        int startpos;
2747    
2748        overlay = XCAR (tail);        XSETMISC (overlay, tail);
2749        if (!GC_OVERLAYP (overlay))        if (!GC_OVERLAYP (overlay))
2750          abort ();          abort ();
2751    
# Line 2946  overlay_strings (pos, w, pstr) Line 2944  overlay_strings (pos, w, pstr)
2944       struct window *w;       struct window *w;
2945       unsigned char **pstr;       unsigned char **pstr;
2946  {  {
2947    Lisp_Object ov, overlay, window, str;    Lisp_Object overlay, window, str;
2948      struct Lisp_Overlay *ov;
2949    int startpos, endpos;    int startpos, endpos;
2950    int multibyte = ! NILP (current_buffer->enable_multibyte_characters);    int multibyte = ! NILP (current_buffer->enable_multibyte_characters);
2951    
2952    overlay_heads.used = overlay_heads.bytes = 0;    overlay_heads.used = overlay_heads.bytes = 0;
2953    overlay_tails.used = overlay_tails.bytes = 0;    overlay_tails.used = overlay_tails.bytes = 0;
2954    for (ov = current_buffer->overlays_before; CONSP (ov); ov = XCDR (ov))    for (ov = current_buffer->overlays_before; ov; ov = ov->next)
2955      {      {
2956        overlay = XCAR (ov);        XSETMISC (overlay, ov);
2957        eassert (OVERLAYP (overlay));        eassert (OVERLAYP (overlay));
2958    
2959        startpos = OVERLAY_POSITION (OVERLAY_START (overlay));        startpos = OVERLAY_POSITION (OVERLAY_START (overlay));
# Line 2980  overlay_strings (pos, w, pstr) Line 2979  overlay_strings (pos, w, pstr)
2979                                 Foverlay_get (overlay, Qpriority),                                 Foverlay_get (overlay, Qpriority),
2980                                 endpos - startpos);                                 endpos - startpos);
2981      }      }
2982    for (ov = current_buffer->overlays_after; CONSP (ov); ov = XCDR (ov))    for (ov = current_buffer->overlays_after; ov; ov = ov->next)
2983      {      {
2984        overlay = XCAR (ov);        XSETMISC (overlay, ov);
2985        eassert (!OVERLAYP (overlay));        eassert (OVERLAYP (overlay));
2986    
2987        startpos = OVERLAY_POSITION (OVERLAY_START (overlay));        startpos = OVERLAY_POSITION (OVERLAY_START (overlay));
2988        endpos = OVERLAY_POSITION (OVERLAY_END (overlay));        endpos = OVERLAY_POSITION (OVERLAY_END (overlay));
# Line 3070  recenter_overlay_lists (buf, pos) Line 3069  recenter_overlay_lists (buf, pos)
3069       struct buffer *buf;       struct buffer *buf;
3070       EMACS_INT pos;       EMACS_INT pos;
3071  {  {
3072    Lisp_Object overlay, tail, next, prev, beg, end;    Lisp_Object overlay, beg, end;
3073      struct Lisp_Overlay *prev, *tail, *next;
3074    
3075    /* See if anything in overlays_before should move to overlays_after.  */    /* See if anything in overlays_before should move to overlays_after.  */
3076    
3077    /* We don't strictly need prev in this loop; it should always be nil.    /* We don't strictly need prev in this loop; it should always be nil.
3078       But we use it for symmetry and in case that should cease to be true       But we use it for symmetry and in case that should cease to be true
3079       with some future change.  */       with some future change.  */
3080    prev = Qnil;    prev = NULL;
3081    for (tail = buf->overlays_before;    for (tail = buf->overlays_before; tail; prev = tail, tail = next)
        CONSP (tail);  
        prev = tail, tail = next)  
3082      {      {
3083        next = XCDR (tail);        next = tail->next;
3084        overlay = XCAR (tail);        XSETMISC (overlay, tail);
3085    
3086        /* If the overlay is not valid, get rid of it.  */        /* If the overlay is not valid, get rid of it.  */
3087        if (!OVERLAY_VALID (overlay))        if (!OVERLAY_VALID (overlay))
# Line 3108  recenter_overlay_lists (buf, pos) Line 3106  recenter_overlay_lists (buf, pos)
3106          {          {
3107            /* OVERLAY needs to be moved.  */            /* OVERLAY needs to be moved.  */
3108            int where = OVERLAY_POSITION (beg);            int where = OVERLAY_POSITION (beg);
3109            Lisp_Object other, other_prev;            struct Lisp_Overlay *other, *other_prev;
3110    
3111            /* Splice the cons cell TAIL out of overlays_before.  */            /* Splice the cons cell TAIL out of overlays_before.  */
3112            if (!NILP (prev))            if (prev)
3113              XSETCDR (prev, next);              prev->next = next;
3114            else            else
3115              buf->overlays_before = next;              buf->overlays_before = next;
3116    
3117            /* Search thru overlays_after for where to put it.  */            /* Search thru overlays_after for where to put it.  */
3118            other_prev = Qnil;            other_prev = NULL;
3119            for (other = buf->overlays_after;            for (other = buf->overlays_after; other;
3120                 CONSP (other);                 other_prev = other, other = other->next)
                other_prev = other, other = XCDR (other))  
3121              {              {
3122                Lisp_Object otherbeg, otheroverlay;                Lisp_Object otherbeg, otheroverlay;
3123    
3124                otheroverlay = XCAR (other);                XSETMISC (otheroverlay, other);
3125                eassert (! OVERLAY_VALID (otheroverlay));                eassert (OVERLAY_VALID (otheroverlay));
3126    
3127                otherbeg = OVERLAY_START (otheroverlay);                otherbeg = OVERLAY_START (otheroverlay);
3128                if (OVERLAY_POSITION (otherbeg) >= where)                if (OVERLAY_POSITION (otherbeg) >= where)
# Line 3133  recenter_overlay_lists (buf, pos) Line 3130  recenter_overlay_lists (buf, pos)
3130              }              }
3131    
3132            /* Add TAIL to overlays_after before OTHER.  */            /* Add TAIL to overlays_after before OTHER.  */
3133            XSETCDR (tail, other);            tail->next = other;
3134            if (!NILP (other_prev))            if (other_prev)
3135              XSETCDR (other_prev, tail);              other_prev->next = tail;
3136            else            else
3137              buf->overlays_after = tail;              buf->overlays_after = tail;
3138            tail = prev;            tail = prev;
# Line 3148  recenter_overlay_lists (buf, pos) Line 3145  recenter_overlay_lists (buf, pos)
3145      }      }
3146    
3147    /* See if anything in overlays_after should be in overlays_before.  */    /* See if anything in overlays_after should be in overlays_before.  */
3148    prev = Qnil;    prev = NULL;
3149    for (tail = buf->overlays_after;    for (tail = buf->overlays_after; tail; prev = tail, tail = next)
        CONSP (tail);  
        prev = tail, tail = next)  
3150      {      {
3151        next = XCDR (tail);        next = tail->next;
3152        overlay = XCAR (tail);        XSETMISC (overlay, tail);
3153    
3154        /* If the overlay is not valid, get rid of it.  */        /* If the overlay is not valid, get rid of it.  */
3155        if (!OVERLAY_VALID (overlay))        if (!OVERLAY_VALID (overlay))
# Line 3184  recenter_overlay_lists (buf, pos) Line 3179  recenter_overlay_lists (buf, pos)
3179          {          {
3180            /* OVERLAY needs to be moved.  */            /* OVERLAY needs to be moved.  */
3181            int where = OVERLAY_POSITION (end);            int where = OVERLAY_POSITION (end);
3182            Lisp_Object other, other_prev;            struct Lisp_Overlay *other, *other_prev;
3183    
3184            /* Splice the cons cell TAIL out of overlays_after.  */            /* Splice the cons cell TAIL out of overlays_after.  */
3185            if (!NILP (prev))            if (prev)
3186              XSETCDR (prev, next);              prev->next = next;
3187            else            else
3188              buf->overlays_after = next;              buf->overlays_after = next;
3189    
3190            /* Search thru overlays_before for where to put it.  */            /* Search thru overlays_before for where to put it.  */
3191            other_prev = Qnil;            other_prev = NULL;
3192            for (other = buf->overlays_before;            for (other = buf->overlays_before; other;
3193                 CONSP (other);                 other_prev = other, other = other->next)
                other_prev = other, other = XCDR (other))  
3194              {              {
3195                Lisp_Object otherend, otheroverlay;                Lisp_Object otherend, otheroverlay;
3196    
3197                otheroverlay = XCAR (other);                XSETMISC (otheroverlay, other);
3198                eassert (! OVERLAY_VALID (otheroverlay));                eassert (OVERLAY_VALID (otheroverlay));
3199    
3200                otherend = OVERLAY_END (otheroverlay);                otherend = OVERLAY_END (otheroverlay);
3201                if (OVERLAY_POSITION (otherend) <= where)                if (OVERLAY_POSITION (otherend) <= where)
# Line 3209  recenter_overlay_lists (buf, pos) Line 3203  recenter_overlay_lists (buf, pos)
3203              }              }
3204    
3205            /* Add TAIL to overlays_before before OTHER.  */            /* Add TAIL to overlays_before before OTHER.  */
3206            XSETCDR (tail, other);            tail->next = other;
3207            if (!NILP (other_prev))            if (other_prev)
3208              XSETCDR (other_prev, tail);              other_prev->next = tail;
3209            else            else
3210              buf->overlays_before = tail;              buf->overlays_before = tail;
3211            tail = prev;            tail = prev;
# Line 3265  fix_overlays_in_range (start, end) Line 3259  fix_overlays_in_range (start, end)
3259       register int start, end;       register int start, end;
3260  {  {
3261    Lisp_Object overlay;    Lisp_Object overlay;
3262    Lisp_Object before_list, after_list;    struct Lisp_Overlay *before_list, *after_list;
3263    /* These are either nil, indicating that before_list or after_list    /* These are either nil, indicating that before_list or after_list
3264       should be assigned, or the cons cell the cdr of which should be       should be assigned, or the cons cell the cdr of which should be
3265       assigned.  */       assigned.  */
3266    Lisp_Object beforep = Qnil, afterp = Qnil;    struct Lisp_Overlay *beforep = NULL, *afterp = NULL;
3267    /* 'Parent', likewise, indicates a cons cell or    /* 'Parent', likewise, indicates a cons cell or
3268       current_buffer->overlays_before or overlays_after, depending       current_buffer->overlays_before or overlays_after, depending
3269       which loop we're in.  */       which loop we're in.  */
3270    Lisp_Object tail, parent;    struct Lisp_Overlay *tail, *parent;
3271    int startpos, endpos;    int startpos, endpos;
3272    
3273    /* This algorithm shifts links around instead of consing and GCing.    /* This algorithm shifts links around instead of consing and GCing.
# Line 3283  fix_overlays_in_range (start, end) Line 3277  fix_overlays_in_range (start, end)
3277       (after_list) if it is, is still uninitialized.  So it's not a bug       (after_list) if it is, is still uninitialized.  So it's not a bug
3278       that before_list isn't initialized, although it may look       that before_list isn't initialized, although it may look
3279       strange.  */       strange.  */
3280    for (parent = Qnil, tail = current_buffer->overlays_before; CONSP (tail);)    for (parent = NULL, tail = current_buffer->overlays_before; tail;)
3281      {      {
3282        overlay = XCAR (tail);        XSETMISC (overlay, tail);
3283        endpos = OVERLAY_POSITION (OVERLAY_END (overlay));        endpos = OVERLAY_POSITION (OVERLAY_END (overlay));
3284        if (endpos < start)        if (endpos < start)
3285          break;          break;
# Line 3307  fix_overlays_in_range (start, end) Line 3301  fix_overlays_in_range (start, end)
3301               recenter_overlay_lists will move it to the right place.  */               recenter_overlay_lists will move it to the right place.  */
3302            if (endpos < current_buffer->overlay_center)            if (endpos < current_buffer->overlay_center)
3303              {              {
3304                if (NILP (afterp))                if (!afterp)
3305                  after_list = tail;                  after_list = tail;
3306                else                else
3307                  XSETCDR (afterp, tail);                  afterp->next = tail;
3308                afterp = tail;                afterp = tail;
3309              }              }
3310            else            else
3311              {              {
3312                if (NILP (beforep))                if (!beforep)
3313                  before_list = tail;                  before_list = tail;
3314                else                else
3315                  XSETCDR (beforep, tail);                  beforep->next = tail;
3316                beforep = tail;                beforep = tail;
3317              }              }
3318            if (NILP (parent))            if (!parent)
3319              current_buffer->overlays_before = XCDR (tail);              current_buffer->overlays_before = tail->next;
3320            else            else
3321              XSETCDR (parent, XCDR (tail));              parent->next = tail->next;
3322            tail = XCDR (tail);            tail = tail->next;
3323          }          }
3324        else        else
3325          parent = tail, tail = XCDR (parent);          parent = tail, tail = parent->next;
3326      }      }
3327    for (parent = Qnil, tail = current_buffer->overlays_after; CONSP (tail);)    for (parent = NULL, tail = current_buffer->overlays_after; tail;)
3328      {      {
3329        overlay = XCAR (tail);        XSETMISC (overlay, tail);
3330        startpos = OVERLAY_POSITION (OVERLAY_START (overlay));        startpos = OVERLAY_POSITION (OVERLAY_START (overlay));
3331        if (startpos >= end)        if (startpos >= end)
3332          break;          break;
# Line 3351  fix_overlays_in_range (start, end) Line 3345  fix_overlays_in_range (start, end)
3345              }              }
3346            if (endpos < current_buffer->overlay_center)            if (endpos < current_buffer->overlay_center)
3347              {              {
3348                if (NILP (afterp))                if (!afterp)
3349                  after_list = tail;                  after_list = tail;
3350                else                else
3351                  XSETCDR (afterp, tail);                  afterp->next = tail;
3352                afterp = tail;                afterp = tail;
3353              }              }
3354            else            else
3355              {              {
3356                if (NILP (beforep))                if (!beforep)
3357                  before_list = tail;                  before_list = tail;
3358                else                else
3359                  XSETCDR (beforep, tail);                  beforep->next = tail;
3360                beforep = tail;                beforep = tail;
3361              }              }
3362            if (NILP (parent))            if (!parent)
3363              current_buffer->overlays_after = XCDR (tail);              current_buffer->overlays_after = tail->next;
3364            else            else
3365              XSETCDR (parent, XCDR (tail));              parent->next = tail->next;
3366            tail = XCDR (tail);            tail = tail->next;
3367          }          }
3368        else        else
3369          parent = tail, tail = XCDR (parent);          parent = tail, tail = parent->next;
3370      }      }
3371    
3372    /* Splice the constructed (wrong) lists into the buffer's lists,    /* Splice the constructed (wrong) lists into the buffer's lists,
3373       and let the recenter function make it sane again.  */       and let the recenter function make it sane again.  */
3374    if (!NILP (beforep))    if (beforep)
3375      {      {
3376        XSETCDR (beforep, current_buffer->overlays_before);        beforep->next = current_buffer->overlays_before;
3377        current_buffer->overlays_before = before_list;        current_buffer->overlays_before = before_list;
3378      }      }
3379    recenter_overlay_lists (current_buffer, current_buffer->overlay_center);    recenter_overlay_lists (current_buffer, current_buffer->overlay_center);
3380    
3381    if (!NILP (afterp))    if (afterp)
3382      {      {
3383        XSETCDR (afterp, current_buffer->overlays_after);        afterp->next = current_buffer->overlays_after;
3384        current_buffer->overlays_after = after_list;        current_buffer->overlays_after = after_list;
3385      }      }
3386    recenter_overlay_lists (current_buffer, current_buffer->overlay_center);    recenter_overlay_lists (current_buffer, current_buffer->overlay_center);
# Line 3409  fix_overlays_before (bp, prev, pos) Line 3403  fix_overlays_before (bp, prev, pos)
3403       struct buffer *bp;       struct buffer *bp;
3404       EMACS_INT prev, pos;       EMACS_INT prev, pos;
3405  {  {
3406    /* If parent is nil, replace overlays_before; otherwise, XCDR(parent).  */    /* If parent is nil, replace overlays_before; otherwise, parent->next.  */
3407    Lisp_Object tail = bp->overlays_before, parent = Qnil;    struct Lisp_Overlay *tail = bp->overlays_before, *parent = NULL, *right_pair;
3408    Lisp_Object right_pair;    Lisp_Object tem;
3409    EMACS_INT end;    EMACS_INT end;
3410    
3411    /* After the insertion, the several overlays may be in incorrect    /* After the insertion, the several overlays may be in incorrect
# Line 3425  fix_overlays_before (bp, prev, pos) Line 3419  fix_overlays_before (bp, prev, pos)
3419       in.  It is where an overlay which end before POS exists. (i.e. an       in.  It is where an overlay which end before POS exists. (i.e. an
3420       overlay whose ending marker is after-insertion-marker if disorder       overlay whose ending marker is after-insertion-marker if disorder
3421       exists).  */       exists).  */
3422    while (!NILP (tail)    while (tail
3423           && ((end = OVERLAY_POSITION (OVERLAY_END (XCAR (tail))))           && (XSETMISC (tem, tail),
3424               >= pos))               (end = OVERLAY_POSITION (OVERLAY_END (tem))) >= pos))
3425      {      {
3426        parent = tail;        parent = tail;
3427        tail = XCDR (tail);        tail = tail->next;
3428      }      }
3429    
3430    /* If we don't find such an overlay,    /* If we don't find such an overlay,
3431       or the found one ends before PREV,       or the found one ends before PREV,
3432       or the found one is the last one in the list,       or the found one is the last one in the list,
3433       we don't have to fix anything.  */       we don't have to fix anything.  */
3434    if (NILP (tail)    if (tail || end < prev || !tail->next)
       || end < prev  
       || NILP (XCDR (tail)))  
3435      return;      return;
3436    
3437    right_pair = parent;    right_pair = parent;
3438    parent = tail;    parent = tail;
3439    tail = XCDR (tail);    tail = tail->next;
3440    
3441    /* Now, end position of overlays in the list TAIL should be before    /* Now, end position of overlays in the list TAIL should be before
3442       or equal to PREV.  In the loop, an overlay which ends at POS is       or equal to PREV.  In the loop, an overlay which ends at POS is
3443       moved ahead to the place indicated by the CDR of RIGHT_PAIR.  If       moved ahead to the place indicated by the CDR of RIGHT_PAIR.  If
3444       we found an overlay which ends before PREV, the remaining       we found an overlay which ends before PREV, the remaining
3445       overlays are in correct order.  */       overlays are in correct order.  */
3446    while (!NILP (tail))    while (tail)
3447      {      {
3448        end = OVERLAY_POSITION (OVERLAY_END (XCAR (tail)));        XSETMISC (tem, tail);
3449          end = OVERLAY_POSITION (OVERLAY_END (tem));
3450    
3451        if (end == pos)        if (end == pos)
3452          {                       /* This overlay is disordered. */          {                       /* This overlay is disordered. */
3453            Lisp_Object found = tail;            struct Lisp_Overlay *found = tail;
3454    
3455            /* Unlink the found overlay.  */            /* Unlink the found overlay.  */
3456            tail = XCDR (found);            tail = found->next;
3457            XSETCDR (parent, tail);            parent->next = tail;
3458            /* Move an overlay at RIGHT_PLACE to the next of the found one,            /* Move an overlay at RIGHT_PLACE to the next of the found one,
3459               and link it into the right place.  */               and link it into the right place.  */
3460            if (NILP (right_pair))            if (!right_pair)
3461              {              {
3462                XSETCDR (found, bp->overlays_before);                found->next = bp->overlays_before;
3463                bp->overlays_before = found;                bp->overlays_before = found;
3464              }              }
3465            else            else
3466              {              {
3467                XSETCDR (found, XCDR (right_pair));                found->next = right_pair->next;
3468                XSETCDR (right_pair, found);                right_pair->next = found;
3469              }              }
3470          }          }
3471        else if (end == prev)        else if (end == prev)
3472          {          {
3473            parent = tail;            parent = tail;
3474            tail = XCDR (tail);            tail = tail->next;
3475          }          }
3476        else                      /* No more disordered overlay. */        else                      /* No more disordered overlay. */
3477          break;          break;
# Line 3543  rear delimiter advance when text is inse Line 3536  rear delimiter advance when text is inse
3536    XOVERLAY (overlay)->start = beg;    XOVERLAY (overlay)->start = beg;
3537    XOVERLAY (overlay)->end = end;    XOVERLAY (overlay)->end = end;
3538    XOVERLAY (overlay)->plist = Qnil;    XOVERLAY (overlay)->plist = Qnil;
3539      XOVERLAY (overlay)->next = NULL;
3540    
3541    /* Put the new overlay on the wrong list.  */    /* Put the new overlay on the wrong list.  */
3542    end = OVERLAY_END (overlay);    end = OVERLAY_END (overlay);
3543    if (OVERLAY_POSITION (end) < b->overlay_center)    if (OVERLAY_POSITION (end) < b->overlay_center)
3544      b->overlays_after = Fcons (overlay, b->overlays_after);      {
3545          if (b->overlays_after)
3546            XOVERLAY (overlay)->next = b->overlays_after;
3547          b->overlays_after = XOVERLAY (overlay);
3548        }
3549    else    else
3550      b->overlays_before = Fcons (overlay, b->overlays_before);      {
3551          if (b->overlays_before)
3552            XOVERLAY (overlay)->next = b->overlays_before;
3553          b->overlays_before = XOVERLAY (overlay);
3554        }
3555    
3556    /* This puts it in the right list, and in the right order.  */    /* This puts it in the right list, and in the right order.  */
3557    recenter_overlay_lists (b, b->overlay_center);    recenter_overlay_lists (b, b->overlay_center);
# Line 3590  modify_overlay (buf, start, end) Line 3592  modify_overlay (buf, start, end)
3592    
3593  Lisp_Object Fdelete_overlay ();  Lisp_Object Fdelete_overlay ();
3594    
3595    static struct Lisp_Overlay *
3596    unchain_overlay (list, overlay)
3597         struct Lisp_Overlay *list, *overlay;
3598    {
3599      struct Lisp_Overlay *tmp, *prev;
3600      for (tmp = list, prev = NULL; tmp; prev = tmp, tmp = tmp->next)
3601        if (tmp == overlay)
3602          {
3603            if (prev)
3604              prev->next = tmp->next;
3605            else
3606              list = tmp->next;
3607            overlay->next = NULL;
3608            break;
3609          }
3610      return list;
3611    }
3612    
3613  DEFUN ("move-overlay", Fmove_overlay, Smove_overlay, 3, 4, 0,  DEFUN ("move-overlay", Fmove_overlay, Smove_overlay, 3, 4, 0,
3614         doc: /* Set the endpoints of OVERLAY to BEG and END in BUFFER.         doc: /* Set the endpoints of OVERLAY to BEG and END in BUFFER.
3615  If BUFFER is omitted, leave OVERLAY in the same buffer it inhabits now.  If BUFFER is omitted, leave OVERLAY in the same buffer it inhabits now.
# Line 3674  buffer.  */) Line 3694  buffer.  */)
3694    
3695    if (!NILP (obuffer))    if (!NILP (obuffer))
3696      {      {
3697        ob->overlays_before = Fdelq (overlay, ob->overlays_before);        ob->overlays_before
3698        ob->overlays_after  = Fdelq (overlay, ob->overlays_after);          = unchain_overlay (ob->overlays_before, XOVERLAY (overlay));
3699          ob->overlays_after
3700            = unchain_overlay (ob->overlays_after, XOVERLAY (overlay));
3701          eassert (XOVERLAY (overlay)->next == NULL);
3702      }      }
3703    
3704    Fset_marker (OVERLAY_START (overlay), beg, buffer);    Fset_marker (OVERLAY_START (overlay), beg, buffer);
# Line 3684  buffer.  */) Line 3707  buffer.  */)
3707    /* Put the overlay on the wrong list.  */    /* Put the overlay on the wrong list.  */
3708    end = OVERLAY_END (overlay);    end = OVERLAY_END (overlay);
3709    if (OVERLAY_POSITION (end) < b->overlay_center)    if (OVERLAY_POSITION (end) < b->overlay_center)
3710      b->overlays_after = Fcons (overlay, b->overlays_after);      {
3711          if (b->overlays_after)
3712            XOVERLAY (overlay)->next = b->overlays_after;
3713        b->overlays_after = XOVERLAY (overlay);
3714        }
3715    else    else
3716      b->overlays_before = Fcons (overlay, b->overlays_before);      {
3717          if (b->overlays_before)
3718            XOVERLAY (overlay)->next = b->overlays_before;
3719        b->overlays_before = XOVERLAY (overlay);
3720        }
3721    
3722    /* This puts it in the right list, and in the right order.  */    /* This puts it in the right list, and in the right order.  */
3723    recenter_overlay_lists (b, b->overlay_center);    recenter_overlay_lists (b, b->overlay_center);
# Line 3712  DEFUN ("delete-overlay", Fdelete_overlay Line 3743  DEFUN ("delete-overlay", Fdelete_overlay
3743    b = XBUFFER (buffer);    b = XBUFFER (buffer);
3744    specbind (Qinhibit_quit, Qt);    specbind (Qinhibit_quit, Qt);
3745    
3746    b->overlays_before = Fdelq (overlay, b->overlays_before);    b->overlays_before = unchain_overlay (b->overlays_before,XOVERLAY (overlay));
3747    b->overlays_after = Fdelq (overlay, b->overlays_after);    b->overlays_after  = unchain_overlay (b->overlays_after, XOVERLAY (overlay));
3748      eassert (XOVERLAY (overlay)->next == NULL);
3749    modify_overlay (b,    modify_overlay (b,
3750                    marker_position (OVERLAY_START (overlay)),                    marker_position (OVERLAY_START (overlay)),
3751                    marker_position (OVERLAY_END   (overlay)));                    marker_position (OVERLAY_END   (overlay)));
# Line 3921  The lists you get are copies, so that ch Line 3953  The lists you get are copies, so that ch
3953  However, the overlays you get are the real objects that the buffer uses.  */)  However, the overlays you get are the real objects that the buffer uses.  */)
3954       ()       ()
3955  {  {
3956    Lisp_Object before, after;    struct Lisp_Overlay *ol;
3957    before = current_buffer->overlays_before;    Lisp_Object before = Qnil, after = Qnil, tmp;
3958    if (CONSP (before))    for (ol = current_buffer->overlays_before; ol; ol = ol->next)
3959      before = Fcopy_sequence (before);      {
3960    after = current_buffer->overlays_after;        XSETMISC (tmp, ol);
3961    if (CONSP (after))        before = Fcons (tmp, before);
3962      after = Fcopy_sequence (after);      }
3963      for (ol = current_buffer->overlays_after; ol; ol = ol->next)
3964    return Fcons (before, after);      {
3965          XSETMISC (tmp, ol);
3966          after = Fcons (tmp, after);
3967        }
3968      return Fcons (Fnreverse (before), Fnreverse (after));
3969  }  }
3970    
3971  DEFUN ("overlay-recenter", Foverlay_recenter, Soverlay_recenter, 1, 1, 0,  DEFUN ("overlay-recenter", Foverlay_recenter, Soverlay_recenter, 1, 1, 0,
# Line 4029  add_overlay_mod_hooklist (functionlist, Line 4065  add_overlay_mod_hooklist (functionlist,
4065               XVECTOR (last_overlay_modification_hooks)->contents,               XVECTOR (last_overlay_modification_hooks)->contents,
4066               sizeof (Lisp_Object) * oldsize);               sizeof (Lisp_Object) * oldsize);
4067      }      }
4068    XVECTOR (last_overlay_modification_hooks)->contents[last_overlay_modification_hooks_used++] = functionlist;    AREF (last_overlay_modification_hooks, last_overlay_modification_hooks_used++) = functionlist;
4069    XVECTOR (last_overlay_modification_hooks)->contents[last_overlay_modification_hooks_used++] = overlay;    AREF (last_overlay_modification_hooks, last_overlay_modification_hooks_used++) = overlay;
4070  }  }
4071    
4072  /* Run the modification-hooks of overlays that include  /* Run the modification-hooks of overlays that include
# Line 4053  report_overlay_modification (start, end, Line 4089  report_overlay_modification (start, end,
4089       int after;       int after;
4090       Lisp_Object arg1, arg2, arg3;       Lisp_Object arg1, arg2, arg3;
4091  {  {
4092    Lisp_Object prop, overlay, tail;    Lisp_Object prop, overlay;
4093      struct Lisp_Overlay *tail;
4094    /* 1 if this change is an insertion.  */    /* 1 if this change is an insertion.  */
4095    int insertion = (after ? XFASTINT (arg3) == 0 : EQ (start, end));    int insertion = (after ? XFASTINT (arg3) == 0 : EQ (start, end));
4096    struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;    struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
4097    
4098    overlay = Qnil;    overlay = Qnil;
4099    tail = Qnil;    tail = NULL;
4100    
4101    if (!after)    if (!after)
4102      {      {
4103        /* We are being called before a change.        /* We are being called before a change.
4104           Scan the overlays to find the functions to call.  */           Scan the overlays to find the functions to call.  */
4105        last_overlay_modification_hooks_used = 0;        last_overlay_modification_hooks_used = 0;
4106        for (tail = current_buffer->overlays_before;        for (tail = current_buffer->overlays_before; tail; tail = tail->next)
            CONSP (tail);  
            tail = XCDR (tail))  
4107          {          {
4108            int startpos, endpos;            int startpos, endpos;
4109            Lisp_Object ostart, oend;            Lisp_Object ostart, oend;
4110    
4111            overlay = XCAR (tail);            XSETMISC (overlay, tail);
4112    
4113            ostart = OVERLAY_START (overlay);            ostart = OVERLAY_START (overlay);
4114            oend = OVERLAY_END (overlay);            oend = OVERLAY_END (overlay);
# Line 4104  report_overlay_modification (start, end, Line 4139  report_overlay_modification (start, end,
4139                  add_overlay_mod_hooklist (prop, overlay);                  add_overlay_mod_hooklist (prop, overlay);
4140              }              }
4141          }          }
4142          
4143        for (tail = current_buffer->overlays_after;        for (tail = current_buffer->overlays_after; tail; tail = tail->next)
            CONSP (tail);  
            tail = XCDR (tail))  
4144          {          {
4145            int startpos, endpos;            int startpos, endpos;
4146            Lisp_Object ostart, oend;            Lisp_Object ostart, oend;
4147    
4148            overlay = XCAR (tail);            XSETMISC (overlay, tail);
4149    
4150            ostart = OVERLAY_START (overlay);            ostart = OVERLAY_START (overlay);
4151            oend = OVERLAY_END (overlay);            oend = OVERLAY_END (overlay);
# Line 4197  void Line 4230  void
4230  evaporate_overlays (pos)  evaporate_overlays (pos)
4231       EMACS_INT pos;       EMACS_INT pos;
4232  {  {
4233    Lisp_Object tail, overlay, hit_list;    Lisp_Object overlay, hit_list;
4234      struct Lisp_Overlay *tail;
4235    
4236    hit_list = Qnil;    hit_list = Qnil;
4237    if (pos <= current_buffer->overlay_center)    if (pos <= current_buffer->overlay_center)
4238      for (tail = current_buffer->overlays_before; CONSP (tail);      for (tail = current_buffer->overlays_before; tail; tail = tail->next)
          tail = XCDR (tail))  
4239        {        {
4240          int endpos;          int endpos;
4241          overlay = XCAR (tail);          XSETMISC (overlay, tail);
4242          endpos = OVERLAY_POSITION (OVERLAY_END (overlay));          endpos = OVERLAY_POSITION (OVERLAY_END (overlay));
4243          if (endpos < pos)          if (endpos < pos)
4244            break;            break;
# Line 4214  evaporate_overlays (pos) Line 4247  evaporate_overlays (pos)
4247            hit_list = Fcons (overlay, hit_list);            hit_list = Fcons (overlay, hit_list);
4248        }        }
4249    else    else
4250      for (tail = current_buffer->overlays_after; CONSP (tail);      for (tail = current_buffer->overlays_after; tail; tail = tail->next)
          tail = XCDR (tail))  
4251        {        {
4252          int startpos;          int startpos;
4253          overlay = XCAR (tail);          XSETMISC (overlay, tail);
4254          startpos = OVERLAY_POSITION (OVERLAY_START (overlay));          startpos = OVERLAY_POSITION (OVERLAY_START (overlay));
4255          if (startpos > pos)          if (startpos > pos)
4256            break;            break;
# Line 4858  init_buffer_once () Line 4890  init_buffer_once ()
4890    buffer_defaults.undo_list = Qnil;    buffer_defaults.undo_list = Qnil;
4891    buffer_defaults.mark_active = Qnil;    buffer_defaults.mark_active = Qnil;
4892    buffer_defaults.file_format = Qnil;    buffer_defaults.file_format = Qnil;
4893    buffer_defaults.overlays_before = Qnil;    buffer_defaults.overlays_before = NULL;
4894    buffer_defaults.overlays_after = Qnil;    buffer_defaults.overlays_after = NULL;
4895    buffer_defaults.overlay_center = BEG;    buffer_defaults.overlay_center = BEG;
4896    
4897    XSETFASTINT (buffer_defaults.tab_width, 8);    XSETFASTINT (buffer_defaults.tab_width, 8);

Legend:
Removed from v.1.430  
changed lines
  Added in v.1.431

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26