unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* nadvice.el: making add-function applicable to key-binding / using a function as generalized value
@ 2015-04-28 18:09 Pontus Michael
  2015-04-29  1:46 ` Stefan Monnier
  0 siblings, 1 reply; 2+ messages in thread
From: Pontus Michael @ 2015-04-28 18:09 UTC (permalink / raw)
  To: emacs-devel

First problem that I would like to address with this proposal, is the
inconvenience faced by the user attempting to alter default args for
existing command.

And secondly, wouldn't it be logical to expect following form to work?

    (add-function :filter-args
          (key-binding [?\M-\(])
          (lambda (args) '(1)))

If my understanding of how this kitchen works, it would only require
implementing gv api for `key-binding' for this to work and probably
`lookup-key' along with it.

My knowledge about involved technologies is very superficial, and my
hope is that someone capable will also see the benefit in it.



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: nadvice.el: making add-function applicable to key-binding / using a function as generalized value
  2015-04-28 18:09 nadvice.el: making add-function applicable to key-binding / using a function as generalized value Pontus Michael
@ 2015-04-29  1:46 ` Stefan Monnier
  0 siblings, 0 replies; 2+ messages in thread
From: Stefan Monnier @ 2015-04-29  1:46 UTC (permalink / raw)
  To: Pontus Michael; +Cc: emacs-devel

[ Not sure exactly what is your proposal.  Is it only adding a gv-setter
  for key-binding, or is there more to it?  ]

>     (add-function :filter-args
>           (key-binding [?\M-\(])
>           (lambda (args) '(1)))

> If my understanding of how this kitchen works, it would only require
> implementing gv api for `key-binding' for this to work and probably
> `lookup-key' along with it.

Yes.  But note that a gv-setter for `key-binding' would have the
task to "make it so that (key-binding <foo>) returns <bar>", and the
problem is that there many different ways to do that: add a binding to
the local map, to a minor-mode map, somewhere in
emulation-mode-map-alists, etc...

For `lookup-key' the task should be a bit easier, but still fraught with
risks: (define-key MAP KEY (lookup-key MAP KEY)) is not always a no-op.
Examples of problems come up if KEY is bound to a `menu-item' (in which
case lookup-key will not return the menu-item structure but only the
binding within it), or if KEY is not directly bound within MAP but only
within a parent of MAP.

Further problems come up because `add-function' is designed to handle
generalized values that contain functions, and only functions.
Whereas keymaps contain many non-function values (the most common such
value is nil, but other examples would be vectors (i.e. keyboard
macros), menu entries, sub-keymaps, ...).

So all-in-all, I think making it work half-reliably will be difficult.


        Stefan



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-04-29  1:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-04-28 18:09 nadvice.el: making add-function applicable to key-binding / using a function as generalized value Pontus Michael
2015-04-29  1:46 ` Stefan Monnier

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