unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Artur Malabarba <bruce.connor.am@gmail.com>
To: emacs-devel <emacs-devel@gnu.org>
Subject: Re: message-function (was: Proposed new core library: alert.el)
Date: Fri, 6 Nov 2015 19:03:00 +0000	[thread overview]
Message-ID: <CAAdUY-K6ygktXi42fA7G+hHAmw+nW1w71j0zUczhL+MX8rVoRQ@mail.gmail.com> (raw)
In-Reply-To: <87d1vnyp5y.fsf_-_@lifelogs.com>

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

Thanks.

> 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
              #'some-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	other threads:[~2015-11-06 19:03 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-05  2:05 Proposed new core library: alert.el John Wiegley
2015-11-05  9:14 ` Artur Malabarba
2015-11-05  9:21 ` Nicolas Petton
2015-11-05 11:39   ` Sven Axelsson
2015-11-05 16:09     ` Random832
2015-11-05 16:24 ` raman
2015-11-05 16:33 ` Vivek Dasmohapatra
2015-11-05 17:09   ` joakim
2015-11-05 17:09   ` Juanma Barranquero
2015-11-05 18:21   ` John Wiegley
2015-11-06 22:31     ` T.V Raman
2015-11-06 21:38   ` Richard Stallman
2015-11-07 13:20     ` Ted Zlatanov
2015-11-07 13:39       ` Artur Malabarba
2015-11-05 19:48 ` Ted Zlatanov
2015-11-05 20:03   ` John Wiegley
2015-11-05 20:23     ` Ted Zlatanov
2015-11-05 20:33       ` John Wiegley
2015-11-05 22:24         ` Bozhidar Batsov
2015-11-06 10:04         ` Eli Zaretskii
2015-11-06 15:32           ` Ted Zlatanov
2015-11-06 15:52             ` Eli Zaretskii
2015-11-06 16:01               ` Artur Malabarba
2015-11-06 16:20               ` Ted Zlatanov
2015-11-06 17:56                 ` Artur Malabarba
2015-11-06 18:10                   ` message-function (was: Proposed new core library: alert.el) Ted Zlatanov
2015-11-06 19:03                     ` Artur Malabarba [this message]
2015-11-07 13:31                       ` Artur Malabarba
2015-11-07 13:39                         ` message-function Ted Zlatanov
2015-11-06 21:20                 ` Proposed new core library: alert.el John Wiegley
2015-11-07 13:26                   ` Artur Malabarba
2015-11-07 10:40             ` Elias Mårtenson
     [not found]             ` <m2io5e6d39.fsf@newartisans.com>
2015-11-07 12:28               ` Ted Zlatanov
2015-11-07 13:09                 ` Artur Malabarba
2015-11-07 13:44                   ` Ted Zlatanov
2015-11-08 20:49                     ` Ted Zlatanov
2015-11-09  0:03                       ` Artur Malabarba
2015-11-09 21:50                 ` John Wiegley
2015-11-10 18:34                   ` Posting new feature proposals on the wiki? (was: Re: Proposed new core library: alert.el) Nicolas Petton
2015-11-10 18:40                     ` Posting new feature proposals on the wiki? John Wiegley
2015-11-11 16:14                     ` raman
2015-11-11 16:43                       ` John Wiegley
2015-11-11 17:35                         ` T.V Raman
2015-11-11 23:27                           ` Richard Stallman
2015-11-11 23:40                             ` T.V Raman
2015-11-12 11:16                               ` Artur Malabarba
2015-11-12 16:40                                 ` T.V Raman
2015-11-12 22:34                               ` Richard Stallman
2015-11-16 16:52                                 ` John Wiegley
2015-11-16 17:03                                   ` raman
2015-11-06 15:50           ` Proposed new core library: alert.el John Wiegley
2015-11-06  1:47     ` raman
2015-11-06  2:16       ` John Wiegley
2015-11-06  9:47         ` Rasmus
2015-11-06 10:42           ` Artur Malabarba
2015-11-06 11:27             ` Xue Fuqiao
2015-11-06  9:50         ` Juanma Barranquero
2015-11-06 10:07           ` Eli Zaretskii
2015-11-06 13:59             ` Stefan Monnier
2015-11-06 16:12         ` raman
2015-11-06 16:13           ` John Wiegley
2015-11-06 17:22             ` T.V Raman

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=CAAdUY-K6ygktXi42fA7G+hHAmw+nW1w71j0zUczhL+MX8rVoRQ@mail.gmail.com \
    --to=bruce.connor.am@gmail.com \
    --cc=emacs-devel@gnu.org \
    /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.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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).