From 9e138e259aac34a95ffbc0588e9b39aae43df1a7 Mon Sep 17 00:00:00 2001 From: Leo Vivier Date: Sat, 18 Apr 2020 07:10:14 +0200 Subject: [PATCH] (feat) remove user-error for org-roam-insert (#486) * (feat) remove user-error for org-roam-insert Closes #477. * (fix) use absolute path when buffer has no associated file Co-authored-by: Jethro Kuan --- org-roam.el | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/org-roam.el b/org-roam.el index 8490d6f..df0645f 100644 --- a/org-roam.el +++ b/org-roam.el @@ -307,13 +307,16 @@ specified via the #+ROAM_ALIAS property." (defun org-roam--format-link (target &optional description) "Formats an org link for a given file TARGET and link DESCRIPTION." - (let* ((here (-> (or (buffer-base-buffer) - (current-buffer)) - (buffer-file-name) - (file-truename) - (file-name-directory)))) + (let* ((here (ignore-errors + (-> (or (buffer-base-buffer) + (current-buffer)) + (buffer-file-name) + (file-truename) + (file-name-directory))))) (org-link-make-string - (concat "file:" (file-relative-name target here)) + (concat "file:" (if here + (file-relative-name target here) + target)) description))) (defun org-roam-insert (prefix &optional filter-fn) @@ -323,9 +326,6 @@ FILTER-FN is the name of a function to apply on the candidates which takes as its argument an alist of path-completions. See `org-roam--get-title-path-completions' for details." (interactive "P") - (unless (org-roam--org-roam-file-p - (buffer-file-name (buffer-base-buffer))) - (user-error "Not in an Org-roam file")) (let* ((region (and (region-active-p) ;; following may lose active region, so save it (cons (region-beginning) (region-end))))