diff options
author | Thanos Apollo <[email protected]> | 2025-01-19 00:57:44 +0200 |
---|---|---|
committer | Thanos Apollo <[email protected]> | 2025-01-19 00:57:44 +0200 |
commit | 62be48df445b1bf880b4e0b87144395aa0e4f793 (patch) | |
tree | 5e240db454a647cb516febf415be8e6670dac21f | |
parent | 7851136732fa64d04b4dfc9f79cd596838e5be07 (diff) |
get-id: Rewrite using recursion.
* Simplify code by using cond with recursion.
-rw-r--r-- | org-gnosis.el | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/org-gnosis.el b/org-gnosis.el index 60b86b8..e33ff27 100644 --- a/org-gnosis.el +++ b/org-gnosis.el @@ -141,19 +141,17 @@ TOPIC-ID: Topic hash id." (list :title title :id id :tags all-tags :master master :level level)))) (defun org-gnosis-get-id () - "Find the nearest ID property searching up the outline hierarchy. - -Return the ID if found, else nil." + "Return id for heading at point." (save-excursion - (while (and (not (org-entry-get nil "ID")) - (not (bobp))) - (ignore-errors - (if (> (funcall outline-level) 1) - ;; Adjust for level <1 headings that do not have a level 1 heading. - (or (org-up-heading-safe) (goto-char (point-min))) - (org-up-heading-safe) - (goto-char (point-min))))) - (org-entry-get nil "ID"))) + (let ((heading-level (org-current-level)) + (id (org-id-get))) + (cond (id id) + ((and (null id) (= heading-level 1)) + (goto-char (point-min)) + (org-id-get)) + (t + (outline-up-heading 1 t) + (org-gnosis-get-id)))))) (defun org-gnosis-collect-id-links () "Collect ID links and current headline ID as (link-id . headline-id) pairs." |