diff --git a/oni-org/oni-org.el b/oni-org/oni-org.el index 28cd58b..af80bfd 100644 --- a/oni-org/oni-org.el +++ b/oni-org/oni-org.el @@ -4,7 +4,7 @@ ;; Author: Tom Willemse ;; 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) ;; 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")) ("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-todo-ignore-scheduled 'future) (setq org-catch-invisible-edits 'error)