Compare commits
3 Commits
949b49226d
...
10e01d4b3b
Author | SHA1 | Date |
---|---|---|
Daniel - | 10e01d4b3b | |
Daniel - | b84eb291e3 | |
Daniel - | 72c67796c2 |
13
init.el
13
init.el
|
@ -974,23 +974,22 @@ respectively."
|
||||||
(description target)
|
(description target)
|
||||||
(rx-to-string `(seq (or bol (1+ blank))
|
(rx-to-string `(seq (or bol (1+ blank))
|
||||||
"[[" (0+ (not (any "]"))) (regexp ,target) (0+ (not (any "]")))
|
"[[" (0+ (not (any "]"))) (regexp ,target) (0+ (not (any "]")))
|
||||||
;; Added `anything'
|
;; Added .* wildcards
|
||||||
"][" (0+ anything) (regexp ,description) (0+ anything)
|
"][" (regexp ".*") (regexp ,description) (regexp ".*")
|
||||||
"]]")))
|
"]]")))
|
||||||
;; Note that these actually allow empty descriptions
|
;; Note that these actually allow empty descriptions
|
||||||
;; or targets, depending on what they are matching.
|
;; or targets, depending on what they are matching.
|
||||||
(match-desc
|
(match-desc
|
||||||
(match) (rx-to-string `(seq (or bol (1+ blank))
|
(match) (rx-to-string `(seq (or bol (1+ blank))
|
||||||
"[[" (0+ (not (any "]")))
|
"[[" (0+ (not (any "]")))
|
||||||
;; Added `anything'
|
;; Added .* wildcards
|
||||||
"][" (0+ anything) (regexp ,match) (0+ anything)
|
"][" (regexp ".*") (regexp ,match) (regexp ".*")
|
||||||
"]]")))
|
"]]")))
|
||||||
(match-target
|
(match-target
|
||||||
(match) (rx-to-string `(seq (or bol (1+ blank))
|
(match) (rx-to-string `(seq (or bol (1+ blank))
|
||||||
"[[" (0+ (not (any "]"))) (regexp ,match) (0+ (not (any "]")))
|
"[[" (0+ (not (any "]"))) (regexp ,match) (0+ (not (any "]")))
|
||||||
;; Added `anything'
|
;; Removed pattern for description
|
||||||
"][" (0+ anything)
|
"][" ))))
|
||||||
"]]"))))
|
|
||||||
(cond (description-or-target
|
(cond (description-or-target
|
||||||
(rx-to-string `(or (regexp ,(no-desc description-or-target))
|
(rx-to-string `(or (regexp ,(no-desc description-or-target))
|
||||||
(regexp ,(match-desc description-or-target))
|
(regexp ,(match-desc description-or-target))
|
||||||
|
|
|
@ -1004,9 +1004,12 @@ referenced in `org-agenda-text-search-extra-files'."
|
||||||
(pop extra-files))
|
(pop extra-files))
|
||||||
(setq files (append files extra-files))
|
(setq files (append files extra-files))
|
||||||
|
|
||||||
|
;; Search directly for “[[id:ITEM-ID]” instead of using the regular
|
||||||
|
;; expression for links, as the latter seems to be broken (as of
|
||||||
|
;; [2022-06-09] when descriptions contain brackets
|
||||||
(org-ql-query :select '(org-id-get-create)
|
(org-ql-query :select '(org-id-get-create)
|
||||||
:from files
|
:from files
|
||||||
:where (let ((link-expression `(link :target ,item-id)))
|
:where (let ((link-expression `(regexp ,(format "\\[\\[id:%s\\]" item-id))))
|
||||||
(if org-ql-match
|
(if org-ql-match
|
||||||
`(and ,link-expression ,org-ql-match)
|
`(and ,link-expression ,org-ql-match)
|
||||||
link-expression)))))
|
link-expression)))))
|
||||||
|
@ -1046,7 +1049,7 @@ PARAMS may contain the following values:
|
||||||
:archives If non-nil, include archives"
|
:archives If non-nil, include archives"
|
||||||
(let* ((org-ql-match (plist-get params :org-ql-match))
|
(let* ((org-ql-match (plist-get params :org-ql-match))
|
||||||
(archives (plist-get params :archives))
|
(archives (plist-get params :archives))
|
||||||
headlines)
|
headlines output-lines)
|
||||||
|
|
||||||
;; Get all backlinks as list of Org mode IDs. Each list consists of the ID
|
;; Get all backlinks as list of Org mode IDs. Each list consists of the ID
|
||||||
;; of the headline (current or partent), followed by the IDs linking back to
|
;; of the headline (current or partent), followed by the IDs linking back to
|
||||||
|
@ -1061,20 +1064,42 @@ PARAMS may contain the following values:
|
||||||
(db/org--backlinks-for-id id-at-point org-ql-match archives))))))
|
(db/org--backlinks-for-id id-at-point org-ql-match archives))))))
|
||||||
(cl-remove-if #'null)))
|
(cl-remove-if #'null)))
|
||||||
|
|
||||||
;; Formatting.
|
;; Change entries in headlines from the format (headline-id backlink-ids...)
|
||||||
(insert (format "| Item | Backlinks | Priority |\n|---|"))
|
;; to (backlink-id headline-ids ...) for grouping them in the output later
|
||||||
(dolist (headline headlines)
|
(setq headlines
|
||||||
(when (cdr headline) ; do not print backlinks if there are none
|
(->> headlines
|
||||||
(insert (format "\n| %s |\n|---|" (db/org--format-link-from-org-id (car headline))))
|
(-mapcat #'(lambda (headline)
|
||||||
(let ((backlink-lines (-> (mapcar #'(lambda (backlink-id)
|
(mapcar #'(lambda (backlink)
|
||||||
(list (db/org--format-link-from-org-id backlink-id)
|
(cons backlink (car headline)))
|
||||||
(org-entry-get (org-id-find backlink-id 'marker)
|
(cdr headline))))
|
||||||
"PRIORITY")))
|
;; Group by backlinks (first entry), returns list of non-empty
|
||||||
(cdr headline))
|
;; lists
|
||||||
(cl-sort #'string< :key #'cl-second))))
|
(-group-by #'car)
|
||||||
(dolist (line backlink-lines)
|
;; Flatten list, to get a list of (backlink-id headline-ids...)
|
||||||
(insert (apply #'format "\n| | %s | %s |" line)))
|
(-map #'(lambda (group)
|
||||||
(insert "\n|---|"))))
|
(cons (car group) (-map #'cdr (cdr group)))))))
|
||||||
|
|
||||||
|
;; Replace IDs by headlines and add priority for sorting
|
||||||
|
(setq output-lines
|
||||||
|
(->> headlines
|
||||||
|
(-map #'(lambda (line)
|
||||||
|
(list (db/org--format-link-from-org-id (cl-first line))
|
||||||
|
(org-entry-get (org-id-find (cl-first line) 'marker)
|
||||||
|
"PRIORITY")
|
||||||
|
(-map #'db/org--format-link-from-org-id (cdr line)))))
|
||||||
|
(-sort #'(lambda (line-1 line-2)
|
||||||
|
(string< (cl-second line-1) (cl-second line-2))))))
|
||||||
|
|
||||||
|
;; Format output-lines as Org table
|
||||||
|
(insert (format "| Backlink | Prio | Backlink Target(s) |\n|---|"))
|
||||||
|
(when output-lines
|
||||||
|
(dolist (line output-lines)
|
||||||
|
(insert (format "\n| %s | %s | %s |"
|
||||||
|
(cl-first line) ; backlink
|
||||||
|
(cl-second line) ; priority
|
||||||
|
(apply #'concat (-interpose ", " (cl-third line))) ; backlink targets
|
||||||
|
)))
|
||||||
|
(insert "\n|---|"))
|
||||||
(org-table-align)))
|
(org-table-align)))
|
||||||
|
|
||||||
(defun db/org-insert-backlink-block ()
|
(defun db/org-insert-backlink-block ()
|
||||||
|
|
Loading…
Reference in New Issue