]> code.delx.au - gnu-emacs/blobdiff - src/search.c
(Voverflow_newline_into_fringe, syms_of_xdisp)
[gnu-emacs] / src / search.c
index 538cb8dfa645d26f6862640a9f9997adfe8c13ec..c60d68b9374266735283f1400eaf6f57b9c56f69 100644 (file)
@@ -2366,13 +2366,21 @@ since only regular expressions have distinguished subexpressions.  */)
                      substart = search_regs.start[sub];
                      subend = search_regs.end[sub];
                    }
-                 else if (c >= '1' && c <= '9' && c <= search_regs.num_regs + '0')
+                 else if (c >= '1' && c <= '9')
                    {
-                     if (search_regs.start[c - '0'] >= 0)
+                     if (search_regs.start[c - '0'] >= 0
+                         && c <= search_regs.num_regs + '0')
                        {
                          substart = search_regs.start[c - '0'];
                          subend = search_regs.end[c - '0'];
                        }
+                     else
+                       {
+                         /* If that subexp did not match,
+                            replace \\N with nothing.  */
+                         substart = 0;
+                         subend = 0;
+                       }
                    }
                  else if (c == '\\')
                    delbackslash = 1;
@@ -2553,8 +2561,16 @@ since only regular expressions have distinguished subexpressions.  */)
        }
 
       if (really_changed)
-       newtext = make_string (substed, substed_len);
+       {
+         if (buf_multibyte)
+           {
+             int nchars = multibyte_chars_in_text (substed, substed_len);
 
+             newtext = make_multibyte_string (substed, nchars, substed_len);
+           }
+         else
+           newtext = make_unibyte_string (substed, substed_len);
+       }
       xfree (substed);
     }