mirror of
https://github.com/org-roam/org-roam
synced 2025-08-03 12:27:23 -05:00
small refactor
This commit is contained in:
27
org-roam.el
27
org-roam.el
@ -108,10 +108,20 @@ Valid states are 'visible, 'exists and 'none."
|
|||||||
(require 'org)
|
(require 'org)
|
||||||
(require 'org-element)
|
(require 'org-element)
|
||||||
,(async-inject-variables "org-roam-")
|
,(async-inject-variables "org-roam-")
|
||||||
(let ((backlinks (make-hash-table :test #'equal)))
|
(let ((backlinks (make-hash-table :test #'equal))
|
||||||
(mapcar (lambda (file)
|
(org-roam-parse-content (lambda (file)
|
||||||
(with-temp-buffer
|
(with-temp-buffer
|
||||||
(insert-file-contents file)
|
(insert-file-contents file)
|
||||||
|
(with-current-buffer (current-buffer)
|
||||||
|
(org-element-map (org-element-parse-buffer) 'link
|
||||||
|
(lambda (link)
|
||||||
|
(let ((type (org-element-property :type link))
|
||||||
|
(path (org-element-property :path link)))
|
||||||
|
(when (and (string= type "file")
|
||||||
|
(string= (file-name-extension path) "org"))
|
||||||
|
path)))))))))
|
||||||
|
(mapcar (lambda (file)
|
||||||
|
(let (paths (org-roam-parse-content file))
|
||||||
(mapcar (lambda (link)
|
(mapcar (lambda (link)
|
||||||
(let* ((item (gethash link backlinks))
|
(let* ((item (gethash link backlinks))
|
||||||
(updated (if item
|
(updated (if item
|
||||||
@ -123,14 +133,7 @@ Valid states are 'visible, 'exists and 'none."
|
|||||||
(list (file-name-nondirectory
|
(list (file-name-nondirectory
|
||||||
file)))))
|
file)))))
|
||||||
(puthash link updated backlinks)))
|
(puthash link updated backlinks)))
|
||||||
(with-current-buffer (current-buffer)
|
paths)))
|
||||||
(org-element-map (org-element-parse-buffer) 'link
|
|
||||||
(lambda (link)
|
|
||||||
(let ((type (org-element-property :type link))
|
|
||||||
(path (org-element-property :path link)))
|
|
||||||
(when (and (string= type "file")
|
|
||||||
(string= (file-name-extension path) "org"))
|
|
||||||
path))))))))
|
|
||||||
org-roam-files)
|
org-roam-files)
|
||||||
(prin1-to-string backlinks)))
|
(prin1-to-string backlinks)))
|
||||||
(lambda (backlinks)
|
(lambda (backlinks)
|
||||||
@ -206,10 +209,12 @@ This needs to be quick/infrequent, because this is run at
|
|||||||
that are amongst deft files, and `org-roam' not already
|
that are amongst deft files, and `org-roam' not already
|
||||||
displaying information for the correct file."
|
displaying information for the correct file."
|
||||||
(interactive)
|
(interactive)
|
||||||
|
(while-no-input
|
||||||
|
(redisplay)
|
||||||
(when (and (eq major-mode 'org-mode)
|
(when (and (eq major-mode 'org-mode)
|
||||||
(not (string= org-roam-current-file (buffer-file-name (current-buffer))))
|
(not (string= org-roam-current-file (buffer-file-name (current-buffer))))
|
||||||
(member (buffer-file-name (current-buffer)) (deft-find-all-files)))
|
(member (buffer-file-name (current-buffer)) (deft-find-all-files)))
|
||||||
(org-roam-update (file-name-nondirectory (buffer-file-name (current-buffer))))))
|
(org-roam-update (file-name-nondirectory (buffer-file-name (current-buffer)))))))
|
||||||
|
|
||||||
(provide 'org-roam)
|
(provide 'org-roam)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user