From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id aEa9Edus02K2dQEAbAwnHQ (envelope-from ) for ; Sun, 17 Jul 2022 08:31:55 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id eFltEdus02K1KAEAauVa8A (envelope-from ) for ; Sun, 17 Jul 2022 08:31:55 +0200 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 EF29D1B9BF for ; Sun, 17 Jul 2022 08:31:54 +0200 (CEST) Received: from localhost ([::1]:50358 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oCxVL-0004b0-3c for larch@yhetil.org; Sun, 17 Jul 2022 02:11:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57910) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oCxUs-0004ac-Jc for emacs-orgmode@gnu.org; Sun, 17 Jul 2022 02:11:18 -0400 Received: from mail-lf1-x136.google.com ([2a00:1450:4864:20::136]:43747) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oCxUq-0005U1-DU for emacs-orgmode@gnu.org; Sun, 17 Jul 2022 02:11:18 -0400 Received: by mail-lf1-x136.google.com with SMTP id r9so14376832lfp.10 for ; Sat, 16 Jul 2022 23:11:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:message-id:date:mime-version:user-agent:subject :content-language:references:from:to:cc:in-reply-to :content-transfer-encoding; bh=bz3wnc82f3SndDaz1lSSkqJRn4yY6zK/3gXP1qQynUo=; b=igygXA528TsvjEaULiJwBVChtoG+TTSzzA5PxmZzProWHMYNuxZbfNMPXCN9Phnwju cyA5IoCAk8e5ypNy4yCgXad4ikf99bXX+z9kKIL8pC2ek9t55s/H1ROeVYLTNDVHMH9u warXP/XF3xA6CWCVZyemazcHozCYqxUE5ldJkrHwjCqcg1g0vbP7kYEAY+phfQ2bv3o0 f/O506ZFVt4wmIwHiRyHphHGQp/OUjGHriMX2PQYXdFsADR9QbGzgRppJTi9yYsrD7E+ 9c4Zv3utHkGtUuxxfaoUFB+H4yQ4jgLuqO+rN5x9Fmm+BlbODtxKbcXucA6jnbA2ixDI vtlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:message-id:date:mime-version:user-agent :subject:content-language:references:from:to:cc:in-reply-to :content-transfer-encoding; bh=bz3wnc82f3SndDaz1lSSkqJRn4yY6zK/3gXP1qQynUo=; b=tuMNOIXoD8G65gB8XcDQsoTYWQpBy3Ubuvgl4rtf1dQJr3AiILSaOnvw6IJYyzawq/ Ws5AetDHNxS1IaW8gZcjk0O/x9Us6JobYE25woIrs2b6PyzI7HMI5Mc9QZlsCLfb49/L qpoSbZVAnplRiMmFc1eGNTgWuqeWhGSb/hwf9j/PWc8dHhDTiF8BlvBVqrU5ocDg38o1 qPGkHMa5t65GRQf1qCnTRUPdjuYsqY6TbLzW4VRjyu0HjLaKOYAD0O3YFQSrJ035c0D2 SLQGGbNs4rW+sB5bkLOswBp5q7KBsl8eBhl71HqjMq6bUuBDMC/+qCy7o4JFT8zueB/i 4Acw== X-Gm-Message-State: AJIora/noYtIE4L1DNONE52z+tLayF4Mtz0A5u1DGTGPi/akF+KWvOFm nUuyJqfu38h13Q2qLmWRVRALeV3LN+g= X-Google-Smtp-Source: AGRyM1vnZaiRwoVhAVdW3Jo1spVqi8h/XSFyWOMLuyxvU0NrS5q8EvrcFfDD03lYFW1CcYYtjnYmTw== X-Received: by 2002:a05:6512:280b:b0:489:e6bd:5e44 with SMTP id cf11-20020a056512280b00b00489e6bd5e44mr12185490lfb.81.1658038273753; Sat, 16 Jul 2022 23:11:13 -0700 (PDT) Received: from [192.168.0.101] (nat-0-0.nsk.sibset.net. [5.44.169.188]) by smtp.googlemail.com with ESMTPSA id q27-20020a05651232bb00b00489de5012d4sm1849632lfe.301.2022.07.16.23.11.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 16 Jul 2022 23:11:13 -0700 (PDT) Message-ID: Date: Sun, 17 Jul 2022 13:11:11 +0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH v5] ol.el: add description format parameter to org-link-parameters Content-Language: en-US References: <87zgl1npow.fsf@localhost> <20220405192931.6747-1-hugo@heagren.com> <87a6cx79xn.fsf@localhost> <87zgi6fckr.fsf@heagren.com> <871qvixhfw.fsf@gmail.com> <87v8s8n1bm.fsf@heagren.com> <87let39d3c.fsf@localhost> <877d4flu3x.fsf@heagren.com> <87cze5e84m.fsf@localhost> <87tu7gkb4l.fsf@heagren.com> From: Max Nikulin To: Org Mode List Cc: Hugo Heagren In-Reply-To: <87tu7gkb4l.fsf@heagren.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Received-SPF: pass client-ip=2a00:1450:4864:20::136; envelope-from=manikulin@gmail.com; helo=mail-lf1-x136.google.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, NICE_REPLY_A=-0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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: , 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=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1658039515; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=bz3wnc82f3SndDaz1lSSkqJRn4yY6zK/3gXP1qQynUo=; b=anm3uwX6l0xZUp4vyc1UJ6XdJAncdT2uAen0WnKqaWrsXzjh+jNslZlrivrS1z7hg6PxZZ /MJ1JF5ZOCuxCbfgxH27xB2qa49/HlffdCZR9c5TU1TXyGM+pHIIW6b1b40T2djo/qg45I OScDZ3wG6qHePg6XpQm4GxMVsbhCDt49T8z5wqYqmLdiwadiTegBFtF3OBiMZvAa4RqME8 b89HwT7ftJY+e2ExwPpb7M3AixW8/iJQhK+QMOfuxyoS/t+jfsxm/hrCeFJPlOAQAPjhrq WskDw2l8fyeplJc+v41p9fco5396kCXQlaGOOey34Inbe6bkeudSZORf4S7R1g== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1658039515; a=rsa-sha256; cv=none; b=jutv6bV56sWUbbgXgWRMnrDj7P9Uq9UmKxsnldO4hRyj1mIAXSLhOPiP0EJVV35ZQwOuq1 924Fxz8ytJL4BSIckbzKFzPxbmTV/VOYP9+6rgogtA5dFKEL7Bya6BesX4MZ25AzDLeITa yinaOK3JdQDizDq+tUTkUEdyOdXVEGE+8xHDh/8bYlDkX/vOIG0bkJLiTfCbr1KMJvZuUS XnjnONCcfhL2c/7lK94Smv9SgAw6p2+j4ifkKCId0TlZuAGP9GXnDNB9+UieU1aW/3NE9e EhJvuP0LqBgaM90xm1MOvvFom8S9DZZL2i1Cwa6TgUBlvO8+EVeP85Vxu5NobA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b=igygXA52; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); 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: 5.97 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b=igygXA52; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); 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: EF29D1B9BF X-Spam-Score: 5.97 X-Migadu-Scanner: scn0.migadu.com X-TUID: u8lzWwXUJoin Hi, Ihor, Hugo raised a question how to interpret nil returned by :insert-description functions. Do you have any opinion? I do not like the idea to consider it as an error since string is expected. I would prefer to call `org-link-make-description-function' as a fallback. On 17/07/2022 04:20, Hugo Heagren wrote: >> Can you also update the documentation for >> org-link-make-description-function? > > I'm not sure what sort of documentation you have in mind? What should > I add? I have no idea what Ihor means. From my point of view, mention of :insert-description and `org-link-parameters' may give a hint to users. >> Have I missed something or the whole macro may be simplified to just >> copy `org-link-parameters'? >> >> `(let ((org-link-parameters (copy-tree org-link-parameters))) >> (org-link-set-parameters ,type ,@parameters) >> ,@body)) > > I had the same thought. I doesn't work though. `copy-tree' and > `copy-sequence' only make shallow copies of each element in a > sequence. `org-link-set-parameters' then uses side effects to alter > the `org-link-parameters', so these changes are propagated to the > copy. This means the values in the copy and the real > `org-link-parameters' are always the same, and so we can't use the > copy to store the original values (which is what we need it to do). I have tried it again (Emacs-26.3). I agree that `copy-sequence' and shallow copy is not enough, but `copy-tree' works for me. It rather a curiosity than demanding related changes. (defmacro nm-with-org-link-parameters (type parameters &rest body) (declare (indent 2)) `(let ((org-link-parameters (copy-tree org-link-parameters))) (org-link-set-parameters ,type ,@parameters) ,@body)) (nm-with-org-link-parameters "help" (:insert-description (lambda (_link _descr) "h1")) (assoc "help" org-link-parameters)) => ("help" :follow org-link--open-help :store org-link--store-help :insert-description (lambda (_link _descr) "h1")) (assoc "help" org-link-parameters) => ("help" :follow org-link--open-help :store org-link--store-help) > I have never used `declare' before. I looked it up in the Elisp manual > and read the docstring, but I couldn't understand how it specifies > which argument is considered the body. I'm also not aware of what this > does/why this is useful? (not a criticism, I just haven't learned this > yet). See info "(elisp) Indenting Macros". Without `declare' automatic indentation is the following: (nm-with-org-link-parameters "help" (:insert-description (lambda (_link _descr) "h1")) (assoc "help" org-link-parameters)) >> and maybe even be a sibling of >> (def (org-link-get-parameter type >> to keep related code more local. > > This isn't possible, because that's a clause in a `let' call, which is > itself inside a `cond' clause, and the `CONDITION' of that clause uses > `type', so it has to be defined at a higher level. It was written with assumption that `or' is used instead of `cond' to call `org-link-make-description-function' if :insert-description returns nil. >> I have not tested, so I may be wrong in respect to the following. It >> seems, you rises priority of desc value that earlier was a fallback. >> The reason why I am in doubts, is that it seems, desc is initialized >> from current link description when point is withing an existing link >> and in such cases desc likely should be preserved. I can not say >> that I like that it is responsibility of all description functions >> to return the desc argument if it is supplied. > > It's right that `desc' is initialized from current link description > when point is withing an existing link. > > Previously, `desc' was only used when > `org-link-make-description-function' was nil. This seems to me a very > odd behaviour: preserve the current link description, but only when > `org-link-make-description-function' is nil. Especially considering > that `org-insert-link' is also used for editing already-existing > links. So in the original version, in some situations, > `org-link-make-description-function' had a higher priority than > `desc', which seems wrong. In addition to changing behavior, you decision is still a trade-off. Consider the case when, editing some link, a user changes link path and expects to get new default description. When description function is called, to respect existing description, it may be defined as (lambda (link desc) (or (org-string-nw-p desc) (format-string "My link %s" link))) I do not like that in such approach checking of DESC is mandatory, so it is OK for me to commit your variant with high priority of DESC and to postpone discussion of possible improvements. A side-note: see the following thread for a feedback form a user who is not happy with current prompt for description: Visuwesh. [BUG] org-insert-link should use DEFAULT in read-string when asking for description. Fri, 25 Feb 2022 19:49:23 +0530. https://list.orgmode.org/87sfs7jafo.fsf@gmail.com > + (t (condition-case nil > + (funcall org-link-make-description-function link desc) You do not check that `org-link-make-description-function' is not nil. You might even add a test for such configuration (no :insert-description is defined). I have not tested the latest version of the patch and I am sorry if I missed some changes intended to address my suggestions.