mirror of
https://github.com/org-roam/org-roam
synced 2025-08-27 14:23:32 -05:00
(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 <jethrokuan95@gmail.com>
This commit is contained in:
18
org-roam.el
18
org-roam.el
@@ -307,13 +307,16 @@ specified via the #+ROAM_ALIAS property."
|
|||||||
|
|
||||||
(defun org-roam--format-link (target &optional description)
|
(defun org-roam--format-link (target &optional description)
|
||||||
"Formats an org link for a given file TARGET and link DESCRIPTION."
|
"Formats an org link for a given file TARGET and link DESCRIPTION."
|
||||||
(let* ((here (-> (or (buffer-base-buffer)
|
(let* ((here (ignore-errors
|
||||||
(current-buffer))
|
(-> (or (buffer-base-buffer)
|
||||||
(buffer-file-name)
|
(current-buffer))
|
||||||
(file-truename)
|
(buffer-file-name)
|
||||||
(file-name-directory))))
|
(file-truename)
|
||||||
|
(file-name-directory)))))
|
||||||
(org-link-make-string
|
(org-link-make-string
|
||||||
(concat "file:" (file-relative-name target here))
|
(concat "file:" (if here
|
||||||
|
(file-relative-name target here)
|
||||||
|
target))
|
||||||
description)))
|
description)))
|
||||||
|
|
||||||
(defun org-roam-insert (prefix &optional filter-fn)
|
(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
|
which takes as its argument an alist of path-completions. See
|
||||||
`org-roam--get-title-path-completions' for details."
|
`org-roam--get-title-path-completions' for details."
|
||||||
(interactive "P")
|
(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)
|
(let* ((region (and (region-active-p)
|
||||||
;; following may lose active region, so save it
|
;; following may lose active region, so save it
|
||||||
(cons (region-beginning) (region-end))))
|
(cons (region-beginning) (region-end))))
|
||||||
|
Reference in New Issue
Block a user