emacs-devel
[Top][All Lists]
Advanced

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

RE: [External] : Re: Is it valid to call isearch-filter-predicate outsid


From: Drew Adams
Subject: RE: [External] : Re: Is it valid to call isearch-filter-predicate outside isearch?
Date: Wed, 31 May 2023 15:22:20 +0000

> >> I expected `isearch-filter-predicate' to be only used by isearch in
> >> isearch-mode. And thus I expected `isearch-mode-end-hook' to be called
> >> later.
> >>
> >> Isn't it a natural expectation?
> >
> > Evidently, that ship sailed a long time ago: "grep isearch-" yields
> > more than 60 hits in replace.el.  And then there are many hits in
> > comint.el, dired-aux.el, info.el, and even in simple.el.
> 
> Sure. I have no issue with this. That's why I asked to add a word of
> warning about the state of affairs to the docstring. It is not normal
> that major mode-specific predicates are used elsewhere.

Where do you find that "not normal" guideline? 

In any case, `isearch-filter-predicate' is not a
"major mode-specific" predicate.  `isearch-mode'
is a minor mode.

And note that the first line of its doc string
says that it's for "Isearch and replace commands."
                            ^^^^^^^^^^^
___

Wrt whether `isearch-done' should restore the
original/previous value of `isearch-filter-predicate':

Yes, there's a certain logic to expecting that
`isearch-done' would do that.

In my library `isearch+.el' `isearch-done' does it.

More precisely, it does it depending on a user
option, because the library has a feature that
lets you alter the predicate on the fly, and you
sometimes want to keep the modified predicate for
subsequent searching.  (You can toggle the option
value during Isearch using `C-z S'.)

The feature: You can add and remove any number
of search filters (predicates) while searching
incrementally.

The value of `isearch-filter-predicate' is
advised by predicates that you add, creating a
suite of predicates that act together.

(AFAIK, this is the only example of dynamically,
interactively, incrementally advising a function,
in this case the function value of a variable.)

See https://www.emacswiki.org/emacs/DynamicIsearchFiltering.

This is the user option that `isearch-done' uses:

 `isearchp-auto-keep-filter-predicate-flag' is a variable
 defined in `isearch+.el'.

 Its value is nil

 Documentation:

 Non-nil means automatically apply `C-z s'.
 Changes to `isearch-filter-predicate' are automatically kept for
 subsequent searches in this Emacs session when you exit Isearch'.
 You can toggle this option using `C-z S during Isearch.

And this is the advice that implements whether to
restore the value:

(defadvice isearch-done (after isearchp-restore/update-filter-pred
                         activate)
  "Reset `isearch-filter-predicate' or `isearchp-kept-filter-predicate'.
If `isearchp-auto-keep-filter-predicate-flag' is non-nil then set
`isearchp-kept-filter-predicate' to the current value of
`isearch-filter-predicate'.  Otherwise, do the opposite."
  (if isearchp-auto-keep-filter-predicate-flag
      (setq isearchp-kept-filter-predicate  isearch-filter-predicate)
    (setq isearch-filter-predicate  isearchp-kept-filter-predicate)))

So yes, in general it makes sense for `isearch-done'
to restore the predicate value.  But it can sometimes
make sense for it not to do so.  Whether it does so
or not should be under user and programmatic control.




reply via email to

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