Christian Barthel <[email protected]> writes:

> Sorry for waiting this long.. I am struggling a bit with
> git.savannah.gnu.org and the emacs repository.  My repo is not
> pulling newer changes.  So, this all is using emacs 30.2.  Is
> there a document that describes how to use the newest org-mode
> git repo?  How am I supposed to set up my emacs and which version
> should it be (30.2?  head?) to follow org-mode head?

org-mode head. See https://orgmode.org/worg/org-contribute.html

> On Sunday, October 12, 2025, Ihor Radchenko wrote:
>
>>> 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).
>
> Like this?
> ...
> +             (list (org-element-property :value context)
> +                   (org-element-property :value context)
> +                   (org-element-begin context)))

Yes, I think.

>> 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.
>
> I don’t know what becomes redundant at this place, sorry.

What I meant is that

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

is redundant because `org-link--file-link-to-here' calls
`org-link-precise-link-target', which, after your changes, will be able
to handle the targets.

>> And the final step will be testing. And adding tests to
>> `test-org-link/precise-link-target' in the git repository.
>>
>
> This is what I figured out so far:
>
> --8<---------------cut here---------------start------------->8---
>   (let ((org-id-link-to-org-use-id t))
>     (should
>      (equal '("id:b82baea1-4203-4f97-a52d-6a0534873c92::myanchor" "myanchor")
>             (test-ol-stored-link-with-text "* H1\n:PROPERTIES:\n:ID: 
> b82baea1-4203-4f97-a52d-6a0534873c92\n:END:\n<point><<myanchor>>\n"
>               (org-id-store-link))))
>     )
> --8<---------------cut here---------------end--------------->8---

Look right.
Maybe you can test a couple of other edge cases like anchor before first 
heading.

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

Reply via email to