emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Evgenii Klimov <eugene.dev@lipklim.org>
To: Ihor Radchenko <yantar92@posteo.net>
Cc: emacs-orgmode@gnu.org
Subject: Re: [PATCH v2] Keep the link if the command was cancelled
Date: Tue, 04 Jul 2023 00:43:33 +0100	[thread overview]
Message-ID: <87y1jwv9sw.fsf@lipklim.org> (raw)
In-Reply-To: <87fs65gnzk.fsf@localhost>

[-- 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


  parent reply	other threads:[~2023-07-03 23:46 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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   ` Evgenii Klimov [this message]
2023-07-04 10:48     ` [PATCH v2] " Ihor Radchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87y1jwv9sw.fsf@lipklim.org \
    --to=eugene.dev@lipklim.org \
    --cc=emacs-orgmode@gnu.org \
    --cc=yantar92@posteo.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).