Mercurial > emacs
comparison src/search.c @ 90192:173dee4e2611
Revision: miles@gnu.org--gnu-2005/emacs--unicode--0--patch-61
Merge from emacs--cvs-trunk--0
Patches applied:
* emacs--cvs-trunk--0 (patch 353-357)
- Update from CVS
author | Miles Bader <miles@gnu.org> |
---|---|
date | Thu, 09 Jun 2005 07:13:03 +0000 |
parents | e465b832ab21 3f80de0be046 |
children | b7da78284d4c |
comparison
equal
deleted
inserted
replaced
90191:c766b49f5bbd | 90192:173dee4e2611 |
---|---|
2699 Lisp_Object subexp; | 2699 Lisp_Object subexp; |
2700 { | 2700 { |
2701 return match_limit (subexp, 0); | 2701 return match_limit (subexp, 0); |
2702 } | 2702 } |
2703 | 2703 |
2704 DEFUN ("match-data", Fmatch_data, Smatch_data, 0, 2, 0, | 2704 DEFUN ("match-data", Fmatch_data, Smatch_data, 0, 3, 0, |
2705 doc: /* Return a list containing all info on what the last search matched. | 2705 doc: /* Return a list containing all info on what the last search matched. |
2706 Element 2N is `(match-beginning N)'; element 2N + 1 is `(match-end N)'. | 2706 Element 2N is `(match-beginning N)'; element 2N + 1 is `(match-end N)'. |
2707 All the elements are markers or nil (nil if the Nth pair didn't match) | 2707 All the elements are markers or nil (nil if the Nth pair didn't match) |
2708 if the last match was on a buffer; integers or nil if a string was matched. | 2708 if the last match was on a buffer; integers or nil if a string was matched. |
2709 Use `store-match-data' to reinstate the data in this list. | 2709 Use `store-match-data' to reinstate the data in this list. |
2711 If INTEGERS (the optional first argument) is non-nil, always use | 2711 If INTEGERS (the optional first argument) is non-nil, always use |
2712 integers \(rather than markers) to represent buffer positions. In | 2712 integers \(rather than markers) to represent buffer positions. In |
2713 this case, and if the last match was in a buffer, the buffer will get | 2713 this case, and if the last match was in a buffer, the buffer will get |
2714 stored as one additional element at the end of the list. | 2714 stored as one additional element at the end of the list. |
2715 | 2715 |
2716 If REUSE is a list, reuse it as part of the value. If REUSE is long enough | 2716 If REUSE is a list, reuse it as part of the value. If REUSE is long |
2717 to hold all the values, and if INTEGERS is non-nil, no consing is done. | 2717 enough to hold all the values, and if INTEGERS is non-nil, no consing |
2718 is done. | |
2719 | |
2720 If optional third arg RESEAT is non-nil, any previous markers on the | |
2721 REUSE list will be modified to point to nowhere. | |
2722 | |
2723 If RESEAT is `evaporate', put markers back on the free list. | |
2724 Note: No other references to the markers must exist if you use this. | |
2718 | 2725 |
2719 Return value is undefined if the last search failed. */) | 2726 Return value is undefined if the last search failed. */) |
2720 (integers, reuse) | 2727 (integers, reuse, reseat) |
2721 Lisp_Object integers, reuse; | 2728 Lisp_Object integers, reuse, reseat; |
2722 { | 2729 { |
2723 Lisp_Object tail, prev; | 2730 Lisp_Object tail, prev; |
2724 Lisp_Object *data; | 2731 Lisp_Object *data; |
2725 int i, len; | 2732 int i, len; |
2733 | |
2734 if (!NILP (reseat)) | |
2735 for (tail = reuse; CONSP (tail); tail = XCDR (tail)) | |
2736 if (MARKERP (XCAR (tail))) | |
2737 { | |
2738 if (EQ (reseat, Qevaporate)) | |
2739 free_marker (XCAR (tail)); | |
2740 else | |
2741 unchain_marker (XMARKER (XCAR (tail))); | |
2742 XSETCAR (tail, Qnil); | |
2743 } | |
2726 | 2744 |
2727 if (NILP (last_thing_searched)) | 2745 if (NILP (last_thing_searched)) |
2728 return Qnil; | 2746 return Qnil; |
2729 | 2747 |
2730 prev = Qnil; | 2748 prev = Qnil; |
2757 } | 2775 } |
2758 else | 2776 else |
2759 /* last_thing_searched must always be Qt, a buffer, or Qnil. */ | 2777 /* last_thing_searched must always be Qt, a buffer, or Qnil. */ |
2760 abort (); | 2778 abort (); |
2761 | 2779 |
2762 len = 2*(i+1); | 2780 len = 2 * i + 2; |
2763 } | 2781 } |
2764 else | 2782 else |
2765 data[2 * i] = data [2 * i + 1] = Qnil; | 2783 data[2 * i] = data[2 * i + 1] = Qnil; |
2766 } | 2784 } |
2767 | 2785 |
2768 if (BUFFERP (last_thing_searched) && !NILP (integers)) | 2786 if (BUFFERP (last_thing_searched) && !NILP (integers)) |
2769 { | 2787 { |
2770 data[len] = last_thing_searched; | 2788 data[len] = last_thing_searched; |
2794 | 2812 |
2795 return reuse; | 2813 return reuse; |
2796 } | 2814 } |
2797 | 2815 |
2798 | 2816 |
2799 DEFUN ("set-match-data", Fset_match_data, Sset_match_data, 1, 1, 0, | 2817 DEFUN ("set-match-data", Fset_match_data, Sset_match_data, 1, 2, 0, |
2800 doc: /* Set internal data on last search match from elements of LIST. | 2818 doc: /* Set internal data on last search match from elements of LIST. |
2801 LIST should have been created by calling `match-data' previously. */) | 2819 LIST should have been created by calling `match-data' previously. |
2802 (list) | 2820 |
2803 register Lisp_Object list; | 2821 If optional arg RESEAT is non-nil, make markers on LIST point nowhere. |
2822 If RESEAT is `evaporate', put the markers back on the free list. | |
2823 Note: No other references to the markers must exist if you use this. */) | |
2824 (list, reseat) | |
2825 register Lisp_Object list, reseat; | |
2804 { | 2826 { |
2805 register int i; | 2827 register int i; |
2806 register Lisp_Object marker; | 2828 register Lisp_Object marker; |
2807 | 2829 |
2808 if (running_asynch_code) | 2830 if (running_asynch_code) |
2842 search_regs.start[i] = -1; | 2864 search_regs.start[i] = -1; |
2843 | 2865 |
2844 search_regs.num_regs = length; | 2866 search_regs.num_regs = length; |
2845 } | 2867 } |
2846 | 2868 |
2847 for (i = 0;; i++) | 2869 for (i = 0; CONSP (list); i++) |
2848 { | 2870 { |
2849 marker = Fcar (list); | 2871 marker = XCAR (list); |
2850 if (BUFFERP (marker)) | 2872 if (BUFFERP (marker)) |
2851 { | 2873 { |
2852 last_thing_searched = marker; | 2874 last_thing_searched = marker; |
2853 break; | 2875 break; |
2854 } | 2876 } |
2855 if (i >= length) | 2877 if (i >= length) |
2856 break; | 2878 break; |
2857 if (NILP (marker)) | 2879 if (NILP (marker)) |
2858 { | 2880 { |
2859 search_regs.start[i] = -1; | 2881 search_regs.start[i] = -1; |
2860 list = Fcdr (list); | 2882 list = XCDR (list); |
2861 } | 2883 } |
2862 else | 2884 else |
2863 { | 2885 { |
2864 int from; | 2886 int from; |
2865 | 2887 Lisp_Object m; |
2888 | |
2889 m = marker; | |
2866 if (MARKERP (marker)) | 2890 if (MARKERP (marker)) |
2867 { | 2891 { |
2868 if (XMARKER (marker)->buffer == 0) | 2892 if (XMARKER (marker)->buffer == 0) |
2869 XSETFASTINT (marker, 0); | 2893 XSETFASTINT (marker, 0); |
2870 else | 2894 else |
2871 XSETBUFFER (last_thing_searched, XMARKER (marker)->buffer); | 2895 XSETBUFFER (last_thing_searched, XMARKER (marker)->buffer); |
2872 } | 2896 } |
2873 | 2897 |
2874 CHECK_NUMBER_COERCE_MARKER (marker); | 2898 CHECK_NUMBER_COERCE_MARKER (marker); |
2875 from = XINT (marker); | 2899 from = XINT (marker); |
2876 list = Fcdr (list); | 2900 |
2877 | 2901 if (!NILP (reseat) && MARKERP (m)) |
2878 marker = Fcar (list); | 2902 { |
2903 if (EQ (reseat, Qevaporate)) | |
2904 free_marker (m); | |
2905 else | |
2906 unchain_marker (XMARKER (m)); | |
2907 XSETCAR (list, Qnil); | |
2908 } | |
2909 | |
2910 if ((list = XCDR (list), !CONSP (list))) | |
2911 break; | |
2912 | |
2913 m = marker = XCAR (list); | |
2914 | |
2879 if (MARKERP (marker) && XMARKER (marker)->buffer == 0) | 2915 if (MARKERP (marker) && XMARKER (marker)->buffer == 0) |
2880 XSETFASTINT (marker, 0); | 2916 XSETFASTINT (marker, 0); |
2881 | 2917 |
2882 CHECK_NUMBER_COERCE_MARKER (marker); | 2918 CHECK_NUMBER_COERCE_MARKER (marker); |
2883 search_regs.start[i] = from; | 2919 search_regs.start[i] = from; |
2884 search_regs.end[i] = XINT (marker); | 2920 search_regs.end[i] = XINT (marker); |
2921 | |
2922 if (!NILP (reseat) && MARKERP (m)) | |
2923 { | |
2924 if (EQ (reseat, Qevaporate)) | |
2925 free_marker (m); | |
2926 else | |
2927 unchain_marker (XMARKER (m)); | |
2928 XSETCAR (list, Qnil); | |
2929 } | |
2885 } | 2930 } |
2886 list = Fcdr (list); | 2931 list = XCDR (list); |
2887 } | 2932 } |
2888 | 2933 |
2889 for (; i < search_regs.num_regs; i++) | 2934 for (; i < search_regs.num_regs; i++) |
2890 search_regs.start[i] = -1; | 2935 search_regs.start[i] = -1; |
2891 } | 2936 } |
2919 } | 2964 } |
2920 } | 2965 } |
2921 | 2966 |
2922 /* Called upon exit from filters and sentinels. */ | 2967 /* Called upon exit from filters and sentinels. */ |
2923 void | 2968 void |
2924 restore_match_data () | 2969 restore_search_regs () |
2925 { | 2970 { |
2926 if (search_regs_saved) | 2971 if (search_regs_saved) |
2927 { | 2972 { |
2928 if (search_regs.num_regs > 0) | 2973 if (search_regs.num_regs > 0) |
2929 { | 2974 { |
2935 search_regs.end = saved_search_regs.end; | 2980 search_regs.end = saved_search_regs.end; |
2936 last_thing_searched = saved_last_thing_searched; | 2981 last_thing_searched = saved_last_thing_searched; |
2937 saved_last_thing_searched = Qnil; | 2982 saved_last_thing_searched = Qnil; |
2938 search_regs_saved = 0; | 2983 search_regs_saved = 0; |
2939 } | 2984 } |
2985 } | |
2986 | |
2987 static Lisp_Object | |
2988 unwind_set_match_data (list) | |
2989 Lisp_Object list; | |
2990 { | |
2991 return Fset_match_data (list, Qevaporate); | |
2992 } | |
2993 | |
2994 /* Called to unwind protect the match data. */ | |
2995 void | |
2996 record_unwind_save_match_data () | |
2997 { | |
2998 record_unwind_protect (unwind_set_match_data, | |
2999 Fmatch_data (Qnil, Qnil, Qnil)); | |
2940 } | 3000 } |
2941 | 3001 |
2942 /* Quote a string to inactivate reg-expr chars */ | 3002 /* Quote a string to inactivate reg-expr chars */ |
2943 | 3003 |
2944 DEFUN ("regexp-quote", Fregexp_quote, Sregexp_quote, 1, 1, 0, | 3004 DEFUN ("regexp-quote", Fregexp_quote, Sregexp_quote, 1, 1, 0, |