emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Matthew Lundin <mdl@imapmail.org>
To: "Gustav Wikström" <gustav@whil.se>,
	"Org Mode List" <emacs-orgmode@gnu.org>
Subject: RE: [Bug] org-store-link should not insert a document level ID property
Date: Thu, 07 May 2020 16:41:18 -0500	[thread overview]
Message-ID: <87k11nifsx.fsf@fastmail.fm> (raw)
In-Reply-To: <HE1PR02MB3033C126946CA3EDC1D10CE4DAC50@HE1PR02MB3033.eurprd02.prod.outlook.com>

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

Gustav Wikström <gustav@whil.se> 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

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

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



[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Allow-configuration-of-whether-to-create-IDs-before-.patch --]
[-- Type: text/x-patch, Size: 2275 bytes --]

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

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
 				  (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

  parent reply	other threads:[~2020-05-07 21:41 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-04 22:13 [Bug] org-store-link should not insert a document level ID property Matt Lundin
2020-04-04 23:07 ` Gustav Wikström
2020-04-05 15:50   ` Gustav Wikström
2020-04-10  8:08     ` Gustav Wikström
2020-05-07 21:41     ` Matthew Lundin [this message]
2020-05-13  8:33       ` Nicolas Goaziou
2020-05-13 13:26         ` Matthew Lundin
2020-05-13 16:45           ` Nicolas Goaziou
2020-05-14 19:27             ` Gustav Wikström
2020-05-14 21:20               ` Nicolas Goaziou
2020-05-14 22:06                 ` Gustav Wikström
2020-05-14 19:11       ` Gustav Wikström

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87k11nifsx.fsf@fastmail.fm \
    --to=mdl@imapmail.org \
    --cc=emacs-orgmode@gnu.org \
    --cc=gustav@whil.se \


* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox


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