prevent update when no backlinks

This commit is contained in:
Jethro Kuan
2020-02-03 01:06:23 +08:00
parent 4ab3c7d314
commit f968529b8d

View File

@ -170,22 +170,23 @@ Valid states are 'visible, 'exists and 'none."
(defun org-roam-update (file) (defun org-roam-update (file)
"Show the backlinks for given org file `FILE'." "Show the backlinks for given org file `FILE'."
(unless (string= org-roam-current-file file) (unless (string= org-roam-current-file file)
(let ((backlinks (gethash file org-roam-hash-backlinks))) (when org-roam-hash-backlinks
(with-current-buffer org-roam-buffer (let ((backlinks (gethash file org-roam-hash-backlinks)))
(read-only-mode -1) (with-current-buffer org-roam-buffer
(erase-buffer) (read-only-mode -1)
(org-mode) (erase-buffer)
(make-local-variable 'org-return-follows-link) (org-mode)
(setq org-return-follows-link t) (make-local-variable 'org-return-follows-link)
(insert (format "Backlinks for %s:\n\n" file)) (setq org-return-follows-link t)
(when backlinks (insert (format "Backlinks for %s:\n\n" file))
(maphash (lambda (link contents) (when backlinks
(insert (format "* [[file:%s][%s]]\n" (expand-file-name link org-roam-directory) link)) (maphash (lambda (link contents)
(dolist (content contents) (insert (format "* [[file:%s][%s]]\n" (expand-file-name link org-roam-directory) link))
(insert (format "\n\n%s\n\n" content)))) (dolist (content contents)
backlinks)) (insert (format "\n\n%s\n\n" content))))
(read-only-mode +1)))) backlinks))
(setq org-roam-current-file file)) (read-only-mode +1)))
(setq org-roam-current-file file))))
(defun org-roam () (defun org-roam ()
"Initialize `org-roam'. "Initialize `org-roam'.