(internal): refactor org-roam-find-file logic (#691)

Fail faster in case of nested capture.
Simplify logic for completions.
This commit is contained in:
N V
2020-05-23 17:42:47 -04:00
committed by GitHub
parent 214f9df844
commit a05b1ebcc3

View File

@ -1048,25 +1048,21 @@ 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) (interactive)
(let* ((completions (--> (or completions (when (org-roam-capture--in-process-p) (user-error "Org-roam capture in process"))
(org-roam--get-title-path-completions)) (let* ((completions (funcall (or filter-fn #'identity)
(if filter-fn (or completions (org-roam--get-title-path-completions))))
(funcall filter-fn it)
it)))
(title-with-tags (org-roam-completion--completing-read "File: " completions (title-with-tags (org-roam-completion--completing-read "File: " completions
:initial-input initial-prompt)) :initial-input initial-prompt))
(res (cdr (assoc title-with-tags completions))) (res (cdr (assoc title-with-tags completions)))
(file-path (plist-get res :path))) (file-path (plist-get res :path)))
(if file-path (if file-path
(find-file file-path) (find-file file-path)
(if (org-roam-capture--in-process-p)
(user-error "Org-roam capture in process")
(let ((org-roam-capture--info `((title . ,title-with-tags) (let ((org-roam-capture--info `((title . ,title-with-tags)
(slug . ,(org-roam--title-to-slug title-with-tags)))) (slug . ,(org-roam--title-to-slug title-with-tags))))
(org-roam-capture--context 'title)) (org-roam-capture--context 'title))
(add-hook 'org-capture-after-finalize-hook #'org-roam-capture--find-file-h) (add-hook 'org-capture-after-finalize-hook #'org-roam-capture--find-file-h)
(org-roam--with-template-error 'org-roam-capture-templates (org-roam--with-template-error 'org-roam-capture-templates
(org-roam-capture--capture))))))) (org-roam-capture--capture))))))
;;;###autoload ;;;###autoload
(defun org-roam-find-directory () (defun org-roam-find-directory ()