(X_IO_BUG): Defined.
[bpt/emacs.git] / src / search.c
index 4d39d38..b0e2b1f 100644 (file)
@@ -1,5 +1,5 @@
 /* String search routines for GNU Emacs.
-   Copyright (C) 1985, 1986, 1987, 1993 Free Software Foundation, Inc.
+   Copyright (C) 1985, 1986, 1987, 1993, 1994 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -472,6 +472,9 @@ skip_chars (forwardp, syntaxp, string, lim)
        }
     }
 
+  if (syntaxp && fastmap['-'] != 0)
+    fastmap[' '] = 1;
+
   /* If ^ was the first character, complement the fastmap. */
 
   if (negate)
@@ -819,7 +822,10 @@ search_buffer (string, pos, lim, n, RE, trt, inverse_trt)
         of pattern would align in a possible match.  */
       while (n != 0)
        {
-         if ((lim - pos - (direction > 0)) * direction < 0)
+         /* It's been reported that some (broken) compiler thinks that
+            Boolean expressions in an arithmetic context are unsigned.
+            Using an explicit ?1:0 prevents this.  */
+         if ((lim - pos - ((direction > 0) ? 1 : 0)) * direction < 0)
            return (n * (0 - direction));
          /* First we do the part we can by pointers (maybe nothing) */
          QUIT;
@@ -1115,17 +1121,17 @@ DEFUN ("re-search-backward", Fre_search_backward, Sre_search_backward, 1, 4,
   "Search backward from point for match for regular expression REGEXP.\n\
 Set point to the beginning of the match, and return point.\n\
 The match found is the one starting last in the buffer\n\
-and yet ending before the place the origin of the search.\n\
+and yet ending before the origin of the search.\n\
 An optional second argument bounds the search; it is a buffer position.\n\
 The match found must start at or after that position.\n\
 Optional third argument, if t, means if fail just return nil (no error).\n\
   If not nil and not t, move to limit of search and return nil.\n\
 Optional fourth argument is repeat count--search for successive occurrences.\n\
 See also the functions `match-beginning', `match-end' and `replace-match'.")
-  (string, bound, noerror, count)
-     Lisp_Object string, bound, noerror, count;
+  (regexp, bound, noerror, count)
+     Lisp_Object regexp, bound, noerror, count;
 {
-  return search_command (string, bound, noerror, count, -1, 1);
+  return search_command (regexp, bound, noerror, count, -1, 1);
 }
 
 DEFUN ("re-search-forward", Fre_search_forward, Sre_search_forward, 1, 4,
@@ -1138,16 +1144,21 @@ Optional third argument, if t, means if fail just return nil (no error).\n\
   If not nil and not t, move to limit of search and return nil.\n\
 Optional fourth argument is repeat count--search for successive occurrences.\n\
 See also the functions `match-beginning', `match-end' and `replace-match'.")
-  (string, bound, noerror, count)
-     Lisp_Object string, bound, noerror, count;
+  (regexp, bound, noerror, count)
+     Lisp_Object regexp, bound, noerror, count;
 {
-  return search_command (string, bound, noerror, count, 1, 1);
+  return search_command (regexp, bound, noerror, count, 1, 1);
 }
 \f
 DEFUN ("replace-match", Freplace_match, Sreplace_match, 1, 3, 0,
   "Replace text matched by last search with NEWTEXT.\n\
 If second arg FIXEDCASE is non-nil, do not alter case of replacement text.\n\
-Otherwise convert to all caps or cap initials, like replaced text.\n\
+Otherwise maybe capitalize the whole text, or maybe just word initials,\n\
+based on the replaced text.\n\
+If the replaced text has only capital letters\n\
+and has at least one multiletter word, convert NEWTEXT to all caps.\n\
+If the replaced text has at least one word starting with a capital letter,\n\
+then capitalize each word in NEWTEXT.\n\n\
 If third arg LITERAL is non-nil, insert NEWTEXT literally.\n\
 Otherwise treat `\\' as special:\n\
   `\\&' in NEWTEXT means substitute original matched text.\n\
@@ -1163,7 +1174,8 @@ Leaves point at end of replacement text.")
   register int pos, last;
   int some_multiletter_word;
   int some_lowercase;
-  int some_uppercase_initial;
+  int some_uppercase;
+  int some_lowercase_initial;
   register int c, prevc;
   int inslen;
 
@@ -1193,7 +1205,8 @@ Leaves point at end of replacement text.")
         is more than one letter long. */
       some_multiletter_word = 0;
       some_lowercase = 0;
-      some_uppercase_initial = 0;
+      some_lowercase_initial = 0;
+      some_uppercase = 0;
 
       for (pos = search_regs.start[0]; pos < last; pos++)
        {
@@ -1204,14 +1217,15 @@ Leaves point at end of replacement text.")
 
              some_lowercase = 1;
              if (SYNTAX (prevc) != Sword)
-               ;
+               some_lowercase_initial = 1;
              else
                some_multiletter_word = 1;
            }
          else if (!NOCASEP (c))
            {
+             some_uppercase = 1;
              if (SYNTAX (prevc) != Sword)
-               some_uppercase_initial = 1;
+               ;
              else
                some_multiletter_word = 1;
            }
@@ -1223,9 +1237,13 @@ Leaves point at end of replacement text.")
         and has at least one multiletter word.  */
       if (! some_lowercase && some_multiletter_word)
        case_action = all_caps;
-      /* Capitalize each word, if the old text has a capitalized word.  */
-      else if (some_uppercase_initial)
+      /* Capitalize each word, if the old text has all capitalized words.  */
+      else if (!some_lowercase_initial && some_multiletter_word)
        case_action = cap_initial;
+      else if (!some_lowercase_initial && some_uppercase)
+       /* Should x -> yz, operating on X, give Yz or YZ?
+          We'll assume the latter.  */
+       case_action = all_caps;
       else
        case_action = nochange;
     }