emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [Bug] org-store-link should not insert a document level ID property


From: Matthew Lundin
Subject: RE: [Bug] org-store-link should not insert a document level ID property
Date: Thu, 07 May 2020 16:41:18 -0500

Gustav Wikström <address@hidden> writes:

> Hi again,
>
> Patch is attached. It's not applied yet as it doesn't include anything
> about user-configuration yet. @Matt Lundin, care to elaborate what you
> had in mind in terms of that?
>
> With this patch a link before first headline is stored with the
> filename (no path) as description. Following the link does what you'd
> expect. Tests ran fine with the patch applied.

Hi Gustav,

Sorry it's taken so long to get back to you. Thanks for applying this.
It makes the behavior consistent.

What I was thinking of in terms of configuration is being able to
preserve path-based links (instead of IDs) if creating a link above the
first headline. This is the behavior that existed in the past when
org-id-link-to-org-use-id was set to t or
'create-if-interactive-and-no-custom-id.

I've attached a patch that implements this. However, I also know that we
are trying to avoid configuration/feature creep in Org, so I'm
submitting this here for comments. Is this a configuration other people
want?

If not, it would be easy enough for me to hack this through advice-add.

Best,

Matt

>From 758c7c513c6e5e0457b483dcf2bf7c9299d1015b Mon Sep 17 00:00:00 2001
From: Matt Lundin <address@hidden>
Date: Thu, 7 May 2020 16:31:05 -0500
Subject: [PATCH 1/1] Allow configuration of whether to create IDs before first
 heading

This allows users to keep file (path-based) links above the first
heading of a file.

* lisp/ol.el: (org-store-link) New test for whether to use ID links
* lisp/org-id.el: (org-id-create-id-before-first-heading) New variable
---
 lisp/ol.el     |  5 ++++-
 lisp/org-id.el | 11 +++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/lisp/ol.el b/lisp/ol.el
index 0cb1b0a7e..d072ad9f1 100644
--- a/lisp/ol.el
+++ b/lisp/ol.el
@@ -35,6 +35,7 @@
 (defvar org-comment-string)
 (defvar org-highlight-links)
 (defvar org-id-link-to-org-use-id)
+(defvar org-id-create-id-before-first-heading)
 (defvar org-inhibit-startup)
 (defvar org-outline-regexp-bol)
 (defvar org-src-source-file-name)
@@ -1619,7 +1620,9 @@ non-nil."
                             (and (eq org-id-link-to-org-use-id
                                      'create-if-interactive-and-no-custom-id)
                                  (not custom-id))))
-                   (and org-id-link-to-org-use-id (org-entry-get nil "ID"))))
+                   (and org-id-link-to-org-use-id (org-entry-get nil "ID")))
+               (or (not (org-before-first-heading-p))
+                   org-id-create-id-before-first-heading))
           ;; Store a link using the ID at point
           (setq link (condition-case nil
                          (prog1 (org-id-store-link)
diff --git a/lisp/org-id.el b/lisp/org-id.el
index 34720b7f2..8792aa3cb 100644
--- a/lisp/org-id.el
+++ b/lisp/org-id.el
@@ -123,6 +123,17 @@ nil   Never use an ID to make a link, instead link using a 
text search for
          (const :tag "Only use existing" use-existing)
          (const :tag "Do not use ID to create link" nil)))
 
+(defcustom org-id-create-id-before-first-heading t
+  "Non-nil means storing a link before the first heading will use IDs.
+This determines how `org-store-link' generates links before the
+first heading in an Org file when `org-id-link-to-org-use-id' is
+configured to create IDs.
+
+When nil, `org-store-link' will create a normal file link instead
+of an ID if before the first heading."
+  :group 'org-id
+  :type 'boolean)
+
 (defcustom org-id-uuid-program "uuidgen"
   "The uuidgen program."
   :group 'org-id
-- 
2.26.2


reply via email to

[Prev in Thread] Current Thread [Next in Thread]