From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms9.migadu.com with LMTPS id II0uAfxDpWRpDQEASxT56A (envelope-from ) for ; Wed, 05 Jul 2023 12:20:44 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id CLstAPxDpWTCzwAAG6o9tA (envelope-from ) for ; Wed, 05 Jul 2023 12:20:44 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 7F1BF25774 for ; Wed, 5 Jul 2023 12:20:43 +0200 (CEST) Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=ZMgk9atG; dmarc=pass (policy=none) header.from=posteo.net; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" ARC-Seal: i=1; s=key1; d=yhetil.org; t=1688552443; a=rsa-sha256; cv=none; b=mWygdQbdSoh/lNR5tjzNhmKdRRVQmYPUtM138DuFt/KtlRh7zqikQha8w9OipRX70eCY3F z0Vdj+rfNBTZW6c4kjQQUfwFEmxx0EMSz/QW8Ad7FgDav8eEP5wR/rYrtCXVI7RoePbNog mHVQNUaeq6PJKnmIEqlmvTh+34gamsIw3xTFeMd+CciUSwtDgnM4VovO7a+5I2CUYkuwJ8 EIY5J/TBJA1tv8aRxNcGxq0k0ir/6oZqwiUSXZgogIs8pTL0YwIfiXajR2gVKFizMSBT8q XuJ1cMD7vw+gQtLumGg9CY1qkrmma427wiZNQ9adoe5ZG82qN9uReC+8sK748Q== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=ZMgk9atG; dmarc=pass (policy=none) header.from=posteo.net; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1688552443; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=MK0ScIRqHUijjQXIbyGAcCrYKJn4fPS0NStsd6kBJIM=; b=oiDpucgjANbYF3nc2rkNX/cP7ZSkFmW+U6zV9CZajM02YtyQPo6O9uCMKkUM6VMUaMq7xm z47k3tvZ1f6mLH0s95AqAfvFMBT3a0qMmYOzAIbCPfDwcZnk1N0WFbDPmYbOHnyGHnpP9y EutUwxZzT6ok5Gnzwb4RV6Zs4WDjBovTU30bzd5KaCwB7Fm1xs3l80QbuyWe//FPdkF3p5 UhYH9Mze8+wLNqjviyR/W9Awp4wv7arOv/rPb/etUqePcB5Eeay3VDRxXshFU+MCbKyw89 LCC2b9EtWQ0k/p/2kUS0+g/M8cq392acFzmQgpreDF8G9ebTuTWU7eKoLUox8g== Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qGzbz-0006is-Ps; Wed, 05 Jul 2023 06:19:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qGzby-0006ii-4d for emacs-orgmode@gnu.org; Wed, 05 Jul 2023 06:19:50 -0400 Received: from mout02.posteo.de ([185.67.36.66]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qGzbv-0008KP-VF for emacs-orgmode@gnu.org; Wed, 05 Jul 2023 06:19:49 -0400 Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id BFC36240104 for ; Wed, 5 Jul 2023 12:19:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1688552384; bh=JQavPHOjSWaK2XfzfjsXw/f9crqqgprGHe7kiOWTeFg=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:From; b=ZMgk9atG/dICNSaRr/eBqOGawqHbEK6C9ErOX+W5NTFkrsFn3jVx44L9AW/UBhAbB /IWEReN8ft5xgqxf1k8/mPUGf8m4WpibOIDB3QWYota0TAy98oyWUTKnDRisMP+qyZ K1MK0AuJMJ3vH5JcEDSKv2F8cVyi9UDYmoTD20eNjAy/y5cr7TDgof9wpWCW8rsB+R 3AdwNX6+4XQQAmaGe4+9Igv7xDGsDgo/KWu2d2oCS9mEA3IC1GaqQxmc2H7VTtBwNU RuOz8NsNMS3Lyn2HHtktJJPy/pJt0GQR8Jm6rOAgOk63Lp+nuT9gDNmDDpz8vOIAOk 6kOoht1KGggjQ== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4QwwdC6HMfz9rxQ; Wed, 5 Jul 2023 12:19:43 +0200 (CEST) From: Ihor Radchenko To: Anthony Carrico Cc: emacs-orgmode@gnu.org Subject: [PATCH] Re: what is the purpose of "This link has already been stored"? In-Reply-To: <87h6qqwh23.fsf@localhost> References: <87ilb8vsns.fsf@localhost> <87mt0iwoii.fsf@localhost> <87h6qqwh23.fsf@localhost> Date: Wed, 05 Jul 2023 10:19:41 +0000 Message-ID: <87fs62acea.fsf@localhost> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=185.67.36.66; envelope-from=yantar92@posteo.net; helo=mout02.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: emacs-orgmode-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN X-Migadu-Scanner: scn1.migadu.com X-Migadu-Spam-Score: -5.24 X-Migadu-Queue-Id: 7F1BF25774 X-Spam-Score: -5.24 X-TUID: qN+httxChK8j --=-=-= Content-Type: text/plain Ihor Radchenko writes: > What Samuel described is a sequence of M-x org-store-link followed by > M-x org-insert-all-links. With such workflow, user can expect that the > links are going to be stored in order. If we are instead shuffle the > stored links, M-x org-insert-all-links may result in unexpected > behaviour. > > Currently, when link to place is already stored, not error is thrown, a > message is displayed, no link is stored, and the stored link list is not > altered. Attaching the patch. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-org-store-link-Move-already-stored-link-to-front-by-.patch >From a05e2cc235b10a7096538da4f6ae6d17c82a6b25 Mon Sep 17 00:00:00 2001 Message-ID: From: Ihor Radchenko Date: Wed, 5 Jul 2023 13:14:56 +0300 Subject: [PATCH] org-store-link: Move already stored link to front by default * lisp/ol.el (org-link-store-existing): New customization controlling how to deal with already stored links. (org-store-link): Respect the new customization, allowing duplicates to (1) be added anyway; (2) be ignored; (3) be moved to front of `org-stored-links'. The default is (3). * etc/ORG-NEWS (~org-store-link~ now moves an already stored link to front of the ~org-stored-links~): Document the breaking change. Reported-by: Samuel Wales Link: https://list.orgmode.org/orgmode/CAJcAo8sjD3_FX5pFQ4git9wRDNM3bMqTgP-R5mM8zcf1B3mjPg@mail.gmail.com/ --- etc/ORG-NEWS | 15 +++++++++++++++ lisp/ol.el | 36 +++++++++++++++++++++++++++++------- 2 files changed, 44 insertions(+), 7 deletions(-) diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index d04e92275..288d50842 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -13,6 +13,21 @@ Please send Org bug reports to mailto:emacs-orgmode@gnu.org. * Version 9.7 (not released yet) ** Important announcements and breaking changes +*** ~org-store-link~ now moves an already stored link to front of the ~org-stored-links~ + +Previously, when the link to be stored were stored already, +~org-store-link~ displayed a message and did nothing. + +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 +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 **** New term: "syntax node" diff --git a/lisp/ol.el b/lisp/ol.el index 6dd7e0fa1..3a8ca5f39 100644 --- a/lisp/ol.el +++ b/lisp/ol.el @@ -509,6 +509,20 @@ (defcustom org-link-keep-stored-after-insertion nil :type 'boolean :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 (defconst org-target-regexp (let ((border "[^<>\n\r \t]")) @@ -1749,16 +1763,24 @@ (defun org-store-link (arg &optional interactive?) ;; Store and return the link (if (not (and interactive? link)) (or agenda-link (and link (org-link-make-string link desc))) - (if (member (list link desc) org-stored-links) - (message "This link has already been stored") - (push (list link desc) org-stored-links) - (message "Stored: %s" (or desc link)) + (dotimes (_ (if custom-id 2 1)) ; Store 2 links when CUSTOM-ID is non-nil. + (pcase org-link-store-existing + ((or `store-duplicate + (guard (not (member (list link desc) org-stored-links)))) + (push (list link desc) org-stored-links) + (message "Stored: %s" (or desc link))) + ((or`nil (guard (equal (list link desc) (car org-stored-links)))) + (message "This link has already been stored")) + (`move-to-front + (setq org-stored-links + (delete (list link desc) org-stored-links)) + (push (list link desc) org-stored-links) + (message "Link moved to front: %s" (or desc link)))) (when custom-id (setq link (concat "file:" (abbreviate-file-name - (buffer-file-name (buffer-base-buffer))) - "::#" custom-id)) - (push (list link desc) org-stored-links))) + (buffer-file-name (buffer-base-buffer))) + "::#" custom-id)))) (car org-stored-links))))) ;;;###autoload -- 2.41.0 --=-=-= Content-Type: text/plain -- Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at . Support Org development at , or support my work at --=-=-=--