From: Ihor Radchenko <yantar92@posteo.net>
To: Rick Lupton <mail@ricklupton.name>
Cc: "Y. E." <emacs-orgmode@gnu.org>
Subject: Re: [PATCH v2] org-id: allow using parent's existing id in links to headlines
Date: Mon, 29 Jan 2024 13:00:49 +0000 [thread overview]
Message-ID: <87r0i0mgzi.fsf@localhost> (raw)
In-Reply-To: <1b50d1a4-8573-4dcc-9427-8970f67e632a@app.fastmail.com>
"Rick Lupton" <mail@ricklupton.name> writes:
> Thanks for trying it out. Updated patches attached, comments below.
Thanks!
>> 3. Consider
>> (setq org-id-link-consider-parent-id t)
>> (setq org-id-link-to-org-use-id t)
>>
>> Then, create a new empty Org file
>> M-x org-store-link with create a top-level properties drawer with ID
>> and store the link. However, that link will not be a simple ID link,
>> but also have ::PROPERTIES search string, which is not expected.
>
> This is because it is trying to link to the current line of the file, which contains the text "PROPERTIES". On main, with (setq org-id-link-to-org-use-id nil), you see the equivalent behaviour (a link to [[file:test.org:::PROPERTIES:]]) when point is before the first heading. So, this seems consistent with non-org-id links?
No. Do note that my instructions start from _empty_ file. With
org-id-link-to-org-use-id, PROPERTIES drawer is not created. This is
different from what happens with your patch - it is unexpected in your
patch that the search string is added for text that did not exist in the
buffer previously.
> (these links don't actually work with the default value of
> `org-link-search-must-match-exact-headline', but I think that's a
> separate issue).
That's a good catch.
The fact that links stored via `org-store-link' cannot be open with
default settings is not good.
Also, your patch disregards this setting - it should not match
non-headline search strings with the default value of
`org-link-search-must-match-exact-headline'.
Probably, changing the default value of
`org-link-search-must-match-exact-headline' to nil is due.
> Subject: [PATCH 2/2] org-id.el: Extend links with search strings, inherit
> parent IDs
I ran make test, and it looks like one test is failing with your patch:
1 unexpected results:
FAILED test-org-link/id-store-link-using-parent ((should (equal '("id:abc" "H1") (test-ol-stored-link-with-text "* H1\n:PROPERTIES:\n:ID: abc\n:END:\n** H2\n<point>" (org-id-store-link)))) :form (equal ("id:abc" "H1") ("id:88e0c8d7-90a6-4628-b35a-cea989e3561b" "H2")) :value nil :explanation (list-elt 0 (arrays-of-different-length 6 39 "id:abc" "id:88e0c8d7-90a6-4628-b35a-cea989e3561b" first-mismatch-at 3)))
> + #+vindex: org-id-link-consider-parent-id
> + When ~org-id-link-consider-parent-id~ is ~t~ (and
> + ~org-context-in-file-links~ and ~org-id-link-use-context~ are both
`org-context-in-file-links' is an obsolete name. Use
`org-link-context-for-files'.
Also, please add `org-id-link-use-context' to #+vindex.
> +**** =org-link= store functions are passed an ~interactive?~ argument
> +
> +The ~:store:~ functions set for link types using
> +~org-link-set-parameters~ are now passed an ~interactive?~ argument,
> +indicating whether ~org-store-link~ was called interactively.
> +
> +Existing store functions will continue to work.
Please update the docstring of `org-store-link-functions' to specify
that an argument is passed to :store functions.
(org-link-parameters docstring says
:store
Function responsible for storing the link. See the function
org-store-link-functions for a description of the expected
arguments.
)
> - (org-insert-heading nil t t)
> + ;; Find appropriate level for new heading
> + (let ((level (save-excursion
> + (goto-char (point-min))
> + (+ 1 (or (org-current-level) 0)))))
This is fragile. You assume that `point-min' always contains a heading.
That may or may not be the case - `org-link-search' may be called by
third-party code that does not care about setting narrowing in certain
ways.
It is more reliable to do something like (while (org-up-heading-safe)
...) to find the lowest-level ancestor.
> +(defun org-link-precise-link-target (&optional relative-to)
> + "Determine search string and description for storing a link.
> +
> +If a search string (see 'org-link-search') is found, return cons
Quoting: `org-link-search'.
> + (let* ((element (org-element-at-point))
> + (name (org-element-property :name element))
> + (heading (org-element-lineage element 'headline t))
What about inlinetasks?
> + (custom-id (org-entry-get nil "CUSTOM_ID")))
May as well pass HEADING as the first argument of `org-entry-get'. It
will be slightly more efficient.
> + (org-link--add-to-stored-links link desc)
> + ;; In org buffers, store an additional "human-readable" link
> + ;; using custom id, if available.
> + (when (and (buffer-file-name (buffer-base-buffer))
> + (derived-mode-p 'org-mode)
> + (org-entry-get nil "CUSTOM_ID"))
> + (setq link (concat "file:"
> + (abbreviate-file-name
> + (buffer-file-name (buffer-base-buffer)))
> + "::#" (org-entry-get nil "CUSTOM_ID")))
This is fragile - you are relying upon the exact code used to store
file:...#CUSTOM-ID link. Instead, please refactor the function to re-use
that code.
> + (id-location (or (and org-entry-property-inherited-from
> + (marker-position org-entry-property-inherited-from))
> + (save-excursion (org-back-to-heading-or-point-min) (point))))
> (case-fold-search nil)
> (desc (save-excursion
> - (org-back-to-heading-or-point-min t)
> + (goto-char id-location)
You are calling `org-back-to-heading-or-point-min' without optional
argument INVISIBLE-OK. This looks like an oversight.
--
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>
next prev parent reply other threads:[~2024-01-29 12:58 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-24 11:40 [PATCH] org-id: allow using parent's existing id in links to headlines Rick Lupton
2023-07-25 7:43 ` Ihor Radchenko
2023-07-25 15:16 ` Max Nikulin
2023-07-26 8:10 ` Ihor Radchenko
2023-07-27 0:16 ` Samuel Wales
2023-07-27 7:42 ` IDs below headline level (for paragraphs, lists, etc) (was: [PATCH] org-id: allow using parent's existing id in links to headlines) Ihor Radchenko
2023-07-28 20:00 ` Rick Lupton
2023-07-28 19:56 ` [PATCH] org-id: allow using parent's existing id in links to headlines Rick Lupton
2023-07-29 8:33 ` Ihor Radchenko
2023-11-09 20:56 ` Rick Lupton
2023-11-10 10:03 ` Ihor Radchenko
2023-11-19 15:21 ` Rick Lupton
2023-12-04 13:23 ` Rick Lupton
2023-12-10 13:35 ` Ihor Radchenko
2023-12-14 20:42 ` Rick Lupton
2023-12-15 12:55 ` Ihor Radchenko
2023-12-15 16:16 ` Rick Lupton
2023-12-16 14:20 ` Ihor Radchenko
2023-12-17 19:07 ` [PATCH v2] " Rick Lupton
2023-12-18 12:27 ` Ihor Radchenko
2024-01-02 16:13 ` Rick Lupton
2024-01-03 14:17 ` Ihor Radchenko
2024-01-28 22:47 ` Rick Lupton
2024-01-29 0:20 ` Samuel Wales
2024-01-29 13:06 ` Ihor Radchenko
2024-01-30 0:03 ` Samuel Wales
2024-02-03 15:08 ` Ihor Radchenko
2024-11-13 3:23 ` Samuel Wales
2024-01-29 13:00 ` Ihor Radchenko [this message]
2024-01-31 18:11 ` Rick Lupton
2024-02-01 12:13 ` Ihor Radchenko
2024-02-01 16:37 ` Rick Lupton
2024-02-03 13:10 ` Ihor Radchenko
2024-02-08 8:24 ` [PATCH] lisp/ol.el: Improve docstring Rick Lupton
2024-02-08 14:52 ` Ihor Radchenko
2024-02-08 8:46 ` [PATCH v2] org-id: allow using parent's existing id in links to headlines Rick Lupton
2024-02-08 13:02 ` Ihor Radchenko
2024-02-08 22:30 ` Rick Lupton
2024-02-09 12:09 ` Ihor Radchenko
2024-02-09 12:47 ` Rick Lupton
2024-02-09 12:57 ` Ihor Radchenko
2024-02-24 10:48 ` Bastien Guerry
2024-02-24 13:02 ` Ihor Radchenko
2024-02-24 15:57 ` Rick Lupton
2024-03-05 14:05 ` Stefan
2024-03-05 14:51 ` Ihor Radchenko
2023-11-04 23:01 ` [PATCH] " Rick Lupton
2023-11-05 12:31 ` Ihor Radchenko
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=87r0i0mgzi.fsf@localhost \
--to=yantar92@posteo.net \
--cc=emacs-orgmode@gnu.org \
--cc=mail@ricklupton.name \
/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).