To avoid having to create a wrapper function and silence the byte-
compiler for both when using a pre-rename and post-rename Org, keep
it simple and just depend on Org 9.6.
* (fix)capture: fill-template preserve whitespace content
Preserve the whitespace content given in the capture template, by
caching it and then appending it to the output template. For
Org-capture's purposes, we need to separately ensure that a newline is
present. Adds tests to the various helper functions to illustrate changes.
Addresses #2115
Special care is taken not to move the point if the original point is no
longer the same (i.e. the user moves the cursor after calling the
capture, but before finalizing it). Fixes#2108.
Let's assume we're evaluating the following region:
```elisp
(org-roam-capture-
:node (org-roam-node-create :title "Org Roam Homepage")
:info '(:ref "https://orgroam.com")
:props '(:immediate-finish nil))
```
Prior to this commit, if you did not require "org-roam-protocol" then
`org-roam-capture-` would ignore the `:info '(:ref
"https://orgroam.com")` parameter. Once you required
"org-roam-protocol" then the callback hooks that process `:info`'s
`:ref` will fire regardless of whether it comes from org-roam-protocol.
After this commit, you no longer need to require "org-roam-protocol" to
ensure that you capture an `:info`'s `:ref`.
Why is this useful? When I'm reading through my elfeed RSS feed, I want
to capture an article. I could use the org-roam-protocol to do this,
but that seems a bit unnecessary given that I'm already in Emacs.
Closesorg-roam/org-roam#2078
See also the discussion in #1961. The summary is that if STUFF contained
the same key twice, `org-roam-capture--put' would favor the last setting in
STUFF while normally `plist-get' and `plist-put' use the first key/value pair
of a plist:
(let ((org-capture-plist nil)
(stuff (list :z 26 :z "ignored")))
(apply 'org-roam-capture--put stuff)
(list (plist-get stuff :z)
(org-roam-capture--get :z)))
; old implementation => (26 "ignored")
; new implementation => Lisp error: wrong-number-of-arguments
In elisp, plists are defined as having no duplicate keys, but there are
no (costly?) runtime checks against this happening by accident. OTOH,
`org-roam-capture--put' is only ever called with one key/value pair: we can
afford to restrict its interface to accept only one key/value pair and then
there can never be duplicate keys in its input.
* (fix) Use read-from-minibuffer instead of completing-read where appropriate
* (feat) Add separate node and ref completion histories
Using separate histories has the advantage that the history only contains node
names and no other strings from other unrelated minibuffer completions.
Currently, roam allows file template *nominally*, but, if one tries to set
up, it causes trouble.
`goto` functions, like `org-roam-dailies-goto-*`, tries to expand file
template with `org-roam-format-template`, which assumes template is
string. Hence, complains about it.
This commit suppress such malfunctions by do nothing for non-string template.
This name will better reflect the current purpose of the property. At
the beginning of the v2 it would only trigger for the new nodes (hence
:if-new), but through the development it's no longer the case, though
the behavior various from each type of the target.
As for now, this will be soft deprecated and won't be strictly enforced
at the user.
Previously, if org-roam-capture- would be triggered for an existing node
it would just move the point to the beginning of the node, ignoring the
target from the :if-new part of the template.
This patch will now also run the :if-new part of the template for
existing nodes, just like it does right now in case of daily
templates (which happened to be never recognized as existing nodes
during the capture process).
In adding this parameter, the external facing methods expose another
point of parameterization for the inner org-roam-capture- method.
This is most useful for the org-roam-node-insert method which has a
complicated inner logic; By adding the :info &key parameter, we
reduce the likelyhood of needing to duplicate that inner logic.
Co-authored-by: Jethro Kuan <jethrokuan95@gmail.com>
Detangle the codebase and change how dependencies are resolved to
allow the package to better modularize and load itself without
introducing circular dependencies, especially when autoloads involved.
Redefine a new file to Org-roam's capture system as one that does not
have a buffer visiting it yet. This means that if a buffer is already
visiting the file, then the HEAD template will not be inserted. This is
important because Org-roam capture does not enforce the save of files,
and this can lead to scenarios where the template is inserted multiple
times to a buffer for a file that has not yet been written to disk.
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`
At the current state autoloads from non `org-roam.el` unable to start
loading of the package from their own file. See the following to learn
more about the problem:
https://github.com/org-roam/org-roam/issues/1590#issuecomment-885817825
This is no more than a workaround to bandage a more deeper underlying
problem. Until the more fundamental problem won't be fixed, all autoload
cookies from non "org-roam.el" file will need to manually point to the
main entry point of the package -- "org-roam.el" file, to load it
without causing errors.
Fixes#1590, #1620, #1600 and other similar issues.
The previous fix[0] for capture targets did the right thing. However, it
didn't account that `org-roam-capture--get-point` branches to 3
different paths, where each of them set the point to a different
location, and the fix only addressed the branch in which
`org-roam-capture--goto-location` would run.
This commit adjusts the point for all other branches, which fixes a
problem where you would try to run capture to existing node with
something like `org-roam-capture` and it wouldn't set the point to the
right location; same with ref capturing through the `org-roam-protocol`.
[0]: c9bed390b6
We need to split the ref into its type/file before querying the db for a
match. Throw a warning when `org-roam--capture-new-file` tries to
recreate an existing file.