* (fix):db: pragma foreign keys to work with sqlite3
This commit is follow-up for PR #2009 should fix issues #1927 & #1910.
Currently, `[:pragma (= foreign_keys ON)]` is present only in function
`org-roam-db--init`. This means the `foreign_keys` is turned on only when the db
file is created for the first time. Subsequent Emacs sessions won't turn it on
as the db file is already present and does not evaluate `org-roam-db--init`.
This PRAGMA needs to be turned on each database connection at runtime according
to sqlite's documentation (https://sqlite.org/foreignkeys.html#fk_enable)
```
Foreign key constraints are disabled by default (for backwards compatibility),
so must be enabled separately for each database connection
```
I have observed that on Windows only the Emacs session that initially creates
the Org-roam db file works correctly with the `sqlite3` option. Subsequent Emacs
sessions have the same "Unique constraint failed" error messages.
I have tested this patch on Windows and Ubuntu; both seem to work in the first
and subsequent Emacs sessions.
I am not 100% sure if the location of the PRAGMA is the best; use it as a
proof-of-cocenpt for the fix. Thank you.
* remove: [:pragma (= foreign_keys ON)] from org-roam-db--init
* fix: defconst org-roam--sqlite-available-p outputs error
When `org-roam-database-connector` is not `sqlite`, it outputs an unnecessary
error when Org-roam starts up as `defconst` evaluates
`(emacsql-sqlite-ensure-binary)`.
```
Org-roam initialization: (error "No EmacSQL SQLite binary available, aborting")
```
For other database connectors, this is not relevant.
* chore: rm org-roam--sqlite-available-p
As per our conversation, org-roam--sqlite-available-p not needed.
* docs: Correct how to install gcc on Windows
PATH needs to be manually set on Windows. Previously, it was explicitly
mentioned that it was unnecessary. More recent experience is that it's necessary.
* regenerate texi
Co-authored-by: Jethro Kuan <jethrokuan95@gmail.com>
Previously node caching used org-map-entries: this only mapped over agenda
entries, hence skipping various nodes. Instead, we should be using
org-map-region, which maps over the entire file.
* (docs): fix examples for .dir-locals.el
Two items:
1. The current example does not work; in order to call a function wihtin
`.dir-locals.el`, you should use `eval`.
- [StackExchange](https://emacs.stackexchange.com/questions/21955/calling-functions-in-dir-locals-in-emacs)
- [Working
example buried in an issue](https://github.com/org-roam/org-roam/issues/1527#issuecomment-933674233))
- `(info "(emacs)Directory Variables")`
2. Add clear instruction to use an absolute path to define `org-roam-directory` in
this context (it's buried in this [issue](https://github.com/org-roam/org-roam/issues/1459#issuecomment-817259656).
* (docs)Fix the `eval` example for subdirectories.
Comment: https://github.com/org-roam/org-roam/pull/2002#issuecomment-991830879
The eval form that uses relative path sets the local variable *relative to the
org file*. This means the eval form woudl need to locate the relevant
`.dir-locals` file by traversing the directory tree upwards from the
file (lightly tested to wrok)
Using absolute path (the first example) should be fine without change (not tested)
* update texi
* (docs) minor correction to #2002
Correcting the example of .dir-locals using an absolute path to avoid confusion.
Lightly tested with a real absolute path in my system; works on my end with a
subdir.
Co-authored-by: Jethro Kuan <jethrokuan95@gmail.com>
This commit adds 3 custom variables:
1. org-roam-buffer-postrender-functions
This list of functions are run within the Org-roam buffer after the
Org-roam buffer is rendered. For example, one can produce latex previews
for all content within the Org-roam buffer:
(add-hook
'org-roam-buffer-postrender-functions (lambda () (org--latex-preview-region
(point-min) (point-max))))
2. org-roam-preview-function
This is the function used to extract the content to populate the buffer.
It defaults to `org-roam-preview-default-function`, which extracts all
contents within the headline up to the next headline.
3. org-roam-preview-postprocess-functions
This is a list of functions run to post-process the content retrieved
from org-roam-preview-function. It can be used to strip additional
content from the buffer, or perform sentence-unwrapping.
Emacs commit 3f096eb3405b2fce7c35366eb2dcf025dda55783 introduced
`string-glyph-compose` and `string-glyph-decompose`, autoloading these instead
of the (still existing) `ucs-normalize-NFC-region` and
`ucs-normalize-NFD-region`.
There are three cases:
- Emacs where these transitions have not happened yet (e.g. 27.1):
`ucs-normalize-NFC-region` and `ucs-normalize-NFD-region` are still
autoloaded, aliasing the new names to them will keep them usable
and the code still works.
- Emacs where the new functions are defined (not yet released): the new names
are autoloaded, no aliases are installed and the code still works.
- A (hypothetical?) Emacs where `string-glyph-compose` and
`string-glyph-decompose` are renamed. If `ucs-normalize-NFC-region` and
`ucs-normalize-NFD-region` do not get their autoloaded status back, the
aliasing will happen but the functions not autoloaded and the code will
break in the same way as in #1981
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.
Org-ref v3 introduced a new citation syntax, and removed some functions
that org-roam had previously relied upon (e.g. for extracting keys from
multi-citations).
This commit introduces support on two fronts:
1. Add `org-roam-org-ref-path-to-keys` which converts a link path to a
list of keys. This supports both Org-ref v2 and v3.
2. Adds support for parsing multi-citations in refs.
The old implementation:
- did not handle duplicate keys well (the function would be applied to each value, but only the first value would be updated with the last value's result)
- was quadratic in the length of the input list (for each key, plist-put would search for the first occurrence of the key by going through all previous elements again)
- copied the input sequence even though this was not really needed
- did not provide a result value that could be useful, thus encouraging imperative programming
- did not need to be a macro, and the macro implementation was evaluating fn multiple times and causing warnings in the native compiler because k and v were not bound.
Some commit in Org 9.5 changed the AST structure, so we our previous
preview content logic was borked and started showing the full contents
of the file. To be forward compatible we change the content preview
logic, and extract everything within the section.
Fixes#1934.
Require optional libraries 'org-ref and 'oc only once per function run:
org-roam-db-update-file and org-roam-db-sync will call these requires at
the top level instead of within the link mapper.
Previously org-roam-set-keyword was unable to handle the syntax of the
:LOGBOOK: drawer. We introduce `org-roam-end-of-meta-data` to move point
over all drawers, allowing us to set the keyword in the right place.