emacs-devel
[Top][All Lists]
Advanced

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

Re: Is it valid to call isearch-filter-predicate outside isearch?


From: Michael Heerdegen
Subject: Re: Is it valid to call isearch-filter-predicate outside isearch?
Date: Sun, 04 Jun 2023 02:06:46 +0200
User-agent: Gnus/5.13 (Gnus v5.13)

Ihor Radchenko <yantar92@posteo.net> writes:

> Michael Heerdegen <michael_heerdegen@web.de> writes:
>
> >> 2. It feels against the interface. If advising this predicate is
> >>    expected, why not convert it into an abnormal hook?
> >
> > It's more flexible and expressive, as Drew already mentioned.  For
> > example, how the members of a hook are logically combined (`and'ed,
> > `or'ed) is fixed in a hook, but not when using advising.
>
> Interesting.
> From Elisp Tips in the manual, I always felt that using advices is
> always frowned upon. And you are suggesting that they are the better way
> to go in these situations.
> I am wondering if this thing with modifying predicates should be
> documented somewhere and recommended approach.

Not sure if we have a consensual approach at all.  But Note this is not
about modifying predicates, it's about modifying variables with function
bindings (in my eyes).  Yes, we don't want to use advices to change
named functions.

But when speaking about modifying function valued variables (or places)
advising has clear advantages: getting to the old value works more
transparently, and interfering actors have some more ways to control
their interaction.

I guess we will have to decide by case whether introducing a hook or
using advices on function valued variables or overwriting a binding with
plain `setq' makes more sense.

But maybe let's continue discussing this in the thread that Drew has
started.


> > I also wonder about the `kill-variable' calls: what if the user or a
> > third-party mode want to have own buffer-local settings for these?
> > We then erase
> > them when killing the local variables.  With using an advice on these
> > the worst thing that could happen is that we leave a buffer local
> > variable with the same binding as the global one, where we started with
> > no buffer local binding.
>
> May you please elaborate? I am not sure what `kill-variable' calls you
> are referring to here.

To those in `wdired-change-to-dired-mode:

#+begin_src emacs-lisp
  (when wdired-search-replace-filenames
    (remove-function (local 'isearch-search-fun-function)
                     #'dired-isearch-search-filenames)
    (kill-local-variable 'replace-search-function)
    (kill-local-variable 'replace-re-search-function)
    ;; Restore dired hook
    (add-hook 'isearch-mode-hook #'dired-isearch-filenames-setup nil t))
#+end_src

This demonstrates a problem when not using an advice: to get rid of the
temporary new binding you simply kill the local variable, but this can
be problematic, especially when we did not create it (but maybe someone
third).


Michael.




reply via email to

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