mirror of
https://github.com/org-roam/org-roam
synced 2025-09-14 15:46:48 -05:00
Merge pull request #45 from jethrokuan/fix/check-cache
Add org-roam--ensure-cache-built
This commit is contained in:
61
org-roam.el
61
org-roam.el
@@ -99,6 +99,12 @@ If called interactively, then PARENTS is non-nil."
|
|||||||
"Currently displayed file in `org-roam' buffer.")
|
"Currently displayed file in `org-roam' buffer.")
|
||||||
|
|
||||||
;;; Utilities
|
;;; Utilities
|
||||||
|
(defun org-roam--ensure-cache-built ()
|
||||||
|
"Ensures that org-roam cache is built."
|
||||||
|
(unless org-roam-cache
|
||||||
|
(org-roam--build-cache-async)
|
||||||
|
(user-error "Your Org-Roam cache isn't built yet! Please wait")))
|
||||||
|
|
||||||
(defun org-roam--org-roam-file-p ()
|
(defun org-roam--org-roam-file-p ()
|
||||||
"Return t if file is part of org-roam system, false otherwise."
|
"Return t if file is part of org-roam system, false otherwise."
|
||||||
(and (buffer-file-name (current-buffer))
|
(and (buffer-file-name (current-buffer))
|
||||||
@@ -460,33 +466,33 @@ This is equivalent to removing the node from the graph."
|
|||||||
|
|
||||||
(defun org-roam-update (file-path)
|
(defun org-roam-update (file-path)
|
||||||
"Show the backlinks for given org file for file at `FILE-PATH'."
|
"Show the backlinks for given org file for file at `FILE-PATH'."
|
||||||
(when org-roam-cache
|
(org-roam--ensure-cache-built)
|
||||||
(let ((buffer-title (org-roam--get-title-or-id file-path)))
|
(let ((buffer-title (org-roam--get-title-or-id file-path)))
|
||||||
(with-current-buffer org-roam-buffer
|
(with-current-buffer org-roam-buffer
|
||||||
(let ((inhibit-read-only t))
|
(let ((inhibit-read-only t))
|
||||||
(erase-buffer)
|
(erase-buffer)
|
||||||
(when (not (eq major-mode 'org-mode))
|
(when (not (eq major-mode 'org-mode))
|
||||||
(org-mode))
|
(org-mode))
|
||||||
(make-local-variable 'org-return-follows-link)
|
(make-local-variable 'org-return-follows-link)
|
||||||
(setq org-return-follows-link t)
|
(setq org-return-follows-link t)
|
||||||
(insert
|
(insert
|
||||||
(propertize buffer-title 'font-lock-face 'org-document-title))
|
(propertize buffer-title 'font-lock-face 'org-document-title))
|
||||||
(if-let ((backlinks (gethash file-path (plist-get org-roam-cache :backward))))
|
(if-let ((backlinks (gethash file-path (plist-get org-roam-cache :backward))))
|
||||||
(progn
|
(progn
|
||||||
(insert (format "\n\n* %d Backlinks\n"
|
(insert (format "\n\n* %d Backlinks\n"
|
||||||
(hash-table-count backlinks)))
|
(hash-table-count backlinks)))
|
||||||
(maphash (lambda (file-from contents)
|
(maphash (lambda (file-from contents)
|
||||||
(insert (format "** [[file:%s][%s]]\n"
|
(insert (format "** [[file:%s][%s]]\n"
|
||||||
file-from
|
file-from
|
||||||
(org-roam--get-title-or-id file-from)))
|
(org-roam--get-title-or-id file-from)))
|
||||||
(dolist (content contents)
|
(dolist (content contents)
|
||||||
(insert (concat (propertize (s-trim (s-replace "\n" " " content))
|
(insert (concat (propertize (s-trim (s-replace "\n" " " content))
|
||||||
'font-lock-face 'org-block)
|
'font-lock-face 'org-block)
|
||||||
"\n\n"))))
|
"\n\n"))))
|
||||||
backlinks))
|
backlinks))
|
||||||
(insert "\n\n* No backlinks!")))
|
(insert "\n\n* No backlinks!")))
|
||||||
(read-only-mode 1)))
|
(read-only-mode 1)))
|
||||||
(setq org-roam-current-file file-path)))
|
(setq org-roam-current-file file-path))
|
||||||
|
|
||||||
;;; Show/hide the org-roam buffer
|
;;; Show/hide the org-roam buffer
|
||||||
(define-inline org-roam--current-visibility ()
|
(define-inline org-roam--current-visibility ()
|
||||||
@@ -575,6 +581,7 @@ This needs to be quick/infrequent, because this is run at
|
|||||||
;;; Building the Graphviz graph
|
;;; Building the Graphviz graph
|
||||||
(defun org-roam-build-graph ()
|
(defun org-roam-build-graph ()
|
||||||
"Build graphviz graph output."
|
"Build graphviz graph output."
|
||||||
|
(org-roam--ensure-cache-built)
|
||||||
(let ((forward-links (plist-get org-roam-cache :forward)))
|
(let ((forward-links (plist-get org-roam-cache :forward)))
|
||||||
(with-temp-buffer
|
(with-temp-buffer
|
||||||
(insert "digraph {\n")
|
(insert "digraph {\n")
|
||||||
|
Reference in New Issue
Block a user