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:03:42 +0200 Message-ID: References: <87bl6fy4cf.fsf@web.de> <87r1faf4fy.fsf@web.de> <871r78ydbb.fsf@web.de> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="34169"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: help-gnu-emacs@gnu.org To: Michael Heerdegen Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Thu Aug 05 08:09:25 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 1mBWZH-0008bP-VK for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 05 Aug 2021 08:09:24 +0200 Original-Received: from localhost ([::1]:57866 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mBWZG-0002BB-Bb for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 05 Aug 2021 02:09:22 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:40228) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mBWYj-00027B-Tq for help-gnu-emacs@gnu.org; Thu, 05 Aug 2021 02:08:49 -0400 Original-Received: from mail-am6eur05olkn2080e.outbound.protection.outlook.com ([2a01:111:f400:7e1b::80e]:51905 helo=EUR05-AM6-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 1mBWYh-0001Oi-Eu for help-gnu-emacs@gnu.org; Thu, 05 Aug 2021 02:08:49 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TueNoN6rRIyUz0/+nGlS0VZ6Z84GHDy29cMzAl90M9g3fUW9FCZcTH+QDXB7orLKTS1lXDSJVZe++RwiEV7fwO0hqT7IbktQjwMSxhn4nFV1MQ1PLlCBCs07OXqyDKbSAgmR1FUMh1caBrye/aLod7pOXzlbVTtlyFdgSyvbrywIVySPMeJ+Ot5bczh63TA3qe6gsT9Ps6b0/QTzXvZPBe3j64zO7viAMbzmRdkkqyXh3XncEXrpgz8DnxVibYI7RB20x7FpTG3KgfzdEvD1mSdztnsc5menmS3pruKjn1F+80RhfHz74Pvg9OiZEevgaAUr9lBkaSabqiqzzohfJg== 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=rvn7DK1GCdMKDAK1iD6UE7iphQ0lRha/3oDo9HOd+Jw=; b=YPsUtx8BSnlQjgjgoYtNWGbbDo4WzRi9ot5Jb6MRzF77bF73kfoGjKfTrSFrLvK3HONUytMoq/gbv/+PsYpnnItuGrLjKLwqTzKCwKny374GJHM92dI7+VBlHV8Sr22MBCJixEdDE43aiN8N9ddXRK2pVLyyD4wHW57E5LYCCHJD8aJv/tKubB6HDNUsF2jgxKWj7wPKabVK3KjrX4q+qYYomvdth0AIGu8QSO+pvnO2F/5YO9BaZ4Q9CABJa7kLHj85NZQTWM2LLOvf74gfqTBjkA3YGqew0Gd2e/TVL0kL8BhgdpgIN6Rkc/8r8qJmCGwqDW1DO8PaXBLeWlH2hA== 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=rvn7DK1GCdMKDAK1iD6UE7iphQ0lRha/3oDo9HOd+Jw=; b=sZXk3PG/sG1D1npgf8GHTfnMrvZFHopyCAM1wnvIVboPKC3RDnyaNJWaM/0uaOBNXgQr0zxTdw1CaW5Rs7aupItyCGznJ1rcMocqh43AnU/EXtGftilAOnAxYf529z5IJ1d0ASN7AFHhJOS27SdRmweeucTFRWbJrpd9VH8iUgbjO/l9SeXIUi6vzj+hOpYQ+w8fkTLLlz9t3ighAadIph6EL/9QkAzZfE9fP54QkLbe2hRx+SlwUoEfxccmaZW9UzZK9O64YsxwuqW1R1anV9jcS/mJc4Z5QoiQ9E2yx1Ckn8vLcBLyV3m5kPYa74Z4HxmplJ2/HFDKzC28R2MbOg== Original-Received: from VI1EUR05FT035.eop-eur05.prod.protection.outlook.com (2a01:111:e400:fc12::42) by VI1EUR05HT130.eop-eur05.prod.protection.outlook.com (2a01:111:e400:fc12::210) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4373.18; Thu, 5 Aug 2021 06:03:43 +0000 Original-Received: from AM9PR09MB4977.eurprd09.prod.outlook.com (2a01:111:e400:fc12::50) by VI1EUR05FT035.mail.protection.outlook.com (2a01:111:e400:fc12::114) 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:03:43 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:6BFD9C214B0BB0C7A3A93DC30F4044CF4FEFF70051FB77F4B06D04ACB348FE33; UpperCasedChecksum:7F61206F9538B9465EC58E0981C3DC8A57D104BE00567911E2967F5F11E6FB59; SizeAsReceived:7668; Count:46 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:03:43 +0000 In-Reply-To: <871r78ydbb.fsf@web.de> (Michael Heerdegen's message of "Thu, 05 Aug 2021 01:56:08 +0200") X-TMN: [IwB499FujbYz5lufMyUJa4nROmesPERa] X-ClientProxiedBy: AS8P189CA0027.EURP189.PROD.OUTLOOK.COM (2603:10a6:20b:31f::28) To AM9PR09MB4977.eurprd09.prod.outlook.com (2603:10a6:20b:304::20) X-Microsoft-Original-Message-ID: <87k0l08m2p.fsf@live.com> X-MS-Exchange-MessageSentRepresentingType: 1 Original-Received: from pascal.homepc (81.232.177.30) by AS8P189CA0027.EURP189.PROD.OUTLOOK.COM (2603:10a6:20b:31f::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4394.15 via Frontend Transport; Thu, 5 Aug 2021 06:03:42 +0000 X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 46 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: b9b64110-99a2-489d-daaa-08d957d6c748 X-MS-TrafficTypeDiagnostic: VI1EUR05HT130: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: c7LqZh2CchZiiQYAvpj7dGK2cK4gL1jp9vqJA6FCRAg4arjJg6NwbrBW3hVNqnN8VB6R48+QPgVTZ073nAzCgLzvhbYyk+s9nvd1ET5Cz5EKjICp101ebKwMIR3I1fB/wsXCFXRD89rB47uhgmhTqZHqNM/LnGykNIDdWaNZXedPxzfwBVEZXxlv+Engs+Doh0kAn/8xXQzGTKiSCbbuWuaE0SlbYza3UyxOFq739pJGbFJ5vZ0CLScqRHiBF0xy5DFBzkAtz4xEcbF8qTOlchZmIl6n/VTVMGf0Cdgy+TAOcJzbTHn8ylY6hByI+d9Wa48UMOGX4CpXS5xFB2dsEAwEyCildny3TpdaqTssWjesnsSZ4ItoeztZn6VX59fJnhegSzg3T4uJUzFEs4UYp9jxjCudgf6A/qCpz9EeQcqR1iGL04BDBfr0pfCnaIhB X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: VOUFa5qygjRCMOXaLsOrCXvl4ociuill3Fy80t3nRzNRzPusexfDGeXRwhIMEUiJp6VzCTajpeyGwDynPvQeLBpPmW5yQwRmZqzOpfBcLoSQHOxfUbCy+6Tmvl0Jc+PCAhj9BYoKUiJgVuP8wgVTJQ== X-OriginatorOrg: live.com X-MS-Exchange-CrossTenant-Network-Message-Id: b9b64110-99a2-489d-daaa-08d957d6c748 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Aug 2021 06:03:43.2821 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-AuthSource: VI1EUR05FT035.eop-eur05.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: VI1EUR05HT130 Received-SPF: pass client-ip=2a01:111:f400:7e1b::80e; envelope-from=arthur.miller@live.com; helo=EUR05-AM6-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, 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:132366 Archived-At: Michael Heerdegen writes: > Arthur Miller writes: > >> > Your `keymapp' fix is an emergency solution but it's not perfect: >> > that test happens at compile time. If the keymap is not defined at >> > compile time your compiled code will be inappropriate. > > I see now that I was wrong here - the test is performed at run-time. I discovered that yesterday too. I tried the new macro on my init file, and it found several left-over bindings after some packages I don't use any more. >> I agree, but do I wish to pass name of undefined keymap to define-key? > > Not at run-time: when the `define-key' call is evaluated, the symbol > must be bound, else you would get an error. Of course, every symbold has to bound when evaled. This is a bit special use case. I am always ensuring it is evaled in context where everythign is defined.The use case for my init file is that I pass those stuff always in 'with-eval-after-load' for some package. So it is always symbols should be always defined otherwise I have bigger problem then misspelled syntax. I also expand this myself so I just just write define-key calls to my init file. However I also have this macro defined for interpretter, so I can test and eval stuff while I hack my init file. > But some way or the other something has to decide how to interpret a > symbol. If you want to use the same notation for the cases, you need to > use some kind of heuristic: in theory a symbol might name a function and > might be bound to a keymap at the same time. Yes, it's 'lisp-2' ... I like that feature. I know a lot of people prefer scheme version, but I think it is handy and also more efficient with 2 namespaces. > And instead of `eval' better use `bound-and-true-p' - you know that you > look at a symbol. Thanks. I can remove at least the eval in test with bound-and-true-p, but I don't think I can remove the second eval, since I have to get object the symbol is representing. However I am getting false positives from keymapp, it accepts anything seems like: (defmacro with-key-map (mapname &rest body) `(dolist (def '(,@body)) (define-key ,mapname (if (vectorp (car def)) (car def) (read-kbd-macro (car def))) (if `(bound-and-true-p ,(cdr def)) (if `(keymapp ,(cdr def)) (eval (cdr def)) (cdr def)))))) Instead I have to use to test for listp and functionp first: (defmacro with-key-map (mapname &rest body) `(dolist (def '(,@body)) (define-key ,mapname (if (vectorp (car def)) (car def) (read-kbd-macro (car def))) (if `(bound-and-true-p ,(cdr def)) (if (or (listp (cdr def)) (functionp (cdr def))) (cdr def) (if `(keymapp ,(cdr def)) (eval (cdr def)))))))) And I can also remove last if, and just leave eval, keymapp does not seems to cull anything out. > You could also check whether the `symbol-name' ends > with "...-map". I could, there is not guarantee, since it is just a convention, but yes I agree, I could have done that. Anyway, thanks you for the help and feedback. I do have some better understanding after this.