emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Gustav Wikström" <gustav@whil.se>
To: Matt Lundin <mdl@imapmail.org>, Org Mode List <emacs-orgmode@gnu.org>
Subject: RE: [Bug] org-store-link should not insert a document level ID property
Date: Sun, 5 Apr 2020 15:50:29 +0000	[thread overview]
Message-ID: <HE1PR02MB3033C126946CA3EDC1D10CE4DAC50@HE1PR02MB3033.eurprd02.prod.outlook.com> (raw)
In-Reply-To: <HE1PR02MB30335EA34EC498F904DE4C73DAC40@HE1PR02MB3033.eurprd02.prod.outlook.com>

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

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.

Regards
Gustav

> Hi,
> 
> > -----Original Message-----
> > From: Matt Lundin <mdl@imapmail.org>
> > Sent: den 5 april 2020 00:13
> > To: Org Mode List <emacs-orgmode@gnu.org>
> > Cc: Gustav Wikström <gustav@whil.se>
> > Subject: [Bug] org-store-link should not insert a document level ID property
> >
> > The introduction of document-level property drawers (commit
> > 1bdff9f73dc1e7ff625a90e3e61350bdea99f29c from May 2019) introduced
> > inconsistencies in the behavior of org-id and org-store-link.
> >
> > If org-id-link-to-org-use-id is set to t or 'create-if-interactive,
> > calling org-store-link above the first headline in an org file will
> > insert a PROPERTY drawer and an ID at top of the file, so that the file
> > (call it "~/test.org") looks like this:
> >
> > --8<---------------cut here---------------start------------->8---
> > :PROPERTIES:
> > :ID:       1f43e860-9e7b-4c8f-82b9-6ed3352e589f
> > :END:
> >
> > * First headline
> > --8<---------------cut here---------------end--------------->8---
> >
> > However, the link that Org actually stores is "[[file:~/test.org]]", so
> > the ID is irrelevant.
> >
> > In addition, a link to a document-level ID does not work. Following
> > "[[id:1f43e860-9e7b-4c8f-82b9-6ed3352e589f]]" results in this error:
> >
> > user-error: Before first headline at position 14 in buffer test.org
> >
> > So either:
> >
> > 1. org-id and org-store-link/org-open-link should support document level
> >    ids in a user-configurable way, or
> > 2. org-id-get-create should detect whether it is above the first heading
> >    and should not create an id
> >
> > Option #2 would obviously be the easier fix.
> >
> > Gustav: were IDs within the scope of your initial thinking about
> > document level properties? Or are these largely irrelevant?
> 
> Yes, they were in scope and ID should mean something also before first
> headline. I'll have a look to see what can be done. Thanks for finding this!
> 
> >
> > Best,
> > Matt

[-- Attachment #2: 0001-Allow-storing-and-following-ID-links-before-first-he.patch --]
[-- Type: application/octet-stream, Size: 1781 bytes --]

From 88adb690f6de58b116cd59965aba14f3cfa7d490 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gustav=20Wikstr=C3=B6m?= <gustav@whil.se>
Date: Sun, 5 Apr 2020 17:36:01 +0200
Subject: [PATCH] Allow storing and following ID links before first heading

* lisp/org.el (org-find-property): Make org-find-property work
  correctly also before first heading.

* lisp/org-id.el (org-id-store-link): Make it possible to store ID
  links also before first heading.
---
 lisp/org-id.el | 7 +++++--
 lisp/org.el    | 3 ++-
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/lisp/org-id.el b/lisp/org-id.el
index d0fdeeb1b..1ff433bd8 100644
--- a/lisp/org-id.el
+++ b/lisp/org-id.el
@@ -665,8 +665,11 @@ optional argument MARKERP, return the position as a new marker."
     (let* ((link (concat "id:" (org-id-get-create)))
 	   (case-fold-search nil)
 	   (desc (save-excursion
-		   (org-back-to-heading t)
-		   (or (and (looking-at org-complex-heading-regexp)
+		   (org-back-to-heading-or-point-min t)
+		   (or (and (org-before-first-heading-p)
+			    (file-name-nondirectory
+			     (buffer-file-name (buffer-base-buffer))))
+		       (and (looking-at org-complex-heading-regexp)
 			    (if (match-end 4)
 				(match-string 4)
 			      (match-string 0)))
diff --git a/lisp/org.el b/lisp/org.el
index 06891b8bd..bdfeafdfb 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -13133,7 +13133,8 @@ part of the buffer."
 	(while (re-search-forward re nil t)
 	  (when (if value (org-at-property-p)
 		  (org-entry-get (point) property nil t))
-	    (throw 'exit (progn (org-back-to-heading t) (point)))))))))
+	    (throw 'exit (progn (org-back-to-heading-or-point-min t)
+				(point)))))))))
 
 (defun org-delete-property (property)
   "In the current entry, delete PROPERTY."
-- 
2.26.0


  reply	other threads:[~2020-04-05 16:29 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 [this message]
2020-04-10  8:08     ` Gustav Wikström
2020-05-07 21:41     ` Matthew Lundin
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:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  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=HE1PR02MB3033C126946CA3EDC1D10CE4DAC50@HE1PR02MB3033.eurprd02.prod.outlook.com \
    --to=gustav@whil.se \
    --cc=emacs-orgmode@gnu.org \
    --cc=mdl@imapmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* 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

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