mirror of
https://github.com/org-roam/org-roam
synced 2025-08-05 12:37:23 -05:00
(feat): add COMPLETIONS argument to insert and find-file (#637)
Needed for smoother interaction with ORB. I’ve elected to keep FILTER-FN for the moment, even though it’s a bit redundant, and the description in the docstring is not correct with the addition of tags.
This commit is contained in:
14
org-roam.el
14
org-roam.el
@ -526,9 +526,11 @@ Examples:
|
|||||||
target))
|
target))
|
||||||
description)))
|
description)))
|
||||||
|
|
||||||
(defun org-roam-insert (&optional lowercase filter-fn description)
|
(defun org-roam-insert (&optional lowercase completions filter-fn description)
|
||||||
"Find an Org-roam file, and insert a relative org link to it at point.
|
"Find an Org-roam file, and insert a relative org link to it at point.
|
||||||
If LOWERCASE, downcase the title before insertion.
|
If LOWERCASE, downcase the title before insertion.
|
||||||
|
COMPLETIONS is a list of completions to be used instead of
|
||||||
|
`org-roam--get-title-path-completions`.
|
||||||
FILTER-FN is the name of a function to apply on the candidates
|
FILTER-FN is the name of a function to apply on the candidates
|
||||||
which takes as its argument an alist of path-completions.
|
which takes as its argument an alist of path-completions.
|
||||||
If DESCRIPTION is provided, use this as the link label. See
|
If DESCRIPTION is provided, use this as the link label. See
|
||||||
@ -540,7 +542,8 @@ If DESCRIPTION is provided, use this as the link label. See
|
|||||||
(region-text (when region
|
(region-text (when region
|
||||||
(buffer-substring-no-properties
|
(buffer-substring-no-properties
|
||||||
(car region) (cdr region))))
|
(car region) (cdr region))))
|
||||||
(completions (--> (org-roam--get-title-path-completions)
|
(completions (--> (or completions
|
||||||
|
(org-roam--get-title-path-completions))
|
||||||
(if filter-fn
|
(if filter-fn
|
||||||
(funcall filter-fn it)
|
(funcall filter-fn it)
|
||||||
it)))
|
it)))
|
||||||
@ -597,14 +600,17 @@ plist containing the path to the file, and the original title."
|
|||||||
(puthash k v ht))))))
|
(puthash k v ht))))))
|
||||||
ht))
|
ht))
|
||||||
|
|
||||||
(defun org-roam-find-file (&optional initial-prompt filter-fn)
|
(defun org-roam-find-file (&optional initial-prompt completions filter-fn)
|
||||||
"Find and open an Org-roam file.
|
"Find and open an Org-roam file.
|
||||||
INITIAL-PROMPT is the initial title prompt.
|
INITIAL-PROMPT is the initial title prompt.
|
||||||
|
COMPLETIONS is a list of completions to be used instead of
|
||||||
|
`org-roam--get-title-path-completions`.
|
||||||
FILTER-FN is the name of a function to apply on the candidates
|
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 (--> (org-roam--get-title-path-completions)
|
(let* ((completions (--> (or completions
|
||||||
|
(org-roam--get-title-path-completions))
|
||||||
(if filter-fn
|
(if filter-fn
|
||||||
(funcall filter-fn it)
|
(funcall filter-fn it)
|
||||||
it)))
|
it)))
|
||||||
|
Reference in New Issue
Block a user