ENH make split functions more specific

This commit is contained in:
Nathan Dwarshuis 2022-03-04 17:48:42 -05:00
parent 9a6ab71ab7
commit fc255cfa5b
1 changed files with 34 additions and 9 deletions

View File

@ -376,7 +376,7 @@ highest in the tree."
"Return the buffer parent id (if any) of ID." "Return the buffer parent id (if any) of ID."
(org-x-dag-id->metaprop id :buffer-parent)) (org-x-dag-id->metaprop id :buffer-parent))
(defun org-x-dag-id->split-parents (id) (defun org-x-dag-id->split-parents-2 (id)
"Return the buffer and non-buffer parents of ID. "Return the buffer and non-buffer parents of ID.
Return value is a list like (BUFFER NON-BUFFER)." Return value is a list like (BUFFER NON-BUFFER)."
@ -385,33 +385,51 @@ Return value is a list like (BUFFER NON-BUFFER)."
(cons buffer-parent (-remove-item buffer-parent parents)) (cons buffer-parent (-remove-item buffer-parent parents))
(cons nil parents)))) (cons nil parents))))
(defun org-x-dag-split-3 (fun id)
(-let* (((buffer linked) (funcall fun id))
(f (org-x-dag-id->file id))
((local foreign) (--separate (equal f (org-x-dag-id->file it)) linked)))
(list buffer local foreign)))
(defun org-x-dag-id->split-parents-3 (id)
"Return the buffer, local, and foreign parents of ID.
Return value is a list like (BUFFER LOCAL FOREIGN)."
(org-x-dag-split-3 #'org-x-dag-id->split-parents-2 id))
(defun org-x-dag-id->linked-parents (id) (defun org-x-dag-id->linked-parents (id)
"Return non-buffer (foreign) parents of ID." "Return non-buffer (foreign) parents of ID."
(cdr (org-x-dag-id->split-parents id))) (cdr (org-x-dag-id->split-parents-2 id)))
(defun org-x-dag-id->split-children (id) (defun org-x-dag-id->split-children-2 (id)
"Return buffer and non-buffer children of ID. "Return buffer and non-buffer children of ID.
Return value is a list like (BUFFER NON-BUFFER)." Return value is a list like (BUFFER NON-BUFFER)."
(->> (org-x-dag-id->children id) (->> (org-x-dag-id->children id)
(--separate (equal (org-x-dag-id->buffer-parent it) id)))) (--separate (equal (org-x-dag-id->buffer-parent it) id))))
(defun org-x-dag-id->split-children-3 (id)
"Return buffer, local, and foreign children of ID.
Return value is a list like (BUFFER LOCAL FOREIGN)."
(org-x-dag-split-3 #'org-x-dag-id->split-children-2 id))
(defun org-x-dag-id->buffer-children (id) (defun org-x-dag-id->buffer-children (id)
"Return children of ID that are not linked." "Return children of ID that are not linked."
(car (org-x-dag-id->split-children id))) (car (org-x-dag-id->split-children-2 id)))
(defun org-x-dag-id->linked-children (id) (defun org-x-dag-id->linked-children (id)
"Return children of ID that are linked." "Return children of ID that are linked."
(cadr (org-x-dag-id->split-children id))) (cadr (org-x-dag-id->split-children-2 id)))
(defmacro org-x-dag-id->with-split-parents (id &rest body) (defmacro org-x-dag-id->with-split-parents (id &rest body)
(declare (indent 1)) (declare (indent 1))
`(let ((it-buffer it-foreign) (org-x-dag-id->split-parents ,id)) `(let ((it-buffer it-foreign) (org-x-dag-id->split-parents-2 ,id))
,@body)) ,@body))
(defmacro org-x-dag-id->with-split-children (id &rest body) (defmacro org-x-dag-id->with-split-children (id &rest body)
(declare (indent 1)) (declare (indent 1))
`(let ((it-buffer it-foreign) (org-x-dag-id->split-children ,id)) `(let ((it-buffer it-foreign) (org-x-dag-id->split-children-2 ,id))
,@body)) ,@body))
(defun org-x-dag-id->group-parent-links-by-file-p (id) (defun org-x-dag-id->group-parent-links-by-file-p (id)
@ -430,6 +448,13 @@ Return value is a list like (BUFFER NON-BUFFER)."
(-mapcat #'org-x-dag-id->all-buffer-children) (-mapcat #'org-x-dag-id->all-buffer-children)
(cons id))) (cons id)))
(defun org-x-dag-id->goal-status-0 (which id)
(-let* (((buffer linked) (org-x-dag-id->split-children-2 id))
(file (org-x-dag-id->file id))
((local foreign) (--separate (equal (org-x-dag-id->file it) file) buffer))
(branchp (and local t)))
()))
(defun org-x-dag-id->goal-status (which id) (defun org-x-dag-id->goal-status (which id)
(let* ((ps (org-x-dag-id->linked-parents id)) (let* ((ps (org-x-dag-id->linked-parents id))
(ks (->> (-map #'org-x-dag-id->file ps) (ks (->> (-map #'org-x-dag-id->file ps)
@ -2291,7 +2316,7 @@ except it ignores inactive timestamps."
(cl-flet (cl-flet
((format-id ((format-id
(category id) (category id)
(-let* (((buffer linked) (org-x-dag-id->split-children id)) (-let* (((buffer linked) (org-x-dag-id->split-children-2 id))
((&alist :action :local :child-goal :plan :other) ((&alist :action :local :child-goal :plan :other)
(--group-by (--group-by
(org-x-dag--classify-goal-link which which-child it) (org-x-dag--classify-goal-link which which-child it)
@ -2312,7 +2337,7 @@ except it ignores inactive timestamps."
((format-id ((format-id
(category id) (category id)
(-let* (((buffer-children linked-children) (-let* (((buffer-children linked-children)
(org-x-dag-id->split-children id)) (org-x-dag-id->split-children-2 id))
(linked-parents (org-x-dag-id->linked-parents id)) (linked-parents (org-x-dag-id->linked-parents id))
((&alist :action :local :plan :other) ((&alist :action :local :plan :other)
(--group-by (org-x-dag--classify-goal-link :endpoint it) linked-children)) (--group-by (org-x-dag--classify-goal-link :endpoint it) linked-children))