Mercurial > hg > xemacs-beta
comparison src/search.c @ 469:ccaeb2a3c329
[xemacs-hg @ 2001-04-13 15:04:38 by michaels]
2001-03-31 Mike Sperber <mike@xemacs.org>
* search.c (Freplace_match): [Again] support FSF-style
specification of match subexpression when applied to a buffer.
author | michaels |
---|---|
date | Fri, 13 Apr 2001 15:04:40 +0000 |
parents | 0784d089fdc9 |
children | 7039e6323819 |
comparison
equal
deleted
inserted
replaced
468:20ae8821c23d | 469:ccaeb2a3c329 |
---|---|
2243 When fourth argument is a string, fifth argument STRBUFFER specifies | 2243 When fourth argument is a string, fifth argument STRBUFFER specifies |
2244 the buffer to be used for syntax-table and case-table lookup and | 2244 the buffer to be used for syntax-table and case-table lookup and |
2245 defaults to the current buffer. When fourth argument is not a string, | 2245 defaults to the current buffer. When fourth argument is not a string, |
2246 the buffer that the match occurred in has automatically been remembered | 2246 the buffer that the match occurred in has automatically been remembered |
2247 and you do not need to specify it. | 2247 and you do not need to specify it. |
2248 | |
2249 When fourth argument is nil, STRBUFFER specifies a subexpression of | |
2250 the match. It says to replace just that subexpression instead of the | |
2251 whole match. This is useful only after a regular expression search or | |
2252 match since only regular expressions have distinguished subexpressions. | |
2248 */ | 2253 */ |
2249 (replacement, fixedcase, literal, string, strbuffer)) | 2254 (replacement, fixedcase, literal, string, strbuffer)) |
2250 { | 2255 { |
2251 /* This function has been Mule-ized. */ | 2256 /* This function has been Mule-ized. */ |
2252 /* This function can GC */ | 2257 /* This function can GC */ |
2262 Lisp_Char_Table *syntax_table; | 2267 Lisp_Char_Table *syntax_table; |
2263 int mc_count; | 2268 int mc_count; |
2264 Lisp_Object buffer; | 2269 Lisp_Object buffer; |
2265 int_dynarr *ul_action_dynarr = 0; | 2270 int_dynarr *ul_action_dynarr = 0; |
2266 int_dynarr *ul_pos_dynarr = 0; | 2271 int_dynarr *ul_pos_dynarr = 0; |
2272 int sub; | |
2267 int speccount; | 2273 int speccount; |
2268 | 2274 |
2269 CHECK_STRING (replacement); | 2275 CHECK_STRING (replacement); |
2270 | 2276 |
2271 if (! NILP (string)) | 2277 if (! NILP (string)) |
2282 buf = decode_buffer (strbuffer, 0); | 2288 buf = decode_buffer (strbuffer, 0); |
2283 XSETBUFFER (buffer, buf); | 2289 XSETBUFFER (buffer, buf); |
2284 } | 2290 } |
2285 else | 2291 else |
2286 { | 2292 { |
2293 if (NILP (strbuffer)) | |
2294 sub = 0; | |
2295 else | |
2296 { | |
2297 CHECK_INT (strbuffer); | |
2298 sub = XINT (strbuffer); | |
2299 if (sub < 0 || sub >= (int) search_regs.num_regs) | |
2300 args_out_of_range (strbuffer, make_int (search_regs.num_regs)); | |
2301 } | |
2287 if (!BUFFERP (last_thing_searched)) | 2302 if (!BUFFERP (last_thing_searched)) |
2288 error ("last thing matched was not a buffer"); | 2303 error ("last thing matched was not a buffer"); |
2289 buffer = last_thing_searched; | 2304 buffer = last_thing_searched; |
2290 buf = XBUFFER (buffer); | 2305 buf = XBUFFER (buffer); |
2291 } | 2306 } |
2298 if (search_regs.num_regs == 0) | 2313 if (search_regs.num_regs == 0) |
2299 error ("replace-match called before any match found"); | 2314 error ("replace-match called before any match found"); |
2300 | 2315 |
2301 if (NILP (string)) | 2316 if (NILP (string)) |
2302 { | 2317 { |
2303 if (search_regs.start[0] < BUF_BEGV (buf) | 2318 if (search_regs.start[sub] < BUF_BEGV (buf) |
2304 || search_regs.start[0] > search_regs.end[0] | 2319 || search_regs.start[sub] > search_regs.end[sub] |
2305 || search_regs.end[0] > BUF_ZV (buf)) | 2320 || search_regs.end[sub] > BUF_ZV (buf)) |
2306 args_out_of_range (make_int (search_regs.start[0]), | 2321 args_out_of_range (make_int (search_regs.start[sub]), |
2307 make_int (search_regs.end[0])); | 2322 make_int (search_regs.end[sub])); |
2308 } | 2323 } |
2309 else | 2324 else |
2310 { | 2325 { |
2311 if (search_regs.start[0] < 0 | 2326 if (search_regs.start[0] < 0 |
2312 || search_regs.start[0] > search_regs.end[0] | 2327 || search_regs.start[0] > search_regs.end[0] |