From d05d86756935ef706de531bbf140d519b1805070 Mon Sep 17 00:00:00 2001 From: Noboru Ota Date: Sat, 13 Jan 2024 14:58:56 +0100 Subject: [PATCH] =?UTF-8?q?fix:=20error=20"rx=20=E2=80=98**=E2=80=99=20ran?= =?UTF-8?q?ge=20error"=20(#80,#81)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The error occurs when the markdown file contains a code blog with an org syntax such as this below: ```org #+title: Org title ``` Before this change, md-roam used function `org-roam-db-insert-file' to insert a new markdown file. This function tries to get the title of the file with function `org-roam-db--file-title' and it calls `org-collect-keywords'. Somewhere down this chain, the error gets raised because the buffer is not a org buffer (and rest of the buffer is written in the markdown syntax). --- md-roam.el | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/md-roam.el b/md-roam.el index 1b93803..bc6c425 100644 --- a/md-roam.el +++ b/md-roam.el @@ -318,12 +318,27 @@ Requied for wiki link capture." (emacsql-with-transaction (org-roam-db) (save-excursion (org-roam-db-clear-file) - (org-roam-db-insert-file) + (md-roam-db-insert-file) (md-roam-db-insert-file-node) (md-roam-db-insert-wiki-links) (md-roam-db-insert-citations) (md-roam-db-insert-links)))) +(defun md-roam-db-insert-file (&optional hash) + "Update the files table for the current buffer. +If UPDATE-P is non-nil, first remove the file in the database. +If HASH is non-nil, use that as the file's hash without recalculating it." + (let* ((file (buffer-file-name)) + (file-title (or (md-roam-get-title) (file-name-base file))) + (attr (file-attributes file)) + (atime (file-attribute-access-time attr)) + (mtime (file-attribute-modification-time attr)) + (hash (or hash (org-roam-db--file-hash file)))) + (org-roam-db-query + [:insert :into files + :values $v1] + (list (vector file file-title hash atime mtime))))) + (defun md-roam-db-insert-file-node () "Insert the file-level node into the Org-roam cache." ;; `org-roam-db-update-file' turns the mode to org-mode (in `org-roam-with-file' macro)