allow point 0 headings

Check if outline level is 0 at point-min before inserting file-level
info. Fixes #1475
This commit is contained in:
Jethro Kuan
2021-04-17 16:09:59 +08:00
parent f43b24a5bf
commit 597d3c6241

View File

@ -266,53 +266,54 @@ If UPDATE-P is non-nil, first remove the file in the database."
(defun org-roam-db-insert-file-node () (defun org-roam-db-insert-file-node ()
"Insert the file-level node into the Org-roam cache." "Insert the file-level node into the Org-roam cache."
(org-with-point-at 1 (org-with-point-at 1
(when-let ((id (org-id-get))) (when (= (org-outline-level) 0)
(let* ((file (buffer-file-name (buffer-base-buffer))) (when-let ((id (org-id-get)))
(title (or (cadr (assoc "TITLE" (org-collect-keywords '("title")) (let* ((file (buffer-file-name (buffer-base-buffer)))
#'string-equal)) (title (or (cadr (assoc "TITLE" (org-collect-keywords '("title"))
(file-relative-name file org-roam-directory))) #'string-equal))
(pos (point)) (file-relative-name file org-roam-directory)))
(todo nil) (pos (point))
(priority nil) (todo nil)
(scheduled nil) (priority nil)
(deadline nil) (scheduled nil)
(level 0) (deadline nil)
(aliases (org-entry-get (point) "ROAM_ALIASES")) (level 0)
(tags org-file-tags) (aliases (org-entry-get (point) "ROAM_ALIASES"))
(refs (org-entry-get (point) "ROAM_REFS"))) (tags org-file-tags)
(org-roam-db-query (refs (org-entry-get (point) "ROAM_REFS")))
[:insert :into nodes
:values $v1]
(vector id file level pos todo priority
scheduled deadline title))
(when tags
(org-roam-db-query (org-roam-db-query
[:insert :into tags [:insert :into nodes
:values $v1] :values $v1]
(mapcar (lambda (tag) (vector id file level pos todo priority
(vector file id (substring-no-properties tag))) scheduled deadline title))
tags))) (when tags
(when aliases (org-roam-db-query
(org-roam-db-query [:insert :into tags
[:insert :into aliases :values $v1]
:values $v1] (mapcar (lambda (tag)
(mapcar (lambda (alias) (vector file id (substring-no-properties tag)))
(vector file id alias)) tags)))
(split-string-and-unquote aliases)))) (when aliases
(when refs (org-roam-db-query
(setq refs (split-string-and-unquote refs)) [:insert :into aliases
(let (rows) :values $v1]
(dolist (ref refs) (mapcar (lambda (alias)
(if (string-match org-link-plain-re ref) (vector file id alias))
(progn (split-string-and-unquote aliases))))
(push (vector file id (match-string 2 ref) (match-string 1 ref)) rows)) (when refs
(lwarn '(org-roam) :warning (setq refs (split-string-and-unquote refs))
"%s:%s\tInvalid ref %s, skipping..." (buffer-file-name) (point) ref))) (let (rows)
(when rows (dolist (ref refs)
(org-roam-db-query (if (string-match org-link-plain-re ref)
[:insert :into refs (progn
:values $v1] (push (vector file id (match-string 2 ref) (match-string 1 ref)) rows))
rows)))))))) (lwarn '(org-roam) :warning
"%s:%s\tInvalid ref %s, skipping..." (buffer-file-name) (point) ref)))
(when rows
(org-roam-db-query
[:insert :into refs
:values $v1]
rows)))))))))
(defun org-roam-db-insert-node-data () (defun org-roam-db-insert-node-data ()
"Insert node data for headline at point into the Org-roam cache." "Insert node data for headline at point into the Org-roam cache."