emacs-devel
[Top][All Lists]
Advanced

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

RE: [External] : Re: Use of advice [was: Is it valid to call isearch-fil


From: Drew Adams
Subject: RE: [External] : Re: Use of advice [was: Is it valid to call isearch-filter-predicate outside isearch?]
Date: Wed, 7 Jun 2023 14:44:33 +0000

> > > Dunno if it would be worth it that variables which are
> > > considered to be modified by advising should have a
> > > special suffix (like "-hook" for hooks).  Or maybe we
> > > already more or less have it: "...-function".
> > > `setq'ing such variables in the Emacs sources is
> > > probably not user friendly.
> >
> > I guess you're talking about a variable that's
> > expected to be used a bit like a hook.
> >
> > That's the case, BTW, for variables such as
> > `isearch-filter-predicate'.  (OK, it uses suffix
> > `-predicate' instead of `-function' or `-hook'.
> > But the idea's the same.)
> 
> Yes, we have a few.  But `-predicate' is irrelevant
> for naming - not all such places will be predicate
> functions.  And you can't tell from the name that
> the variable should be advised and not set.

Are you talking about an advice name or the name
of a predicate-valued variable?

For the latter, we could adopt suffix `-predicate'
conventionally.  A predicate in Lisp is a Boolean
function.  (It's not just a Boolean value.)

However, just as with other functions, predicates
can have different signatures.  So that suffix
would correspond to an "abnormal" hook, i.e., one
whose value could accept args.
____

I'll also pointed out that predicates are
_particularly_ useful use cases for advice, as
the ways you can combine the advice include the
usual logical combinations (AND, OR, NOT).

IOW, knowing that the function being advised, as
well as the intended result of advising, are to
be _predicates_ means you can use such general
logical combinations as ways of advising them.

That's what my Isearch dynamic filtering code
does: it lets you combine predicates easily
(interactively) using AND, OR, and NOT, among
other possibilities.

And there are two versions of ORing and
complementing:

1. Just add a predicate, ORing/complementing
   the current predicate.

2. Replace the last-added predicate (advice)
   by its disjunction with a new predicate
   or by its complement.

https://www.emacswiki.org/emacs/DynamicIsearchFiltering#FilteringCommandsAvailableDuringSearch

Advising an arbitrary function doesn't allow such
combining possibilities.  But at least you still
have some other general operations: add advice,
remove advice, replace advice, list/show/describe
current advice, save current advised definition
(to reuse later), keep or not for subsequent
commands, reset to original predicate.



reply via email to

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