Christian Barthel <[email protected]> writes:
>> The feature you describe generally makes sense, but it should honor
>> `org-link-context-for-files' and `org-id-link-use-context'. What you
>> need to modify is `org-link-precise-link-target', not `org-store-link'
>> itself.
>
> Thanks for your hints and suggestions. Attached is a new patch.
> I hope I understood your comments, didn’t mess up anything and
> the patch is helpful for the org community.
> 1. I have extended ‘org-store-link’ so it recognizes when ID is
> set (additionally to CUSTOM_ID).
Please, do not touch org-store-link. All the ID property handling is in
org-id.el.
> 2. I have extended ‘org-link-precise-link-target’ to store an id:
> link if the ID is set.
I think you misunderstood the purpose of org-link-precise-link-target.
It is not intended to return id:<heading id>, but to provide
<search string> in id:<heading id>::<search string>.
In your case, you need to extend
((derived-mode-p 'org-mode)
(let* ((element (org-element-at-point))
(name (org-element-property :name element))
(heading (org-element-lineage element '(headline inlinetask)
t))
(custom-id (org-entry-get heading "CUSTOM_ID")))
(cond
(name
(list name
name
(org-element-begin element)))
((org-before-first-heading-p)
(list (org-link--normalize-string (org-current-line-string) t)
nil
(line-beginning-position)))
(heading
(list (if custom-id (concat "#" custom-id)
(org-link-heading-search-string))
(org-link--normalize-string
(org-get-heading t t t t))
(org-element-begin heading))))))
to check when point is at dedicated target and, when yes, return target
name as search string. Like what is done for NAME, but you will need to
use org-element-context to check whether there is target at point.
--
Ihor Radchenko // yantar92,
Org mode maintainer,
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>