remove external dependencies

This commit is contained in:
Jethro Kuan
2020-01-22 19:45:42 +08:00
parent 3c57caf1ea
commit b173b0e12a

View File

@ -1,6 +1,4 @@
(require 'deft) (require 'deft)
(require 'dash)
(require 'ht)
(require 'async) (require 'async)
(defgroup org-roam nil (defgroup org-roam nil
@ -87,13 +85,13 @@ Valid states are 'visible, 'exists and 'none."
(defun org-roam-add-backlink (hash link_a link_b) (defun org-roam-add-backlink (hash link_a link_b)
"Adds a backlink link_a <- link_b to hash table `hash'." "Adds a backlink link_a <- link_b to hash table `hash'."
(let* ((item (ht-get hash link_a)) (let* ((item (gethash link_a hash))
(updated (if item (updated (if item
(if (member link_b item) (if (member link_b item)
item item
(cons link_b item)) (cons link_b item))
(list link_b)))) (list link_b))))
(ht-set! hash link_a updated))) (puthash link_a updated hash)))
(defun org-roam-build-backlinks () (defun org-roam-build-backlinks ()
"Builds the backlink hash table, saving it into `org-roam-hash-backlinks'." "Builds the backlink hash table, saving it into `org-roam-hash-backlinks'."
@ -133,7 +131,7 @@ 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))) (let ((backlinks (make-hash-table :test #'equal)))
(mapcar (lambda (file) (mapcar (lambda (file)
(with-temp-buffer (with-temp-buffer
(insert-file-contents file) (insert-file-contents file)
@ -182,7 +180,7 @@ Valid states are 'visible, 'exists and 'none."
(defun org-roam-update (file) (defun org-roam-update (file)
"Show the backlinks for the current org-buffer." "Show the backlinks for the current org-buffer."
(unless (string= org-roam-current-file file) (unless (string= org-roam-current-file file)
(let ((backlinks (ht-get org-roam-hash-backlinks file))) (let ((backlinks (gethash file org-roam-hash-backlinks)))
(with-current-buffer org-roam-buffer (with-current-buffer org-roam-buffer
(read-only-mode -1) (read-only-mode -1)
(erase-buffer) (erase-buffer)
@ -190,9 +188,9 @@ Valid states are 'visible, 'exists and 'none."
(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 (format "Backlinks for %s:\n\n" file)) (insert (format "Backlinks for %s:\n\n" file))
(-map (lambda (link) (mapcar (lambda (link)
(insert (format "- [[file:%s][%s]]\n" (expand-file-name link deft-directory) link)) (insert (format "- [[file:%s][%s]]\n" (expand-file-name link org-roam-directory) link))
) backlinks) ) backlinks)
(read-only-mode +1)))) (read-only-mode +1))))
(setq org-roam-current-file file)) (setq org-roam-current-file file))
@ -216,8 +214,9 @@ Valid states are 'visible, 'exists and 'none."
(defun org-roam-setup-buffer () (defun org-roam-setup-buffer ()
"Sets up the org-roam buffer at the side." "Sets up the org-roam buffer at the side."
(-> (get-buffer-create org-roam-buffer) (display-buffer-in-side-window
(display-buffer-in-side-window `((side . ,org-roam-position))))) (get-buffer-create org-roam-buffer)
`((side . ,org-roam-position))))
(defun org-roam-update-buffer () (defun org-roam-update-buffer ()
(interactive) (interactive)