Skip to content

Commit

Permalink
(feat)db: include self in outline (org-roam#1756)
Browse files Browse the repository at this point in the history
Include the current headline in outline extraction for links, so the
org-roam-buffer contains this information as well.
  • Loading branch information
jethrokuan authored Aug 9, 2021
1 parent 1f853ad commit eb1d420
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions org-roam-db.el
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
;;
;;; Code:
(require 'org-roam)
(defvar org-outline-path-cache)

;;; Options
(defcustom org-roam-db-location (expand-file-name "org-roam.db" user-emacs-directory)
Expand Down Expand Up @@ -312,7 +313,7 @@ If UPDATE-P is non-nil, first remove the file in the database."
(tags org-file-tags)
(refs (org-entry-get (point) "ROAM_REFS"))
(properties (org-entry-properties))
(olp (org-get-outline-path)))
(olp nil))
(org-roam-db-query!
(lambda (err)
(lwarn 'org-roam :warning "%s for %s (%s) in %s"
Expand Down Expand Up @@ -371,7 +372,7 @@ If UPDATE-P is non-nil, first remove the file in the database."
(1+ (- (point) (line-beginning-position))))
(cl-return-from org-roam-db-insert-node-data))))
(properties (org-entry-properties))
(olp (org-get-outline-path))
(olp (org-get-outline-path nil 'use-cache))
(title (org-link-display-format title)))
(org-roam-db-query!
(lambda (err)
Expand Down Expand Up @@ -425,7 +426,10 @@ If UPDATE-P is non-nil, first remove the file in the database."
(goto-char (org-element-property :begin link))
(let ((type (org-element-property :type link))
(path (org-element-property :path link))
(properties (list :outline (org-get-outline-path)))
(properties (list :outline (condition-case nil
;; This can error if link is not under any headline
(org-get-outline-path 'with-self 'use-cache)
(t nil))))
(source (org-roam-id-at-point)))
;; For Org-ref links, we need to split the path into the cite keys
(when (and (boundp 'org-ref-cite-types)
Expand Down Expand Up @@ -514,11 +518,13 @@ If the file exists, update the cache with information."
(org-roam-db-clear-file)
(org-roam-db-insert-file)
(org-roam-db-insert-file-node)
(setq org-outline-path-cache nil)
(org-roam-db-map-nodes
(list #'org-roam-db-insert-node-data
#'org-roam-db-insert-aliases
#'org-roam-db-insert-tags
#'org-roam-db-insert-refs))
(setq org-outline-path-cache nil)
(org-roam-db-map-links
(list #'org-roam-db-insert-link)))))))

Expand Down

0 comments on commit eb1d420

Please sign in to comment.