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.
Previously we had set `org-capture-link-is-already-stored` to `t` in
org-roam captures, because org-roam-protocol stores links. This
prevented regular captures from utilizing the %a element in the
templates.
Instead, only set `org-capture-link-is-already-stored` in the
org-roam-protocol capture command.
Fixes#1341.
* (feat): Temporarily store link when capturing with ORP
* org-roam-protocol.el (org-roam-protocol-open-ref): Replicate default
`org-protocol' behaviour temporarily for storing links
* org-roam-capture.el (org-roam-capture--capture): Prevent stored link from
being reset
When capturing a web-page with org-roam-protocol, a link is now temporarily
stored in `org-store-link-plist' via `org-link-store-props'. This is to allow
the forwarding of properties to `org-capture', one of them being `:initial'
which contains the content of the selected text in the browser.
* (feat): Add toggle for storing link when capturing with ORP
* org-roam-protocol.el (org-roam-protocol-store-links): Add new toggle
(org-roam-protocol-open-ref): Conditionally store link for later used
Building up on b2ee5f2c68, the user can now
decide whether to store links when capturing with org-roam-protocol (default
nil).
* Update changelog
Additionally cache IDs at outline-level 0, now that property drawers are supported in Org 9.4.
Update org-roam--format-link to prefer ID links wherever possible. That is, when a file has an ID, use an id link instead of file link.
This PR enables the long-awaited nested-captures.
1. Adds a hook to org-capture-prepare-finalize-hook, which installs org-roam-capture--finalize into org-capture-after-finalize-hook if the capture is an Org-roam capture. This function contains key functionality for Org-roam to Do The Right Thing after specific interactive functions, such as finding the file, or inserting a link.
2. A patch for org-capture-finalize. Specifically, we make org-capture-plist valid during org-capture-finalize.
3. Many hacks that were originally in place are now replaced with nicer alternatives.
Co-authored-by: Leo Vivier <zaephon@gmail.com>
* (feat): Add customize settings to `org-roam-capture-templates`
Declare `org-roam-capture-templates` with `defcustom` and update the
docstring.
Co-authored-by: Leo Vivier <leo.vivier+dev@gmail.com>
New option: `org-roam-capture-function`
Specifies which command is used by org-roam to run the org-capture
process. The default behaviour maintains compatibility with earlier
versions of org-roam. I.E.:
- uses `org-capture`.
- immeadiately chooses the first capture template when
`org-roam-capture-templates` has only one template.
When you've changed `org-roam-capture-function` AND
`org-roam-capture-templates` has multiple templates,
`org-roam-capture-function` is run interactively to
start the org capture process.
Eg. usage: `(setq org-roam-capture-function 'counsel-org-capture)`