(feat): add filter-fn and templates to interactive commands (#1693)

The rationale for this change is to allow context-specific capture
consideration.  That is to say, in my experience, when I'm working on a
project, I often want to scope my note finding and creation to that
project.  By adding `filter-fn` and `templates` I can easily craft
context-aware functions for my note-taking.

I chose to switch these to `cl-defun` to expose `&key` parameters, which I
find more useful as the method signature grows.

Closes #1681

From the Github Issue:

> Adding a `filter-fn` parameter to `org-roam-capture` and a `templates`
> parameter to `org-roam-capture` , `org-roam-node-insert`,
> `org-roam-node-find` would improve their general utility, and reduce
> fiddling with the more inner functionality of `org-roam-capture-` and
> `org-roam-node-read`
This commit is contained in:
Jeremy Friesen
2021-07-27 14:16:00 -04:00
committed by GitHub
parent 33ed817826
commit e31ac73a4d
2 changed files with 18 additions and 7 deletions

View File

@ -807,14 +807,19 @@ TEMPLATES is a list of org-roam templates."
(org-capture goto keys)))
;;;###autoload (autoload 'org-roam-capture "org-roam" nil t)
(defun org-roam-capture (&optional goto keys)
(cl-defun org-roam-capture (&optional goto keys &key filter-fn templates)
"Launches an `org-capture' process for a new or existing note.
This uses the templates defined at `org-roam-capture-templates'.
Arguments GOTO and KEYS see `org-capture'."
Arguments GOTO and KEYS see `org-capture'.
FILTER-FN is a function to filter out nodes: it takes an `org-roam-node',
and when nil is returned the node will be filtered out.
The TEMPLATES, if provided, override the list of capture templates (see
`org-roam-capture-'.)"
(interactive "P")
(let ((node (org-roam-node-read)))
(let ((node (org-roam-node-read nil filter-fn)))
(org-roam-capture- :goto goto
:keys keys
:templates templates
:node node
:props '(:immediate-finish nil))))