[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Emacs-diffs] master b75fb81 1/4: Extend button.el to take callback
Re: [Emacs-diffs] master b75fb81 1/4: Extend button.el to take callback data
Fri, 02 Aug 2019 20:46:56 +0200
Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)
"Basil L. Contovounesios" <address@hidden> writes:
> (defun button-callback-action (button)
> "Call BUTTON's `button-callback' property."
> (apply #'funcall (button-get button 'button-callback)))
> (define-button-type 'rcirc-url
> 'face 'rcirc-url
> 'follow-link t
> 'action #'button-callback-action)
> (make-text-button start (point)
> 'type 'rcirc-url
> 'button-callback (list #'browse-url url))
> (Using define-button-type is optional, but encouraged.)
Button is such a nice and light-weight library (especially compared to
widget). Having to write these wrapper functions to do these trivial
transforms is the one bad thing in the API.
> Button action functions have until now expected a button as an argument,
> but now they may or may not be given a button, and this is determined by
> the presence or not of a button property. Why introduce this brittle
> backward incompatibility?
I don't see how it's brittle, and it's not backwards incompatible.
If you add a 'button-data 'foo to your buttons, then you presumably want
your action to get the data. Otherwise, why would you do it?
> Oh, we seem to be interpreting "naming collision" slightly differently.
> I took it to mean that a client of the button library has used a
> property name for one purpose, which is used for another purpose
> But what is happening here is that existing code is written with the
> assumption that button action functions receive a button as argument.
> This assumption now breaks down on buttons with a non-nil button-data
> property. Why make this unnecessary and backward-incompatible change?
I still don't understand what you mean here.
If somebody writes a new button that has 'button-data, how does that
affect the existing button? If you write a new button, and say
'button-data, then the 'action you've written takes that data as the
argument, not the button.
There's nobody randomly adding 'button-data to random existing code,
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no