GNU bug report logs - #11025
23.1; re-search-backward does not find the right beginning of the regexp

Previous Next

Package: emacs;

Reported by: Jack Duthen <duthen.mac.01 <at> gmail.com>

Date: Fri, 16 Mar 2012 16:50:02 UTC

Severity: minor

Tags: notabug

Merged with 9681, 24801

Found in versions 23.1, 25.1

Done: npostavs <at> users.sourceforge.net

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Jack Duthen <duthen.mac.01 <at> gmail.com>
To: 11025 <at> debbugs.gnu.org
Subject: bug#11025: Fwd: bug#9681: Broken behaviour of re-search-backward (.+ matching only a single character)
Date: Fri, 16 Mar 2012 17:29:20 +0100
Oops!  It's a feature, not a bug...
Sorry for the noise.

I just found the same problem addressed in bug#9681.
I understood the current behavior of re-search-backward.
see my reply.
sincerely
)jack(

---------- Forwarded message ----------
From: Jack Duthen <duthen.mac.01 <at> gmail.com>
Date: 2012/3/16
Subject: Re: bug#9681: Broken behaviour of re-search-backward (.+
matching only a single character)
To: bug-gnu-emacs <at> gnu.org

On Thu, Oct 06, 2011 at 08:57:09AM -0400, Stefan Monnier wrote:
> re-search-* stops at the first character position that has a match.
> And then it chooses the longest match at that position.

Stepan wrote:
> So, again: it definitely needs better documentation,
> and IMO it also needs fixing.

Hi!

For my own imenu-prev-index-position-function, I needed
a backward regexp search which would match something like ".+"
the way one (like Stepan) can expect rather than the way it actually
does (as described by Stefan).

So, I just wrote a function to do that.

The way it handles the COUNT variable is not as good as one could want
but, as I almost never use it, I don't care.
It's not very efficient but, since I can't notice the time it takes
when used in the "*rescan" menu and since I can't imagine a better algorithm,
it's ok for me.

(defun jd-re-search-backward (regexp &optional bound noerror count)
 (let ((orig-point (point)) bom)
   (when (re-search-backward regexp bound noerror count)
     (setq bom (point)) ; should not be useful
     (goto-char (point-min))
     (while (re-search-forward regexp orig-point 'noerror)
       ;; remember the last beginning of match
       (setq bom (match-beginning 0)))
     (goto-char bom)
     ;; set match data (erased by the last failing search) and return T
     (looking-at regexp))))

HTH
)jack(




This bug report was last modified 8 years and 208 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.