From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id wHcZCZR6hmGCRwEAgWs5BA (envelope-from ) for ; Sat, 06 Nov 2021 13:52:36 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id RxugBJR6hmEgaAAAbx9fmQ (envelope-from ) for ; Sat, 06 Nov 2021 12:52:36 +0000 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 55C822F82B for ; Sat, 6 Nov 2021 13:52:35 +0100 (CET) Received: from localhost ([::1]:33774 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mjLBR-0006RK-AT for larch@yhetil.org; Sat, 06 Nov 2021 08:52:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47744) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mjLAg-0006RC-6J for emacs-orgmode@gnu.org; Sat, 06 Nov 2021 08:51:46 -0400 Received: from mail-lf1-x132.google.com ([2a00:1450:4864:20::132]:36681) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mjLAb-0000Pw-Hf; Sat, 06 Nov 2021 08:51:43 -0400 Received: by mail-lf1-x132.google.com with SMTP id j2so24576377lfg.3; Sat, 06 Nov 2021 05:51:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language; bh=TirF0di8LY6LxoQND0KRgxaPRyspyBD5E5p4oyTcio4=; b=dj5GPsL3gFR2q1HOe6ncSAxe7PNndpkhHJw5mPTZ2i5X3WPAUJ+eFAlr3OcDJ4qfHw R+C/20ZPNkJen1Mc1GlERas5vOo/sBWB15NeIED/paX5mWlwUS/zQUVHuLimPOE1iZzz q2jG9bS1Bx6Nt4rDGTlUwEB0qQPOh4XwKW8tM8v20Lndcqj84YDROsW4BJUlL8I87xH7 HQTiSeAoVer6cWiR+ZacsJep8BMzomttL6nH0rHVRAkrnOxS17qmH6nK3SebYmZTguls 5+PvTzMumy4P+nCmbYiNsCrOfl2Rlfyej3TnJ5/svHBwuG9tf36N3mv9hiADVSHQblPY nVxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:subject:to:cc:references:from:message-id :date:user-agent:mime-version:in-reply-to:content-language; bh=TirF0di8LY6LxoQND0KRgxaPRyspyBD5E5p4oyTcio4=; b=y415sWgX+ZSwEPdAwepSZIGzdeGi3VhSYVHdz8TaSn02OtlNz8EY6agrjB6lZu62Cz 2/9cyNvTBIbgQ+h1Y8QqEf5DlEniypnqEqVIObT6JIt1JMenb/cZSBtennNpWb3FlfRm SJnnBBPZOticxZA2AE5Dy5MaIA5RhwpiCQqzGdiT0lwvYToXT9Oa1WZTJ1ICO09C8xSZ +nxg21yVPOwNZe7ypFPRCl1eELLF5A4hKMFHhd3RtsVRoZwnA8+oYUrxc/XOaiShQLuY iBPfoeq2MECca5CV//deAzTFSIcb1NL/YdmcxhIg0vbtGc1viz3ZmjnWLW2ofe7q4qbO uyoQ== X-Gm-Message-State: AOAM533g3blOVhje9S0+b4OG668QYTjViekRjVqkisWx6OK2O0sbx5eU 0hmkYyVCqcHcnPT8RFRNT+ZztDKJZj0= X-Google-Smtp-Source: ABdhPJxzV7sSxonma+eKgQa+pdM5GnoTJpKVPed7fQhRCi/YCYHJFuGk8RclX+KCiPYt6eJGS0Qyeg== X-Received: by 2002:a05:6512:3887:: with SMTP id n7mr60468286lft.356.1636203097275; Sat, 06 Nov 2021 05:51:37 -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 o11sm1152508lfr.98.2021.11.06.05.51.35 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 06 Nov 2021 05:51:36 -0700 (PDT) Subject: Re: Bug: org-store-link uses CUSTOM_ID instead of target point [9.4.4 (release_9.4.4 @ /usr/share/emacs/27.2/lisp/org/)] To: Bastien , Fr Ml References: <87im3wqbk6.fsf@gnu.org> From: Max Nikulin X-Woof-Patch: ol.el: Skip #CUSTOM_ID when <> link is stored Message-ID: Date: Sat, 6 Nov 2021 19:51:29 +0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: <87im3wqbk6.fsf@gnu.org> Content-Type: multipart/mixed; boundary="------------3B3654F49F6D4A994F67489E" Content-Language: en-US Received-SPF: pass client-ip=2a00:1450:4864:20::132; envelope-from=manikulin@gmail.com; helo=mail-lf1-x132.google.com X-Spam_score_int: -54 X-Spam_score: -5.5 X-Spam_bar: ----- X-Spam_report: (-5.5 / 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=-3.407, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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: emacs-orgmode@gnu.org Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1636203155; 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=TirF0di8LY6LxoQND0KRgxaPRyspyBD5E5p4oyTcio4=; b=ZY+MGSEr7kiVOdemxVRga7EsuSfVyi2jgvEJubJcfS4deCvKqNEOQ7j0Gp5GeSyogNCNjB g6QUMl4xFeYLQAgS0+rWhEQGeHNeAaCDggRPaB7XE0EXSiHuTwlRKAPDFhpGlsOXKp9juT VtWOazHGmCC3IMy251lXxAaJ0VXeP6h7Y3JD3gyn9OassVo7BLw0spgUPLZmWvHhRV+3Qw HaAD4PZt1PwGZvnAodK8o80hZphU3Qj/TK3E7yQKvr0hlOyoldmxHz/s9f8Eg2PcKnBVFr LY9Xd1Zcb8gBFgVe584QTa6Ze5O18o8+WSBe1Mv9HrKh8DYfSJ8UZRvGGr0CNQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1636203155; a=rsa-sha256; cv=none; b=R8s2UNC33iydoZDnaeKrfPSS2rl4ka3/OdxcaVXWgUvGYyF8aLPsCclUzmGl3OdeumjQlW Hgx1gy7/g56ZCXqp85ZT1VXpuMVKC0WH4lXWzFkvTaB8AynO1UZD30WAUynrF9qA9+vWHu THkrqkMTu3/FiAVzac+X5l9vPdVlIClEJ6dQCjVfZQ3w4pmTuDjIYTpRDvijXTWf5SLWH2 C7aLDXw1Hk+3THY0FpnRekTFiXq+JcyOQ7ne/FCBepqsJTuXmBj9FLYV2jI+GQO7g9et+3 SqarI4jzuxwAXFDM5CAFwE+54ALQlDTdkoFGGxHyP+ijLUremSotbSjGO7a/mg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b=dj5GPsL3; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Spam-Score: -1.32 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b=dj5GPsL3; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Queue-Id: 55C822F82B X-Spam-Score: -1.32 X-Migadu-Scanner: scn0.migadu.com X-TUID: qEczbzlKAYqC This is a multi-part message in MIME format. --------------3B3654F49F6D4A994F67489E Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit On 06/05/2021 19:41, Bastien wrote: > Fr Ml writes: > >> I have a problem with the function org-store-link it doesn't work as >> described in the documentation: >> https://orgmode.org/manual/Handling-Links.html >> "For Org files, if there is a '<>' at point, the link points >> to >> the target." > > Fixed in maint, thanks a lot for reporting this and Ihor for > confirming the bug. Bastien, unfortunately your fix caused duplication of stored links like "file:~/org/file.org::#custom_id" when point is outside of <>. Earlier #CUSTOM_ID link was stored in addition to "file:~/org/file.org::*Heading" search link. My suggestion is to revert your patch and to just reset custom-id variable when <> link is stored. Another effect or your patch, that I consider unintentional, is storing [[file:~/org/file.org::#custom_id][file:~/org/file.org::#custom_id]] instead of [[file:~/org/file.org::#custom_id][Heading]]. I prefer "original" behavior. Third patch is intended to avoid links inserted as [[target][file:~/org/file.org::target]] in the case of same file. I suppose, just [[target]] is better. Current variant looks unbalanced and misleading. Of course, you are free to skip last patch. I am confused by `org-insert-link' behavior. It inserts links like [[file:~/org/file.org::#custom_id][file:~/org/file.org::#custom_id]] without user prompt for description but [[file:~/org/file.org::#custom_id][Heading]] requires to confirm "Heading" description explicitly. I would expect that "raw" link is subject to ask user for more friendly option. --------------3B3654F49F6D4A994F67489E Content-Type: text/x-patch; charset=UTF-8; name="0001-Revert-lisp-ol.el-Fix-bug-when-storing-links.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-Revert-lisp-ol.el-Fix-bug-when-storing-links.patch" >From 28f1d331888ebd22d60343bb06d3b307aff9fc93 Mon Sep 17 00:00:00 2001 From: Max Nikulin Date: Fri, 5 Nov 2021 19:03:59 +0700 Subject: [PATCH 1/3] Revert "lisp/ol.el: Fix bug when storing links" This reverts commit b4b35fc92d6ea8eb2ac061b8ccf026e9b4ebfe33. Avoid duplication of CUSTOM_ID links. --- lisp/ol.el | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/lisp/ol.el b/lisp/ol.el index aa1849715..6fe50ed60 100644 --- a/lisp/ol.el +++ b/lisp/ol.el @@ -1613,8 +1613,9 @@ non-nil." ((and (buffer-file-name (buffer-base-buffer)) (derived-mode-p 'org-mode)) (org-with-limited-levels - (cond - ;; Store a link using the target at point. + (setq custom-id (org-entry-get nil "CUSTOM_ID")) + (cond + ;; Store a link using the target at point ((org-in-regexp "[^<]<<\\([^<>]+\\)>>[^>]" 1) (setq cpltxt (concat "file:" @@ -1622,15 +1623,6 @@ non-nil." (buffer-file-name (buffer-base-buffer))) "::" (match-string 1)) link cpltxt)) - ;; Store a link using the CUSTOM_ID property. - ((setq custom-id (org-entry-get nil "CUSTOM_ID")) - (setq cpltxt - (concat "file:" - (abbreviate-file-name - (buffer-file-name (buffer-base-buffer))) - "::#" custom-id) - link cpltxt)) - ;; Store a link using (and perhaps creating) the ID property. ((and (featurep 'org-id) (or (eq org-id-link-to-org-use-id t) (and interactive? @@ -1639,13 +1631,14 @@ non-nil." 'create-if-interactive-and-no-custom-id) (not custom-id)))) (and org-id-link-to-org-use-id (org-entry-get nil "ID")))) + ;; Store a link using the ID at point (setq link (condition-case nil (prog1 (org-id-store-link) (setq desc (or (plist-get org-store-link-plist :description) ""))) (error - ;; Probably before first headline, link only to file. + ;; Probably before first headline, link only to file (concat "file:" (abbreviate-file-name (buffer-file-name (buffer-base-buffer)))))))) -- 2.25.1 --------------3B3654F49F6D4A994F67489E Content-Type: text/x-patch; charset=UTF-8; name="0002-ol.el-Skip-CUSTOM_ID-when-target-link-is-stored.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0002-ol.el-Skip-CUSTOM_ID-when-target-link-is-stored.patch" >From 1fb5a5e071141e47d551202eeca5776185ca8461 Mon Sep 17 00:00:00 2001 From: Max Nikulin Date: Fri, 5 Nov 2021 19:49:23 +0700 Subject: [PATCH 2/3] ol.el: Skip #CUSTOM_ID when <> link is stored * list/ol.el (org-store-link): Suppress storing of "file:file.org::#custom_id" link when point is <>. CUSTOM_ID link is stored as additional option, so new chunk of code introduced by b4b35fc92 is not necessary. It prevented adding of "file:file.org::*Heading" link and caused duplication of "file:file.org::#custom_id" link. Reported-by: Fr Ml Link: https://orgmode.org/list/aadb23f3-c0fe-19aa-be79-50e51d16c41a@t-online.de/ --- lisp/ol.el | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lisp/ol.el b/lisp/ol.el index 6fe50ed60..5e1f1f2d2 100644 --- a/lisp/ol.el +++ b/lisp/ol.el @@ -1622,7 +1622,9 @@ non-nil." (abbreviate-file-name (buffer-file-name (buffer-base-buffer))) "::" (match-string 1)) - link cpltxt)) + link cpltxt + ;; Do not append #CUSTOM_ID link below. + custom-id nil)) ((and (featurep 'org-id) (or (eq org-id-link-to-org-use-id t) (and interactive? -- 2.25.1 --------------3B3654F49F6D4A994F67489E Content-Type: text/x-patch; charset=UTF-8; name="0003-ol.el-Avoid-links-like-target-file-org-test.org-targ.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0003-ol.el-Avoid-links-like-target-file-org-test.org-targ.pa"; filename*1="tch" >From f307c7059744b28b26f5c3b8dd4a0f563b22e586 Mon Sep 17 00:00:00 2001 From: Max Nikulin Date: Sat, 6 Nov 2021 18:23:25 +0700 Subject: [PATCH 3/3] ol.el: Avoid links like "[[target][file:~/org/test.org::target]]" * lisp/ol.el (org-store-link): Do not set description for "<>" links to avoid case when it is more detailed than link target. While inserting to the same file, file part of the link target is stripped, description is inserted without modification. I do not think, file path adds real value in comparison to "[[target]]" link to some point in the same file. A side effect is user prompt for description since link and description are not identical any more. --- lisp/ol.el | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lisp/ol.el b/lisp/ol.el index 5e1f1f2d2..ec5427e7c 100644 --- a/lisp/ol.el +++ b/lisp/ol.el @@ -1617,12 +1617,17 @@ non-nil." (cond ;; Store a link using the target at point ((org-in-regexp "[^<]<<\\([^<>]+\\)>>[^>]" 1) - (setq cpltxt + (setq link (concat "file:" (abbreviate-file-name (buffer-file-name (buffer-base-buffer))) "::" (match-string 1)) - link cpltxt + ;; Target may be shortened when link is inserted. + ;; Avoid [[target][file:~/org/test.org::target]] + ;; links. Maybe the case of identical target and + ;; description should be handled by `org-insert-link'. + cpltxt nil + desc nil ;; Do not append #CUSTOM_ID link below. custom-id nil)) ((and (featurep 'org-id) -- 2.25.1 --------------3B3654F49F6D4A994F67489E--