From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Michal Nazarewicz Newsgroups: gmane.emacs.bugs Subject: bug#18729: [PATCH] subr.el (set-key): New macro making creating new bindings more concise. Date: Thu, 16 Oct 2014 14:39:08 +0200 Organization: http://mina86.com/ Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1413463225 10460 80.91.229.3 (16 Oct 2014 12:40:25 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 16 Oct 2014 12:40:25 +0000 (UTC) Cc: 18729@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Oct 16 14:40:17 2014 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1XekLo-0006Ks-Ln for geb-bug-gnu-emacs@m.gmane.org; Thu, 16 Oct 2014 14:40:16 +0200 Original-Received: from localhost ([::1]:50200 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XekLo-0005Sm-9K for geb-bug-gnu-emacs@m.gmane.org; Thu, 16 Oct 2014 08:40:16 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:38849) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XekLg-0005Px-PS for bug-gnu-emacs@gnu.org; Thu, 16 Oct 2014 08:40:13 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XekLb-0002Cb-OA for bug-gnu-emacs@gnu.org; Thu, 16 Oct 2014 08:40:08 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:53800) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XekLb-0002CJ-Kb for bug-gnu-emacs@gnu.org; Thu, 16 Oct 2014 08:40:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1XekLb-00040j-3w for bug-gnu-emacs@gnu.org; Thu, 16 Oct 2014 08:40:03 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Michal Nazarewicz Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 16 Oct 2014 12:40:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 18729 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 18729-submit@debbugs.gnu.org id=B18729.141346315815329 (code B ref 18729); Thu, 16 Oct 2014 12:40:02 +0000 Original-Received: (at 18729) by debbugs.gnu.org; 16 Oct 2014 12:39:18 +0000 Original-Received: from localhost ([127.0.0.1]:45364 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XekKr-0003zA-1q for submit@debbugs.gnu.org; Thu, 16 Oct 2014 08:39:17 -0400 Original-Received: from mail-wg0-f44.google.com ([74.125.82.44]:44077) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XekKn-0003yu-9A for 18729@debbugs.gnu.org; Thu, 16 Oct 2014 08:39:14 -0400 Original-Received: by mail-wg0-f44.google.com with SMTP id y10so3595819wgg.27 for <18729@debbugs.gnu.org>; Thu, 16 Oct 2014 05:39:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=sender:from:to:cc:subject:in-reply-to:organization:references :user-agent:face:date:message-id:mime-version:content-type :content-transfer-encoding; bh=W8gZMZfe1Sekm9F7CNq8T0PJzqhGD2ND6c2J+pFtBJ4=; b=VpsOdl020TOF4eNc6P1EHe6jtn9/C758sfjXRCJt4z1dlnGzH0f2VQSKoFhoHFTFBX rBVGXAqJg2cCyCj4MjGcS3uxzw3IhktS6tRbtlr7VeW9lobwFrFXdNntCuFK1wCsFtOA 3v3S2affnEs3C3hfYWQOHi/mhg3TIj4LD2QbZ2Qu3SLkscNlZyM5mFn6ffdQjjtwJcFy ecL17MUpn/WEMr5CialJWJ7sdQ3PsabyGzEyyuWi0jCC0Md804wZOA+V8LyCsoidjAGK H7jHGG9N31LMb9ZNYvGjU+NGsMtuKxMDpcHeIV5v9GFYkDpDNbnJIBPcQGkHAwCQbCfV D4DQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:in-reply-to :organization:references:user-agent:face:date:message-id :mime-version:content-type:content-transfer-encoding; bh=W8gZMZfe1Sekm9F7CNq8T0PJzqhGD2ND6c2J+pFtBJ4=; b=IzHmxn5i3A2PZkqaIP/d4EcaEcB3Iad3Xx0bAOZnQZA14dh5EPTYiBkyrlzladoGGh Vg+0vCWzxjoKyJWuiIc+rVEfZpXFNWugdri6AFmlIcem+C/dlVamS/5PqRXt5moCif9+ xXp08kWpOhsI+A3sBSDFVSSo7wVmuA0xk0lCu2DS9onmeaTltYnHOKasHl4nrAqtkYBX xigqpxlt4ugEPde78sfxix8tIMWMNGAm+C0ZBsx2qRxgGLq/gP1Z4ntRPfdEYjKYtGJi PujzD8p7UAXLZkBLfXBtRKL7E7zPDejrO4NsXAxo2Y7PgdiDR2X0NqpXkw2B0NiJWlZz 0+ZA== X-Gm-Message-State: ALoCoQkaM/TJTAhhvM6LG1rIKtTvao7xwj93oB8wmeom+iMZ4dhqMwWFS8xNiiiCirU/BJTdDn0+ X-Received: by 10.194.206.106 with SMTP id ln10mr1719807wjc.90.1413463152117; Thu, 16 Oct 2014 05:39:12 -0700 (PDT) Original-Received: from mpn-glaptop.roam.corp.google.com ([62.156.150.204]) by mx.google.com with ESMTPSA id u9sm1868920wiv.8.2014.10.16.05.39.10 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 16 Oct 2014 05:39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HDWfPniR 4iw5vJaw2nzSjfq2zffcE/GDjRC2dn0J0XwPAbDL84TvaFCJEU4Oml9pRyEUhR3Cl2t01AoEjRbs0sYugp14/4X5n4pU4EHHnMAAAAAElFTkSuQmCC X-PGP: 50751FF4 X-PGP-FP: AC1F 5F5C D418 88F8 CC84 5858 2060 4012 5075 1FF4 X-Hashcash: 1:20:141016:monnier@iro.umontreal.ca::byCoV0CIuOf7kOkZ:000000000000000000000000000000000000006ij X-Hashcash: 1:20:141016:18729@debbugs.gnu.org::UPD8ypRLjuntt5ns:0000000000000000000000000000000000000000AMrS X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:94596 On Wed, Oct 15 2014, Stefan Monnier wrote: >> +(defmacro set-key (keymap key &rest def) > I'm not convinced the added complexity is worth the trouble, I'm afraid. > I don't see a real benefit in > > (set-key :global KEY CMD) You wouldn't normally put =E2=80=9C:global=E2=80=9D here=E2=80=A6 > (set-key :local KEY CMD) > (set-key MAP KEY CMD) > > over > > (global-set-key KEY CMD) > (local-set-key KEY CMD) > (define-key MAP KEY CMD) [=E2=80=A6] =E2=80=A6but I can see your point and it's true that for those cases, the s= aving is not that big. > I also don't see the benefit of (:args ARGS INTERACTIVE . BODY) > over (lambda ARGS (interactive INTERACTIVE) . BODY). > > The only thing I think is really valuable is things like > > (set-key ... KEY (dired "foo")) Indeed, this is the main reason I've created the macro (I would still argue :args syntax is also convenient though). > For which there is also a precedent in easy-define-menu (where the CMD > can be either a symbol or an expression, in which case that expression > gets wrapped in (lambda () (interactive) ...)). > > Maybe we could simply extend define-key to accept > > (define-key MAP KEY '(dired "foo")) So are you think about something like: diff --git a/src/keymap.c b/src/keymap.c index c7c7d19..4b8251b 100644 --- a/src/keymap.c +++ b/src/keymap.c @@ -786,6 +786,9 @@ store_in_keymap (Lisp_Object keymap, register Lisp_Obje= ct idx, Lisp_Object def) && (EQ (XCAR (def), Qmenu_item) || STRINGP (XCAR (def)))) def =3D Fcons (XCAR (def), XCDR (def)); =20 + if (CONSP (def) && !EQ (XCAR (quoted), Qlambda) && !EQ (XCAR (quoted), Q= closure)) + def =3D Fcons (Qlambda, Fcons (Qnil, Fcons (Fcons (Qinteractive, Qnil)= , def))); + if (!CONSP (keymap) || !EQ (XCAR (keymap), Qkeymap)) error ("attempt to define a key in a non-keymap"); =20 ? Or am I looking at completely wrong place. Thing I'm worried about here is that the function will not get byte-compiled, whereas with set-key macro it will. Also, I'm not entirely sure whether the function should use lexical-binding. -- Best regards, _ _ .o. | Liege of Serenely Enlightened Majesty of o' \,=3D./ `o ..o | Computer Science, Micha=C5=82 =E2=80=9Cmina86=E2=80=9D Nazarewicz = (o o) ooo +------ooO--(_)--Ooo--