all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Jack Duthen <duthen.mac.01@gmail.com>
To: 9681@debbugs.gnu.org
Subject: bug#9681: Broken behaviour of re-search-backward (.+ matching only a single character)
Date: Fri, 16 Mar 2012 16:49:37 +0100	[thread overview]
Message-ID: <CALGVPOqN9zv_vdhrMxQ8e0Ai-EsB9pu8=_MtrFfXd61NArA+SQ@mail.gmail.com> (raw)
In-Reply-To: <8762k21o09.fsf@gmail.com>

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(





  parent reply	other threads:[~2012-03-16 15:49 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-06  9:13 bug#9681: Broken behaviour of re-search-backward (.+ matching only a single character) Štěpán Němec
2011-10-06 12:57 ` Stefan Monnier
2011-10-06 18:48   ` Štěpán Němec
2011-10-07 13:02     ` Stefan Monnier
2011-10-07 13:19       ` Štěpán Němec
2011-10-11  2:03       ` Kenichi Handa
2011-10-11  3:56         ` Stefan Monnier
2011-10-06 19:46 ` Johan Bockgård
2012-03-16 15:49 ` Jack Duthen [this message]
2012-03-16 16:29   ` bug#11025: Fwd: " Jack Duthen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CALGVPOqN9zv_vdhrMxQ8e0Ai-EsB9pu8=_MtrFfXd61NArA+SQ@mail.gmail.com' \
    --to=duthen.mac.01@gmail.com \
    --cc=9681@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.