Last active
March 24, 2025 20:47
-
-
Save rtrppl/44f702822a49c63c2ce07da3c0e03c9d to your computer and use it in GitHub Desktop.
my-org-link-to-headline
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
| (require 'org-element) | |
| (require 'org-id) | |
| (defun my-org-link-to-headline () | |
| "Insert org-id link to a headline from a selected Org file." | |
| (interactive) | |
| (let ((file (read-file-name "Select Org file: " default-directory nil t nil)) | |
| (table (make-hash-table :test 'equal)) | |
| (parsed-data) | |
| (headline)) | |
| (with-temp-buffer | |
| (insert-file-contents file) | |
| (setq parsed-data (org-element-parse-buffer))) | |
| (org-element-map parsed-data 'headline | |
| (lambda (hl) | |
| (let* ((title (org-element-property :raw-value hl)) | |
| (id (org-element-property :ID hl))) | |
| (when title | |
| (puthash title id table))))) | |
| (setq headline (completing-read "Which headline: " (hash-table-keys table))) | |
| (insert (org-make-link-string (concat "id:" (gethash headline table)) headline)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment