emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] Keep the link if the command was cancelled
@ 2023-06-30 22:11 Evgenii Klimov
  2023-07-03 12:48 ` Ihor Radchenko
  0 siblings, 1 reply; 13+ messages in thread
From: Evgenii Klimov @ 2023-06-30 22:11 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: Evgenii Klimov

* lisp/ol.el (org-insert-link): Keep the link in `org-stored-links' if
the command was interrupted by the user during the reading of a
description from the minibuffer.
---
Currently the link is lost if the user chooses the link but cancells
the comand while writing the description.

 lisp/ol.el | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/lisp/ol.el b/lisp/ol.el
index e2bf90acd..e48138ef9 100644
--- a/lisp/ol.el
+++ b/lisp/ol.el
@@ -1896,11 +1896,6 @@ Use TAB to complete link prefixes, then RET for type-specific completion support
       (or entry (push link org-link--insert-history))
       (setq desc (or desc (nth 1 entry)))))
 
-    (when (funcall (if (equal complete-file '(64)) 'not 'identity)
-		   (not org-link-keep-stored-after-insertion))
-      (setq org-stored-links (delq (assoc link org-stored-links)
-				   org-stored-links)))
-
     (when (and (string-match org-link-plain-re link)
 	       (not (string-match org-ts-regexp link)))
       ;; URL-like link, normalize the use of angular brackets.
@@ -1995,6 +1990,10 @@ Use TAB to complete link prefixes, then RET for type-specific completion support
                      (read-string "Description: " initial-input)
                    initial-input)))
 
+    (when (funcall (if (equal complete-file '(64)) 'not 'identity)
+                   (not org-link-keep-stored-after-insertion))
+      (setq org-stored-links (delq (assoc link org-stored-links)
+                                   org-stored-links)))
     (unless (org-string-nw-p desc) (setq desc nil))
     (when remove (apply #'delete-region remove))
     (insert (org-link-make-string link desc))
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH] Keep the link if the command was cancelled
  2023-06-30 22:11 [PATCH] Keep the link if the command was cancelled Evgenii Klimov
@ 2023-07-03 12:48 ` Ihor Radchenko
  2023-07-03 15:08   ` Max Nikulin
                     ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: Ihor Radchenko @ 2023-07-03 12:48 UTC (permalink / raw)
  To: Evgenii Klimov; +Cc: emacs-orgmode

Evgenii Klimov <eugene.dev@lipklim.org> writes:

> * lisp/ol.el (org-insert-link): Keep the link in `org-stored-links' if
> the command was interrupted by the user during the reading of a
> description from the minibuffer.
> ---
> Currently the link is lost if the user chooses the link but cancells
> the comand while writing the description.

Thanks!
This makes sense, but the patch may break removing stored link in
certain scenarios.

> -    (when (funcall (if (equal complete-file '(64)) 'not 'identity)
> -		   (not org-link-keep-stored-after-insertion))
> -      (setq org-stored-links (delq (assoc link org-stored-links)
> -				   org-stored-links)))
> -
>      (when (and (string-match org-link-plain-re link)
>  	       (not (string-match org-ts-regexp link)))
>        ;; URL-like link, normalize the use of angular brackets.
> @@ -1995,6 +1990,10 @@ Use TAB to complete link prefixes, then RET for type-specific completion support
>                       (read-string "Description: " initial-input)
>                     initial-input)))

The code below the removed form can modify `link' variable. If such
modification does happen, your patch will fail to remove the link from
`org-stored-links' - (assoc link org-stored-links) will no longer return
non-nil.
 

-- 
Ihor Radchenko // yantar92,
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>


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] Keep the link if the command was cancelled
  2023-07-03 12:48 ` Ihor Radchenko
@ 2023-07-03 15:08   ` Max Nikulin
  2023-07-03 15:11     ` Ihor Radchenko
  2023-07-03 15:53   ` Evgenii Klimov
  2023-07-03 23:43   ` [PATCH v2] " Evgenii Klimov
  2 siblings, 1 reply; 13+ messages in thread
From: Max Nikulin @ 2023-07-03 15:08 UTC (permalink / raw)
  To: Ihor Radchenko, Evgenii Klimov; +Cc: emacs-orgmode

On 03/07/2023 19:48, Ihor Radchenko wrote:
> Evgenii Klimov writes:
> 
>> * lisp/ol.el (org-insert-link): Keep the link in `org-stored-links' if
>> the command was interrupted by the user during the reading of a
>> description from the minibuffer.
>> ---
>> Currently the link is lost if the user chooses the link but cancells
>> the comand while writing the description.
> 
> This makes sense

Sometimes I am using it as a feature to remove a link stored by mistake 
or due to

Max Nikulin. [Bug] org-insert-link removes on one link from 2 added by 
org-store-link. Sun, 2 Jul 2023 13:08:18 +0700.
https://list.orgmode.org/u7r48j$9oo$1@ciao.gmane.io

On the other hand it is still possible to call undo after a link is 
inserted.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] Keep the link if the command was cancelled
  2023-07-03 15:08   ` Max Nikulin
@ 2023-07-03 15:11     ` Ihor Radchenko
  2023-07-03 15:15       ` Max Nikulin
  0 siblings, 1 reply; 13+ messages in thread
From: Ihor Radchenko @ 2023-07-03 15:11 UTC (permalink / raw)
  To: Max Nikulin; +Cc: Evgenii Klimov, emacs-orgmode

Max Nikulin <manikulin@gmail.com> writes:

> Sometimes I am using it as a feature to remove a link stored by mistake 
> or due to ...

This argument sounds like https://xkcd.com/1172/ to me.
It is unexpected and undocumented that not inserting the link, but
stopping in the middle removes it from the store list.

-- 
Ihor Radchenko // yantar92,
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>


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] Keep the link if the command was cancelled
  2023-07-03 15:11     ` Ihor Radchenko
@ 2023-07-03 15:15       ` Max Nikulin
  2023-07-03 15:28         ` Ihor Radchenko
  0 siblings, 1 reply; 13+ messages in thread
From: Max Nikulin @ 2023-07-03 15:15 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Evgenii Klimov, emacs-orgmode

On 03/07/2023 22:11, Ihor Radchenko wrote:
> Max Nikulin writes:
> 
>> Sometimes I am using it as a feature to remove a link stored by mistake
>> or due to ...
> 
> This argument sounds like https://xkcd.com/1172/ to me.

I had it in mind when I was writing my message. I had even tried to find 
another command that allows to remove stored links.



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] Keep the link if the command was cancelled
  2023-07-03 15:15       ` Max Nikulin
@ 2023-07-03 15:28         ` Ihor Radchenko
  2023-07-03 16:04           ` Evgenii Klimov
  2023-07-12 12:00           ` Max Nikulin
  0 siblings, 2 replies; 13+ messages in thread
From: Ihor Radchenko @ 2023-07-03 15:28 UTC (permalink / raw)
  To: Max Nikulin; +Cc: Evgenii Klimov, emacs-orgmode

Max Nikulin <manikulin@gmail.com> writes:

>> This argument sounds like https://xkcd.com/1172/ to me.
>
> I had it in mind when I was writing my message. I had even tried to find 
> another command that allows to remove stored links.

If necessary, removing stored links without inserting can be made as an
effect of negative prefix argument in `org-insert-link' or in
`org-insert-all-links'.

-- 
Ihor Radchenko // yantar92,
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>


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] Keep the link if the command was cancelled
  2023-07-03 12:48 ` Ihor Radchenko
  2023-07-03 15:08   ` Max Nikulin
@ 2023-07-03 15:53   ` Evgenii Klimov
  2023-07-03 23:43   ` [PATCH v2] " Evgenii Klimov
  2 siblings, 0 replies; 13+ messages in thread
From: Evgenii Klimov @ 2023-07-03 15:53 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: emacs-orgmode


Ihor Radchenko <yantar92@posteo.net> writes:
> Evgenii Klimov <eugene.dev@lipklim.org> writes:
>> ...
>
> This makes sense, but the patch may break removing stored link in
> certain scenarios.

Thanks for response, I'll look into this issue and try to avoid this
breakage.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] Keep the link if the command was cancelled
  2023-07-03 15:28         ` Ihor Radchenko
@ 2023-07-03 16:04           ` Evgenii Klimov
  2023-07-03 16:20             ` Ihor Radchenko
  2023-07-12 12:00           ` Max Nikulin
  1 sibling, 1 reply; 13+ messages in thread
From: Evgenii Klimov @ 2023-07-03 16:04 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Max Nikulin, emacs-orgmode


Ihor Radchenko <yantar92@posteo.net> writes:

> Max Nikulin <manikulin@gmail.com> writes:
[...]
>> I had it in mind when I was writing my message. I had even tried to find 
>> another command that allows to remove stored links.
>
> If necessary, removing stored links without inserting can be made as an
> effect of negative prefix argument in `org-insert-link' or in
> `org-insert-all-links'.

I tried `org-insert-link' with the negative prefix argument, but the
link was inserted though.

And this behaviour is not mentioned in the docstring.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] Keep the link if the command was cancelled
  2023-07-03 16:04           ` Evgenii Klimov
@ 2023-07-03 16:20             ` Ihor Radchenko
  0 siblings, 0 replies; 13+ messages in thread
From: Ihor Radchenko @ 2023-07-03 16:20 UTC (permalink / raw)
  To: Evgenii Klimov; +Cc: Max Nikulin, emacs-orgmode

Evgenii Klimov <eugene.dev@lipklim.org> writes:

>> If necessary, removing stored links without inserting can be made as an
>> effect of negative prefix argument in `org-insert-link' or in
>> `org-insert-all-links'.
>
> I tried `org-insert-link' with the negative prefix argument, but the
> link was inserted though.
>
> And this behaviour is not mentioned in the docstring.

This behaviour is not there. I just said that we can add it to Org, if
necessary. What Max described should not stop this patch from being
merged.

-- 
Ihor Radchenko // yantar92,
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>


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2] Keep the link if the command was cancelled
  2023-07-03 12:48 ` Ihor Radchenko
  2023-07-03 15:08   ` Max Nikulin
  2023-07-03 15:53   ` Evgenii Klimov
@ 2023-07-03 23:43   ` Evgenii Klimov
  2023-07-04 10:48     ` Ihor Radchenko
  2 siblings, 1 reply; 13+ messages in thread
From: Evgenii Klimov @ 2023-07-03 23:43 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 1069 bytes --]


Ihor Radchenko <yantar92@posteo.net> writes:

> Evgenii Klimov <eugene.dev@lipklim.org> writes:
>
[...]
>> -    (when (funcall (if (equal complete-file '(64)) 'not 'identity)
>> -		   (not org-link-keep-stored-after-insertion))
>> -      (setq org-stored-links (delq (assoc link org-stored-links)
>> -				   org-stored-links)))
>> -
>>      (when (and (string-match org-link-plain-re link)
>>  	       (not (string-match org-ts-regexp link)))
>>        ;; URL-like link, normalize the use of angular brackets.
>> @@ -1995,6 +1990,10 @@ Use TAB to complete link prefixes, then RET for type-specific completion support
>>                       (read-string "Description: " initial-input)
>>                     initial-input)))
>
> The code below the removed form can modify `link' variable. If such
> modification does happen, your patch will fail to remove the link from
> `org-stored-links' - (assoc link org-stored-links) will no longer return
> non-nil.

I added `link-original' variable to keep it intact until we want to
remove the link from `org-stored-links'.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Keep-the-link-if-it-was-not-inserted.patch --]
[-- Type: text/x-diff, Size: 2199 bytes --]

From a5ff8d4fe27fd503a6ddb719a622a980a73789a7 Mon Sep 17 00:00:00 2001
From: Evgenii Klimov <eugene.dev@lipklim.org>
Date: Fri, 30 Jun 2023 22:56:39 +0100
Subject: [PATCH] Keep the link if it was not inserted

* lisp/ol.el (org-insert-link): Keep the link in `org-stored-links' if
the command was interrupted by the user during the reading of a
description from the minibuffer.
---
 lisp/ol.el | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/lisp/ol.el b/lisp/ol.el
index e2bf90acd..1490bde86 100644
--- a/lisp/ol.el
+++ b/lisp/ol.el
@@ -1820,7 +1820,7 @@ non-interactively, don't allow to edit the default description."
 	 (all-prefixes (append (mapcar #'car abbrevs)
 			       (mapcar #'car org-link-abbrev-alist)
 			       (org-link-types)))
-         entry)
+         entry link-original)
     (cond
      (link-location)		      ; specified by arg, just use it.
      ((org-in-regexp org-link-bracket-re 1)
@@ -1896,11 +1896,7 @@ Use TAB to complete link prefixes, then RET for type-specific completion support
       (or entry (push link org-link--insert-history))
       (setq desc (or desc (nth 1 entry)))))
 
-    (when (funcall (if (equal complete-file '(64)) 'not 'identity)
-		   (not org-link-keep-stored-after-insertion))
-      (setq org-stored-links (delq (assoc link org-stored-links)
-				   org-stored-links)))
-
+    (setq link-original link)
     (when (and (string-match org-link-plain-re link)
 	       (not (string-match org-ts-regexp link)))
       ;; URL-like link, normalize the use of angular brackets.
@@ -1995,6 +1991,10 @@ Use TAB to complete link prefixes, then RET for type-specific completion support
                      (read-string "Description: " initial-input)
                    initial-input)))
 
+    (when (funcall (if (equal complete-file '(64)) 'not 'identity)
+                   (not org-link-keep-stored-after-insertion))
+      (setq org-stored-links (delq (assoc link-original org-stored-links)
+                                   org-stored-links)))
     (unless (org-string-nw-p desc) (setq desc nil))
     (when remove (apply #'delete-region remove))
     (insert (org-link-make-string link desc))
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH v2] Keep the link if the command was cancelled
  2023-07-03 23:43   ` [PATCH v2] " Evgenii Klimov
@ 2023-07-04 10:48     ` Ihor Radchenko
  0 siblings, 0 replies; 13+ messages in thread
From: Ihor Radchenko @ 2023-07-04 10:48 UTC (permalink / raw)
  To: Evgenii Klimov; +Cc: emacs-orgmode

Evgenii Klimov <eugene.dev@lipklim.org> writes:

> I added `link-original' variable to keep it intact until we want to
> remove the link from `org-stored-links'.

Thanks!
Applied, onto main, with amendments.
I have added TINYCHANGE cookie to the commit message and provided a bit
more details in the commit summary.
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=48fffa5da

You are now listed as an Org contributor.
https://git.sr.ht/~bzg/worg/commit/f7d16cc1

-- 
Ihor Radchenko // yantar92,
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>


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] Keep the link if the command was cancelled
  2023-07-03 15:28         ` Ihor Radchenko
  2023-07-03 16:04           ` Evgenii Klimov
@ 2023-07-12 12:00           ` Max Nikulin
  2023-07-16  8:46             ` Ihor Radchenko
  1 sibling, 1 reply; 13+ messages in thread
From: Max Nikulin @ 2023-07-12 12:00 UTC (permalink / raw)
  To: emacs-orgmode

On 03/07/2023 22:28, Ihor Radchenko wrote:
> If necessary, removing stored links without inserting can be made as an
> effect of negative prefix argument in `org-insert-link' or in
> `org-insert-all-links'.

I do not think it would be a noticeable improvement. It increases code 
complexity, but `org-insert-link' + `undo' requires the same amount of 
keystrokes.

Maybe I just do not like prefix argument. Instead of triple C-u to keep 
the link I would prefer to be able to activate it from the link prompt 
(something similar to to M-s i switches for incremental search).

It might be more reasonable to have some binding to cancel 
`org-store-links' immediately after this command.



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] Keep the link if the command was cancelled
  2023-07-12 12:00           ` Max Nikulin
@ 2023-07-16  8:46             ` Ihor Radchenko
  0 siblings, 0 replies; 13+ messages in thread
From: Ihor Radchenko @ 2023-07-16  8:46 UTC (permalink / raw)
  To: Max Nikulin; +Cc: emacs-orgmode

Max Nikulin <manikulin@gmail.com> writes:

> On 03/07/2023 22:28, Ihor Radchenko wrote:
>> If necessary, removing stored links without inserting can be made as an
>> effect of negative prefix argument in `org-insert-link' or in
>> `org-insert-all-links'.
>
> I do not think it would be a noticeable improvement. It increases code 
> complexity, but `org-insert-link' + `undo' requires the same amount of 
> keystrokes.
>
> Maybe I just do not like prefix argument. Instead of triple C-u to keep 
> the link I would prefer to be able to activate it from the link prompt 
> (something similar to to M-s i switches for incremental search).
>
> It might be more reasonable to have some binding to cancel 
> `org-store-links' immediately after this command.

I feel like this direction is overcomplicating things.
What about trying to mimic some of the existing Emacs behaviours, like
kill ring.

What I have in mind is how M-w C-y M-y M-y ... works.
We may have a command to replace the last inserted link with previous
link in the org-stored-links when previous command was org-insert-link.

-- 
Ihor Radchenko // yantar92,
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>


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2023-07-16  8:47 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-30 22:11 [PATCH] Keep the link if the command was cancelled Evgenii Klimov
2023-07-03 12:48 ` Ihor Radchenko
2023-07-03 15:08   ` Max Nikulin
2023-07-03 15:11     ` Ihor Radchenko
2023-07-03 15:15       ` Max Nikulin
2023-07-03 15:28         ` Ihor Radchenko
2023-07-03 16:04           ` Evgenii Klimov
2023-07-03 16:20             ` Ihor Radchenko
2023-07-12 12:00           ` Max Nikulin
2023-07-16  8:46             ` Ihor Radchenko
2023-07-03 15:53   ` Evgenii Klimov
2023-07-03 23:43   ` [PATCH v2] " Evgenii Klimov
2023-07-04 10:48     ` Ihor Radchenko

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).