emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] choices in org-id-find for handling missing ids
@ 2021-06-12 14:16 Marc-Oliver Ihm
  2021-06-13  5:51 ` Marc Ihm
  0 siblings, 1 reply; 3+ messages in thread
From: Marc-Oliver Ihm @ 2021-06-12 14:16 UTC (permalink / raw)
  To: emacs-orgmode@gnu.org

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

Hi,

please find attached a patch to allow more flexible handling of missing ids in org-id-find; some people (like me) tend to lose ids now and then and may benefit from more choices.

The current behaviour of calling org-id-update-id-locations is pretty perfect for situations where the id has been moved to another file (which will be the case in most situations, I guess). However, sometimes an id has simply been deleted and then searching for it in all files can not be helpful. Especially lisp-code calling org-id-find might want to handle things on its own.

To this goal, a new custom org-id-action-on-missing-id has been added; reproducing its description from the patch:

> (defcustom org-id-action-on-missing-id 'update
>   "Special action to be taken, if `org-id-find' cannot find an id.
> 
> With 'update (default), org-id-find will silently call
> `org-id-update-id-locations' and try again; this will help,
> e.g. if you have moved the id to another file.
> 
> With 'exception, the exception 'not-found will be thrown, which
> can be useful, if `org-id-find' is called from within lisp and
> the caller wants to handle the situation.
> 
> With 'error, a descriptive error will be raised, causing the
> current command to terminate."
>   :group 'org-id
>   :type '(choice
> 	  (const :tag "Run `org-id-update-id-locations' if an id cannot be found" update)
> 	  (const :tag "Throw exception `not-found'" exception)
> 	  (const :tag "Raise an error" error)
>           ))

the handling in org-id-find is straightforward.

The default corresponds to the current behaviour.
 
I would like to ask for opinions/discussion on this patch and maybe see it applied if found fit.

Best regards
Marc Ihm

[-- Attachment #2: 0001-choices-in-org-id-find-for-handling-missing-ids.patch --]
[-- Type: application/octet-stream, Size: 1993 bytes --]

From 70fb6f4ab26e9fae67d7b7900a0c6ec132199112 Mon Sep 17 00:00:00 2001
From: Marc Ihm <marc@ihm.name>
Date: Sat, 12 Jun 2021 15:49:50 +0200
Subject: [PATCH] choices in org-id-find for handling missing ids

---
 lisp/org-id.el | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/lisp/org-id.el b/lisp/org-id.el
index 784f41ccd..d5b818f85 100644
--- a/lisp/org-id.el
+++ b/lisp/org-id.el
@@ -248,6 +248,27 @@ This variable is only relevant when `org-id-track-globally' is set."
   :group 'org-id
   :type 'boolean)
 
+(defcustom org-id-action-on-missing-id 'update
+  "Special action to be taken, if `org-id-find' cannot find an id.
+
+With 'update (default), org-id-find will silently call
+`org-id-update-id-locations' and try again; this will help,
+e.g. if you have moved the id to another file.
+
+With 'exception, the exception 'not-found will be thrown, which
+can be useful, if `org-id-find' is called from within lisp and
+the caller wants to handle the situation.
+
+With 'error, a descriptive error will be raised, causing the
+current command to terminate."
+  :group 'org-id
+  :type '(choice
+	  (const :tag "Run `org-id-update-id-locations' if an id cannot be found" update)
+	  (const :tag "Throw exception `not-found'" exception)
+	  (const :tag "Raise an error" error)
+          ))
+
+
 ;;; The API functions
 
 ;;;###autoload
@@ -347,7 +368,10 @@ With optional argument MARKERP, return the position as a new marker."
     (when file
       (setq where (org-id-find-id-in-file id file markerp)))
     (unless where
-      (org-id-update-id-locations nil t)
+      (cl-case org-id-action-on-missing-id
+        ('exception (throw 'not-found id))
+        ('error (error "Could not find id '%s'; but running `org-id-update-id-locations' might help" id))
+        (t (org-id-update-id-locations nil t)))
       (setq file (org-id-find-id-file id))
       (when file
 	(setq where (org-id-find-id-in-file id file markerp))))
-- 
2.30.2


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

* Re: [PATCH] choices in org-id-find for handling missing ids
  2021-06-12 14:16 [PATCH] choices in org-id-find for handling missing ids Marc-Oliver Ihm
@ 2021-06-13  5:51 ` Marc Ihm
  2021-09-26  6:24   ` Bastien
  0 siblings, 1 reply; 3+ messages in thread
From: Marc Ihm @ 2021-06-13  5:51 UTC (permalink / raw)
  To: emacs-orgmode@gnu.org

Hi once more,
well after sending this patch I noticed, that org-id-update-id-locations 
has become orders of magnitude faster on my system; with org 9.4 it 
takes seconds instead of minutes as with org 9.3. Which is great news :-)
This alone may dratically reduce the need for changing the behaviour of 
org-id-find as contained in my patch.
So you may feel free to ignore it ...
Best Marc

Am 12.06.2021 um 16:16 schrieb Marc-Oliver Ihm:
> Hi,
> 
> please find attached a patch to allow more flexible handling of missing ids in org-id-find; some people (like me) tend to lose ids now and then and may benefit from more choices.
> 
> The current behaviour of calling org-id-update-id-locations is pretty perfect for situations where the id has been moved to another file (which will be the case in most situations, I guess). However, sometimes an id has simply been deleted and then searching for it in all files can not be helpful. Especially lisp-code calling org-id-find might want to handle things on its own.
> 
> To this goal, a new custom org-id-action-on-missing-id has been added; reproducing its description from the patch:
> 
>> (defcustom org-id-action-on-missing-id 'update
>>    "Special action to be taken, if `org-id-find' cannot find an id.
>>
>> With 'update (default), org-id-find will silently call
>> `org-id-update-id-locations' and try again; this will help,
>> e.g. if you have moved the id to another file.
>>
>> With 'exception, the exception 'not-found will be thrown, which
>> can be useful, if `org-id-find' is called from within lisp and
>> the caller wants to handle the situation.
>>
>> With 'error, a descriptive error will be raised, causing the
>> current command to terminate."
>>    :group 'org-id
>>    :type '(choice
>> 	  (const :tag "Run `org-id-update-id-locations' if an id cannot be found" update)
>> 	  (const :tag "Throw exception `not-found'" exception)
>> 	  (const :tag "Raise an error" error)
>>            ))
> 
> the handling in org-id-find is straightforward.
> 
> The default corresponds to the current behaviour.
>   
> I would like to ask for opinions/discussion on this patch and maybe see it applied if found fit.
> 
> Best regards
> Marc Ihm
> 


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

* Re: [PATCH] choices in org-id-find for handling missing ids
  2021-06-13  5:51 ` Marc Ihm
@ 2021-09-26  6:24   ` Bastien
  0 siblings, 0 replies; 3+ messages in thread
From: Bastien @ 2021-09-26  6:24 UTC (permalink / raw)
  To: Marc Ihm; +Cc: emacs-orgmode@gnu.org

Hi Marc,

Marc Ihm <marc@ihm.name> writes:

> So you may feel free to ignore it ...

Done ;)

It's good to have people paying attention to this feature anyway,
so thanks!

-- 
 Bastien


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

end of thread, other threads:[~2021-09-26  6:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-06-12 14:16 [PATCH] choices in org-id-find for handling missing ids Marc-Oliver Ihm
2021-06-13  5:51 ` Marc Ihm
2021-09-26  6:24   ` Bastien

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