`=' assumes that both objects being compared are numbers. In some
buffers `outline-level' can return nil, so `=' returns an error. `eq'
does not assume this, but does return t when comparing two numbers.
* (node): new custom `org-roam-ref-prompt-function'
Function for prompting when adding a ref.
* (node): use `org-roam-ref-prompt' in `org-roam-ref-add'
Prompt properly for ref.
This has an effect on find-file-hook for totally unrelated files,
through the callchain of `org-roam-db-autosync--setup-file-h ->
org-roam-file-p -> org-roam-descendant-of-p'.
From an org file, inside a project-el project, (find-file
"some/other/file") will intermittently reproduce this error:
org-roam-descendant-of-p: Wrong type argument: arrayp, nil
If this fix seems inappropriate -- it could amount to surppressing a
valid error in routine calls -- then I would advise throwing an
explicit signal here, or finding a safer way to get the `path` inside
`org-roam-file-p'; the current means:
(or file (buffer-file-name (buffer-base-buffer)))
.. can result in nil, which then bleeds errors into use elsewhere.
for posterity, here is the full calling context I'm referring to, from
`org-roam-file-p'.
(let* ((path (or file (buffer-file-name (buffer-base-buffer))))
(ext (when path (org-roam--file-name-extension path)))
(ext (if (string= ext "gpg")
(org-roam--file-name-extension (file-name-sans-extension path))
ext))
(org-roam-dir-p (org-roam-descendant-of-p path
org-roam-directory))
...
* don't complete org-roam nodes in source blocks
This fixes the following situation where
`org-roam-completion-everywhere = t` and you are working with org-babel
blocks in one of your org-roam nodes.
```
```
Before my nodes would be suggested, but after this change only valid
babel headers are suggested as desired.
Previously completions from org-roam nodes would be suggested
* fix lints
Co-authored-by: Jethro Kuan <jethrokuan95@gmail.com>
`org-roam-unlinked-references-section` would get nil org-roam-node-title
when create a headline node, which caused the issue #1625. This commit
add a check to make `org-roam-unlinked-references-section` work
correctly.
Without specifying `t`, it is only pushing the PROPERTIES drawer up to
the file level, missing any other "planning information, clocking lines and
any kind of drawer." We want to promote all of this to the file level.
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