[Top][All Lists]

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

Re: address@hidden: Re: re-builder bug(s)]

From: Detlev Zundel
Subject: Re: address@hidden: Re: re-builder bug(s)]
Date: Fri, 09 Mar 2007 17:38:46 +0100
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.93 (gnu/linux)


> This is the bug report.  Can you fix it for us?
> I don't know whether Detlev Zundel is still available,
> so I cc'd this to emacs-devel.  If Detlev doesn't fix this,
> I hope that someone else will do so.
> From: address@hidden (P.L.Hayes)
> Subject: Re: re-builder bug(s)
> To: address@hidden
> Cc: address@hidden
> Date: Tue, 06 Mar 2007 07:33:44 +0000
> Richard Stallman <address@hidden> writes:
>> 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:
>     .\\>
> 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.
> ----------

Ok, attached is a patch that changes the behaviour of re-builder when
it comes to what it previously considered empty regexps.  It now
counts words, lines and other zero-width regexps.  

Although I think the new behaviour is consistent in that it now also
counts (up to its defined maximum) the numbers of characters in a
buffer when confronted with an empty regexp (after all
re-search-forward matches), I don't know if that is what users would

What do you think?


Progress in  mathematics comes from  repeated acts of generalization.
If mathematics is anything, it is the art of chosing the most elegant
generalization for some abstract pattern.  Thus esthetics is central.
                                     -- Douglas Hofstadter
--- lisp/emacs-lisp/re-builder.el       2007-03-08 15:44:12.000000000 +0100
+++ /tmp/re-builder.el  2007-03-09 16:22:18.000000000 +0100
@@ -639,11 +640,13 @@
       (set-buffer reb-target-buffer)
       (goto-char (point-min))
-      (while (and (re-search-forward re (point-max) t)
+      (while (and (not (eobp))
+                 (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!"))
+           (unless (eobp) 
+             (forward-char 1)))
        (let ((i 0)
              suffix max-suffix)
          (setq matches (1+ matches))

reply via email to

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