emacs-pretest-bug
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: re-builder bug(s)


From: Stefan Monnier
Subject: Re: re-builder bug(s)
Date: Tue, 06 Mar 2007 11:53:53 -0500
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.93 (gnu/linux)

>> I fixed the bug in the custom type, I think.
>> 
>> I also find (and I'm not quite sure whether it's a real bug or just
>> something I haven't understood about regexps or re-builder) that
>> expressions such as "\\>" and "$" in the re-builder buffer don't work
>> (and are flagged as "*invalid*" in the modeline) but ".\\>" and ".$",
>> 
>> Would you please send a precise, complete test case for this?

> Open a new buffer, put it in text mode and insert a line of text into it:

>      C-x b *reb-test* RET M-x text-mode RET
>      Kidman's publicist, Catherine Olim, said the star was trying to shake 
> zombies off the bonnet of her Jaguar when the car spun off the road. RET

> Try to use re-builder to count the number of words in the buffer:

>     M-x re-builder RET
>     \\>

> As soon as the first `\' is entered between the `"'s, in the
> *RE-Builder* buffer, "*invalid*" appears in the modeline.
> Now replace the regexp in the *RE-Builder* buffer with another:

>     DEL DEL DEL
>     .\\>

> Success! - the last character of each word in the *reb-test* buffer
> has been highlighted and a message, "25 matches" has appeared in the
> minibuffer. Likewise, the regexp, "^" will not find the empty string
> at the beginning of the buffer but "^." will and "$" will not find the
> end of the buffer but ".$" will.

It's because re-builder declares as "invalid" any regexp that matches the
empty string.  I find it a bit odd as well.  The patch below would change
that behavior, but since the current behavior is done on purpose, I'll let
someone else decide whether to install it or not.


        Stefan


--- orig/lisp/emacs-lisp/re-builder.el
+++ mod/lisp/emacs-lisp/re-builder.el
@@ -635,15 +648,15 @@
         (matches 0)
         (submatches 0)
         firstmatch)
-    (save-excursion
-      (set-buffer reb-target-buffer)
+    (with-current-buffer reb-target-buffer
       (reb-delete-overlays)
       (goto-char (point-min))
       (while (and (re-search-forward re (point-max) t)
                  (or (not reb-auto-match-limit)
                      (< matches reb-auto-match-limit)))
        (if (= 0 (length (match-string 0)))
-           (error "Empty regular expression!"))
+           ;; (error "Empty regular expression!")
+            (goto-char (point-max)))
        (let ((i 0)
              suffix max-suffix)
          (setq matches (1+ matches))
@@ -688,5 +701,5 @@
 
 (provide 're-builder)
 
-;;; arch-tag: 5c5515ac-4085-4524-a421-033f44f032e7
+;; arch-tag: 5c5515ac-4085-4524-a421-033f44f032e7
 ;;; re-builder.el ends here




reply via email to

[Prev in Thread] Current Thread [Next in Thread]