I am using org-id to create links to different headlines in an org file. When using org-insert-link (C-c C-l), I select id as the link type option. Then I press RET. I have :complete configured to show a list of headlines from which I select the one I want, I use this:

(defun org-id-complete-link ()
  (concat "id:" (org-id-get-with-outline-path-completion org-refile-targets)))

(org-link-set-parameters "id" :complete #'org-id-complete-link)

Then I press RET and I am prompted for a description. I want the default description to be the headline I just selected from the complete menu. I have found that I can use org-set-link-parameters to specify a default string for this prompt, by using :insert-description followed by a string or a variable or a function. The problem is that I don't know how to use the headline I just selected as the default description.

I am testing this:

(org-link-set-parameters "id" :insert-description "my default description")

I want to replace the string with the headline.

  • emacs.stackexchange.com/tags/elisp/info
    – Drew
    Aug 19, 2023 at 4:21
  • For easily reproducing it, it would be nice if you could add the definition of your org-id-complete-link to the question. Anyway, I looked at it, and it seems to me that there is a bug in org-insert-link. Somewhere in that function there is a (org-link-get-parameter type :insert-description), but it receives a type nil when using the :complete method, because in that case the link is set earlier to the value returned by the complete method (while it should be "id" for the org-link-get-parameter to return a non-nil value). Aug 19, 2023 at 8:34
  • If you insert (setq link (concat "id:" link)) just above the line (let* ((type just above that (org-link-get-parameter type :insert-description), then the function defined as the value of :insert-description in your org-link-parameters will get called with a usable non-nil first argument (but the description will also include an id:). Of course it would be great if you could report this bug, possibly with a link to this comment :) Aug 19, 2023 at 8:47
  • I'm not sure if that is a bug. I'm using ID links, which require some configuration to get working. This think this is similar to an http: link or a file: link, where you need to provide the description since there is no default (I might be wrong). The complete method I use provides the link for an ID; I'm wondering if the headline title can be obtained from this, but I have no idea how.
    – NandKN
    Aug 21, 2023 at 23:40


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.