Compare commits

..

No commits in common. "7e2860a9d96f4afa3eef68722680778162a70c7f" and "10e01d4b3b3ef573a60f36ddbc38aadff9d24fe3" have entirely different histories.

View File

@ -1061,53 +1061,45 @@ PARAMS may contain the following values:
(org-with-point-at mark (org-with-point-at mark
(when-let ((id-at-point (org-id-get))) (when-let ((id-at-point (org-id-get)))
(cons id-at-point (cons id-at-point
(db/org--backlinks-for-id id-at-point (db/org--backlinks-for-id id-at-point org-ql-match archives))))))
org-ql-match
archives))))))
(cl-remove-if #'null))) (cl-remove-if #'null)))
;; Change entries in headlines from the format (headline-id backlink-ids...) ;; Change entries in headlines from the format (headline-id backlink-ids...)
;; to (backlink-id headline-ids ...) for grouping them in the output later. ;; to (backlink-id headline-ids ...) for grouping them in the output later
(setq headlines (setq headlines
(->> headlines (->> headlines
;; Transform (headline-id backlink-ids) to pairs (-mapcat #'(lambda (headline)
;; (headline-id . backlink-id) (mapcar #'(lambda (backlink)
(-mapcat (pcase-lambda (`(,headline . ,backlinks)) (cons backlink (car headline)))
(mapcar #'(lambda (backlink) (cdr headline))))
(cons backlink headline)) ;; Group by backlinks (first entry), returns list of non-empty
backlinks))) ;; lists
;; Group by backlinks (first entry), returns alist of
;; backlink-ids and list of pairs (backlink-id . headline-id)
(-group-by #'car) (-group-by #'car)
;; Flatten list, to get a list of (backlink-id headline-ids...) ;; Flatten list, to get a list of (backlink-id headline-ids...)
(-map (pcase-lambda (`(,backlink . ,backlink-headline-conses)) (-map #'(lambda (group)
(cons backlink (-map #'cdr backlink-headline-conses)))))) (cons (car group) (-map #'cdr (cdr group)))))))
;; Replace IDs by headlines and add priority for sorting ;; Replace IDs by headlines and add priority for sorting
(setq output-lines (setq output-lines
(->> headlines (->> headlines
(-map (pcase-lambda (`(,backlink-id . ,headline-ids)) (-map #'(lambda (line)
(list (db/org--format-link-from-org-id backlink-id) (list (db/org--format-link-from-org-id (cl-first line))
(org-entry-get (org-id-find backlink-id 'marker) (org-entry-get (org-id-find (cl-first line) 'marker)
"PRIORITY") "PRIORITY")
(-map #'db/org--format-link-from-org-id headline-ids)))) (-map #'db/org--format-link-from-org-id (cdr line)))))
(-sort (pcase-lambda (`(_ ,prio-1 _) `(_ ,prio-2 _)) (-sort #'(lambda (line-1 line-2)
(string< prio-1 prio-2))))) (string< (cl-second line-1) (cl-second line-2))))))
;; Format output-lines as Org table ;; Format output-lines as Org table
(insert (format "| Backlink | Prio | Backlink Target(s) |\n|---|")) (insert (format "| Backlink | Prio | Backlink Target(s) |\n|---|"))
(when output-lines (when output-lines
(let (pp) ; pervious-priority, to draw hlines between groups of same priority (dolist (line output-lines)
(pcase-dolist (`(,backlink ,priority ,backlink-targets) output-lines) (insert (format "\n| %s | %s | %s |"
(when (and pp (not (equal pp priority))) (cl-first line) ; backlink
(insert "\n|--|")) (cl-second line) ; priority
(setq pp priority) (apply #'concat (-interpose ", " (cl-third line))) ; backlink targets
(insert )))
(format "\n| %s | %s | %s |" (insert "\n|---|"))
backlink
priority
(apply #'concat (-interpose ", " backlink-targets)))))
(insert "\n|---|")))
(org-table-align))) (org-table-align)))
(defun db/org-insert-backlink-block () (defun db/org-insert-backlink-block ()