org-store-link: Never allow link duplicates in `org-stored-links'

* lisp/ol.el (org-link-store-existing): Remove the previously added
custom option.
(org-store-link): Do not use `org-link-store-existing' removing all
the code branches for values other than 'move-to-front.
* etc/ORG-NEWS (~org-store-link~ now moves an already stored link to
front of the ~org-stored-links~): Remove reference to the removed
custom option.

Link: https://orgmode.org/list/87leeffd1z.fsf@localhost
This commit is contained in:
Ihor Radchenko 2023-08-14 13:39:47 +03:00
parent 1c00632f11
commit 6954fe93ed
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
2 changed files with 11 additions and 32 deletions

View File

@ -31,12 +31,6 @@ Now, ~org-store-link~ moves the stored link to front of the list of
stored links. This way, the link will show up first in the completion stored links. This way, the link will show up first in the completion
and when inserting all the stored links with ~org-insert-all-links~. and when inserting all the stored links with ~org-insert-all-links~.
The new behavior is controlled by new customization ~org-link-store-existing~.
Users can set ~org-link-store-existing~ to nil to revert previous
defaults. The value of =store-duplicate= will force duplicate links
in ~org-stored-links~. The default value is =move-to-front=.
*** Major changes and additions to Org API *** Major changes and additions to Org API
**** New term: "syntax node" **** New term: "syntax node"

View File

@ -509,20 +509,6 @@ links more efficient."
:type 'boolean :type 'boolean
:safe #'booleanp) :safe #'booleanp)
(defcustom org-link-store-existing 'move-to-front
"Variable controlling how to deal with already stored links.
When nil, ignore store request for an already stored link.
When symbol `move-to-front', move the stored link to the front of
`org-stored-links'.
When symbol `store-duplicate', add a duplicate in front."
:group 'org-link-store
:type '(choice
(const :tag "Do no store duplicate" nil)
(const :tag "Move stored duplicate to front" move-to-front)
(const :tag "Store duplicate" store-duplicate))
:safe #'symbolp
:package-version '(Org . "9.7"))
;;; Public variables ;;; Public variables
(defconst org-target-regexp (let ((border "[^<>\n\r \t]")) (defconst org-target-regexp (let ((border "[^<>\n\r \t]"))
@ -1764,14 +1750,13 @@ non-nil."
(if (not (and interactive? link)) (if (not (and interactive? link))
(or agenda-link (and link (org-link-make-string link desc))) (or agenda-link (and link (org-link-make-string link desc)))
(dotimes (_ (if custom-id 2 1)) ; Store 2 links when CUSTOM-ID is non-nil. (dotimes (_ (if custom-id 2 1)) ; Store 2 links when CUSTOM-ID is non-nil.
(pcase org-link-store-existing (cond
((or `store-duplicate ((not (member (list link desc) org-stored-links))
(guard (not (member (list link desc) org-stored-links))))
(push (list link desc) org-stored-links) (push (list link desc) org-stored-links)
(message "Stored: %s" (or desc link))) (message "Stored: %s" (or desc link)))
((or`nil (guard (equal (list link desc) (car org-stored-links)))) ((equal (list link desc) (car org-stored-links))
(message "This link has already been stored")) (message "This link has already been stored"))
(`move-to-front (t
(setq org-stored-links (setq org-stored-links
(delete (list link desc) org-stored-links)) (delete (list link desc) org-stored-links))
(push (list link desc) org-stored-links) (push (list link desc) org-stored-links)