On Saturday, October 11, 2025, Ihor Radchenko wrote:

>>  And with the current ol.el on my disk (Emacs 30.1.90), it
>> only gets executed when CUSTOM_ID is set.  It happens in the
>> below snippet where the CUSTOM_ID property is checked:
>>
>> --8<---------------cut here---------------start------------->8---
>> ;; org-store-link:
>> ;; 
>> https://cgit.git.savannah.gnu.org/cgit/emacs/org-mode.git/tree/lisp/ol.el#n2570
>> ...
>>         (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.

> You likely have `org-id-link-to-org-use-id' set to nil (the default),
> which prevents Org from creating id links.

Yes, you’re right.

>>> In your case, you need to extend
>>> ...
>>> 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.
>>
>> Sorry - I am not that deep into elisp to provide a better patch
>> right now.
>
> This should actually be fairly simple.
> You need org-element-context, org-element-type-p, and org-element-property
> (see https://orgmode.org/worg/dev/org-element-api.html#org682dd2a).
> It will be just an additional cond clause.

Ok sorry - one more attempt.  Is this patch going into the right
direction (defun: org-link-precise-link-target) ?

--- /opt/emacs-30.1.90/share/emacs/30.1.90/lisp/org/ol.el.gz
+++ #<buffer ol.el.gz<org>>
@@ -1482,8 +1482,13 @@
             (let* ((element (org-element-at-point))
                    (name (org-element-property :name element))
                    (heading (org-element-lineage element '(headline 
inlinetask) t))
+                  (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)))
                (name
                 (list name
                       name

Diff finished.  Sat Oct 11 22:00:22 2025


-- 
Christian Barthel

Reply via email to