ENH store links when scanning the buffer

This commit is contained in:
Nathan Dwarshuis 2022-03-06 12:32:24 -05:00
parent fc255cfa5b
commit 12b49124da
1 changed files with 12 additions and 8 deletions

View File

@ -1220,7 +1220,7 @@ headline."
(line-re (org-x-dag-line-regexp kws)) (line-re (org-x-dag-line-regexp kws))
cur-path this-point this-key this-level this-todo has-todo this-parent cur-path this-point this-key this-level this-todo has-todo this-parent
this-tags this-meta all-tags this-file-links this-links acc acc-meta this-tags this-meta all-tags this-file-links this-links acc acc-meta
this-parent-key) acc-links this-parent-key)
;; TODO add org-mode sanity check ;; TODO add org-mode sanity check
(goto-char (point-min)) (goto-char (point-min))
;; If not on a headline, check for a property drawer with links in it ;; If not on a headline, check for a property drawer with links in it
@ -1279,6 +1279,7 @@ headline."
this-planning this-planning
this-props this-props
this-parent-key)) this-parent-key))
(!cons (cons this-key this-links) acc-links)
(!cons (cons this-key this-meta) acc-meta) (!cons (cons this-key this-meta) acc-meta)
(!cons (cons this-key `(,(nth 1 this-parent) ,@this-links)) acc)) (!cons (cons this-key `(,(nth 1 this-parent) ,@this-links)) acc))
;; Add current headline to stack ;; Add current headline to stack
@ -1286,7 +1287,7 @@ headline."
;; Since we know the next headline's position already, skip ahead to ;; Since we know the next headline's position already, skip ahead to
;; save some work ;; save some work
(goto-char next-pos)) (goto-char next-pos))
(list (nreverse acc) (nreverse acc-meta)))) (list (nreverse acc) (nreverse acc-meta) acc-links)))
(defun org-x-dag-get-file-nodes (file) (defun org-x-dag-get-file-nodes (file)
"Return all nodes in FILE in one pass." "Return all nodes in FILE in one pass."
@ -1341,14 +1342,16 @@ removed from, added to, or edited within the DAG respectively."
(cl-flet (cl-flet
((append-results ((append-results
(acc file) (acc file)
(-let* (((acc-ids acc-meta acc-filemaps) acc) (-let* (((acc-ids acc-meta acc-filemaps acc-links) acc)
((ids metas) (org-x-dag-get-file-nodes file)) ((ids metas links) (org-x-dag-get-file-nodes file))
(filemap (cons file (-map #'car ids)))) (filemap (cons file (-map #'car ids))))
(list (append ids acc-ids) `((,@ids ,@acc-ids)
(append metas acc-meta) (,@metas ,@acc-meta)
(cons filemap acc-filemaps))))) (,filemap ,@acc-filemaps)
(,@links ,@acc-links)))))
(-reduce-from #'append-results nil files))) (-reduce-from #'append-results nil files)))
;; TODO what about all the nodes that don't need to be updated?
(defun org-x-dag-update-ht (to-remove to-insert ht) (defun org-x-dag-update-ht (to-remove to-insert ht)
(--each to-remove (--each to-remove
(ht-remove ht it)) (ht-remove ht it))
@ -1375,7 +1378,8 @@ plist holding the files to be used in the DAG."
(files2rem (append to-update to-remove)) (files2rem (append to-update to-remove))
(files2ins (append to-update to-insert)) (files2ins (append to-update to-insert))
(ids2rem (org-x-dag-files->ids files2rem)) (ids2rem (org-x-dag-files->ids files2rem))
((ids2ins meta2ins fms2ins) (org-x-dag-read-files files2ins))) ((ids2ins meta2ins fms2ins links2ins)
(org-x-dag-read-files files2ins)))
(org-x-dag-update-ht ids2rem meta2ins id->meta) (org-x-dag-update-ht ids2rem meta2ins id->meta)
(org-x-dag-update-ht files2rem fms2ins file->ids) (org-x-dag-update-ht files2rem fms2ins file->ids)
(org-x-dag-update-dag ids2ins ids2rem) (org-x-dag-update-dag ids2ins ids2rem)