Fix org-roam-insert inserting absolute paths (#71)

Fixes #70
This commit is contained in:
Jethro Kuan
2020-02-13 16:04:41 +08:00
committed by GitHub
parent 270995b2d4
commit e00538f909

View File

@ -233,8 +233,6 @@ If not provided, derive the title from the file name."
(defun org-roam--make-file (file-path &optional title) (defun org-roam--make-file (file-path &optional title)
"Create an org-roam file at FILE-PATH, optionally setting the TITLE attribute." "Create an org-roam file at FILE-PATH, optionally setting the TITLE attribute."
(unless (string= "org" (file-name-extension file-path))
(setq file-path (concat file-path ".org")))
(if (file-exists-p file-path) (if (file-exists-p file-path)
(error (format "Aborting, file already exists at %s" file-path)) (error (format "Aborting, file already exists at %s" file-path))
(if org-roam-autopopulate-title (if org-roam-autopopulate-title
@ -279,12 +277,12 @@ Optionally pass it the title, for a smart file name."
file)) file))
(org-roam--find-all-files))) (org-roam--find-all-files)))
(title (completing-read "File: " completions)) (title (completing-read "File: " completions))
(file-path (or (cadr (assoc title completions)) (absolute-file-path (or (cadr (assoc title completions))
(org-roam--get-new-id title)))) (org-roam--get-file-path (org-roam--get-new-id title) t))))
(unless (file-exists-p file-path) (unless (file-exists-p absolute-file-path)
(org-roam--make-file file-path title)) (org-roam--make-file absolute-file-path title))
(insert (format "[[%s][%s]]" (insert (format "[[%s][%s]]"
(concat "file:" file-path) (concat "file:" (file-relative-name absolute-file-path org-roam-directory))
(format org-roam-link-title-format title))))) (format org-roam-link-title-format title)))))
;;; Finding org-roam files ;;; Finding org-roam files
@ -295,12 +293,12 @@ Optionally pass it the title, for a smart file name."
(list (org-roam--get-title-or-slug file) file)) (list (org-roam--get-title-or-slug file) file))
(org-roam--find-all-files))) (org-roam--find-all-files)))
(title-or-slug (completing-read "File: " completions)) (title-or-slug (completing-read "File: " completions))
(file-path (or (cadr (assoc title-or-slug completions)) (absolute-file-path (or (cadr (assoc title-or-slug completions))
(org-roam--get-file-path (org-roam--get-file-path
(org-roam--get-new-id title-or-slug) t)))) (org-roam--get-new-id title-or-slug) t))))
(unless (file-exists-p file-path) (unless (file-exists-p absolute-file-path)
(org-roam--make-file file-path title-or-slug)) (org-roam--make-file absolute-file-path title-or-slug))
(find-file file-path))) (find-file absolute-file-path)))
;;; Building the org-roam cache (asynchronously) ;;; Building the org-roam cache (asynchronously)
(defun org-roam--build-cache-async () (defun org-roam--build-cache-async ()