Created
March 15, 2025 02:48
-
-
Save mmarshall540/61601368dbb6143c04aff59060096682 to your computer and use it in GitHub Desktop.
Org-mode: Select a heading for link with completion, but use ID property for link heading text as default description
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun my/org-id-insert-link-with-completion () | |
"Insert a link to another heading using completion. | |
Use the heading text as default description, but provide an | |
opportunity to edit same. | |
The `org-outline-path-complete-in-steps' option affects the behavior of | |
this command. It works best when set to nil. | |
To change which headings are presented as candidates, modify the command | |
by adding a `targets' argument in the call to | |
`org-id-get-with-outline-path-completion'. By default all headings in | |
the current buffer are presented as completion-candidates, but you can | |
use any value that would work as a value of `org-refile-targets' to set | |
the completion candidates to use. Or you could do something fancy with | |
prefix arguments to select different sets of targets. I am too lazy to | |
do that at the moment." | |
(interactive) | |
(let* ((id (org-id-get-with-outline-path-completion)) | |
(desc (save-excursion | |
(org-id-goto id) | |
(org-get-heading :notags :notodo :noprty :nocmnt)))) | |
(funcall-interactively 'org-insert-link nil (concat "id:" id) desc))) | |
(keymap-set org-mode-map "C-c C-M-l" | |
'my/org-id-insert-link-with-completion) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
(There was an Org-mode bug that made selection unusable if the above option was enabled. It will be fixed in Org 9.8, or now if you run the main branch.)
Fixed, it actually works better when enabled (the default), if you are using Emacs's default completion system. If using something like Vertico, it's probably still better to disable the option.