[oni-org] Allow project references to work with archived tasks
This commit fixes the issue that project tasks found in the archive of the org file can't be accessed through the link that's been generated. This fixes that.
This commit is contained in:
parent
1d8734b275
commit
875e63d62a
1 changed files with 56 additions and 28 deletions
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
;; Author: Tom Willemse <tom@ryuslash.org>
|
;; Author: Tom Willemse <tom@ryuslash.org>
|
||||||
;; Keywords: local
|
;; Keywords: local
|
||||||
;; Version: 2022.0928.004858
|
;; Version: 2022.1019.224918
|
||||||
;; Package-Requires: (oni-yasnippet oni-alert oni-hydra org org-contrib org-bullets org-edna diminish all-the-icons olivetti form-feed)
|
;; Package-Requires: (oni-yasnippet oni-alert oni-hydra org org-contrib org-bullets org-edna diminish all-the-icons olivetti form-feed)
|
||||||
|
|
||||||
;; This program is free software; you can redistribute it and/or modify
|
;; This program is free software; you can redistribute it and/or modify
|
||||||
|
@ -845,15 +845,9 @@ This is an around advice for ‘org-html--svg-image’ as FUN."
|
||||||
|
|
||||||
(add-hook 'org-property-allowed-value-functions #'oni-org-pick-project)
|
(add-hook 'org-property-allowed-value-functions #'oni-org-pick-project)
|
||||||
|
|
||||||
(defun oni-org-dblock-write-project-steps (_params)
|
(defun oni-org-collect-project-references (heading-id)
|
||||||
"Generate back-links to org headings."
|
(let ((files (org-add-archive-files (list (buffer-file-name))))
|
||||||
(let ((current-heading-id
|
|
||||||
(let ((properties (org-entry-properties)))
|
|
||||||
(or (alist-get "CUSTOM_ID" properties nil nil #'string=)
|
|
||||||
(org-id-get-create))))
|
|
||||||
(files (org-add-archive-files (list (buffer-file-name))))
|
|
||||||
backlinks)
|
backlinks)
|
||||||
(when (not (null current-heading-id))
|
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(mapc (lambda (file)
|
(mapc (lambda (file)
|
||||||
(with-current-buffer (or (get-file-buffer file)
|
(with-current-buffer (or (get-file-buffer file)
|
||||||
|
@ -862,19 +856,53 @@ This is an around advice for ‘org-html--svg-image’ as FUN."
|
||||||
(get-file-buffer file)))
|
(get-file-buffer file)))
|
||||||
(goto-char (point-min))
|
(goto-char (point-min))
|
||||||
(while (re-search-forward
|
(while (re-search-forward
|
||||||
(rx (or (seq "[[id:" (literal current-heading-id) "]")
|
(rx (or (seq "[[id:" (literal heading-id) "]")
|
||||||
(seq "#" (literal current-heading-id) "]")))
|
(seq "#" (literal heading-id) "]")))
|
||||||
nil t)
|
nil t)
|
||||||
(unless (or (oni-org-in-dblock-p)
|
(unless (or (oni-org-in-dblock-p)
|
||||||
(oni-org-at-origin-property-p))
|
(oni-org-at-origin-property-p))
|
||||||
(let ((components (org-heading-components)))
|
(let ((components (org-heading-components)))
|
||||||
(push (list (org-entry-is-done-p) (point) (nth 4 components)) backlinks))))))
|
(push `((done . ,(and (org-entry-is-done-p) t))
|
||||||
files)))
|
(position . ,(point))
|
||||||
|
(title . ,(replace-regexp-in-string (rx (zero-or-more whitespace)
|
||||||
|
"[" (or (seq (zero-or-more digit) "%")
|
||||||
|
(seq (zero-or-more digit) "/" (zero-or-more digit)))
|
||||||
|
"]" eol)
|
||||||
|
"" (nth 4 components)))
|
||||||
|
(file . ,file))
|
||||||
|
backlinks))))))
|
||||||
|
files))
|
||||||
|
backlinks))
|
||||||
|
|
||||||
|
(defun oni-org-linkify-backlink (link)
|
||||||
|
(format "- [%s] [[%s*%s][%s]]"
|
||||||
|
(if (alist-get 'done link) "X" " ")
|
||||||
|
(let ((file-name (alist-get 'file link)))
|
||||||
|
(if (string-suffix-p "_archive" file-name t)
|
||||||
|
(format "file:%s::" (alist-get 'file link))
|
||||||
|
""))
|
||||||
|
(alist-get 'title link)
|
||||||
|
(alist-get 'title link)))
|
||||||
|
|
||||||
|
(defun oni-org-link= (a b)
|
||||||
|
(= (alist-get 'position a)
|
||||||
|
(alist-get 'position b)))
|
||||||
|
|
||||||
|
(defun oni-org-link< (a b)
|
||||||
|
(< (alist-get 'position a)
|
||||||
|
(alist-get 'position b)))
|
||||||
|
|
||||||
|
(defun oni-org-dblock-write-project-steps (_params)
|
||||||
|
"Generate back-links to org headings."
|
||||||
|
(let* ((current-heading-id
|
||||||
|
(let ((properties (org-entry-properties)))
|
||||||
|
(or (alist-get "CUSTOM_ID" properties nil nil #'string=)
|
||||||
|
(org-id-get-create))))
|
||||||
|
(backlinks (and (not (null current-heading-id))
|
||||||
|
(oni-org-collect-project-references current-heading-id))))
|
||||||
(insert (string-join
|
(insert (string-join
|
||||||
(mapcar (lambda (link)
|
(mapcar #'oni-org-linkify-backlink
|
||||||
(concat "- " (if (car link) "[X]" "[ ]") " [[*" (caddr link) "][" (caddr link) "]]"))
|
(sort (seq-uniq backlinks #'oni-org-link=) #'oni-org-link<))
|
||||||
(sort (seq-uniq backlinks (lambda (a b) (= (cadr a) (cadr b))))
|
|
||||||
(lambda (a b) (< (cadr a) (cadr b)))))
|
|
||||||
"\n"))
|
"\n"))
|
||||||
(org-update-statistics-cookies nil)))
|
(org-update-statistics-cookies nil)))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue