1
0
Fork 0

Add dynamic block function for backlinks

Use it like so:

    #+BEGIN: oni-backlinks

    #+END
This commit is contained in:
Tom Willemse 2020-09-21 15:32:25 -07:00
parent d3390126d5
commit e652d0f47b

View file

@ -4,7 +4,7 @@
;; Author: Tom Willemse <tom@ryuslash.org> ;; Author: Tom Willemse <tom@ryuslash.org>
;; Keywords: local ;; Keywords: local
;; Version: 2020.0824.155403 ;; Version: 2020.0921.142856
;; Package-Requires: (oni-yasnippet oni-alert oni-hydra org-plus-contrib org-bullets org-edna diminish all-the-icons) ;; Package-Requires: (oni-yasnippet oni-alert oni-hydra org-plus-contrib org-bullets org-edna diminish all-the-icons)
;; This program is free software; you can redistribute it and/or modify ;; This program is free software; you can redistribute it and/or modify
@ -177,6 +177,34 @@ _l_: Store link ^^ _j_: Journal entry
("A" (org-capture nil "a")) ("A" (org-capture nil "a"))
("j" (org-capture nil "j"))) ("j" (org-capture nil "j")))
(defun oni-org-in-dblock-p ()
"Non-nil when point belongs to a dynamic block."
(save-match-data
(let ((case-fold-search t)
(lim-up (save-excursion (outline-previous-heading)))
(lim-down (save-excursion (outline-next-heading))))
(org-between-regexps-p
"^[ \t]*#\\+begin"
"^[ \t]*#\\+end"
lim-up lim-down))))
(defun oni-org-dblock-write-backlinks (_params)
"Generate backlinks to org headings."
(let ((current-heading (nth 4 (org-heading-components)))
backlinks)
(save-excursion
(goto-char (point-min))
(while (re-search-forward (rx-to-string `(and "*" ,current-heading "]")) nil t)
(unless (oni-org-in-dblock-p)
(push (nth 4 (org-heading-components)) backlinks))))
(insert (string-join
(mapcar (lambda (link)
(concat "- [[*" link "][" link "]]"))
(sort backlinks #'string<))
"\n"))))
(defalias 'org-dblock-write:oni-backlinks 'oni-org-dblock-write-backlinks)
(setq org-agenda-tags-todo-honor-ignore-options t) (setq org-agenda-tags-todo-honor-ignore-options t)
(setq org-agenda-todo-ignore-scheduled 'future) (setq org-agenda-todo-ignore-scheduled 'future)
(setq org-catch-invisible-edits 'error) (setq org-catch-invisible-edits 'error)