unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Philip Kaludercic <philipk@posteo.net>
To: Ergus <spacibba@aol.com>
Cc: "help-gnu-emacs@gnu.org" <help-gnu-emacs@gnu.org>
Subject: Re: isearch-lax question error?
Date: Thu, 04 Apr 2024 05:15:20 +0000	[thread overview]
Message-ID: <87o7apemjb.fsf@posteo.net> (raw)
In-Reply-To: <5cxaqmf35sbcpvdfmvd2n7nvgunqwbfsgrxa6cyng3cbpo5z7u@itqcn57665a2> (Ergus's message of "Wed, 3 Apr 2024 20:56:51 +0200")

Ergus <spacibba@aol.com> writes:

> Hi:
>
> I am trying to create a lax isearch interactive that use ".*?" but
> independent from the default one very useful as well.
>
> I already have isearch-lax-whitespace and search-whitespace-regexp to
> the defaults.
>
> And in my function I only want to change search-spaces-regexp in order
> to make the command temporarily more flexible.
>
> so far I have something simple like this:
>
> (defun my/isearch-forward ()
>   (interactive)
>   (let ((search-spaces-regexp ".*?"))        ;; I alternated this with search-whitespace-regexp
>     (call-interactively 'isearch-forward)))
>
> However this does not behave as expected; it changes nothing compared to
> the default behavior.
>
> But If I set (defcustom isearch-lax-whitespace ".*?") then I get the
> right behavior in the normal isearch-forward.
>
> What I am missing here?

isearch-forward enabled isearch-mode, and then returns.  The dynamic
binding of search-spaces-regexp will not be in effect anymore, when the
actual searching is taking place (recall that isearch doesn't take over
the event-loop, but just rebinds commands: "a" which is usually bound to
`self-insert-command' is rebound to `isearch-printing-char').

So what you would need, might be something like this

--8<---------------cut here---------------start------------->8---
(defun my/isearch-forward ()
  (interactive)
  (letrec ((hook 'isearch-mode-end-hook)
	   (reset (lambda () (remove-hook hook reset t))))
    (add-hook hook reset       nil t)
    (setq-local search-spaces-regexp ".*?")
    (call-interactively #'isearch-forward)))
--8<---------------cut here---------------end--------------->8---

(not tested extensivly)

> Thanks in advance,
> Ergus
>
>
>

-- 
	Philip Kaludercic on peregrine



      parent reply	other threads:[~2024-04-04  5:15 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <5cxaqmf35sbcpvdfmvd2n7nvgunqwbfsgrxa6cyng3cbpo5z7u.ref@itqcn57665a2>
2024-04-03 18:56 ` isearch-lax question error? Ergus
2024-04-04  5:07   ` Philip Kaludercic
2024-04-04  5:15   ` Philip Kaludercic [this message]

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=87o7apemjb.fsf@posteo.net \
    --to=philipk@posteo.net \
    --cc=help-gnu-emacs@gnu.org \
    --cc=spacibba@aol.com \
    /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).