[Top][All Lists]

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

Re: message-function (was: Proposed new core library: alert.el)

From: Artur Malabarba
Subject: Re: message-function (was: Proposed new core library: alert.el)
Date: Fri, 6 Nov 2015 19:03:00 +0000

2015-11-06 18:10 GMT+00:00 Ted Zlatanov <address@hidden>:
> OK, it will be `message-function'.


> AM> 2. The variable's default value should be a function (which implements
> AM> the default behaviour), not nil.
> Well, your point (2) is not exactly what I think is best. Your proposal
> requires a new `message-function-standard' name for the internal
> Fmessage(), and changes the current `message' completely.

Well, this makes it sound more complicated than it is. :-)
I'm just saying to rename the current `message' function, and redefine
`message' to simply call `(apply message-function args)' (of course,
this could be in C).

> By contrast, my proposal has `message' calling Fmessage() (the current
> behavior) and then, iff `message-function' is set, doing something
> different. So it preserves the current behavior exactly. I think that's
> an important consideration for changing a very fundamental Emacs function.

Maybe we're miscommunicating. I don't propose to change the current
behavior in any way. In fact, the outcome of my proposal should be
identical to yours. I'm just saying "instead of having the current
behavior correspond to a nil value of the variable, have it correspond
to a proper function value".

> AM> Allowing a nil value is just going to make it harder for
> AM> users/packages to use the `add-function' mechanisms on this variable.
> AM> For instance, see the variable `font-lock-fontify-region-function'.
> AM> Its name ends in `-function', and its default value is
> AM> #'font-lock-default-fontify-region. That's the convention we should
> AM> follow with these variables.
> If the user wants to `add-function' on `message', they should
> `add-function' on `message'.  I don't see why they care that
> `message-function' is nil or something else.  But maybe I'm missing
> something here.  I've been away from Emacs development for a bit.

You're probably thinking of advice-add. You don't call `add-function'
on a function, you call it on a variable that holds a function.
Add-function is a proper (and very useful) macro for changing the
value of a variable that holds a function. For instance, if I do:

(add-function :after font-lock-fontify-region-function
              (lambda (&rest _) (message "Fontification done!")))

I am replacing the value of the variable
font-lock-fontify-region-function, with a function that calls the
original value and then calls my function. I couldn't do that if its
default value were nil.

For a more practical example, say I don't want font-lock to fontify a
certain region of the buffer (this is something we do in cider.el). I
can just do:
(add-function :filter-args font-lock-fontify-region-function
where some-function is a function that takes a list of arguments and
returns another list of arguments.

This way, many different minor modes can edit the same -function
variable without having to override it and so without getting all over
each other. You can also easily remove yourself from a -function
variable by just using `remove-function'.
It's really a very powerful and useful interface. Have a quick look at
the docstring for add-function and you'll see all the many options.

reply via email to

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