[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: nadvice.el: making add-function applicable to key-binding / using a
From: |
Stefan Monnier |
Subject: |
Re: nadvice.el: making add-function applicable to key-binding / using a function as generalized value |
Date: |
Tue, 28 Apr 2015 21:46:35 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux) |
[ 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