(fix): do not store empty-string refs in db (#586)

* (fix): do not store empty-string refs in db

* Error when ROAM_KEY is empty

* Handle nil

Co-authored-by: Jethro Kuan <jethrokuan95@gmail.com>
This commit is contained in:
Leo Vivier
2020-05-09 13:47:56 +02:00
committed by GitHub
parent 46fd2a9a68
commit dee540b62f

View File

@ -382,13 +382,17 @@ current buffer is used."
(defun org-roam--extract-ref ()
"Extract the ref from current buffer and return the type and the key of the ref."
(if-let ((ref (cdr (assoc "ROAM_KEY" (org-roam--extract-global-props '("ROAM_KEY"))))))
(let* ((type (org-roam--ref-type ref))
(key (cond ((string= "cite" type)
(s-chop-prefix (org-roam--cite-prefix ref) ref))
(t ref))))
(cons type key))
nil))
(pcase (cdr (assoc "ROAM_KEY"
(org-roam--extract-global-props '("ROAM_KEY"))))
('nil nil)
((pred string-empty-p)
(user-error "ROAM_KEY cannot be empty"))
(ref
(let* ((type (org-roam--ref-type ref))
(key (cond ((string= "cite" type)
(s-chop-prefix (org-roam--cite-prefix ref) ref))
(t ref))))
(cons type key)))))
(defun org-roam--ref-type (ref)
"Determine the type of the REF from the prefix."