From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel 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 Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1430272014 2276 80.91.229.3 (29 Apr 2015 01:46:54 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 29 Apr 2015 01:46:54 +0000 (UTC) Cc: emacs-devel@gnu.org To: Pontus Michael Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Apr 29 03:46:45 2015 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1YnH5I-0008KH-RX for ged-emacs-devel@m.gmane.org; Wed, 29 Apr 2015 03:46:44 +0200 Original-Received: from localhost ([::1]:36437 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YnH5I-0002eS-0J for ged-emacs-devel@m.gmane.org; Tue, 28 Apr 2015 21:46:44 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:55053) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YnH5E-0002bN-Fj for emacs-devel@gnu.org; Tue, 28 Apr 2015 21:46:41 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YnH5A-0003Qw-Cv for emacs-devel@gnu.org; Tue, 28 Apr 2015 21:46:40 -0400 Original-Received: from ironport2-out.teksavvy.com ([206.248.154.181]:40564) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YnH5A-0003Qq-9C for emacs-devel@gnu.org; Tue, 28 Apr 2015 21:46:36 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgUFAGvvdVRMCqjW/2dsb2JhbAA3gVOhb4EIgXUBAQQBViMFCwsOJgcLFBgNJIgTohGLdixCDAODPgMLg2UEo2OEWA X-IPAS-Result: AgUFAGvvdVRMCqjW/2dsb2JhbAA3gVOhb4EIgXUBAQQBViMFCwsOJgcLFBgNJIgTohGLdixCDAODPgMLg2UEo2OEWA X-IronPort-AV: E=Sophos;i="5.11,557,1422939600"; d="scan'208";a="117734587" Original-Received: from 76-10-168-214.dsl.teksavvy.com (HELO pastel.home) ([76.10.168.214]) by ironport2-out.teksavvy.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 28 Apr 2015 21:46:36 -0400 Original-Received: by pastel.home (Postfix, from userid 20848) id 88C074650; Tue, 28 Apr 2015 21:46:35 -0400 (EDT) In-Reply-To: (Pontus Michael's message of "Tue, 28 Apr 2015 21:09:01 +0300") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 206.248.154.181 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:185990 Archived-At: [ 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 ) returns ", 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