unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Pontus Michael <m.pontus@gmail.com>
Cc: emacs-devel@gnu.org
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	[thread overview]
Message-ID: <jwvk2wvoh5v.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <CAPpfmHKLHxTk4QiHNDO3NSgu9gHcjs0vGFKNi_12GPq0WAgFKQ@mail.gmail.com> (Pontus Michael's message of "Tue, 28 Apr 2015 21:09:01 +0300")

[ 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



      reply	other threads:[~2015-04-29  1:46 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]

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=jwvk2wvoh5v.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=emacs-devel@gnu.org \
    --cc=m.pontus@gmail.com \
    /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).