Christian Barthel <[email protected]> writes:
>>> (when (and (buffer-file-name (buffer-base-buffer))
>>> (derived-mode-p 'org-mode)
>>> (org-entry-get nil "CUSTOM_ID"))
>>> --8<---------------cut here---------------end--------------->8---
>>
>> That's an additional link stored beside the main link.
>
> I thought it would be the best to mimic this behavior.
Not really. If you read the docstring, you will see
In Org buffers, an additional "human-readable" simple file link
is stored as an alternative to persistent org-id or other links,
if at a heading with a CUSTOM_ID property or an element with a
NAME.
ID links are generally not human-readable, so your change would go
against the intended purpose of storing that additional link.
> Ok sorry - one more attempt. Is this patch going into the right
> direction (defun: org-link-precise-link-target) ?
Yup.
> + (context (org-element-context element))
> (custom-id (org-entry-get heading "CUSTOM_ID")))
> (cond
> + ((org-element-type-p context 'target)
> + (list (org-element-property :value context)
> + (org-element-property :value context)
> + (org-element-begin element)))
Maybe just (org-element-begin context). We return the position of
target then. Your variant returns the position of the containing
paragraph.
Also, after your change, `org-link--file-link-to-here' will be able to
handle target links. So, in org-store-link
(cond
;; Store a link using the target at point
((org-in-regexp "[^<]<<\\([^<>]+\\)>>[^>]" 1)
(setq link
(concat "file:"
(abbreviate-file-name
(buffer-file-name (buffer-base-buffer)))
"::" (match-string 1))
;; Target may be shortened when link is inserted.
;; Avoid [[target][file:~/org/test.org::target]]
;; links. Maybe the case of identical target and
;; description should be handled by `org-insert-link'.
desc nil))
(t
;; Just link to current headline.
(let ((here (org-link--file-link-to-here)))
(setq link (car here))
(setq desc (cdr here)))))
becomes redundant. The special clause for target at point will no longer
be necessary.
And the final step will be testing. And adding tests to
`test-org-link/precise-link-target' in the git repository.
Let me know if you need any help with this.
--
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>