From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Arthur Miller Newsgroups: gmane.emacs.help Subject: Re: Eval keymapp in a macros Date: Thu, 05 Aug 2021 08:12:41 +0200 Message-ID: References: <87bl6fy4cf.fsf@web.de> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="12823"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: Stefan Monnier To: Stefan Monnier via Users list for the GNU Emacs text editor Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Thu Aug 05 08:13:45 2021 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mBWdT-00033I-7S for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 05 Aug 2021 08:13:43 +0200 Original-Received: from localhost ([::1]:36298 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mBWdR-0006kL-Rt for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 05 Aug 2021 02:13:41 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:41178) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mBWcZ-0006jw-8c for help-gnu-emacs@gnu.org; Thu, 05 Aug 2021 02:12:47 -0400 Original-Received: from mail-oln040092067049.outbound.protection.outlook.com ([40.92.67.49]:38077 helo=EUR02-AM5-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mBWcX-0004je-3F for help-gnu-emacs@gnu.org; Thu, 05 Aug 2021 02:12:46 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nSPBZvz28C7r1ntbAMrkUYfy1F+DTj0lAkxAsfZdfcimfYP7Cztihl/LP9o5dYDkcgyGIrDGUjWWsp8nM7WZB6MV8hl7yKzeh+JRH/YEbo/JK0znNc1E3KNstkJ/BJRO1BIhXC3ZRDQOxRvgzKOgtKD1bXHVT9h34UujKTNq5PWdG9K8F2hTGQ8q5gSdWCtEJcVjo/Os+YXoz8DtJd9aIeKIZ73W16CmdFvR1P/t6BNFqaWAYXAkth2WhmDdwwcQmzgyHToJNUMz9PBN3IlPZJItcVN/9coWj8/dA/plohY2IkhjXU55YsXj0RzhR9OgzMnwBwFaNIIMBfNZpffpZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=lDop4njaqo77DOv7g3ZIV5TPjs12ikHgxs4PQkm/jYk=; b=ZntWArICJIvtEpZ8X/WRhtwinmdDSQ4hGIjnmepMpkEH4CyWlWYMfA3hSd6Bm5qmtQBURClisomAZ3Qo0k7C77TYy/49r8/tY4hwmQUh9sK4UYu9UrtlkzSPCj+5OQnkvvL0Xd8bden/MLal6TrrrEiZa9+ExcFlQRyIHtnyEOeA6mV0h3md3Pqbui7kkViyBGyYeTMq43alGI94zJK5oWh8PnAMMpGQRDgjpl1VTCcsS3yZdomwSDWv98EQKOZPmYReVQNLQ8PFW+wjo/AQK2i/QcH7KQi+YnZJvh4+xSunHLSeEBXncsf1JV34RRbAs5xbdrRjEbAbVJqz3Qf4lQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=live.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=lDop4njaqo77DOv7g3ZIV5TPjs12ikHgxs4PQkm/jYk=; b=Cx8LM4smD99QgwCJBaTQ/V38RhNbdrHDWsB+x1IvRYZmL7fRoDq/OLHjNaiKyLvdtR0i/iZI8oeJ3B6/s0zBvQudDhdaecmJw/0M3yeoE92/3XTC3dvQboD5Uefky0Xc4mdJia65unzXFqQKyhR/WuNa8YEceFhiZQ9/ZJTu/VK37WNyztI5Zj20BJQsCyiPYrUPwjeChP29INVSYwTpVvyVCPvkw/jARYoGLBA2rtIGko9DHFdzAtJ8Lacbe+XAzsVSVooEOlsToFfZbHGZLuVJMwPDsb3Bs0TRU5Ws4E+hs4+eTIovOOz6HQvSLXQYG5J7o0jKdxPTM0kvKtmKEQ== Original-Received: from HE1EUR02FT017.eop-EUR02.prod.protection.outlook.com (2a01:111:e400:7e1d::44) by HE1EUR02HT015.eop-EUR02.prod.protection.outlook.com (2a01:111:e400:7e1d::284) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4394.16; Thu, 5 Aug 2021 06:12:42 +0000 Original-Received: from AM9PR09MB4977.eurprd09.prod.outlook.com (2a01:111:e400:7e1d::49) by HE1EUR02FT017.mail.protection.outlook.com (2a01:111:e400:7e1d::73) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4394.16 via Frontend Transport; Thu, 5 Aug 2021 06:12:42 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:0BBEFA519ECD53B61D6B07C22A04A9CCADBF7DD3D4FBE394B82888E878E06459; UpperCasedChecksum:21ADBF842313FD76A3C4E6E79BA8D30EB47234AA46523AF606E9A560FBC62609; SizeAsReceived:9027; Count:47 Original-Received: from AM9PR09MB4977.eurprd09.prod.outlook.com ([fe80::6558:f201:6d1a:3f39]) by AM9PR09MB4977.eurprd09.prod.outlook.com ([fe80::6558:f201:6d1a:3f39%2]) with mapi id 15.20.4394.016; Thu, 5 Aug 2021 06:12:42 +0000 In-Reply-To: (Stefan Monnier via Users list for the's message of "Wed, 04 Aug 2021 11:37:22 -0400") X-TMN: [o3EQGTKBbarW43vBCNWzTff/rNqKdI3r] X-ClientProxiedBy: AS8PR05CA0014.eurprd05.prod.outlook.com (2603:10a6:20b:311::19) To AM9PR09MB4977.eurprd09.prod.outlook.com (2603:10a6:20b:304::20) X-Microsoft-Original-Message-ID: <87fsvo8lnq.fsf@live.com> X-MS-Exchange-MessageSentRepresentingType: 1 Original-Received: from pascal.homepc (81.232.177.30) by AS8PR05CA0014.eurprd05.prod.outlook.com (2603:10a6:20b:311::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4394.16 via Frontend Transport; Thu, 5 Aug 2021 06:12:42 +0000 X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 47 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: c6000108-0e8f-43dc-f8d7-08d957d808c5 X-MS-TrafficTypeDiagnostic: HE1EUR02HT015: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: nq/0SYqU4dr2N6YOfhU5cKlf6aUASDpmJNdANmWu5ASQ3Ad9Apxbj5HEIiaZGYit06wbKhy5ZC4Npqp/FC/ebutHfEUoQyBiL8GWU89cowsVUCNV7DBW17xuNCuQSFVvgSz7+tF8lQccb5RGe08yaeRZRoITJrdHpIxg9C/bChSsJUaCfCbOD91hfye5jW4PYlFTmVoR9RtzPc/DvRIcZD8YQ8EmIAXlNeDs6G3tNJLCYT2L7csa5ey7hSQoIwwxbg5lIj6bpac8rEfmz1DFBvgpsqs0HCbAGdBygQUlPcdjUMPDkk2yrNN1EUtclPNIkhWuqEBDEe8ppsW0Xe3qbB+TvIJy9G1AyqF5tiviyYifNj3wehahgjSlteLEPjM484N6MSlaLd5zYA1ZKf7rGH7mXmUFIs27+cf6ZHJzjGUjxROun8CooYFMeRjgwlmA X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: u5iym7Ums8XJgEa2kIqImlyKMN25X/PqJvb0jZOAp9Y1kt5SixZasSsSdNA9AZe/5Veo8UsTdqU8FJlptdGcpSfxJbRSsUF0gxtMu7GsZ8JQY8vDdZsFIVghdyIj1dlIMDDKhtTl2fs8L/y1GbmfYA== X-OriginatorOrg: live.com X-MS-Exchange-CrossTenant-Network-Message-Id: c6000108-0e8f-43dc-f8d7-08d957d808c5 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Aug 2021 06:12:42.5004 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-AuthSource: HE1EUR02FT017.eop-EUR02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1EUR02HT015 Received-SPF: pass client-ip=40.92.67.49; envelope-from=arthur.miller@live.com; helo=EUR02-AM5-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:132367 Archived-At: Stefan Monnier via Users list for the GNU Emacs text editor writes: >>> * If you sacrifice a quote and a pair of braces, you can have your >>> typing saving as a simple function: >>> >>> (my-define-keys global-map >>> '(("C-" . term-toggle) >>> ("" . term-toggle-eshell) >>> =E2=80=A6)) >> >> I know, but I wish the least noise as possible :-): > > In most cases, macros are best defined in 2 steps: > > 1- provide a function-based solution > 2- provide a simple macro that expands to a call to the function-based > solution, with a very simple massaging (typically adding a few quotes > or wrapping with some `lambda`). > > That also makes debugging easier. > Agree. When I wrote this more than a year ago, I wasn't yet red On Lisp. Since then I have actually got (almost) through On Lisp and Let Over Lambda, and have start doing so. If I wrote it today I would probably wrote a defun to return something I evaluate in macro, and I would use that macro as "entrance" so I skip quoting. But I had this 6-lines small macro to just save some typing, and thought it would be easier to fix. Actually for my own use, this is from my init file (defmacro with-key-map (mapname &rest body) `(let ((map (eval-and-compile (if (string-match-p "-map$" (symbol-name ',= mapname)) (symbol-name ',mapname) (concat (symbol-name ',mapname) "-map")))) (defs '(,@body))) (dolist (def defs) (define-key (symbol-value (intern map)) (if (vectorp (car def)) (car def) (read-kbd-macro (car def))) (cdr def))))) I am still good enough with that one, because I don't have so much more need that to define some bindings in few places, but it was a bit of challenge to adapt to the use case as pointed in the reddit thread.