comparison src/search.c @ 89945:59dcbfe97385

Revision: miles@gnu.org--gnu-2004/emacs--unicode--0--patch-17 Merge from emacs--cvs-trunk--0 Patches applied: * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-417 - miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-419 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-420 Tweak permissions * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-421 - miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-430 Update from CVS
author Miles Bader <miles@gnu.org>
date Tue, 29 Jun 2004 16:46:06 +0000
parents 4c90ffeb71c5 b04610e283ce
children 6f6e9fe4658b
comparison
equal deleted inserted replaced
89944:ecb75580442e 89945:59dcbfe97385
2541 make_number (newpoint)); 2541 make_number (newpoint));
2542 2542
2543 /* Adjust search data for this change. */ 2543 /* Adjust search data for this change. */
2544 { 2544 {
2545 int oldend = search_regs.end[sub]; 2545 int oldend = search_regs.end[sub];
2546 int oldstart = search_regs.start[sub];
2546 int change = newpoint - search_regs.end[sub]; 2547 int change = newpoint - search_regs.end[sub];
2547 int i; 2548 int i;
2548 2549
2549 for (i = 0; i < search_regs.num_regs; i++) 2550 for (i = 0; i < search_regs.num_regs; i++)
2550 { 2551 {
2551 if (search_regs.start[i] > oldend) 2552 if (search_regs.start[i] >= oldend)
2552 search_regs.start[i] += change; 2553 search_regs.start[i] += change;
2553 if (search_regs.end[i] > oldend) 2554 else if (search_regs.start[i] > oldstart)
2555 search_regs.start[i] = oldstart;
2556 if (search_regs.end[i] >= oldend)
2554 search_regs.end[i] += change; 2557 search_regs.end[i] += change;
2558 else if (search_regs.end[i] > oldstart)
2559 search_regs.end[i] = oldstart;
2555 } 2560 }
2556 } 2561 }
2557 2562
2558 /* Put point back where it was in the text. */ 2563 /* Put point back where it was in the text. */
2559 if (opoint <= 0) 2564 if (opoint <= 0)
2618 Element 2N is `(match-beginning N)'; element 2N + 1 is `(match-end N)'. 2623 Element 2N is `(match-beginning N)'; element 2N + 1 is `(match-end N)'.
2619 All the elements are markers or nil (nil if the Nth pair didn't match) 2624 All the elements are markers or nil (nil if the Nth pair didn't match)
2620 if the last match was on a buffer; integers or nil if a string was matched. 2625 if the last match was on a buffer; integers or nil if a string was matched.
2621 Use `store-match-data' to reinstate the data in this list. 2626 Use `store-match-data' to reinstate the data in this list.
2622 2627
2623 If INTEGERS (the optional first argument) is non-nil, always use integers 2628 If INTEGERS (the optional first argument) is non-nil, always use
2624 \(rather than markers) to represent buffer positions. 2629 integers \(rather than markers) to represent buffer positions. In
2630 this case, and if the last match was in a buffer, the buffer will get
2631 stored as one additional element at the end of the list.
2632
2625 If REUSE is a list, reuse it as part of the value. If REUSE is long enough 2633 If REUSE is a list, reuse it as part of the value. If REUSE is long enough
2626 to hold all the values, and if INTEGERS is non-nil, no consing is done. 2634 to hold all the values, and if INTEGERS is non-nil, no consing is done.
2627 2635
2628 Return value is undefined if the last search failed. */) 2636 Return value is undefined if the last search failed. */)
2629 (integers, reuse) 2637 (integers, reuse)
2636 if (NILP (last_thing_searched)) 2644 if (NILP (last_thing_searched))
2637 return Qnil; 2645 return Qnil;
2638 2646
2639 prev = Qnil; 2647 prev = Qnil;
2640 2648
2641 data = (Lisp_Object *) alloca ((2 * search_regs.num_regs) 2649 data = (Lisp_Object *) alloca ((2 * search_regs.num_regs + 1)
2642 * sizeof (Lisp_Object)); 2650 * sizeof (Lisp_Object));
2643 2651
2644 len = -1; 2652 len = 0;
2645 for (i = 0; i < search_regs.num_regs; i++) 2653 for (i = 0; i < search_regs.num_regs; i++)
2646 { 2654 {
2647 int start = search_regs.start[i]; 2655 int start = search_regs.start[i];
2648 if (start >= 0) 2656 if (start >= 0)
2649 { 2657 {
2666 } 2674 }
2667 else 2675 else
2668 /* last_thing_searched must always be Qt, a buffer, or Qnil. */ 2676 /* last_thing_searched must always be Qt, a buffer, or Qnil. */
2669 abort (); 2677 abort ();
2670 2678
2671 len = i; 2679 len = 2*(i+1);
2672 } 2680 }
2673 else 2681 else
2674 data[2 * i] = data [2 * i + 1] = Qnil; 2682 data[2 * i] = data [2 * i + 1] = Qnil;
2675 } 2683 }
2676 2684
2685 if (BUFFERP(last_thing_searched)
2686 && ! NILP (integers))
2687 {
2688 XSETBUFFER(data[len], last_thing_searched);
2689 len++;
2690 }
2691
2677 /* If REUSE is not usable, cons up the values and return them. */ 2692 /* If REUSE is not usable, cons up the values and return them. */
2678 if (! CONSP (reuse)) 2693 if (! CONSP (reuse))
2679 return Flist (2 * len + 2, data); 2694 return Flist (len, data);
2680 2695
2681 /* If REUSE is a list, store as many value elements as will fit 2696 /* If REUSE is a list, store as many value elements as will fit
2682 into the elements of REUSE. */ 2697 into the elements of REUSE. */
2683 for (i = 0, tail = reuse; CONSP (tail); 2698 for (i = 0, tail = reuse; CONSP (tail);
2684 i++, tail = XCDR (tail)) 2699 i++, tail = XCDR (tail))
2685 { 2700 {
2686 if (i < 2 * len + 2) 2701 if (i < len)
2687 XSETCAR (tail, data[i]); 2702 XSETCAR (tail, data[i]);
2688 else 2703 else
2689 XSETCAR (tail, Qnil); 2704 XSETCAR (tail, Qnil);
2690 prev = tail; 2705 prev = tail;
2691 } 2706 }
2692 2707
2693 /* If we couldn't fit all value elements into REUSE, 2708 /* If we couldn't fit all value elements into REUSE,
2694 cons up the rest of them and add them to the end of REUSE. */ 2709 cons up the rest of them and add them to the end of REUSE. */
2695 if (i < 2 * len + 2) 2710 if (i < len)
2696 XSETCDR (prev, Flist (2 * len + 2 - i, data + i)); 2711 XSETCDR (prev, Flist (len - i, data + i));
2697 2712
2698 return reuse; 2713 return reuse;
2699 } 2714 }
2700 2715
2701 2716
2712 save_search_regs (); 2727 save_search_regs ();
2713 2728
2714 if (!CONSP (list) && !NILP (list)) 2729 if (!CONSP (list) && !NILP (list))
2715 list = wrong_type_argument (Qconsp, list); 2730 list = wrong_type_argument (Qconsp, list);
2716 2731
2717 /* Unless we find a marker with a buffer in LIST, assume that this 2732 /* Unless we find a marker with a buffer or an explicit buffer
2718 match data came from a string. */ 2733 in LIST, assume that this match data came from a string. */
2719 last_thing_searched = Qt; 2734 last_thing_searched = Qt;
2720 2735
2721 /* Allocate registers if they don't already exist. */ 2736 /* Allocate registers if they don't already exist. */
2722 { 2737 {
2723 int length = XFASTINT (Flength (list)) / 2; 2738 int length = XFASTINT (Flength (list)) / 2;
2744 for (i = search_regs.num_regs; i < length; i++) 2759 for (i = search_regs.num_regs; i < length; i++)
2745 search_regs.start[i] = -1; 2760 search_regs.start[i] = -1;
2746 2761
2747 search_regs.num_regs = length; 2762 search_regs.num_regs = length;
2748 } 2763 }
2764
2765 for (i = 0;; i++)
2766 {
2767 marker = Fcar (list);
2768 if (BUFFERP(marker))
2769 {
2770 XSETBUFFER(last_thing_searched, marker);
2771 break;
2772 }
2773 if (i >= length)
2774 break;
2775 if (NILP (marker))
2776 {
2777 search_regs.start[i] = -1;
2778 list = Fcdr (list);
2779 }
2780 else
2781 {
2782 int from;
2783
2784 if (MARKERP (marker))
2785 {
2786 if (XMARKER (marker)->buffer == 0)
2787 XSETFASTINT (marker, 0);
2788 else
2789 XSETBUFFER (last_thing_searched, XMARKER (marker)->buffer);
2790 }
2791
2792 CHECK_NUMBER_COERCE_MARKER (marker);
2793 from = XINT (marker);
2794 list = Fcdr (list);
2795
2796 marker = Fcar (list);
2797 if (MARKERP (marker) && XMARKER (marker)->buffer == 0)
2798 XSETFASTINT (marker, 0);
2799
2800 CHECK_NUMBER_COERCE_MARKER (marker);
2801 search_regs.start[i] = from;
2802 search_regs.end[i] = XINT (marker);
2803 }
2804 list = Fcdr (list);
2805 }
2806
2807 for (; i < search_regs.num_regs; i++)
2808 search_regs.start[i] = -1;
2749 } 2809 }
2750
2751 for (i = 0; i < search_regs.num_regs; i++)
2752 {
2753 marker = Fcar (list);
2754 if (NILP (marker))
2755 {
2756 search_regs.start[i] = -1;
2757 list = Fcdr (list);
2758 }
2759 else
2760 {
2761 int from;
2762
2763 if (MARKERP (marker))
2764 {
2765 if (XMARKER (marker)->buffer == 0)
2766 XSETFASTINT (marker, 0);
2767 else
2768 XSETBUFFER (last_thing_searched, XMARKER (marker)->buffer);
2769 }
2770
2771 CHECK_NUMBER_COERCE_MARKER (marker);
2772 from = XINT (marker);
2773 list = Fcdr (list);
2774
2775 marker = Fcar (list);
2776 if (MARKERP (marker) && XMARKER (marker)->buffer == 0)
2777 XSETFASTINT (marker, 0);
2778
2779 CHECK_NUMBER_COERCE_MARKER (marker);
2780 search_regs.start[i] = from;
2781 search_regs.end[i] = XINT (marker);
2782 }
2783 list = Fcdr (list);
2784 }
2785 2810
2786 return Qnil; 2811 return Qnil;
2787 } 2812 }
2788 2813
2789 /* If non-zero the match data have been saved in saved_search_regs 2814 /* If non-zero the match data have been saved in saved_search_regs
2790 during the execution of a sentinel or filter. */ 2815 during the execution of a sentinel or filter. */
2791 static int search_regs_saved; 2816 static int search_regs_saved;
2792 static struct re_registers saved_search_regs; 2817 static struct re_registers saved_search_regs;
2818 static Lisp_Object saved_last_thing_searched;
2793 2819
2794 /* Called from Flooking_at, Fstring_match, search_buffer, Fstore_match_data 2820 /* Called from Flooking_at, Fstring_match, search_buffer, Fstore_match_data
2795 if asynchronous code (filter or sentinel) is running. */ 2821 if asynchronous code (filter or sentinel) is running. */
2796 static void 2822 static void
2797 save_search_regs () 2823 save_search_regs ()
2799 if (!search_regs_saved) 2825 if (!search_regs_saved)
2800 { 2826 {
2801 saved_search_regs.num_regs = search_regs.num_regs; 2827 saved_search_regs.num_regs = search_regs.num_regs;
2802 saved_search_regs.start = search_regs.start; 2828 saved_search_regs.start = search_regs.start;
2803 saved_search_regs.end = search_regs.end; 2829 saved_search_regs.end = search_regs.end;
2830 saved_last_thing_searched = last_thing_searched;
2831 last_thing_searched = Qnil;
2804 search_regs.num_regs = 0; 2832 search_regs.num_regs = 0;
2805 search_regs.start = 0; 2833 search_regs.start = 0;
2806 search_regs.end = 0; 2834 search_regs.end = 0;
2807 2835
2808 search_regs_saved = 1; 2836 search_regs_saved = 1;
2821 xfree (search_regs.end); 2849 xfree (search_regs.end);
2822 } 2850 }
2823 search_regs.num_regs = saved_search_regs.num_regs; 2851 search_regs.num_regs = saved_search_regs.num_regs;
2824 search_regs.start = saved_search_regs.start; 2852 search_regs.start = saved_search_regs.start;
2825 search_regs.end = saved_search_regs.end; 2853 search_regs.end = saved_search_regs.end;
2826 2854 last_thing_searched = saved_last_thing_searched;
2855 saved_last_thing_searched = Qnil;
2827 search_regs_saved = 0; 2856 search_regs_saved = 0;
2828 } 2857 }
2829 } 2858 }
2830 2859
2831 /* Quote a string to inactivate reg-expr chars */ 2860 /* Quote a string to inactivate reg-expr chars */