From 758c7c513c6e5e0457b483dcf2bf7c9299d1015b Mon Sep 17 00:00:00 2001 From: Matt Lundin 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