unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Spencer Baugh <sbaugh@janestreet.com>
To: help-gnu-emacs@gnu.org
Subject: Re: search-backward returning matches which end after point
Date: Mon, 26 Aug 2024 10:26:13 -0400	[thread overview]
Message-ID: <iered6buzqy.fsf@janestreet.com> (raw)
In-Reply-To: jwvseuuar4z.fsf-monnier+emacs@gnu.org

Stefan Monnier via Users list for the GNU Emacs text editor
<help-gnu-emacs@gnu.org> writes:

>> search-backward (and re-search-backward, and looking-back) don't return
>> matches which end after point.  Is there a version which does?
>
> No 🙁
> You could write a `while + looking-at` loop to do that, but if you want
> something faster, you'll need to change the C code.
> I don't expect it would be a difficult change, tho (it should not require
> any significant change in the regexp engine, for example).

I'm happy to do that, if this is an addition which is likely to be
accepted into Emacs.

Should the API be a new flag in
search-backward/re-search-backward/looking-back?  Or should it maybe be
a new special variable?

>> The -prev commands defined by easy-mmode-define-navigation use
>> re-search-backward.  So if the point is inside the thing which the regex
>> matches, then thing-prev command will not go to the start of the thing.
>
> Of course, the same problem appears for search-forward when searching
> from within the thing we're searching.  In both cases the usual
> workaround is to start your search elsewhere (i.e. take "small" step
> back before searching forward or vice-versa).

Yes, that seems to be a common workaround.  Particularly common seems to
be going to pos-bol first, since the search is for something which can't
contain a newline.

In my case this is tricky though because the thing I'm searching for
*can* contain a newline, so it's not totally trivial to determin what
small step is correct to take...




  reply	other threads:[~2024-08-26 14:26 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-23 14:18 search-backward returning matches which end after point Spencer Baugh
2024-08-24 15:20 ` Stefan Monnier via Users list for the GNU Emacs text editor
2024-08-26 14:26   ` Spencer Baugh [this message]
2024-08-26 16:54     ` Stefan Monnier via Users list for the GNU Emacs text editor
2024-08-28 13:45       ` Spencer Baugh via Users list for the GNU Emacs text editor
2024-08-29  1:24         ` Stefan Monnier via Users list for the GNU Emacs text editor
2024-08-26 18:27 ` Andreas Röhler
2024-08-26 19:37   ` Stefan Monnier via Users list for the GNU Emacs text editor

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=iered6buzqy.fsf@janestreet.com \
    --to=sbaugh@janestreet.com \
    --cc=help-gnu-emacs@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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).