Created
March 5, 2021 23:07
-
-
Save joelmccracken/3caf459e486e47afc3d271d061173ec9 to your computer and use it in GitHub Desktop.
This file contains 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 jnm/make-id-for-title (title) | |
"Return an ID based on TITLE." | |
(let* ((new-id (replace-regexp-in-string "[^[:alnum:]]" "-" (downcase title)))) | |
new-id)) | |
(defun jnm/org-custom-id-get-or-create (new-id) | |
"Get or create CUSTOM_ID. | |
If no CUSTOM_ID already exists,u se NEW-ID (and save it)." | |
(let ((old-id (org-entry-get nil "CUSTOM_ID"))) | |
(if old-id | |
old-id | |
(org-entry-put nil "CUSTOM_ID" new-id) | |
(org-id-add-location new-id (buffer-file-name (buffer-base-buffer))) | |
new-id))) | |
(defun jnm/org-cust-id-store-link (orig-fun &rest args) | |
"Advice for org-id-store link (ORIG-FUN) with ARGS. | |
instead of storing id and link as it does, | |
make a custom id, unless it already exists, and | |
use the full path to this headline for both the custom id" | |
(interactive) | |
(if jnm/in-ef-dir | |
(progn | |
(let* ((the-path (org-display-outline-path t t ":" t)) | |
(new-id (jnm/make-id-for-title the-path)) | |
(the-id (jnm/org-custom-id-get-or-create new-id)) | |
(link (concat "file:" | |
(abbreviate-file-name | |
(buffer-file-name (buffer-base-buffer))) | |
"::#" the-id)) | |
(desc (substring-no-properties the-path))) | |
(push (list link desc) org-stored-links)) | |
nil) | |
(apply orig-fun args))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment