From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id ECiWIlKlL2LdNQEAgWs5BA (envelope-from ) for ; Mon, 14 Mar 2022 21:28:02 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id gFP4H1KlL2KdQAAA9RJhRA (envelope-from ) for ; Mon, 14 Mar 2022 21:28:02 +0100 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 16320A554 for ; Mon, 14 Mar 2022 21:28:02 +0100 (CET) Received: from localhost ([::1]:53320 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nTrIP-0008AB-8O for larch@yhetil.org; Mon, 14 Mar 2022 16:28:01 -0400 Received: from eggs.gnu.org ([209.51.188.92]:47694) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nTrHy-00088Q-2G for emacs-orgmode@gnu.org; Mon, 14 Mar 2022 16:27:34 -0400 Received: from mail-db8eur05olkn2054.outbound.protection.outlook.com ([40.92.89.54]:32608 helo=EUR05-DB8-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 1nTrHv-0000P1-Mn for emacs-orgmode@gnu.org; Mon, 14 Mar 2022 16:27:33 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eBZVgQsMEELZVSZON0MtLmB5CS7bpa5G1ewrcTtvJnIvdm0Hj9oDDLcPKeFQ3+JIL1KO6qXhY7a7LGfD2kU99yvVRpYsmkKBODP1+7SG58cF5FSSYXkVpwBwANXuSs3PuQEwoSMSuYPAo05grmtSfnS1AQ9ZgCR4RwJYuDKyy7h2jn6JFH8hyotSh9NrmIfUkJLJBsduY1B8EZpHMJZeU8CWV1i7Y/BvUokkljfrzmEZZIMghUwSiH3AI+pSpsDarG9q7z3peymfJxRu77kda05RApHZB/W/Uvq1lYl7WZzRB2lNeQ/yScBNNMrzv1CcvU1BaqyR0qF6Ln5bipc5kw== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=x2Znw591TeuXkP2I7l/J/rcpMfwvmR5STlG3glyYx4w=; b=NShDqPg6uXgyduI5FhF12gVnqE/iQURJwz3ZoPTgtaQs6yoiShADi5bFDNCvdGCTfsHXi0OqgqKrJBWULzGQ2nndbGZHxCzp+AnH0w6Fty5P3tbUbZE65J8ngm06r/50VLt114tDYj6FDk/AAgkZyP6ZDtj34w0/Z96iBrS4g18IcluGFuzPOSFSoFNg1KFYotrUaSVKnenWPf49jQ8swjOUzkTD0vjQr8I0UXfUjUweMuTU+HiSX+iSml14FQU1KhkvTcrrIUHUCwCUEo5DRkUslXDLMXDI3aA8SiqNkwqi5tPYNarLB9T5Y0FtHOrw3t90BVDEDInnFxyGcgBEaw== 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=hotmail.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=x2Znw591TeuXkP2I7l/J/rcpMfwvmR5STlG3glyYx4w=; b=bm5u5DAZC75sTgeIJF0hJHfR1mxvXhLULT+uCzRhZN3vZTiuE6JJ5kP3igw5hmTJc6TjdJ28ltifAjtAOSqD4L8LiG5v2IyJG2dDJmpg71NIg6gxf6i04X+La1dMUzWzVRFBww6f4e6wbyap9lVlAWQc72gsCB9flIqLcrAsCxPBB7uJyeqK2wY4rfz7aK7clONkT8UZ/sEm3JMjIKkL3bIcjqk0migY2iIGgqJ8Vp+4TrWYbkhd1NdAxbn0Vjf4r8LYQOIfdUscjOFUaP8Tazw3ROQMApS3HOn7CZew4xT6K4DplCuIj6SmkrkZ/8WzjEi4uZGvOHLb1V4H3fROtA== Received: from PAXPR06MB7760.eurprd06.prod.outlook.com (2603:10a6:102:155::8) by VI1PR06MB4702.eurprd06.prod.outlook.com (2603:10a6:803:93::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.22; Mon, 14 Mar 2022 20:27:28 +0000 Received: from PAXPR06MB7760.eurprd06.prod.outlook.com ([fe80::e05a:8d81:8648:b10f]) by PAXPR06MB7760.eurprd06.prod.outlook.com ([fe80::e05a:8d81:8648:b10f%9]) with mapi id 15.20.5061.028; Mon, 14 Mar 2022 20:27:28 +0000 References: <87mthw8b74.fsf@gmail.com> <87tuc0mjjj.fsf@gmail.com> User-agent: mu4e 1.6.10; emacs 27.2 From: Ignacio Casso To: Tim Cross Subject: Re: [BUG] org-capture autoload bug? [9.5.2 (9.5.2-gfbff08 @ /home/ignacio/.emacs.d/elpa/org-9.5.2/)] Date: Mon, 14 Mar 2022 20:43:10 +0100 In-reply-to: <87tuc0mjjj.fsf@gmail.com> Message-ID: Content-Type: text/plain X-TMN: [Y7xnVgHMgu5Artl+96tOekJpPgMt6Bgx] X-ClientProxiedBy: MR1P264CA0019.FRAP264.PROD.OUTLOOK.COM (2603:10a6:501:2f::6) To PAXPR06MB7760.eurprd06.prod.outlook.com (2603:10a6:102:155::8) X-Microsoft-Original-Message-ID: <87h780cmac.fsf@hotmail.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 06a12721-9849-4fb8-8a4b-08da05f90f08 X-MS-TrafficTypeDiagnostic: VI1PR06MB4702:EE_ X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: OBTdJbKBWq5Ha8SYuTUcMIfLZRfO7L+YoZmqAY3ZZGKWibRvN+Ntlw1xCFWVSw/iZ2GD93sUS2cLvkmSTg7NUc8+UZSOcWBoG4VPXY9wCpz8y6+CxxWXdTf9rOij7MjSsHTQfG7Aj/8ynQAeSKid4wGi/hhbYZQhi3aZfM8v6So33kiZdjivntX5eExOmvrx9GPpPv9+1GwzbifZ9Pa2KE+822Wlep7SCeiGLYhrQJnLRO7fUckYO/efkAynbHeUSgC4b6KS8xNkQSJrCX9bJ+5cS/lYFyHSzM3SpFOMsYMMBXxRuu9C94oB2ouFrXXTXBMLiuDPNahMWBwrJc/62Cpu7wu5iWJY+cTTW+tWpXqpSJBGqGCeNrDBuwp/CubCdEwriGHfTy2aEpEzD3yB86+XpBeqbwtCjMbZX2QkVtggDUogakjdtszJdVpICwR5l735auVwZVjhbR8Y1ZuYtmcV2lzYKaP7xLP7oFxsWMx+8EQhNKAvbvCsTsRiHO8sxBJ8oZVKXv93WURbg8mzZ8nSBZnGHsZHVBmTaw1q2f8nzcDOKQ73kvhZ0R8g+GokeRRTg57ClBeTnBTCDSSpHr6FdRTOFUMUVN3U/jcDBJIFKWOTlUIbRm9+U8Aq70+f X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?sfxCjNNBKpk44mZO2OO/l3pvyvp3l7mooaNF7sSoGnVgKMgI4bjpYD8CGXKU?= =?us-ascii?Q?RnupyGV0KgAO7VCgHX22l7RjOgA3nbQcQe3YqAhXlRcJJVOtaKSeRgQ0BOEd?= =?us-ascii?Q?u9j/5VUcgJc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UR0Pa78CYfENqcHvgAe28Al?= =?us-ascii?Q?CB50mDoJcTEYjUbFBQhn87sFbQK92HeEt9XrsKfirmEK2MhS6xJ53vDRFIsn?= =?us-ascii?Q?eD877NW204TG3lowqTReGR0AwvdRWNET6hzCB6g9IkqXQ48ENSfNmrrAeFc4?= =?us-ascii?Q?a6WwxJwamjXoFVBlemtLkt55FjGwzED8mw=3D=3D?= X-OriginatorOrg: sct-15-20-4755-11-msonline-outlook-6e454.templateTenant X-MS-Exchange-CrossTenant-Network-Message-Id: 06a12721-9849-4fb8-8a4b-08da05f90f08 X-MS-Exchange-CrossTenant-AuthSource: PAXPR06MB7760.eurprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Mar 2022 20:27:28.8884 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR06MB4702 Received-SPF: pass client-ip=40.92.89.54; envelope-from=ignaciocasso@hotmail.com; helo=EUR05-DB8-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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Max Nikulin , emacs-orgmode@gnu.org Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1647289682; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=x2Znw591TeuXkP2I7l/J/rcpMfwvmR5STlG3glyYx4w=; b=ewJ/SJnWjxqHYGVTuDtXJgNtMjI1TkdyTSsX1Ngz5LAhsdzPvmstqiry5mkjtQSq8nvmvd slzoIIb4cX+wOvQH7U2LYOJCfPK9s53qrji7CzfclO1g+zmCpjRQSH86shfhsCVhFSokEY j58WhNrWULQIK8i0gp0POBDMAQWS4KkPLXPZuXcolZemC38rPFkiqaz/eiWyA/L81B9wk3 1ZLQHvFqlpKfjJd+Zm9OdNuk6t9EmXMNUgu6UuP/ty21QZyp2W29dT54pJBoyRby44qVGq 28q7lXKWNrlJvGHLmRSpkzwQMHU0hyPUl02f/oMjli3FRPigNDSpHUT9SCttFQ== ARC-Seal: i=2; s=key1; d=yhetil.org; t=1647289682; a=rsa-sha256; cv=pass; b=Ha2u7W0dDTRBHDuiM877wk8NJ8pBqK9ND1mliJD0zwsJgbxD3gY6wtcxero9v2X524ovCf yVKxPUcIWS6lrh7UR3X9Y/aTVVyAAhaYjBTgiNokL6sQ2Fi/yDQcdIuYyj80jSqmh+cMbe gnWlt13R5pE1SNUf5+yqSa47F7TqNIJJDWv9NRDabS8S46WJ8l/EQjlfChhitTJBsGS8Q9 5I4exfFfHyY6JQqON9bXIT3oBM+qVuSfePQCwtVhgl77BDURbHKlqTrsywYl+8wtcFkr/0 DCmmnQQCde/v8T3MWVVwwAuvydlOCphou+q9v5Z9H2SbaQjBtiu92SRk9X81wQ== ARC-Authentication-Results: i=2; aspmx1.migadu.com; dkim=pass header.d=hotmail.com header.s=selector1 header.b=bm5u5DAZ; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=none) header.from=hotmail.com; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -7.48 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=hotmail.com header.s=selector1 header.b=bm5u5DAZ; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=none) header.from=hotmail.com; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 16320A554 X-Spam-Score: -7.48 X-Migadu-Scanner: scn0.migadu.com X-TUID: lrtkxnVgBn5f I've also investigated the issue a little bit further and wrote and email with my conclusions about the same time Max wrote his. I comment inline about a few of your thoughts: > For `defcustom' autoload generates no more than > > (defvar org-capture-templates nil "...") > > It seems, behavior depends on whether `org-capture-templates' has the :set > attribute. Not really, all defcustoms have a :set attribute, be it passed explicitly as a parameter or the default value, set-default. This issue happens with all autoload functions that use a custom variable: if they are called inside a let form binding that variable and the feature was not loaded yet, the let-binding will have no effect. > The setter receives nil instead of the let-bound value. I can not say > I understand the tricks with bypassing lexical binding in `defcustom' and some > checks in `custom-declare-variable'. Since emacs-26 something has changed: > I am unsure that the setter of `defcustom' should get let-bound value in the > case of autoloading since it might lead to fragile behavior. See my other email where I explain what I think that defcustom of a variable is doing when called inside a let-binding of that variable. >> https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=6309131349 >>> - ;; Use defvar to set the docstring as well as the special-variable-p flag. >>> - ;; FIXME: We should reproduce more of `defvar's behavior, such as the warning >>> - ;; when the var is currently let-bound. >>> - (if (not (default-boundp symbol)) But the conclusion is that right now it does not work, so I think that warning is needed. > It looks like the setter on org-capture-template is used to do some > form of conversion on the template specification to force a new > format. Not sure how long that has been there or whether it is > actually still required. Could be that this setter was added to aid in > transition to a new template format which could/should be removed at > some point. That is right, it seems it was added for backwards compatibility when a new template format was added. However, it's not actually needed, since org-capture-select-template also calls that function to ensure they are in the new format. It needs to do so in order to allow setting org-capture-templates also with setq, or let-binding org-capture-templates as I do. That's not the problem anyway, as I explained above. > However, this behaviour seems like it may be the tip of a much bigger > issue outside of org-mode and potential source of bugs for Emacs. > Bottom line is I don't think any function should behave differently > depending on when autoload runs > Regardless, I don't think having the situation where the programmer must > know (guess) whether autoload will/could execute during the evaluation > of code they write is tenable and am beginning to suspect it may be an > Emacs bug OR a subtle bug in org-mode as a result to the transition to > lexical binding as the default. My recommendation would be to come up > with a non-org specific example which reproduces the behaviour and then > ask on emacs-devel, using the example to demonstrate the issue. I agree. I'm on it. >> Reading the code I noticed `org-capture-templates-contexts' so I wonder if it >> might help for the original use case. > > I thought about that as well. However, from re-reading the OP's posts, I > suspect not. org-capture-templates-contexts seems to be useful when you > want to restrict access to some templates based on context. However, > from reading the OP's posts, I get the impression that what they want is > for templates to be different based on context i.e. they still want the > template associated with 'd', but want its definition to be different. > > It is possible org-capture-template-contexts might provide an > alternative solution where you don't need to dynamically modify/add > templates in this manner. For example, you could have all your templates > defined, but only offer those relevant based on context. However, I > guess this would mean having to have different template keys, which > might be an issue. If I recall correctly template contexts allow to redefine the template key, so that would not be an issue. And yes, using template contexts could probably be a solution to my use case, as it would be having an org-capture version with template parameter. But don't worry too much about my use case, since a simple (require 'org-capture) is enough to keep doing what I was doing.