comparison src/search.c @ 707:a307f9a2021d

[xemacs-hg @ 2001-12-20 05:49:28 by andyp] sync with 21-4-6-windows
author andyp
date Thu, 20 Dec 2001 05:49:48 +0000
parents fdefd0186b75
children 943eaba38521
comparison
equal deleted inserted replaced
706:c9bf82d465b5 707:a307f9a2021d
2291 buf = decode_buffer (strbuffer, 0); 2291 buf = decode_buffer (strbuffer, 0);
2292 XSETBUFFER (buffer, buf); 2292 XSETBUFFER (buffer, buf);
2293 } 2293 }
2294 else 2294 else
2295 { 2295 {
2296 if (NILP (strbuffer)) 2296 if (!NILP (strbuffer))
2297 sub = 0;
2298 else
2299 { 2297 {
2300 CHECK_INT (strbuffer); 2298 CHECK_INT (strbuffer);
2301 sub = XINT (strbuffer); 2299 sub = XINT (strbuffer);
2302 if (sub < 0 || sub >= (int) search_regs.num_regs) 2300 if (sub < 0 || sub >= (int) search_regs.num_regs)
2303 args_out_of_range (strbuffer, make_int (search_regs.num_regs)); 2301 args_out_of_range (strbuffer, make_int (search_regs.num_regs));
2335 2333
2336 if (NILP (fixedcase)) 2334 if (NILP (fixedcase))
2337 { 2335 {
2338 /* Decide how to casify by examining the matched text. */ 2336 /* Decide how to casify by examining the matched text. */
2339 2337
2340 last = search_regs.end[0]; 2338 last = search_regs.end[sub];
2341 prevc = '\n'; 2339 prevc = '\n';
2342 case_action = all_caps; 2340 case_action = all_caps;
2343 2341
2344 /* some_multiletter_word is set nonzero if any original word 2342 /* some_multiletter_word is set nonzero if any original word
2345 is more than one letter long. */ 2343 is more than one letter long. */
2346 some_multiletter_word = 0; 2344 some_multiletter_word = 0;
2347 some_lowercase = 0; 2345 some_lowercase = 0;
2348 some_nonuppercase_initial = 0; 2346 some_nonuppercase_initial = 0;
2349 some_uppercase = 0; 2347 some_uppercase = 0;
2350 2348
2351 for (pos = search_regs.start[0]; pos < last; pos++) 2349 for (pos = search_regs.start[sub]; pos < last; pos++)
2352 { 2350 {
2353 if (NILP (string)) 2351 if (NILP (string))
2354 c = BUF_FETCH_CHAR (buf, pos); 2352 c = BUF_FETCH_CHAR (buf, pos);
2355 else 2353 else
2356 c = string_char (XSTRING (string), pos); 2354 c = string_char (XSTRING (string), pos);
2562 /* frees the Dynarrs if necessary. */ 2560 /* frees the Dynarrs if necessary. */
2563 unbind_to (speccount, Qnil); 2561 unbind_to (speccount, Qnil);
2564 return concat3 (before, replacement, after); 2562 return concat3 (before, replacement, after);
2565 } 2563 }
2566 2564
2567 mc_count = begin_multiple_change (buf, search_regs.start[0], 2565 mc_count = begin_multiple_change (buf, search_regs.start[sub],
2568 search_regs.end[0]); 2566 search_regs.end[sub]);
2569 2567
2570 /* begin_multiple_change() records an unwind-protect, so we need to 2568 /* begin_multiple_change() records an unwind-protect, so we need to
2571 record this value now. */ 2569 record this value now. */
2572 speccount = specpdl_depth (); 2570 speccount = specpdl_depth ();
2573 2571
2574 /* We insert the replacement text before the old text, and then 2572 /* We insert the replacement text before the old text, and then
2575 delete the original text. This means that markers at the 2573 delete the original text. This means that markers at the
2576 beginning or end of the original will float to the corresponding 2574 beginning or end of the original will float to the corresponding
2577 position in the replacement. */ 2575 position in the replacement. */
2578 BUF_SET_PT (buf, search_regs.start[0]); 2576 BUF_SET_PT (buf, search_regs.start[sub]);
2579 if (!NILP (literal)) 2577 if (!NILP (literal))
2580 Finsert (1, &replacement); 2578 Finsert (1, &replacement);
2581 else 2579 else
2582 { 2580 {
2583 Charcount stlen = XSTRING_CHAR_LENGTH (replacement); 2581 Charcount stlen = XSTRING_CHAR_LENGTH (replacement);
2584 Charcount strpos; 2582 Charcount strpos;
2585 struct gcpro gcpro1; 2583 struct gcpro gcpro1;
2586 GCPRO1 (replacement); 2584 GCPRO1 (replacement);
2587 for (strpos = 0; strpos < stlen; strpos++) 2585 for (strpos = 0; strpos < stlen; strpos++)
2588 { 2586 {
2589 Charcount offset = BUF_PT (buf) - search_regs.start[0]; 2587 /* on the first iteration assert(offset==0),
2588 exactly complementing BUF_SET_PT() above.
2589 During the loop, it keeps track of the amount inserted.
2590 */
2591 Charcount offset = BUF_PT (buf) - search_regs.start[sub];
2590 2592
2591 c = string_char (XSTRING (replacement), strpos); 2593 c = string_char (XSTRING (replacement), strpos);
2592 if (c == '\\' && strpos < stlen - 1) 2594 if (c == '\\' && strpos < stlen - 1)
2593 { 2595 {
2596 /* XXX FIXME: replacing just a substring non-literally
2597 using backslash refs to the match looks dangerous. But
2598 <15366.18513.698042.156573@ns.caldera.de> from Torsten Duwe
2599 <duwe@caldera.de> claims Finsert_buffer_substring already
2600 handles this correctly.
2601 */
2594 c = string_char (XSTRING (replacement), ++strpos); 2602 c = string_char (XSTRING (replacement), ++strpos);
2595 if (c == '&') 2603 if (c == '&')
2596 Finsert_buffer_substring 2604 Finsert_buffer_substring
2597 (buffer, 2605 (buffer,
2598 make_int (search_regs.start[0] + offset), 2606 make_int (search_regs.start[0] + offset),
2631 buffer_insert_emacs_char (buf, c); 2639 buffer_insert_emacs_char (buf, c);
2632 } 2640 }
2633 UNGCPRO; 2641 UNGCPRO;
2634 } 2642 }
2635 2643
2636 inslen = BUF_PT (buf) - (search_regs.start[0]); 2644 inslen = BUF_PT (buf) - (search_regs.start[sub]);
2637 buffer_delete_range (buf, search_regs.start[0] + inslen, search_regs.end[0] + 2645 buffer_delete_range (buf, search_regs.start[sub] + inslen,
2638 inslen, 0); 2646 search_regs.end[sub] + inslen, 0);
2639 2647
2640 if (case_action == all_caps) 2648 if (case_action == all_caps)
2641 Fupcase_region (make_int (BUF_PT (buf) - inslen), 2649 Fupcase_region (make_int (BUF_PT (buf) - inslen),
2642 make_int (BUF_PT (buf)), buffer); 2650 make_int (BUF_PT (buf)), buffer);
2643 else if (case_action == cap_initial) 2651 else if (case_action == cap_initial)