Created
November 21, 2025 20:58
-
-
Save jwiegley/3a37261bac230d99f1204402e69454c7 to your computer and use it in GitHub Desktop.
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 org-ext-chain-blockers-in-region (beg end) | |
| "Chain tasks in region BEG to END with BLOCKER dependencies. | |
| Each task blocked by previous task. Creates IDs if needed. | |
| Returns count of tasks chained." | |
| (interactive "r") | |
| (unless (derived-mode-p 'org-mode) | |
| (user-error "Not in org buffer")) | |
| (save-excursion | |
| (goto-char beg) | |
| (let ((end-marker (copy-marker end)) | |
| (ids nil) | |
| (count 0) | |
| (first-heading t)) | |
| ;; First pass: collect heading IDs | |
| (while (and (< (point) end-marker) | |
| (re-search-forward org-heading-regexp end-marker t)) | |
| (save-excursion | |
| (org-back-to-heading t) | |
| (push (org-id-get-create) ids))) | |
| (setq ids (nreverse ids)) | |
| ;; Second pass: set BLOCKER properties | |
| (goto-char beg) | |
| (let ((prev-id nil)) | |
| (while (and (< (point) end-marker) | |
| (re-search-forward org-heading-regexp end-marker t)) | |
| (save-excursion | |
| (org-back-to-heading t) | |
| (let ((current-id (car ids))) | |
| (setq ids (cdr ids)) | |
| (when prev-id | |
| (let* ((blocker-prop "BLOCKER") | |
| (blocker-existing (org-entry-get nil blocker-prop 'selective)) | |
| (blocker-base (or blocker-existing "ids()")) | |
| (blocker-value | |
| (with-temp-buffer | |
| (insert blocker-base) | |
| (backward-char) | |
| (when blocker-existing | |
| (insert " ")) | |
| (insert "id:" prev-id) | |
| (buffer-string)))) | |
| (org-set-property blocker-prop blocker-value) | |
| (setq count (1+ count)))) | |
| (setq prev-id current-id))))) | |
| (set-marker end-marker nil) | |
| (message "Chained %d task%s with blocker dependencies" | |
| count (if (= count 1) "" "s")) | |
| count))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment