(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 () (defun org-roam--extract-ref ()
"Extract the ref from current buffer and return the type and the key of the 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")))))) (pcase (cdr (assoc "ROAM_KEY"
(let* ((type (org-roam--ref-type ref)) (org-roam--extract-global-props '("ROAM_KEY"))))
(key (cond ((string= "cite" type) ('nil nil)
(s-chop-prefix (org-roam--cite-prefix ref) ref)) ((pred string-empty-p)
(t ref)))) (user-error "ROAM_KEY cannot be empty"))
(cons type key)) (ref
nil)) (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) (defun org-roam--ref-type (ref)
"Determine the type of the REF from the prefix." "Determine the type of the REF from the prefix."