One example of an edge case:
- If a file has LF line endings,
- and is situated in a repository where .editorconfig asks for
CRLF,
(Such repositories exist, for example
<https://github.com/obsidianmd/obsidian-docs/>.)
- and editorconfig-mode is enabled,
org-roam-db--file-hash would then return different results depending
on whether the file path is passed to it or not.
While this is a contrived edge case, there may be other cases like
this where the data from insert-file-contents-literally and the data
from find-file-noselect makes secure-hash return different values.
This commit removes the branch in org-roam-db--file-hash to compute
the hash based on buffer content, instead making it always require a
file path.
(This commit also allows org-roam-db-insert-file to take an optional
HASH argument, allowing it to avoid recalculating the hash.)
Since now we always compute the hash with the file on disk, the
special case for encrypted files is no longer needed.
This should have no impact on whether db is synchronized. The only
case when db--file-hash uses the "calculate in current buffer" path is
in db-insert-file; the only use of db-insert-file is in
db-update-file, which already calls db--file-hash with the file path,
and does not rely on the value from the current buffer.
When trying to save from a narrowed buffer, only the Roam nodes visible
in the narrowed buffer are written to the database.
This commit ensures that org-roam behaves the same whether the current
buffer is narrowed or not.
org-roam-node-at-point returned the wrong value if point-min is a
level-1 heading node. We make sure that everytime we go up one
heading, the outline-level changes (reduces by 1) to prevent this error.
* Fix undefined incf.
Calling org-roam-extract-subtree failes with "Symbol’s function definition is void: incf"
org-roam.el includes cl-lib. org-roam--h1-count uses a bare incf call, which is undefined. Fix this by using cl-incf.
* Save buffer before promoting it.
After fixing incf in 8ec2e59e67, org-roam-extract-subtree still fails.
The error is now: org-roam-db--file-hash: Opening input file: No such file or directory,...
The buffer with the newly created content is still unsaved at this time, so save it before calling (org-roam-promote-entire-buffer)
Caveat is we now save the buffer two times, before and after promoting it.
Previously we only updated the database on file save, but we need to
update the file's atime on file access, so we hook into `find-file-hook`
to do so. We only update the file atime if the file exists in the file table.
* (fix) org-roam-file-p handle opening a buffer with no path
Found this issue when opening a .epub file with nov.el (a package
that renders EPUB file) because nov.el doesn't store the filename
in buffer-file-name, opening it caused errors with org-roam-file-p.
* (minor): org-roam-file-p check if filename is non-nil first
Prior to this commit, when we would render backlinks in the
`org-buffer`, we would render each reference. This meant that if a
source file referenced the node 5 times, there would be 5 backlink
references in the `org-buffer` (one for each position of the reference).
With this change, we add a parameter that specifies that backlink
sources should be unique. In the above example, that would mean instead
of 5 backlinks we'd see 1. And, as a concession, we'd use the lowest
position (e.g. the first reference in the source).
Closes#2119
Change #2025 broke the `org-roam--shell-command-files` filter that
affects all of the `org-roam-list-files-command` methods except
`elisp`. This causes `org-roam--list-files` to iterate through the
variants executing their commands via `org-roam--shell-command-files`
but to not see any output, until it finally lands upon `elisp` and
gets some results.
The issue is that "#'s-present?" was replaced by
(or (null s) (string= "" s))
effectively negating the test and converting it to "#'s-blank?".
This addresses that by negating the current test.
* (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
* Revert "(fix): `org-roam-descendant-of-p` bug on Windows (#2089)"
This reverts commit 97a342fd3f.
Reason:
It seems that the `file-in-directory-p` function proposed in #2089 is provided only for
*physical directories*, does not work as we would like with *symlinked directories*.
It dereferences all the symlinks in its path, and previously seemed related paths
cease to be such.
Because of this, such notes are ignored and not indexed, although they
were indexed earlier.
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.