emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [Bug] org-insert-link removes on one link from 2 added by org-store-link
@ 2023-07-02  6:08 Max Nikulin
  2023-07-02  7:49 ` Ihor Radchenko
  0 siblings, 1 reply; 7+ messages in thread
From: Max Nikulin @ 2023-07-02  6:08 UTC (permalink / raw)
  To: emacs-orgmode

When some heading has the CUSTOM_ID property

---- 8< ----
* title
:PROPERTIES:
:CUSTOM_ID: a-heading
:END:
---- >8 ----

M-x org-store-link adds 2 entries:
- [[*title][title]]
- [[#a-heading][title]]

however `org-insert-link' (C-c C-l) removes from the stored link only 
one of them. As a result the number of unused stored links increases 
during an Emacs session.

My expectation is that
- either `org-store-links' adds a single option (my preference is 
#custom_id)
- or `org-insert-link' removes the whole group.

I have no idea how to implement second variant keeping backward 
compatibility.


Ihor Radchenko. Re: [BUG] org-store-link-functions advertizes that the 
first non-nil return value is used, but it is not how org-store-link 
handles it. Wed, 28 Sep 2022 09:03:59 +0800.
https://list.orgmode.org/87bkr0gvi8.fsf@localhost

> Would you mind reporting this and MWE in a new thread?
> It will be easier to track then.



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

* Re: [Bug] org-insert-link removes on one link from 2 added by org-store-link
  2023-07-02  6:08 [Bug] org-insert-link removes on one link from 2 added by org-store-link Max Nikulin
@ 2023-07-02  7:49 ` Ihor Radchenko
  2023-07-12 12:12   ` Max Nikulin
  0 siblings, 1 reply; 7+ messages in thread
From: Ihor Radchenko @ 2023-07-02  7:49 UTC (permalink / raw)
  To: Max Nikulin; +Cc: emacs-orgmode

Max Nikulin <manikulin@gmail.com> writes:

> When some heading has the CUSTOM_ID property
>
> ---- 8< ----
> * title
> :PROPERTIES:
> :CUSTOM_ID: a-heading
> :END:
> ---- >8 ----
>
> M-x org-store-link adds 2 entries:
> - [[*title][title]]
> - [[#a-heading][title]]
>
> however `org-insert-link' (C-c C-l) removes from the stored link only 
> one of them. As a result the number of unused stored links increases 
> during an Emacs session.

Confirmed.
Not Urgent.

> My expectation is that
> - either `org-store-links' adds a single option (my preference is 
> #custom_id)

That could be a defcustom, maybe.

> - or `org-insert-link' removes the whole group.

> I have no idea how to implement second variant keeping backward 
> compatibility.

We can, for example, group the links into sub-lists in org-stored-links.
Or maintain a separate helper register that will keep track of the links
to be removed together.
That said, removing multiple lines by `org-insert-link' will most likely
be unexpected for some users.

-- 
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] 7+ messages in thread

* Re: [Bug] org-insert-link removes on one link from 2 added by org-store-link
  2023-07-02  7:49 ` Ihor Radchenko
@ 2023-07-12 12:12   ` Max Nikulin
  2023-07-13  3:34     ` Samuel Wales
  0 siblings, 1 reply; 7+ messages in thread
From: Max Nikulin @ 2023-07-12 12:12 UTC (permalink / raw)
  To: emacs-orgmode

On 02/07/2023 14:49, Ihor Radchenko wrote:
> Max Nikulin  writes:
>> M-x org-store-link adds 2 entries:
>> - [[*title][title]]
>> - [[#a-heading][title]]
>>
>> however `org-insert-link' (C-c C-l) removes from the stored link only
>> one of them. As a result the number of unused stored links increases
>> during an Emacs session.
> Confirmed.
> Not Urgent.

Agree. I forgot to mention that the "This link has already been stored" 
feature works only for one link from this pair.




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

* Re: [Bug] org-insert-link removes on one link from 2 added by org-store-link
  2023-07-12 12:12   ` Max Nikulin
@ 2023-07-13  3:34     ` Samuel Wales
  2023-07-13 10:46       ` Improve org-insert-link completion (was: [Bug] org-insert-link removes on one link from 2 added by org-store-link) Ihor Radchenko
  2023-07-23 10:39       ` [Bug] org-insert-link removes on one link from 2 added by org-store-link Max Nikulin
  0 siblings, 2 replies; 7+ messages in thread
From: Samuel Wales @ 2023-07-13  3:34 UTC (permalink / raw)
  To: Max Nikulin; +Cc: emacs-orgmode

link has already been stored is a bug in my case in that i can't just
go to a header, grab it [whether rabbed bfere or not] and then paste
it.  i surprise easily when the wrong link gets pasted.

[also the id links with no desc and the prefix links do not help me
find the link i want to insert if it is opne previously.

in answer to a q by ihor, indeed puttig previously stored id liks as
descriptions in front of all the prefixes woudl be useful to me, but
idk who is doing the sorting, so idk whether it wold make a difference
but if it dos then gret..]

it seems org-insert-=inki is overloaded.  one use case says insert a
previously stored link.  the other says insert a brand new link which
i will now specify.  might it be useful to separate those two
functions?

On 7/12/23, Max Nikulin <manikulin@gmail.com> wrote:
> On 02/07/2023 14:49, Ihor Radchenko wrote:
>> Max Nikulin  writes:
>>> M-x org-store-link adds 2 entries:
>>> - [[*title][title]]
>>> - [[#a-heading][title]]
>>>
>>> however `org-insert-link' (C-c C-l) removes from the stored link only
>>> one of them. As a result the number of unused stored links increases
>>> during an Emacs session.
>> Confirmed.
>> Not Urgent.
>
> Agree. I forgot to mention that the "This link has already been stored"
> feature works only for one link from this pair.
>
>
>
>


-- 
The Kafka Pandemic

A blog about science, health, human rights, and misopathy:
https://thekafkapandemic.blogspot.com


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

* Improve org-insert-link completion (was: [Bug] org-insert-link removes on one link from 2 added by org-store-link)
  2023-07-13  3:34     ` Samuel Wales
@ 2023-07-13 10:46       ` Ihor Radchenko
  2023-07-23 10:39       ` [Bug] org-insert-link removes on one link from 2 added by org-store-link Max Nikulin
  1 sibling, 0 replies; 7+ messages in thread
From: Ihor Radchenko @ 2023-07-13 10:46 UTC (permalink / raw)
  To: Samuel Wales; +Cc: Max Nikulin, emacs-orgmode

Samuel Wales <samologist@gmail.com> writes:

> link has already been stored is a bug in my case in that i can't just
> go to a header, grab it [whether rabbed bfere or not] and then paste
> it.  i surprise easily when the wrong link gets pasted.

This has been fixed already.

> in answer to a q by ihor, indeed puttig previously stored id liks as
> descriptions in front of all the prefixes woudl be useful to me, but
> idk who is doing the sorting, so idk whether it wold make a difference
> but if it dos then gret..]

Org is actually not supposed to control sorting. It is to be customized
by user via `completions-sort'.

What we can do instead is provide grouping metadata.

Below, I provide a simple demo on how it looks like.
However, the demo will only make a difference starting from Emacs 28
that has the necessary completion API.

(defun org--complete-links (string predicate flag)
  (let* ((links '(:type ("id:" "file:") :path ("/a/a/b" "file.org") :description ("foo" "barr" "baz")))
	 (all-links (append (plist-get links :type) (plist-get links :path) (plist-get links :description)))
         matches)
    (pcase flag
      (`nil (try-completion string all-links predicate))
      (`t (all-completions string all-links predicate))
      (`lambda (test-completion string all-links predicate))
      (`(boundaries . suffix) (completion-boundaries string all-links predicate suffix))
      (`metadata
       `(metadata
         (group-function
          .
	  (lambda (completion transform)
            (if transform completion
              (let ((links ',links))
		(cond
		 ((member completion (plist-get links :type)) "Link type")
		 ((member completion (plist-get links :path)) "Link path")
		 ((member completion (plist-get links :description)) "Link description")))))))))))


(completing-read "Test: " #'org--complete-links)

> it seems org-insert-=inki is overloaded.  one use case says insert a
> previously stored link.  the other says insert a brand new link which
> i will now specify.  might it be useful to separate those two
> functions?

I do not see why it is overloaded. The last stored link is used as
default completion option, which is a common practice.

You can also use C-u 1 C-c C-M-l to insert the last stored link.
Or just C-c C-M-l.

-- 
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] 7+ messages in thread

* Re: [Bug] org-insert-link removes on one link from 2 added by org-store-link
  2023-07-13  3:34     ` Samuel Wales
  2023-07-13 10:46       ` Improve org-insert-link completion (was: [Bug] org-insert-link removes on one link from 2 added by org-store-link) Ihor Radchenko
@ 2023-07-23 10:39       ` Max Nikulin
  2023-07-24  1:06         ` Samuel Wales
  1 sibling, 1 reply; 7+ messages in thread
From: Max Nikulin @ 2023-07-23 10:39 UTC (permalink / raw)
  To: emacs-orgmode

On 13/07/2023 10:34, Samuel Wales wrote:
> link has already been stored is a bug in my case in that i can't just
> go to a header, grab it [whether rabbed bfere or not] and then paste
> it.  i surprise easily when the wrong link gets pasted.

The message is not a bug, it tells me that I am trying to store a wrong 
link. The issue is that current implementation does not prevent 
appearance of multiple identical links after several cycles 
store-link/insert-link to the same heading.

Whether stored links should be reordered depends on specific action, so 
a defcustom user option is not a rescue:

1. Collect links in certain order for `org-insert-org-links'. Duplicated 
link is a real error.

2. Copy link going to immediately insert it. Making the link the default 
one sounds reasonable. Perhaps the user still should be notified.

So I disagree that "already stored" is a bug, but there is room for 
improvements.



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

* Re: [Bug] org-insert-link removes on one link from 2 added by org-store-link
  2023-07-23 10:39       ` [Bug] org-insert-link removes on one link from 2 added by org-store-link Max Nikulin
@ 2023-07-24  1:06         ` Samuel Wales
  0 siblings, 0 replies; 7+ messages in thread
From: Samuel Wales @ 2023-07-24  1:06 UTC (permalink / raw)
  To: Max Nikulin; +Cc: emacs-orgmode

"in my case"

On 7/23/23, Max Nikulin <manikulin@gmail.com> wrote:
> On 13/07/2023 10:34, Samuel Wales wrote:
>> link has already been stored is a bug in my case in that i can't just
>> go to a header, grab it [whether rabbed bfere or not] and then paste
>> it.  i surprise easily when the wrong link gets pasted.
>
> The message is not a bug, it tells me that I am trying to store a wrong
> link. The issue is that current implementation does not prevent
> appearance of multiple identical links after several cycles
> store-link/insert-link to the same heading.
>
> Whether stored links should be reordered depends on specific action, so
> a defcustom user option is not a rescue:
>
> 1. Collect links in certain order for `org-insert-org-links'. Duplicated
> link is a real error.
>
> 2. Copy link going to immediately insert it. Making the link the default
> one sounds reasonable. Perhaps the user still should be notified.
>
> So I disagree that "already stored" is a bug, but there is room for
> improvements.
>
>
>


-- 
The Kafka Pandemic

A blog about science, health, human rights, and misopathy:
https://thekafkapandemic.blogspot.com


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

end of thread, other threads:[~2023-07-24  1:12 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-02  6:08 [Bug] org-insert-link removes on one link from 2 added by org-store-link Max Nikulin
2023-07-02  7:49 ` Ihor Radchenko
2023-07-12 12:12   ` Max Nikulin
2023-07-13  3:34     ` Samuel Wales
2023-07-13 10:46       ` Improve org-insert-link completion (was: [Bug] org-insert-link removes on one link from 2 added by org-store-link) Ihor Radchenko
2023-07-23 10:39       ` [Bug] org-insert-link removes on one link from 2 added by org-store-link Max Nikulin
2023-07-24  1:06         ` Samuel Wales

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).