Re: [PATCH v2] Re: Adding target and custom id links doesn't ask for description

2022-09-13 Thread Ihor Radchenko
Ihor Radchenko  writes:

>> Yes, I've tested it with target and custom_id links and, as you said, there
>> is no change in behavior. The entire URL is still pasted and no chance to
>> edit it is given to the user.
>
> Oops. Somehow some way things worked for me at some point when I was
> making the patch.
>
> See the updated version of the patch attached. It works on my side.

According to the further discussion, this patch does not resolve the
original problem. However, it improves similar cases with link
descriptions being set equal to the link values.

Applied.
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=4fc2c8dd89bfbe9f6ad7620c1b4d6def4114489b

The original problem is resolved in another applied patch from an
earlier discussion.
https://list.orgmode.org/e2c807a7-1924-6f08-9e63-4f70aee9d...@gmail.com

-- 
Ihor Radchenko,
Org mode contributor,
Learn more about Org mode at https://orgmode.org/.
Support Org development at https://liberapay.com/org-mode,
or support my work at https://liberapay.com/yantar92



Re: [PATCH v2] Re: Adding target and custom id links doesn't ask for description

2022-09-12 Thread Max Nikulin

On 12/09/2022 18:02, Ihor Radchenko wrote:

Max Nikulin writes:


Unfortunately, your patch does not fix the real issue. The title (not
nil) should be saved for link description when the heading contains the
CUSTOM_ID property. I tried to address it in the following patches:

Max Nikulin. Re: Bug: org-store-link uses CUSTOM_ID instead of target
point. Sat, 6 Nov 2021 19:51:29 +0700.
https://list.orgmode.org/e2c807a7-1924-6f08-9e63-4f70aee9d...@gmail.com


Does it mean that my patch + the patch you linked can be used to fix the
issue reported in this thread?


To fix the #custom_id issue it is enough to commit 2 patches from the 
linked thread: reverting the change caused duplication of stored 
#custom_id links and an alternative fix to store link to <>.


As to <> links, I am unsure what description should be stored 
for <>. I do not think it should be heading title and I do not 
like /full/path/file.org::target that looks strange when file is 
stripped for a link to the same file, but description contains full 
path. I proposed (3rd patch) to store just "target" as description, you 
may prefer nil. Both approaches allows to bypass broken auto-desc logic 
(which I would like to remove) and to show the prompt for description.


I consider your patch as a general improvement because it allows to 
avoid description = link in more cases.





Re: [PATCH v2] Re: Adding target and custom id links doesn't ask for description

2022-09-12 Thread Ihor Radchenko
Max Nikulin  writes:

> Unfortunately, your patch does not fix the real issue. The title (not 
> nil) should be saved for link description when the heading contains the 
> CUSTOM_ID property. I tried to address it in the following patches:
>
> Max Nikulin. Re: Bug: org-store-link uses CUSTOM_ID instead of target 
> point. Sat, 6 Nov 2021 19:51:29 +0700. 
> https://list.orgmode.org/e2c807a7-1924-6f08-9e63-4f70aee9d...@gmail.com

Does it mean that my patch + the patch you linked can be used to fix the
issue reported in this thread?

-- 
Ihor Radchenko,
Org mode contributor,
Learn more about Org mode at https://orgmode.org/.
Support Org development at https://liberapay.com/org-mode,
or support my work at https://liberapay.com/yantar92



Re: [PATCH v2] Re: Adding target and custom id links doesn't ask for description

2022-09-11 Thread Max Nikulin

On 14/08/2022 16:53, Max Nikulin wrote:

On 13/08/2022 12:01, Ihor Radchenko wrote:

See the updated version of the patch attached. It works on my side.

--- a/lisp/ol.el
+++ b/lisp/ol.el
@@ -1577,10 +1577,8 @@ (defun org-store-link (arg &optional interactive?)
   t
 (setq link (plist-get org-store-link-plist :link))
 ;; If store function actually set `:description' property, use
-    ;; it, even if it is nil.  Otherwise, fallback to link value.
-    (setq desc (if (plist-member org-store-link-plist :description)
-   (plist-get org-store-link-plist :description)
- link)))
+    ;; it, even if it is nil.  Otherwise, fallback to nil (ask 
user).

+    (setq desc (plist-get org-store-link-plist :description)))


I can not say that I understand design of `org-store-link` and 
`org-insert-link' pair, but I suspect that you might try to fix the 
issue in a wrong place.


It seems the same :link and :description value were set for purpose, see 
`org-insert-link' code:


     (dolist (l org-stored-links)
   (when (equal link (cadr l))
     (setq link (car l))
     (setq auto-desc t)))


Ihor, I beg you pardon. I was wrong writing that you are trying to fix 
the issue in a wrong place. I figured out that the purpose of this 
snippet is completion by link description, not detecting of the case of 
identical link target and description. You have just committed the patch 
from the following thread where I provided more details:
Max Nikulin. ido, org-insert-link, and completion based on link 
description. Tue, 6 Sep 2022 21:34:12 +0700. 
https://list.orgmode.org/tf7lp4$5ha$1...@ciao.gmane.io


Now I believe that your change is an improvement. I do not see any real 
reason to store the same description as the target. 
"~/Desktop/Org/captures.org::target" for <> as default value of 
the description prompt might be a hint to the user for which link their 
should write description, but I hope, there is a better way to do the 
same. I have seen a mention that some export backend may create perhaps 
invisible links if description is omitted, but if it is still an issue, 
it should be fixed in affected backends.


Unfortunately, your patch does not fix the real issue. The title (not 
nil) should be saved for link description when the heading contains the 
CUSTOM_ID property. I tried to address it in the following patches:


Max Nikulin. Re: Bug: org-store-link uses CUSTOM_ID instead of target 
point. Sat, 6 Nov 2021 19:51:29 +0700. 
https://list.orgmode.org/e2c807a7-1924-6f08-9e63-4f70aee9d...@gmail.com





Re: [PATCH v2] Re: Adding target and custom id links doesn't ask for description

2022-08-14 Thread Max Nikulin

On 13/08/2022 12:01, Ihor Radchenko wrote:

See the updated version of the patch attached. It works on my side.

--- a/lisp/ol.el
+++ b/lisp/ol.el
@@ -1577,10 +1577,8 @@ (defun org-store-link (arg &optional interactive?)
  t
(setq link (plist-get org-store-link-plist :link))
 ;; If store function actually set `:description' property, use
-;; it, even if it is nil.  Otherwise, fallback to link value.
-   (setq desc (if (plist-member org-store-link-plist :description)
-   (plist-get org-store-link-plist :description)
-link)))
+;; it, even if it is nil.  Otherwise, fallback to nil (ask user).
+   (setq desc (plist-get org-store-link-plist :description)))


I can not say that I understand design of `org-store-link` and 
`org-insert-link' pair, but I suspect that you might try to fix the 
issue in a wrong place.


It seems the same :link and :description value were set for purpose, see 
`org-insert-link' code:


(dolist (l org-stored-links)
  (when (equal link (cadr l))
(setq link (car l))
(setq auto-desc t)))

However I am puzzled by

(unless auto-desc

I would say that namely the same :link and :description should cause 
query to default description and user prompt.


I may be wrong. Maybe the protocol of communication between these 
functions may be documented with more details.





[PATCH v2] Re: Adding target and custom id links doesn't ask for description

2022-08-12 Thread Ihor Radchenko
Carlos Pita  writes:

>> Carlos, have you tried Ihor's patch? I like the intention, but I do not
>> see any effect.
>>
>
> Yes, I've tested it with target and custom_id links and, as you said, there
> is no change in behavior. The entire URL is still pasted and no chance to
> edit it is given to the user.

Oops. Somehow some way things worked for me at some point when I was
making the patch.

See the updated version of the patch attached. It works on my side.

>From 64c85eed9471b73e379e063dc3becefceb1ec650 Mon Sep 17 00:00:00 2001
Message-Id: <64c85eed9471b73e379e063dc3becefceb1ec650.1660366803.git.yanta...@gmail.com>
From: Ihor Radchenko 
Date: Wed, 10 Aug 2022 13:25:26 +0800
Subject: [PATCH v2] org-store-link: Default to empty description for
 target/custom-id links

* lisp/ol.el (org-store-link): Use empty description by default (ask user).

Fixes https://orgmode.org/list/d99a712c-18d1-4a4f-8093-35a0bfb46...@gmail.com
---
 lisp/ol.el | 13 -
 1 file changed, 4 insertions(+), 9 deletions(-)

diff --git a/lisp/ol.el b/lisp/ol.el
index b7d74d0bf..358a96aae 100644
--- a/lisp/ol.el
+++ b/lisp/ol.el
@@ -1577,10 +1577,8 @@ (defun org-store-link (arg &optional interactive?)
 		  t
 	(setq link (plist-get org-store-link-plist :link))
 ;; If store function actually set `:description' property, use
-;; it, even if it is nil.  Otherwise, fallback to link value.
-	(setq desc (if (plist-member org-store-link-plist :description)
-   (plist-get org-store-link-plist :description)
-		 link)))
+;; it, even if it is nil.  Otherwise, fallback to nil (ask user).
+	(setq desc (plist-get org-store-link-plist :description)))
 
;; Store a link from a remote editing buffer.
((org-src-edit-buffer-p)
@@ -1697,9 +1695,7 @@ (defun org-store-link (arg &optional interactive?)
 		(and org-id-link-to-org-use-id (org-entry-get nil "ID"
 	   (setq link (condition-case nil
 			  (prog1 (org-id-store-link)
-			(setq desc (or (plist-get org-store-link-plist
-		  :description)
-	   "")))
+			(setq desc (plist-get org-store-link-plist :description)))
 			(error
 			 ;; Probably before first headline, link only to file.
 			 (concat "file:"
@@ -1761,8 +1757,7 @@ (defun org-store-link (arg &optional interactive?)
 
   ;; We're done setting link and desc, clean up
   (when (consp link) (setq cpltxt (car link) link (cdr link)))
-  (setq link (or link cpltxt)
-	desc (or desc cpltxt))
+  (setq link (or link cpltxt))
   (cond ((not desc))
 	((equal desc "NONE") (setq desc nil))
 	(t (setq desc (org-link-display-format desc
-- 
2.35.1



-- 
Ihor Radchenko,
Org mode contributor,
Learn more about Org mode at https://orgmode.org/.
Support Org development at https://liberapay.com/org-mode,
or support my work at https://liberapay.com/yantar92