comparison src/textprop.c @ 32849:e1dec7e5a57c

(get_char_property_and_overlay): New function. (Fget_char_property): Use it.
author Miles Bader <miles@gnu.org>
date Wed, 25 Oct 2000 05:14:01 +0000
parents f886557e4b2a
children ca22422634ac
comparison
equal deleted inserted replaced
32848:6957ecbc11fe 32849:e1dec7e5a57c
555 Lisp_Object prop; 555 Lisp_Object prop;
556 { 556 {
557 return textget (Ftext_properties_at (position, object), prop); 557 return textget (Ftext_properties_at (position, object), prop);
558 } 558 }
559 559
560 /* Return the value of POSITION's property PROP, in OBJECT.
561 OBJECT is optional and defaults to the current buffer.
562 If OVERLAY is non-0, then in the case that the returned property is from
563 an overlay, the overlay found is returned in *OVERLAY, otherwise nil is
564 returned in *OVERLAY.
565 If POSITION is at the end of OBJECT, the value is nil.
566 If OBJECT is a buffer, then overlay properties are considered as well as
567 text properties.
568 If OBJECT is a window, then that window's buffer is used, but
569 window-specific overlays are considered only if they are associated
570 with OBJECT. */
571 Lisp_Object
572 get_char_property_and_overlay (position, prop, object, overlay)
573 Lisp_Object position, object;
574 register Lisp_Object prop;
575 Lisp_Object *overlay;
576 {
577 struct window *w = 0;
578
579 CHECK_NUMBER_COERCE_MARKER (position, 0);
580
581 if (NILP (object))
582 XSETBUFFER (object, current_buffer);
583
584 if (WINDOWP (object))
585 {
586 w = XWINDOW (object);
587 object = w->buffer;
588 }
589 if (BUFFERP (object))
590 {
591 int posn = XINT (position);
592 int noverlays;
593 Lisp_Object *overlay_vec, tem;
594 int next_overlay;
595 int len;
596 struct buffer *obuf = current_buffer;
597
598 set_buffer_temp (XBUFFER (object));
599
600 /* First try with room for 40 overlays. */
601 len = 40;
602 overlay_vec = (Lisp_Object *) alloca (len * sizeof (Lisp_Object));
603
604 noverlays = overlays_at (posn, 0, &overlay_vec, &len,
605 &next_overlay, NULL, 0);
606
607 /* If there are more than 40,
608 make enough space for all, and try again. */
609 if (noverlays > len)
610 {
611 len = noverlays;
612 overlay_vec = (Lisp_Object *) alloca (len * sizeof (Lisp_Object));
613 noverlays = overlays_at (posn, 0, &overlay_vec, &len,
614 &next_overlay, NULL, 0);
615 }
616 noverlays = sort_overlays (overlay_vec, noverlays, w);
617
618 set_buffer_temp (obuf);
619
620 /* Now check the overlays in order of decreasing priority. */
621 while (--noverlays >= 0)
622 {
623 tem = Foverlay_get (overlay_vec[noverlays], prop);
624 if (!NILP (tem))
625 {
626 if (overlay)
627 /* Return the overlay we got the property from. */
628 *overlay = overlay_vec[noverlays];
629 return tem;
630 }
631 }
632 }
633
634 if (overlay)
635 /* Indicate that the return value is not from an overlay. */
636 *overlay = Qnil;
637
638 /* Not a buffer, or no appropriate overlay, so fall through to the
639 simpler case. */
640 return Fget_text_property (position, prop, object);
641 }
642
560 DEFUN ("get-char-property", Fget_char_property, Sget_char_property, 2, 3, 0, 643 DEFUN ("get-char-property", Fget_char_property, Sget_char_property, 2, 3, 0,
561 "Return the value of POSITION's property PROP, in OBJECT.\n\ 644 "Return the value of POSITION's property PROP, in OBJECT.\n\
562 OBJECT is optional and defaults to the current buffer.\n\ 645 OBJECT is optional and defaults to the current buffer.\n\
563 If POSITION is at the end of OBJECT, the value is nil.\n\ 646 If POSITION is at the end of OBJECT, the value is nil.\n\
564 If OBJECT is a buffer, then overlay properties are considered as well as\n\ 647 If OBJECT is a buffer, then overlay properties are considered as well as\n\
567 overlays are considered only if they are associated with OBJECT.") 650 overlays are considered only if they are associated with OBJECT.")
568 (position, prop, object) 651 (position, prop, object)
569 Lisp_Object position, object; 652 Lisp_Object position, object;
570 register Lisp_Object prop; 653 register Lisp_Object prop;
571 { 654 {
572 struct window *w = 0; 655 return get_char_property_and_overlay (position, prop, object, 0);
573
574 CHECK_NUMBER_COERCE_MARKER (position, 0);
575
576 if (NILP (object))
577 XSETBUFFER (object, current_buffer);
578
579 if (WINDOWP (object))
580 {
581 w = XWINDOW (object);
582 object = w->buffer;
583 }
584 if (BUFFERP (object))
585 {
586 int posn = XINT (position);
587 int noverlays;
588 Lisp_Object *overlay_vec, tem;
589 int next_overlay;
590 int len;
591 struct buffer *obuf = current_buffer;
592
593 set_buffer_temp (XBUFFER (object));
594
595 /* First try with room for 40 overlays. */
596 len = 40;
597 overlay_vec = (Lisp_Object *) alloca (len * sizeof (Lisp_Object));
598
599 noverlays = overlays_at (posn, 0, &overlay_vec, &len,
600 &next_overlay, NULL, 0);
601
602 /* If there are more than 40,
603 make enough space for all, and try again. */
604 if (noverlays > len)
605 {
606 len = noverlays;
607 overlay_vec = (Lisp_Object *) alloca (len * sizeof (Lisp_Object));
608 noverlays = overlays_at (posn, 0, &overlay_vec, &len,
609 &next_overlay, NULL, 0);
610 }
611 noverlays = sort_overlays (overlay_vec, noverlays, w);
612
613 set_buffer_temp (obuf);
614
615 /* Now check the overlays in order of decreasing priority. */
616 while (--noverlays >= 0)
617 {
618 tem = Foverlay_get (overlay_vec[noverlays], prop);
619 if (!NILP (tem))
620 return (tem);
621 }
622 }
623 /* Not a buffer, or no appropriate overlay, so fall through to the
624 simpler case. */
625 return (Fget_text_property (position, prop, object));
626 } 656 }
627 657
628 DEFUN ("next-char-property-change", Fnext_char_property_change, 658 DEFUN ("next-char-property-change", Fnext_char_property_change,
629 Snext_char_property_change, 1, 2, 0, 659 Snext_char_property_change, 1, 2, 0,
630 "Return the position of next text property or overlay change.\n\ 660 "Return the position of next text property or overlay change.\n\