mirror of
https://github.com/org-roam/org-roam
synced 2025-08-03 12:27:23 -05:00
Compare commits
210 Commits
Author | SHA1 | Date | |
---|---|---|---|
3a78422a09 | |||
aee3467b3e | |||
756f6215b6 | |||
53c9a16e90 | |||
8ad1414030 | |||
f754160402 | |||
02e35e3b01 | |||
d2e933cc3e | |||
15c1a46e41 | |||
9065f6a999 | |||
997ddcbf4b | |||
2d58651699 | |||
8ad57b1218 | |||
0b964ca428 | |||
643b98eeb3 | |||
b0fd12647b | |||
fde40dc1c4 | |||
96b0a52273 | |||
aa52b65a4a | |||
2a1c73c0a3 | |||
16c7a7bd93 | |||
1b3a0abd36 | |||
06e5814898 | |||
cc2572e48b | |||
05deb64d85 | |||
f10fbad386 | |||
05a9bc44f2 | |||
3fb4e21adf | |||
62bba9755c | |||
78a371cdc4 | |||
15d864a500 | |||
65c0f0dc8c | |||
48e195dd82 | |||
777f6d23ec | |||
8f1cf7b449 | |||
3ce6e299d4 | |||
ecf515f650 | |||
43831c5819 | |||
4d63f99fe8 | |||
57cfb3dbb7 | |||
9c23218553 | |||
7ad32e8395 | |||
d87dd011aa | |||
f2976fa3be | |||
8aa793b021 | |||
be95b42d32 | |||
cff1168ac1 | |||
06d0db736a | |||
fb0662efe7 | |||
9ca5461a2f | |||
33805c3ff5 | |||
3a4ff76508 | |||
bf41352c1c | |||
1b598a4618 | |||
ab34dd138d | |||
b17cc3b1e3 | |||
f9b1e53894 | |||
dbed2bcf5d | |||
060a29c91d | |||
8efec080e0 | |||
61e01430e0 | |||
d70198bba9 | |||
face683e00 | |||
baf0dd9d00 | |||
a9fd6c0fc7 | |||
6502874576 | |||
8401784cd2 | |||
6dc316c450 | |||
48ef3fee11 | |||
16c520068b | |||
b1608bf869 | |||
cc01cf346e | |||
eaf99cba03 | |||
65a2cb6efd | |||
bc12d1cf04 | |||
a86d82b20e | |||
d4c875b53b | |||
2159b6a846 | |||
1db4c22950 | |||
9c0f030ffd | |||
983d7a8798 | |||
910b37268e | |||
d39556a78b | |||
167553b8ee | |||
76affe177a | |||
e96685b1a9 | |||
aef71f1623 | |||
d913447939 | |||
47e83f7d3f | |||
023bcce867 | |||
4f6eb285bf | |||
8c81104816 | |||
7602b8c48d | |||
c6797cbd75 | |||
440461a90b | |||
4d423a916e | |||
b184cdaef0 | |||
b2cc997976 | |||
bc5c41d212 | |||
7c83a84db3 | |||
56c47fbff8 | |||
0d235686f4 | |||
ac2044b84b | |||
cffa0bd201 | |||
bd8b5587f5 | |||
b937bc9655 | |||
a7cf48ea89 | |||
46327991ef | |||
a4da8f32bf | |||
5d483f2d4d | |||
09fd41ce24 | |||
a0c4abf579 | |||
cbf1b585ac | |||
66cd5b6226 | |||
5348654a7e | |||
87d7c07e87 | |||
02fda3adb1 | |||
82bd6c6cda | |||
e8d3516fa8 | |||
0cce9d1165 | |||
7a76f7b476 | |||
ceee2348e0 | |||
32bf91077e | |||
d973e8f6e0 | |||
6759bee56b | |||
ce17e7eecd | |||
369753c98b | |||
93d8c477fe | |||
30d52e5508 | |||
19c5e9b0f3 | |||
3ec2ed8874 | |||
be64f107e9 | |||
64d8ba1900 | |||
2f4034cebc | |||
668f135aa1 | |||
273d0dffa6 | |||
fadb515a87 | |||
2e58d3df19 | |||
c05368a16b | |||
346bbf50a1 | |||
176b2bf19d | |||
ae32c465de | |||
da6af3a468 | |||
cd87cfdd58 | |||
feda1f41e5 | |||
d170c4ac85 | |||
f59c18fda5 | |||
f5257cefa7 | |||
18c0f2da7f | |||
b2aa8bdad0 | |||
925d225f13 | |||
6c89eb82af | |||
8ec4cafa2b | |||
e881ea26b1 | |||
efb592907e | |||
da507a5bee | |||
fc3a03977d | |||
70539c40d2 | |||
fac0465dd8 | |||
6d09323218 | |||
e3ff54616e | |||
d3a920a5b7 | |||
8fff0b86f9 | |||
df174bb52b | |||
cb10b16fc0 | |||
9ff57c8fd1 | |||
a6aabf4038 | |||
f8c8fcee6b | |||
6f0a38e64e | |||
b8b180d60d | |||
fe5566c0dc | |||
cc8a2184b7 | |||
4f0b1b8d43 | |||
0a64a5def4 | |||
2cd993e0a5 | |||
82ac6b6b9c | |||
f6bf9d9401 | |||
38234b491d | |||
4e5b52fbd3 | |||
c33867e6bc | |||
30b2e97426 | |||
9ee591f7a4 | |||
2081e1268a | |||
11aac39a1b | |||
e58ec84b7c | |||
7813b1fe1f | |||
22006be751 | |||
0318983cac | |||
9753ee451f | |||
8c442a72de | |||
0ed9057a87 | |||
5d02e6407b | |||
4fa966d366 | |||
6d03e7626d | |||
c437052b4b | |||
a26c262048 | |||
4f3668a1e3 | |||
09b5357a94 | |||
444eedc799 | |||
da6fdd7542 | |||
f18ecd1fc3 | |||
f206b5bbf9 | |||
30fab7bcc4 | |||
76d2e3f6b4 | |||
8881c9732b | |||
0aa0a7c05a | |||
ea4bfbb55d | |||
0443351800 | |||
6345d0c22e | |||
f2c1500beb |
@ -1,6 +1,13 @@
|
|||||||
;;; Directory Local Variables
|
|
||||||
;;; For more information see (info "(emacs) Directory Variables")
|
|
||||||
|
|
||||||
((emacs-lisp-mode
|
((emacs-lisp-mode
|
||||||
(eval . (require 'org-roam-dev))
|
(fill-column . 110)
|
||||||
(eval . (org-roam-dev-mode))))
|
(indent-tabs-mode . nil)
|
||||||
|
(elisp-lint-ignored-validators . ("byte-compile" "package-lint"))
|
||||||
|
(elisp-lint-indent-specs . ((describe . 1)
|
||||||
|
(it . 1)
|
||||||
|
(org-element-map . defun)
|
||||||
|
(org-roam-with-temp-buffer . 1)
|
||||||
|
(org-with-point-at . 1)
|
||||||
|
(magit-insert-section . defun)
|
||||||
|
(magit-section-case . 0)
|
||||||
|
(->> . 1)
|
||||||
|
(org-roam-with-file . 2)))))
|
||||||
|
34
.github/workflows/test.yml
vendored
34
.github/workflows/test.yml
vendored
@ -34,36 +34,28 @@ jobs:
|
|||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
matrix:
|
||||||
emacs_version:
|
emacs_version:
|
||||||
|
- 27.1
|
||||||
- snapshot
|
- snapshot
|
||||||
steps:
|
steps:
|
||||||
- uses: purcell/setup-emacs@master
|
- uses: purcell/setup-emacs@master
|
||||||
with:
|
with:
|
||||||
version: ${{ matrix.emacs_version }}
|
version: ${{ matrix.emacs_version }}
|
||||||
|
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
- name: Initialize sandbox
|
- name: Install Eldev
|
||||||
run: |
|
run: curl -fsSL https://raw.github.com/doublep/eldev/master/webinstall/github-eldev | sh
|
||||||
SANDBOX_DIR=$(mktemp -d) || exit 1
|
|
||||||
echo ::set-env name=SANDBOX_DIR::$SANDBOX_DIR
|
|
||||||
./makem.sh -vv --sandbox $SANDBOX_DIR --install-deps --install-linters
|
|
||||||
|
|
||||||
# The "all" rule is not used, because it treats compilation warnings
|
- name: Install dependencies
|
||||||
# as failures, so linting and testing are run as separate steps.
|
run: make prepare
|
||||||
|
|
||||||
# org-roam-compat is excluded from linting because it contains
|
- name: Lint
|
||||||
# symbols/aliases from other packages
|
run: make lint
|
||||||
- name: Lint
|
|
||||||
continue-on-error: false
|
|
||||||
run: ./makem.sh -vv --sandbox $SANDBOX_DIR --exclude org-roam-compat.el lint
|
|
||||||
|
|
||||||
- name: Test
|
|
||||||
if: always() # Run test even if linting fails.
|
|
||||||
run: ./makem.sh -vv --sandbox $SANDBOX_DIR test
|
|
||||||
|
|
||||||
|
- name: Test
|
||||||
|
run: make test
|
||||||
# Local Variables:
|
# Local Variables:
|
||||||
# eval: (outline-minor-mode)
|
# eval: (outline-minor-mode)
|
||||||
# End:
|
# End:
|
||||||
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -12,4 +12,5 @@
|
|||||||
/doc/mimetype
|
/doc/mimetype
|
||||||
/doc/stats/
|
/doc/stats/
|
||||||
/config.mk
|
/config.mk
|
||||||
/doc/manual/
|
/doc/manual.html
|
||||||
|
/.eldev/
|
||||||
|
@ -1,8 +0,0 @@
|
|||||||
version: 2
|
|
||||||
mkdocs:
|
|
||||||
configuration: mkdocs.yml
|
|
||||||
formats: all
|
|
||||||
python:
|
|
||||||
version: 3.7
|
|
||||||
install:
|
|
||||||
- requirements: doc/requirements.txt
|
|
103
CHANGELOG.md
103
CHANGELOG.md
@ -1,5 +1,103 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 1.2.4 (TBD)
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- [#1396](https://github.com/org-roam/org-roam/pull/1396) add option to choose between prepending, appending, and omitting `roam_tags` in file completion
|
||||||
|
- [#1270](https://github.com/org-roam/org-roam/pull/1270) capture: create OLP if it does not exist. Removes need for OLP setup in `:head`.
|
||||||
|
- [#1353](https://github.com/org-roam/org-roam/pull/1353) support file-level property drawers
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- [#1352](https://github.com/org-roam/org-roam/pull/1352) prefer lower-case for roam_tag and roam_alias in interactive commands
|
||||||
|
- [#1513](https://github.com/org-roam/org-roam/pull/1513) replaced hardcoded "svg" with defcustom org-roam-graph-filetype
|
||||||
|
- [#1540](https://github.com/org-roam/org-roam/pull/1540) allow `roam_tag` and `roam_alias` to be specified on multiple lines
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- [#1281](https://github.com/org-roam/org-roam/pull/1281) fixed idle-timer not instantiated on `org-roam-mode`
|
||||||
|
- [#1308](https://github.com/org-roam/org-roam/pull/1308) fixed file renames corrupting database
|
||||||
|
- [#1325](https://github.com/org-roam/org-roam/pull/1325) make titles and tags extracted unique per note
|
||||||
|
- [#1327](https://github.com/org-roam/org-roam/pull/1327) preserve existing link description during automatic replacement
|
||||||
|
- [#1346](https://github.com/org-roam/org-roam/pull/1346) prevent malformed path to `org-roam-index-file`
|
||||||
|
- [#1347](https://github.com/org-roam/org-roam/pull/1347) allow use of `%a` element in regular Org-roam captures
|
||||||
|
- [#1352](https://github.com/org-roam/org-roam/pull/1352) fixed org-roam-{tag/alias}-{add/delete} altering the original case of the Org property
|
||||||
|
- [#1374](https://github.com/org-roam/org-roam/pull/1374) fix headline completions erroring out
|
||||||
|
- [#1375](https://github.com/org-roam/org-roam/pull/1375) fix org-roam-protocol to use existing ref file
|
||||||
|
- [#1403](https://github.com/org-roam/org-roam/issues/1403) fixed inconsistency between how we write and read props like alias and tags
|
||||||
|
- [#1409](https://github.com/org-roam/org-roam/issues/1398) prevent inclusion of non-org-roam files in `org-roam-dailies--list-files`
|
||||||
|
- [#1542](https://github.com/org-roam/org-roam/issues/1542) fix files not excluded when `org-roam-list-files-commands` is nil
|
||||||
|
|
||||||
|
## 1.2.3 (13-11-2020)
|
||||||
|
|
||||||
|
Primarily a stabilization and bug-fix release.
|
||||||
|
|
||||||
|
Org-roam-dailies has also been revamped to include new features, see [this video](https://www.youtube.com/watch?v=1q9x2aZCJJ4) for a quick overview.
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- [#978](https://github.com/org-roam/org-roam/pull/978) Revamp org-roam-dailies
|
||||||
|
- [#1183](https://github.com/org-roam/org-roam/pull/1183) Interactive functions for managing aliases and tags in Org-roam file, namely `org-roam-alias-add`, `org-roam-alias-delete`, `org-roam-tag-add`, and `org-roam-tag-delete`.
|
||||||
|
- [#1215](https://github.com/org-roam/org-roam/pull/1215) Multiple `ROAM_KEY` keywords can now be specified in one file. This allows bibliographical entries to share the same note file.
|
||||||
|
- [#1238](https://github.com/org-roam/org-roam/pull/1238) Add `org-roam-prefer-id-links` variable to select linking method
|
||||||
|
- [#1239](https://github.com/org-roam/org-roam/pull/1239) Allow `org-roam-protocol` to capture the webpage's selection, and add a toggle for storing the links to the pages
|
||||||
|
- [#1264](https://github.com/org-roam/org-roam/pull/1264) add `org-roam-db-update-method` to control when the cache is rebuilt.
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- [#1264](https://github.com/org-roam/org-roam/pull/1264) renamed `org-roam-update-db-idle-seconds` to `org-roam-db-idle-idle-seconds`
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- [#1074](https://github.com/org-roam/org-roam/issues/1074) fix `org-roam--extract-links` to handle content boundaries.
|
||||||
|
- [#1193](https://github.com/org-roam/org-roam/issues/1193) fix `org-roam-db-build-cache` by not killing temporary buffer in `org-roam--extract-links`.
|
||||||
|
- [#1195](https://github.com/org-roam/org-roam/issues/1195) fix ID face showing as invalid if within Org ID files, but not Org-roam's.
|
||||||
|
- [#1199](https://github.com/org-roam/org-roam/issues/1199) make Org-roam link insertions respect `org-roam-link-title-format` everywhere.
|
||||||
|
- [#1201](https://github.com/org-roam/org-roam/issues/1201) fix `org-roam-db-build-cache` failing in scenarios involving duplicate IDs and deleted files.
|
||||||
|
- [#1226](https://github.com/org-roam/org-roam/issues/1226) only update relative path of file links
|
||||||
|
- [#1232](https://github.com/org-roam/org-roam/issues/1232) fix incorrect title extractions from narrowed buffers
|
||||||
|
- [#1233](https://github.com/org-roam/org-roam/issues/1233) fixes bug where descriptive file links become plain links during update for relative paths
|
||||||
|
- [#1252](https://github.com/org-roam/org-roam/issues/1252) respect original link type during automatic replacement
|
||||||
|
|
||||||
|
## 1.2.2 (06-10-2020)
|
||||||
|
|
||||||
|
In this release we support fuzzy links of the form `[[roam:Title]]`, `[[roam:*Headline]]` and `[[roam:Title*Headline]]`. Completion for these fuzzy links is supported via `completion-at-point`.
|
||||||
|
|
||||||
|
Org-roam now does not resolve symlinks. This significantly speeds up cache builds, but may result in some workflows breaking. In particular, Org-roam now cannot figure out if two distinct file paths in the Org-roam directory are the same file, and both files will be processed as if they were different files. This error seems to be unavoidable now that symlinks are not resolved, but this workflow is rare and should not affect most users.
|
||||||
|
|
||||||
|
This change requires you to set `org-roam-directory` to the resolved path of a folder. That is:
|
||||||
|
|
||||||
|
```elisp
|
||||||
|
(setq org-roam-directory (file-truename "/path/to/directory/"))
|
||||||
|
```
|
||||||
|
|
||||||
|
### Breaking Changes
|
||||||
|
|
||||||
|
- [#1164](https://github.com/org-roam/org-roam/pull/1164) Org-roam now stores the database in the user's Emacs directory by default
|
||||||
|
- [#910](https://github.com/org-roam/org-roam/pull/910) Deprecate `company-org-roam`, using `completion-at-point` instead. To use this with company, add the `company-capf` backend instead.
|
||||||
|
- [#1109](https://github.com/org-roam/org-roam/pull/1109) Org-roam now does not resolve symlinks.
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
- [#1163](https://github.com/org-roam/org-roam/pull/1163) Support file-level IDs introduced in Org 9.4
|
||||||
|
- [#1093](https://github.com/org-roam/org-roam/pull/1093) Add `vanilla` org-roam-tag-source to extract buffer Org tags
|
||||||
|
- [#1079](https://github.com/org-roam/org-roam/pull/1079) Add `org-roam-tag-face` to customize appearance of tags in interactive commands
|
||||||
|
- [#1073](https://github.com/org-roam/org-roam/pull/1073) Rename file on title change, when `org-roam-rename-file-on-title-change` is non-nil.
|
||||||
|
- [#1071](https://github.com/org-roam/org-roam/pull/1071) Update link descriptions on title changes, and clean-up rename file advice
|
||||||
|
- [#1061](https://github.com/org-roam/org-roam/pull/1061) Speed up the extraction of file properties, headlines, and titles
|
||||||
|
- [#1046](https://github.com/org-roam/org-roam/pull/1046) New user option to exclude files from Org-roam
|
||||||
|
- [#1032](https://github.com/org-roam/org-roam/pull/1032) File changes are now propagated to the database on idle timer. This prevents large wait times during file saves.
|
||||||
|
- [#974](https://github.com/org-roam/org-roam/pull/974) Protect region targeted by `org-roam-insert`
|
||||||
|
- [#994](https://github.com/org-roam/org-roam/pull/994) Simplify org-roam-store-link
|
||||||
|
- [#1062](https://github.com/org-roam/org-roam/pull/1062) Variable `org-roam-completions-everywhere` allows for completions everywhere from word at point
|
||||||
|
- [#910](https://github.com/org-roam/org-roam/pull/910), [#1105](https://github.com/org-roam/org-roam/pull/1105) Support fuzzy links of the form `[[roam:Title]]`, `[[roam:*Headline]]` and `[[roam:Title*Headline]]`
|
||||||
|
|
||||||
|
### Bugfixes
|
||||||
|
|
||||||
|
- [#1057](https://github.com/org-roam/org-roam/pull/1057) Improve performance of database builds by preventing generation of LaTeX and image previews.
|
||||||
|
- [#1103](https://github.com/org-roam/org-roam/pull/1103) Fix long build-times for Windows on files with URL links
|
||||||
|
|
||||||
## 1.2.1 (27-07-2020)
|
## 1.2.1 (27-07-2020)
|
||||||
|
|
||||||
This release consisted of a big deal of refactoring and bug fixes. Notably, we fixed several catastrophic failures on db builds with bad setups (#854), and modularized tag and title extractions.
|
This release consisted of a big deal of refactoring and bug fixes. Notably, we fixed several catastrophic failures on db builds with bad setups (#854), and modularized tag and title extractions.
|
||||||
@ -10,11 +108,13 @@ We also added some new features that had been a long time coming:
|
|||||||
2. We now support nested captures, which is crucial for `org-roam-protocol` (#966)
|
2. We now support nested captures, which is crucial for `org-roam-protocol` (#966)
|
||||||
|
|
||||||
### Breaking Changes
|
### Breaking Changes
|
||||||
|
|
||||||
- [#908](https://github.com/org-roam/org-roam/pull/908) Normalized titles in database. May break external packages that rely on unnormalized titles.
|
- [#908](https://github.com/org-roam/org-roam/pull/908) Normalized titles in database. May break external packages that rely on unnormalized titles.
|
||||||
|
|
||||||
### Features
|
### Features
|
||||||
|
|
||||||
- [#814](https://github.com/org-roam/org-roam/pull/814) Implement `org-roam-insert-immediate`
|
- [#814](https://github.com/org-roam/org-roam/pull/814) Implement `org-roam-insert-immediate`
|
||||||
- [#833](https://github.com/org-roam/org-roam/pull/833) Add customization of file titles with `org-roam-title-to-slug-function`.
|
- [#833](https://github.com/org-roam/org-roam/pull/833) Add customization of file titles with `org-roam-title-to-slug-function`.
|
||||||
- [#839](https://github.com/org-roam/org-roam/pull/839) Return selected file from `org-roam-insert`
|
- [#839](https://github.com/org-roam/org-roam/pull/839) Return selected file from `org-roam-insert`
|
||||||
- [#847](https://github.com/org-roam/org-roam/pull/847) Add GC threshold `org-roam-db-gc-threshold` to temporarily change the threshold on expensive operations.
|
- [#847](https://github.com/org-roam/org-roam/pull/847) Add GC threshold `org-roam-db-gc-threshold` to temporarily change the threshold on expensive operations.
|
||||||
- [#847](https://github.com/org-roam/org-roam/pull/847) Use sqlite3 transactions instead of storing the values to be inserted.
|
- [#847](https://github.com/org-roam/org-roam/pull/847) Use sqlite3 transactions instead of storing the values to be inserted.
|
||||||
@ -54,6 +154,7 @@ We also add `org-roam-unlinked-references`, which naively finds text that could
|
|||||||
- [#679](https://github.com/org-roam/org-roam/pull/679), [#683](https://github.com/org-roam/org-roam/pull/683) Building of the graph now happens in a separate process
|
- [#679](https://github.com/org-roam/org-roam/pull/679), [#683](https://github.com/org-roam/org-roam/pull/683) Building of the graph now happens in a separate process
|
||||||
|
|
||||||
### Bugfixes
|
### Bugfixes
|
||||||
|
|
||||||
- [#714](https://github.com/org-roam/org-roam/pull/714) No longer print citelinks in backlinks buffer if there is no `ROAM_KEY` property or `org-ref` is not installed
|
- [#714](https://github.com/org-roam/org-roam/pull/714) No longer print citelinks in backlinks buffer if there is no `ROAM_KEY` property or `org-ref` is not installed
|
||||||
- [#759](https://github.com/org-roam/org-roam/pull/759), [#760](https://github.com/org-roam/org-roam/pull/760) Tags are only added to the tags table if there are actually tags present
|
- [#759](https://github.com/org-roam/org-roam/pull/759), [#760](https://github.com/org-roam/org-roam/pull/760) Tags are only added to the tags table if there are actually tags present
|
||||||
- [#700](https://github.com/org-roam/org-roam/pull/700), [#733](https://github.com/org-roam/org-roam/pull/733) Allow symlinks within the `org-roam` directory
|
- [#700](https://github.com/org-roam/org-roam/pull/700), [#733](https://github.com/org-roam/org-roam/pull/733) Allow symlinks within the `org-roam` directory
|
||||||
|
29
Eldev
Normal file
29
Eldev
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
; -*- mode: emacs-lisp; lexical-binding: t; no-byte-compile: t -*-
|
||||||
|
|
||||||
|
;; explicitly set main file
|
||||||
|
(setf eldev-project-main-file "org-roam.el")
|
||||||
|
|
||||||
|
(eldev-use-package-archive 'gnu)
|
||||||
|
(eldev-use-package-archive 'melpa-unstable)
|
||||||
|
|
||||||
|
;; allow to load test helpers
|
||||||
|
(eldev-add-loading-roots 'test "test/utils")
|
||||||
|
|
||||||
|
;; Tell checkdoc not to demand two spaces after a period.
|
||||||
|
(setq sentence-end-double-space nil)
|
||||||
|
|
||||||
|
(setf eldev-lint-default '(elisp))
|
||||||
|
(setf eldev-standard-excludes `(:or ,eldev-standard-excludes "org-roam-macs.el"))
|
||||||
|
|
||||||
|
(with-eval-after-load 'elisp-lint
|
||||||
|
;; We will byte-compile with Eldev.
|
||||||
|
(setf elisp-lint-ignored-validators '("package-lint" "fill-column")
|
||||||
|
enable-local-variables :all))
|
||||||
|
|
||||||
|
;; Teach linter how to properly indent emacsql vectors
|
||||||
|
(eldev-add-extra-dependencies 'lint 'emacsql)
|
||||||
|
(add-hook 'eldev-lint-hook
|
||||||
|
(lambda ()
|
||||||
|
(eldev-load-project-dependencies 'lint nil t)
|
||||||
|
(require 'emacsql)
|
||||||
|
(call-interactively #'emacsql-fix-vector-indentation)))
|
73
Makefile
73
Makefile
@ -1,70 +1,29 @@
|
|||||||
# * makem.sh/Makefile --- Script to aid building and testing Emacs Lisp packages
|
.PHONY: clean
|
||||||
|
clean:
|
||||||
|
eldev clean all
|
||||||
|
|
||||||
# This Makefile is from the makem.sh repo: <https://github.com/alphapapa/makem.sh>.
|
.PHONY: prepare
|
||||||
|
prepare:
|
||||||
|
eldev -C --unstable -p -dtT prepare
|
||||||
|
|
||||||
# * Arguments
|
.PHONY: lint
|
||||||
|
lint:
|
||||||
|
eldev -C --unstable -T lint
|
||||||
|
|
||||||
# For consistency, we use only var=val options, not hyphen-prefixed options.
|
.PHONY: test
|
||||||
|
test:
|
||||||
# NOTE: I don't like duplicating the arguments here and in makem.sh,
|
eldev -C --unstable -T test
|
||||||
# but I haven't been able to find a way to pass arguments which
|
|
||||||
# conflict with Make's own arguments through Make to the script.
|
|
||||||
# Using -- doesn't seem to do it.
|
|
||||||
|
|
||||||
ifdef install-deps
|
|
||||||
INSTALL_DEPS = "--install-deps"
|
|
||||||
endif
|
|
||||||
ifdef install-linters
|
|
||||||
INSTALL_LINTERS = "--install-linters"
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifdef sandbox
|
|
||||||
ifeq ($(sandbox), t)
|
|
||||||
SANDBOX = --sandbox
|
|
||||||
else
|
|
||||||
SANDBOX = --sandbox $(sandbox)
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifdef debug
|
|
||||||
DEBUG = "--debug"
|
|
||||||
endif
|
|
||||||
|
|
||||||
# ** Verbosity
|
|
||||||
|
|
||||||
# Since the "-v" in "make -v" gets intercepted by Make itself, we have
|
|
||||||
# to use a variable.
|
|
||||||
|
|
||||||
verbose = $(v)
|
|
||||||
|
|
||||||
ifneq (,$(findstring vv,$(verbose)))
|
|
||||||
VERBOSE = "-vv"
|
|
||||||
else ifneq (,$(findstring v,$(verbose)))
|
|
||||||
VERBOSE = "-v"
|
|
||||||
endif
|
|
||||||
|
|
||||||
# * Rules
|
|
||||||
|
|
||||||
# TODO: Handle cases in which "test" or "tests" are called and a
|
|
||||||
# directory by that name exists, which can confuse Make.
|
|
||||||
|
|
||||||
%:
|
|
||||||
@./makem.sh $(DEBUG) $(VERBOSE) $(SANDBOX) $(INSTALL_DEPS) $(INSTALL_LINTERS) $(@)
|
|
||||||
|
|
||||||
.DEFAULT: init
|
|
||||||
init:
|
|
||||||
@./makem.sh $(DEBUG) $(VERBOSE) $(SANDBOX) $(INSTALL_DEPS) $(INSTALL_LINTERS)
|
|
||||||
|
|
||||||
docs:
|
docs:
|
||||||
@$(MAKE) -C doc all
|
make -C doc all
|
||||||
|
|
||||||
html:
|
html:
|
||||||
@$(MAKE) -C doc html-dir
|
make -C doc html-dir
|
||||||
|
|
||||||
install: install-docs
|
install: install-docs
|
||||||
|
|
||||||
install-docs: docs
|
install-docs: docs
|
||||||
@$(MAKE) -C doc install-docs
|
make -C doc install-docs
|
||||||
|
|
||||||
install-info: info
|
install-info: info
|
||||||
@$(MAKE) -C doc install-info
|
make -C doc install-info
|
||||||
|
131
README.md
131
README.md
@ -1,42 +1,35 @@
|
|||||||
[![License GPL 3][badge-license]](http://www.gnu.org/licenses/gpl-3.0.txt)
|
# Org-roam [![GitHub Release][release-badge]][release] [![MELPA][melpa-badge]][melpa] [![License GPL 3][gpl3-badge]][gpl3]
|
||||||
[](https://img.shields.io/github/v/release/org-roam/org-roam)
|
|
||||||
[](https://melpa.org/#/org-roam)
|
|
||||||
|
|
||||||
## Synopsis
|
<img src="https://www.orgroam.com/img/logo.svg" align="right" alt="Org-roam Logo" width="240">
|
||||||
|
|
||||||
Org-roam is a [Roam][roamresearch] replica built on top of the
|
Org-roam is a plain-text knowledge management system. It brings some of
|
||||||
all-powerful [Org-mode][org].
|
[Roam's][roamresearch] more powerful features into the [Org-mode][org]
|
||||||
|
ecosystem.
|
||||||
|
|
||||||
Org-roam is a solution for effortless non-hierarchical note-taking
|
Org-roam borrows principles from the Zettelkasten method, providing a solution
|
||||||
with Org-mode. With Org-roam, notes flow naturally, making note-taking
|
for non-hierarchical note-taking. It should also work as a plug-and-play
|
||||||
fun and easy. Org-roam should also work as a plug-and-play solution
|
solution for anyone already using Org-mode for their personal wiki.
|
||||||
for anyone already using Org-mode for their personal wiki.
|
|
||||||
|
|
||||||
Org-roam aims to implement the core features of Roam, leveraging the
|
- **Private and Secure**: Edit your personal wiki completely offline, entirely
|
||||||
mature ecosystem around Org-mode where possible. Eventually, we hope
|
in your control. Encrypt your notes with GPG. Take lasting notes in
|
||||||
to further introduce features enabled by the Emacs ecosystem.
|
plain-text.
|
||||||
|
- **Networked Thought**: Connect notes and thoughts together with ease using
|
||||||
|
backlinks. Discover surprising and previously unseen connections in your notes
|
||||||
|
with the built-in graph visualization.
|
||||||
|
- **Extensible and Powerful**: Leverage Emacs' fantastic text-editing interface,
|
||||||
|
and the mature Emacs and Org-mode ecosystem of packages.
|
||||||
|
- **Free and Open Source**: Org-roam is licensed under the GNU General Public
|
||||||
|
License version 3 or later.
|
||||||
|
|
||||||
[@technovangelist](https://github.com/technovangelist/) has produced a video
|
<p align="center">
|
||||||
describing Org-roam and the concepts behind it:
|
<img src="https://www.orgroam.com/img/screenshot.png" alt="Org-roam Screenshot" width="738">
|
||||||
|
</p>
|
||||||
[](http://www.youtube.com/watch?v=Lg61ocfxk3c "Making Connections in your Notes")
|
|
||||||
|
|
||||||
Important links:
|
|
||||||
|
|
||||||
- **[Documentation][docs]**
|
- **[Documentation][docs]**
|
||||||
- **[Discourse][discourse]**
|
- **[Discourse][discourse]**
|
||||||
- **[Slack][slack]**
|
- **[Slack][slack]**
|
||||||
|
- **[Frequently Asked Questions][faq]**
|
||||||
## A Preview
|
- **[Changelog](CHANGELOG.md)**
|
||||||
|
|
||||||
Here's a screencast of Org-roam. The `org-roam-buffer` (window on the
|
|
||||||
right) shows backlinks for the active Org-roam buffer (window on the
|
|
||||||
left), as well as the surrounding content in the backlink file. The
|
|
||||||
database is built once, and updated incrementally. The graph is
|
|
||||||
generated from the link structure, and can be used to navigate to the
|
|
||||||
respective files.
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
@ -46,61 +39,53 @@ You can install `org-roam` using `package.el`:
|
|||||||
M-x package-install RET org-roam RET
|
M-x package-install RET org-roam RET
|
||||||
```
|
```
|
||||||
|
|
||||||
Here's a sample configuration with using `use-package`:
|
Here's a sample configuration with `use-package`:
|
||||||
|
|
||||||
```emacs-lisp
|
```emacs-lisp
|
||||||
(use-package org-roam
|
(use-package org-roam
|
||||||
:ensure t
|
:ensure t
|
||||||
:hook
|
|
||||||
(after-init . org-roam-mode)
|
|
||||||
:custom
|
:custom
|
||||||
(org-roam-directory "/path/to/org-files/")
|
(org-roam-directory (file-truename "/path/to/org-files/"))
|
||||||
:bind (:map org-roam-mode-map
|
:bind (("C-c n l" . org-roam-buffer-toggle)
|
||||||
(("C-c n l" . org-roam)
|
("C-c n f" . org-roam-node-find)
|
||||||
("C-c n f" . org-roam-find-file)
|
("C-c n g" . org-roam-graph)
|
||||||
("C-c n g" . org-roam-graph-show))
|
("C-c n i" . org-roam-node-insert)
|
||||||
:map org-mode-map
|
("C-c n c" . org-roam-capture)
|
||||||
(("C-c n i" . org-roam-insert))
|
;; Dailies
|
||||||
(("C-c n I" . org-roam-insert-immediate))))
|
("C-c n j" . org-roam-dailies-capture-today))
|
||||||
|
:config
|
||||||
|
(org-roam-setup)
|
||||||
|
;; If using org-roam-protocol
|
||||||
|
(require 'org-roam-protocol))
|
||||||
```
|
```
|
||||||
|
|
||||||
`org-roam-graph` by default expects to find the `dot` executable
|
The `file-truename` function is only necessary when you use symbolic links
|
||||||
from the `graphviz` package in the `exec-path`.
|
inside `org-roam-directory`: Org-roam does not resolve symbolic links.
|
||||||
Ensure `graphviz` is installed and found if you want to use this
|
|
||||||
feature or customize your configuration for `org-roam-graph` to use a
|
|
||||||
different tool.
|
|
||||||
|
|
||||||
For more detailed installation and configuration instructions (including for
|
Org-roam requires sqlite to function. Org-roam optionally uses Graphviz for
|
||||||
Doom and Spacemacs users), please see [the
|
graph-related functionality. It is recommended to install PCRE-enabled ripgrep
|
||||||
documentation][docs].
|
for better performance and extended functionality.
|
||||||
|
|
||||||
## Frequently-asked Questions
|
|
||||||
|
|
||||||
Q: How do I create a note whose title already matches one of the candidates (e.g. creating `bar` when `barricade` already exists)?
|
|
||||||
|
|
||||||
A: With `ivy`, you need to press `C-M-j` to use the current input instead of the nearest candidate. (Source: [`ivy`’s
|
|
||||||
FAQ](https://github.com/abo-abo/swiper#frequently-asked-questions))
|
|
||||||
|
|
||||||
## Getting Help
|
## Getting Help
|
||||||
|
|
||||||
Before creating a new topic/issue, please be mindful of our time and ensure
|
Before creating a new topic/issue, please be mindful of our time and ensure that
|
||||||
that it has not already been addressed on
|
it has not already been addressed on [GitHub][issues] or on
|
||||||
[GitHub][issues] or on
|
|
||||||
[Discourse][discourse].
|
[Discourse][discourse].
|
||||||
|
|
||||||
- If you are new to Emacs and have problem setting up Org-roam, please ask your question on [Slack, channel #how-do-i][slack].
|
- If you are new to Emacs and have problem setting up Org-roam, please ask your
|
||||||
- For quick questions, please ask them on [Slack, channel #troubleshooting][slack].
|
question on [Slack, channel #how-do-i][slack].
|
||||||
- If something is not working as it should, or if you would like to suggest a new feature, please [create a new issue][issues].
|
- For quick questions, please ask them on [Slack, channel
|
||||||
- If you have questions about your workflow with the slip-box method, please find a relevant topic on [Discourse][discourse], or create a new one.
|
#troubleshooting][slack].
|
||||||
|
- If something is not working as it should, or if you would like to suggest a
|
||||||
|
new feature, please [create a new issue][issues].
|
||||||
|
- If you have questions about your workflow with the slip-box method, please
|
||||||
|
find a relevant topic on [Discourse][discourse], or create a new one.
|
||||||
|
|
||||||
## Knowledge Bases using Org-roam
|
## Knowledge Bases using Org-roam
|
||||||
|
|
||||||
- [Jethro Kuan](https://braindump.jethro.dev/)
|
- [Jethro Kuan](https://braindump.jethro.dev/)
|
||||||
([Source](https://github.com/jethrokuan/braindump/tree/master/org))
|
([Source](https://github.com/jethrokuan/braindump/tree/master/org))
|
||||||
|
- [Alexey Shmalko](https://braindump.rasen.dev/)
|
||||||
## Changelog
|
|
||||||
|
|
||||||
A changelog is being maintained [here](CHANGELOG.md)
|
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
@ -111,12 +96,18 @@ request. Please also see [CONTRIBUTING.md](.github/CONTRIBUTING.md).
|
|||||||
## License
|
## License
|
||||||
|
|
||||||
Copyright © Jethro Kuan and contributors. Distributed under the GNU
|
Copyright © Jethro Kuan and contributors. Distributed under the GNU
|
||||||
General Public License, Version 3
|
General Public License, Version 3.
|
||||||
|
|
||||||
[roamresearch]: https://www.roamresearch.com/
|
[roamresearch]: https://www.roamresearch.com/
|
||||||
[org]: https://orgmode.org/
|
[org]: https://orgmode.org/
|
||||||
[badge-license]: https://img.shields.io/badge/license-GPL_3-green.svg
|
[gpl3-badge]: https://img.shields.io/badge/license-GPL_3-green.svg
|
||||||
[docs]: https://www.orgroam.com/manual/
|
[gpl3]: http://www.gnu.org/licenses/gpl-3.0.txt
|
||||||
|
[melpa-badge]: https://melpa.org/packages/org-roam-badge.svg
|
||||||
|
[melpa]: https://melpa.org/#/org-roam
|
||||||
|
[release-badge]: https://img.shields.io/github/v/release/org-roam/org-roam
|
||||||
|
[release]: https://github.com/org-roam/org-roam/releases
|
||||||
|
[docs]: https://www.orgroam.com/manual.html
|
||||||
[discourse]: https://org-roam.discourse.group/
|
[discourse]: https://org-roam.discourse.group/
|
||||||
[slack]: https://join.slack.com/t/orgroam/shared_invite/zt-deoqamys-043YQ~s5Tay3iJ5QRI~Lxg
|
[slack]: https://join.slack.com/t/orgroam/shared_invite/zt-deoqamys-043YQ~s5Tay3iJ5QRI~Lxg
|
||||||
[issues]: https://github.com/org-roam/org-roam/issues
|
[issues]: https://github.com/org-roam/org-roam/issues
|
||||||
|
[faq]: https://www.orgroam.com/manual.html#FAQ
|
||||||
|
@ -34,4 +34,4 @@ Contributors
|
|||||||
- Rafael Accácio Nogueira <raccacio@poli.ufrj.br>
|
- Rafael Accácio Nogueira <raccacio@poli.ufrj.br>
|
||||||
- Roland Coeurjoly <rolandcoeurjoly@gmail.com>
|
- Roland Coeurjoly <rolandcoeurjoly@gmail.com>
|
||||||
- Sayan <dit7ya@users.noreply.github.com>
|
- Sayan <dit7ya@users.noreply.github.com>
|
||||||
- Tim Quelch <tim@quelch.name>
|
- Tim Quelch <tim@tquelch.com>
|
||||||
|
@ -27,12 +27,9 @@ dir: org-roam.info
|
|||||||
@printf "Generating $@\n"
|
@printf "Generating $@\n"
|
||||||
@$(MAKEINFO) --html --no-split $(MANUAL_HTML_ARGS) $<
|
@$(MAKEINFO) --html --no-split $(MANUAL_HTML_ARGS) $<
|
||||||
|
|
||||||
html-dir:
|
html-dir:
|
||||||
@printf "Generating org-roam/*.html\n"
|
@$(MAKEINFO) --html --no-split $(MANUAL_HTML_ARGS) org-roam.texi
|
||||||
@$(MAKEINFO) --html $(MANUAL_HTML_ARGS) org-roam.texi
|
mv org-roam.html manual.html
|
||||||
mv org-roam manual
|
|
||||||
cp -r assets manual
|
|
||||||
cp -r images manual
|
|
||||||
|
|
||||||
%.pdf: %.texi
|
%.pdf: %.texi
|
||||||
@printf "Generating $@\n"
|
@printf "Generating $@\n"
|
||||||
|
@ -1,442 +1,68 @@
|
|||||||
/* Import Inter font */
|
|
||||||
/* More info at https://github.com/xz/fonts */
|
|
||||||
@import url("https://fonts.xz.style/serve/inter.css");
|
|
||||||
|
|
||||||
:root {
|
:root {
|
||||||
--nc-font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
|
--border: #526980;
|
||||||
Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif,
|
--code: #007;
|
||||||
"Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
|
|
||||||
--nc-font-mono: "Courier New", Courier, "Ubuntu Mono", "Liberation Mono",
|
|
||||||
monospace;
|
|
||||||
--nc-tx-1: #000000;
|
|
||||||
--nc-tx-2: #1a1a1a;
|
|
||||||
--nc-bg-1: #ffffff;
|
|
||||||
--nc-bg-2: #f6f8fa;
|
|
||||||
--nc-bg-3: #e5e7eb;
|
|
||||||
--nc-lk-1: #0070f3;
|
|
||||||
--nc-lk-2: #0366d6;
|
|
||||||
--nc-lk-tx: #ffffff;
|
|
||||||
--nc-ac-1: #79ffe1;
|
|
||||||
--nc-ac-tx: #0c4047;
|
|
||||||
}
|
|
||||||
|
|
||||||
@media (prefers-color-scheme: dark) {
|
|
||||||
:root {
|
|
||||||
--nc-tx-1: #ffffff;
|
|
||||||
--nc-tx-2: #eeeeee;
|
|
||||||
--nc-bg-1: #000000;
|
|
||||||
--nc-bg-2: #111111;
|
|
||||||
--nc-bg-3: #222222;
|
|
||||||
--nc-lk-1: #3291ff;
|
|
||||||
--nc-lk-2: #0070f3;
|
|
||||||
--nc-lk-tx: #ffffff;
|
|
||||||
--nc-ac-1: #7928ca;
|
|
||||||
--nc-ac-tx: #ffffff;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
* {
|
|
||||||
/* Reset margins and padding */
|
|
||||||
margin: 0;
|
|
||||||
padding: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
address,
|
|
||||||
area,
|
|
||||||
article,
|
|
||||||
aside,
|
|
||||||
audio,
|
|
||||||
blockquote,
|
|
||||||
datalist,
|
|
||||||
details,
|
|
||||||
dl,
|
|
||||||
fieldset,
|
|
||||||
figure,
|
|
||||||
form,
|
|
||||||
input,
|
|
||||||
iframe,
|
|
||||||
img,
|
|
||||||
meter,
|
|
||||||
nav,
|
|
||||||
ol,
|
|
||||||
optgroup,
|
|
||||||
option,
|
|
||||||
output,
|
|
||||||
p,
|
|
||||||
pre,
|
|
||||||
progress,
|
|
||||||
ruby,
|
|
||||||
section,
|
|
||||||
table,
|
|
||||||
textarea,
|
|
||||||
ul,
|
|
||||||
video {
|
|
||||||
/* Margins for most elements */
|
|
||||||
margin-bottom: 1rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
html,
|
|
||||||
input,
|
|
||||||
select,
|
|
||||||
button {
|
|
||||||
/* Set body font family and some finicky elements */
|
|
||||||
font-family: var(--nc-font-sans);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
/* Center body in page */
|
margin: 5ex 10ex;
|
||||||
margin: 0 auto;
|
max-width: 80ex;
|
||||||
max-width: 750px;
|
line-height: 1.5;
|
||||||
padding: 2rem;
|
font-family: sans-serif;
|
||||||
border-radius: 6px;
|
|
||||||
overflow-x: hidden;
|
|
||||||
background: var(--nc-bg-1);
|
|
||||||
|
|
||||||
/* Main body text */
|
|
||||||
color: var(--nc-tx-2);
|
|
||||||
font-size: 1.03rem;
|
|
||||||
line-height: 1.5;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
::selection {
|
h1, h2, h3 {
|
||||||
/* Set background color for selected text */
|
font-weight: normal;
|
||||||
background: var(--nc-ac-1);
|
|
||||||
color: var(--nc-ac-tx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
p {
|
pre, code {
|
||||||
margin-bottom: 1rem;
|
font-family: x, monospace;
|
||||||
}
|
|
||||||
|
|
||||||
h1,
|
|
||||||
h2,
|
|
||||||
h3,
|
|
||||||
h4,
|
|
||||||
h5,
|
|
||||||
h6 {
|
|
||||||
line-height: 1;
|
|
||||||
color: var(--nc-tx-1);
|
|
||||||
padding-top: 0.875rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
h1,
|
|
||||||
h2,
|
|
||||||
h3 {
|
|
||||||
color: var(--nc-tx-1);
|
|
||||||
padding-bottom: 2px;
|
|
||||||
margin-bottom: 8px;
|
|
||||||
border-bottom: 1px solid var(--nc-bg-2);
|
|
||||||
}
|
|
||||||
|
|
||||||
h4,
|
|
||||||
h5,
|
|
||||||
h6 {
|
|
||||||
margin-bottom: 0.3rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
h1 {
|
|
||||||
font-size: 2.25rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
h2 {
|
|
||||||
font-size: 1.85rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
h3 {
|
|
||||||
font-size: 1.55rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
h4 {
|
|
||||||
font-size: 1.25rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
h5 {
|
|
||||||
font-size: 1rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
h6 {
|
|
||||||
font-size: 0.875rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
a {
|
|
||||||
color: var(--nc-lk-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
a:hover {
|
|
||||||
color: var(--nc-lk-2);
|
|
||||||
}
|
|
||||||
|
|
||||||
abbr:hover {
|
|
||||||
/* Set the '?' cursor while hovering an abbreviation */
|
|
||||||
cursor: help;
|
|
||||||
}
|
|
||||||
|
|
||||||
blockquote {
|
|
||||||
padding: 1.5rem;
|
|
||||||
background: var(--nc-bg-2);
|
|
||||||
border-left: 5px solid var(--nc-bg-3);
|
|
||||||
}
|
|
||||||
|
|
||||||
abbr {
|
|
||||||
cursor: help;
|
|
||||||
}
|
|
||||||
|
|
||||||
blockquote *:last-child {
|
|
||||||
padding-bottom: 0;
|
|
||||||
margin-bottom: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
header {
|
|
||||||
background: var(--nc-bg-2);
|
|
||||||
border-bottom: 1px solid var(--nc-bg-3);
|
|
||||||
padding: 2rem 1.5rem;
|
|
||||||
|
|
||||||
/* This sets the right and left margins to cancel out the body's margins. It's width is still the same, but the background stretches across the page's width. */
|
|
||||||
|
|
||||||
margin: -2rem calc(0px - (50vw - 50%)) 2rem;
|
|
||||||
|
|
||||||
/* Shorthand for:
|
|
||||||
|
|
||||||
margin-top: -2rem;
|
|
||||||
margin-bottom: 2rem;
|
|
||||||
|
|
||||||
margin-left: calc(0px - (50vw - 50%));
|
|
||||||
margin-right: calc(0px - (50vw - 50%)); */
|
|
||||||
|
|
||||||
padding-left: calc(50vw - 50%);
|
|
||||||
padding-right: calc(50vw - 50%);
|
|
||||||
}
|
|
||||||
|
|
||||||
header h1,
|
|
||||||
header h2,
|
|
||||||
header h3 {
|
|
||||||
padding-bottom: 0;
|
|
||||||
border-bottom: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
header > *:first-child {
|
|
||||||
margin-top: 0;
|
|
||||||
padding-top: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
header > *:last-child {
|
|
||||||
margin-bottom: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.button,
|
|
||||||
button,
|
|
||||||
input[type="submit"],
|
|
||||||
input[type="reset"],
|
|
||||||
input[type="button"] {
|
|
||||||
font-size: 1rem;
|
|
||||||
display: inline-block;
|
|
||||||
padding: 6px 12px;
|
|
||||||
text-align: center;
|
|
||||||
text-decoration: none;
|
|
||||||
white-space: nowrap;
|
|
||||||
background: var(--nc-lk-1);
|
|
||||||
color: var(--nc-lk-tx);
|
|
||||||
border: 0;
|
|
||||||
border-radius: 4px;
|
|
||||||
box-sizing: border-box;
|
|
||||||
cursor: pointer;
|
|
||||||
color: var(--nc-lk-tx);
|
|
||||||
}
|
|
||||||
|
|
||||||
.button[disabled],
|
|
||||||
button[disabled],
|
|
||||||
input[type="submit"][disabled],
|
|
||||||
input[type="reset"][disabled],
|
|
||||||
input[type="button"][disabled] {
|
|
||||||
cursor: default;
|
|
||||||
opacity: 0.5;
|
|
||||||
|
|
||||||
/* Set the [X] cursor while hovering a disabled link */
|
|
||||||
cursor: not-allowed;
|
|
||||||
}
|
|
||||||
|
|
||||||
.button:focus,
|
|
||||||
.button:hover,
|
|
||||||
button:focus,
|
|
||||||
button:hover,
|
|
||||||
input[type="submit"]:focus,
|
|
||||||
input[type="submit"]:hover,
|
|
||||||
input[type="reset"]:focus,
|
|
||||||
input[type="reset"]:hover,
|
|
||||||
input[type="button"]:focus,
|
|
||||||
input[type="button"]:hover {
|
|
||||||
background: var(--nc-lk-2);
|
|
||||||
}
|
|
||||||
|
|
||||||
code,
|
|
||||||
pre,
|
|
||||||
kbd,
|
|
||||||
samp {
|
|
||||||
/* Set the font family for monospaced elements */
|
|
||||||
font-family: var(--nc-font-mono);
|
|
||||||
}
|
|
||||||
|
|
||||||
code,
|
|
||||||
samp,
|
|
||||||
kbd,
|
|
||||||
pre {
|
|
||||||
/* The main preformatted style. This is changed slightly across different cases. */
|
|
||||||
background: var(--nc-bg-2);
|
|
||||||
border: 1px solid var(--nc-bg-3);
|
|
||||||
border-radius: 4px;
|
|
||||||
padding: 3px 6px;
|
|
||||||
font-size: 0.9rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
kbd {
|
|
||||||
/* Makes the kbd element look like a keyboard key */
|
|
||||||
border-bottom: 3px solid var(--nc-bg-3);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pre {
|
pre {
|
||||||
padding: 1rem 1.4rem;
|
padding: 1ex;
|
||||||
max-width: 100%;
|
background: #eee;
|
||||||
overflow: auto;
|
border: solid 1px #ddd;
|
||||||
|
min-width: 0;
|
||||||
|
font-size: 80%;
|
||||||
|
overflow: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
pre code {
|
code {
|
||||||
/* When <code> is in a <pre>, reset it's formatting to blend in */
|
color: var(--code);
|
||||||
background: inherit;
|
|
||||||
font-size: inherit;
|
|
||||||
color: inherit;
|
|
||||||
border: 0;
|
|
||||||
padding: 0;
|
|
||||||
margin: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
code pre {
|
|
||||||
/* When <pre> is in a <code>, reset it's formatting to blend in */
|
|
||||||
display: inline;
|
|
||||||
background: inherit;
|
|
||||||
font-size: inherit;
|
|
||||||
color: inherit;
|
|
||||||
border: 0;
|
|
||||||
padding: 0;
|
|
||||||
margin: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
details {
|
|
||||||
/* Make the <details> look more "clickable" */
|
|
||||||
padding: 0.6rem 1rem;
|
|
||||||
background: var(--nc-bg-2);
|
|
||||||
border: 1px solid var(--nc-bg-3);
|
|
||||||
border-radius: 4px;
|
|
||||||
}
|
|
||||||
|
|
||||||
summary {
|
|
||||||
/* Makes the <summary> look more like a "clickable" link with the pointer cursor */
|
|
||||||
cursor: pointer;
|
|
||||||
font-weight: bold;
|
|
||||||
}
|
|
||||||
|
|
||||||
details[open] {
|
|
||||||
/* Adjust the <details> padding while open */
|
|
||||||
padding-bottom: 0.75rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
details[open] summary {
|
|
||||||
/* Adjust the <details> padding while open */
|
|
||||||
margin-bottom: 6px;
|
|
||||||
}
|
|
||||||
|
|
||||||
details[open] > *:last-child {
|
|
||||||
/* Resets the bottom margin of the last element in the <details> while <details> is opened. This prevents double margins/paddings. */
|
|
||||||
margin-bottom: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
dt {
|
|
||||||
font-weight: bold;
|
|
||||||
}
|
|
||||||
|
|
||||||
dd::before {
|
|
||||||
/* Add an arrow to data table definitions */
|
|
||||||
content: "→ ";
|
|
||||||
}
|
|
||||||
|
|
||||||
hr {
|
|
||||||
/* Reset the border of the <hr> separator, then set a better line */
|
|
||||||
border: 0;
|
|
||||||
border-bottom: 1px solid var(--nc-bg-3);
|
|
||||||
margin: 1rem auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
fieldset {
|
|
||||||
margin-top: 1rem;
|
|
||||||
padding: 2rem;
|
|
||||||
border: 1px solid var(--nc-bg-3);
|
|
||||||
border-radius: 4px;
|
|
||||||
}
|
|
||||||
|
|
||||||
legend {
|
|
||||||
padding: auto 0.5rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
textarea {
|
|
||||||
/* Don't let the <textarea> extend off the screen naturally or when dragged by the user */
|
|
||||||
max-width: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
ol,
|
|
||||||
ul {
|
|
||||||
/* Replace the browser default padding */
|
|
||||||
padding-left: 2rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
li {
|
|
||||||
margin-top: 0.4rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
ul ul,
|
|
||||||
ol ul,
|
|
||||||
ul ol,
|
|
||||||
ol ol {
|
|
||||||
margin-bottom: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
mark {
|
|
||||||
padding: 3px 6px;
|
|
||||||
background: var(--nc-ac-1);
|
|
||||||
color: var(--nc-ac-tx);
|
|
||||||
}
|
|
||||||
|
|
||||||
textarea,
|
|
||||||
select,
|
|
||||||
input {
|
|
||||||
padding: 6px 12px;
|
|
||||||
margin-bottom: 0.5rem;
|
|
||||||
background: var(--nc-bg-2);
|
|
||||||
color: var(--nc-tx-2);
|
|
||||||
|
|
||||||
/* Set a border of the same color as the main background. It isn't visible on idle, but prevents the cell from growing in size when a darker border is set on focus. */
|
|
||||||
border: 1px solid var(--nc-bg-2);
|
|
||||||
border-radius: 4px;
|
|
||||||
box-shadow: none;
|
|
||||||
box-sizing: border-box;
|
|
||||||
}
|
|
||||||
|
|
||||||
textarea:focus,
|
|
||||||
select:focus,
|
|
||||||
input[type]:focus {
|
|
||||||
border: 1px solid var(--nc-bg-3);
|
|
||||||
|
|
||||||
/* Reset any browser default outlines */
|
|
||||||
outline: 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
img {
|
img {
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Customizations */
|
table {
|
||||||
.menu-comment {
|
border-collapse: collapse;
|
||||||
font-weight: bold;
|
width: 100%;
|
||||||
border: 0;
|
}
|
||||||
margin: 0;
|
|
||||||
padding: 0;
|
pre.menu-comment {
|
||||||
font-size: 1.2rem;
|
background: none;
|
||||||
|
border: none;
|
||||||
|
font-family: sans-serif;
|
||||||
|
padding: 0;
|
||||||
|
margin: 0;
|
||||||
|
font-size: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
thead {
|
||||||
|
border-bottom: 1px solid var(--border);
|
||||||
|
}
|
||||||
|
|
||||||
|
tfoot {
|
||||||
|
border-top: 1px solid var(--border);
|
||||||
|
}
|
||||||
|
|
||||||
|
blockquote {
|
||||||
|
margin-left: 1rem;
|
||||||
|
font-style: italic;
|
||||||
|
font-family: serif;
|
||||||
|
border-left: 3px solid;
|
||||||
|
border-left-color: currentcolor;
|
||||||
|
border-color: var(--text-color);
|
||||||
|
padding-left: 1em;
|
||||||
}
|
}
|
||||||
|
@ -93,7 +93,7 @@
|
|||||||
You can find us on Discourse and Slack.
|
You can find us on Discourse and Slack.
|
||||||
|
|
||||||
<ul>
|
<ul>
|
||||||
<li>Read our documentation within Emacs, or on the <a href="https://www.orgroam.com/manual/">Online Manual</a></li>
|
<li>Read our documentation within Emacs, or on the <a href="https://www.orgroam.com/manual.html">Online Manual</a></li>
|
||||||
<li>Participate in our forum discussions on <a href="https://org-roam.discourse.group">Discourse</a></li>
|
<li>Participate in our forum discussions on <a href="https://org-roam.discourse.group">Discourse</a></li>
|
||||||
<li>Chat with us on <a href="https://join.slack.com/t/orgroam/shared_invite/zt-deoqamys-043YQ~s5Tay3iJ5QRI~Lxg">Slack</a></li>
|
<li>Chat with us on <a href="https://join.slack.com/t/orgroam/shared_invite/zt-deoqamys-043YQ~s5Tay3iJ5QRI~Lxg">Slack</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
@ -120,13 +120,6 @@
|
|||||||
>org-roam-server</a
|
>org-roam-server</a
|
||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
|
||||||
<a
|
|
||||||
class="content footer-links"
|
|
||||||
href="https://github.com/org-roam/company-org-roam"
|
|
||||||
>company-org-roam</a
|
|
||||||
>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col">
|
<div class="col">
|
||||||
|
1872
doc/org-roam.org
1872
doc/org-roam.org
File diff suppressed because it is too large
Load Diff
1591
doc/org-roam.texi
1591
doc/org-roam.texi
File diff suppressed because it is too large
Load Diff
@ -1,302 +0,0 @@
|
|||||||
;;; org-roam-buffer.el --- Metadata buffer -*- coding: utf-8; lexical-binding: t; -*-
|
|
||||||
|
|
||||||
;; Copyright © 2020 Jethro Kuan <jethrokuan95@gmail.com>
|
|
||||||
|
|
||||||
;; Author: Jethro Kuan <jethrokuan95@gmail.com>
|
|
||||||
;; URL: https://github.com/org-roam/org-roam
|
|
||||||
;; Keywords: org-mode, roam, convenience
|
|
||||||
;; Version: 1.2.1
|
|
||||||
;; Package-Requires: ((emacs "26.1") (dash "2.13") (f "0.17.2") (s "1.12.0") (org "9.3") (emacsql "3.0.0") (emacsql-sqlite3 "1.0.0"))
|
|
||||||
|
|
||||||
;; This file is NOT part of GNU Emacs.
|
|
||||||
|
|
||||||
;; This program is free software; you can redistribute it and/or modify
|
|
||||||
;; it under the terms of the GNU General Public License as published by
|
|
||||||
;; the Free Software Foundation; either version 3, or (at your option)
|
|
||||||
;; any later version.
|
|
||||||
;;
|
|
||||||
;; This program is distributed in the hope that it will be useful,
|
|
||||||
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
;; GNU General Public License for more details.
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the GNU General Public License
|
|
||||||
;; along with GNU Emacs; see the file COPYING. If not, write to the
|
|
||||||
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
||||||
;; Boston, MA 02110-1301, USA.
|
|
||||||
|
|
||||||
;;; Commentary:
|
|
||||||
;;
|
|
||||||
;; This library provides the org-roam-buffer functionality for org-roam
|
|
||||||
;;; Code:
|
|
||||||
;;;; Library Requires
|
|
||||||
(eval-when-compile (require 'subr-x))
|
|
||||||
(require 'cl-lib)
|
|
||||||
(require 'dash)
|
|
||||||
(require 's)
|
|
||||||
|
|
||||||
(defvar org-roam-directory)
|
|
||||||
(defvar org-link-frame-setup)
|
|
||||||
(defvar org-return-follows-link)
|
|
||||||
(defvar org-roam-backlinks-mode)
|
|
||||||
(defvar org-roam-last-window)
|
|
||||||
(defvar org-ref-cite-types) ;; in org-ref-core.el
|
|
||||||
(defvar org-roam-mode)
|
|
||||||
|
|
||||||
(declare-function org-roam-db--ensure-built "org-roam-db")
|
|
||||||
(declare-function org-roam--extract-ref "org-roam")
|
|
||||||
(declare-function org-roam--get-title-or-slug "org-roam")
|
|
||||||
(declare-function org-roam--get-backlinks "org-roam")
|
|
||||||
(declare-function org-roam-backlinks-mode "org-roam")
|
|
||||||
(declare-function org-roam-mode "org-roam")
|
|
||||||
(declare-function org-roam--find-file "org-roam")
|
|
||||||
|
|
||||||
(defcustom org-roam-buffer-position 'right
|
|
||||||
"Position of `org-roam' buffer.
|
|
||||||
Valid values are
|
|
||||||
* left,
|
|
||||||
* right,
|
|
||||||
* top,
|
|
||||||
* bottom."
|
|
||||||
:type '(choice (const left)
|
|
||||||
(const right)
|
|
||||||
(const top)
|
|
||||||
(const bottom))
|
|
||||||
:group 'org-roam)
|
|
||||||
|
|
||||||
(defcustom org-roam-buffer-width 0.33
|
|
||||||
"Width of `org-roam' buffer.
|
|
||||||
Has an effect if and only if `org-roam-buffer-position' is `left' or `right'."
|
|
||||||
:type 'number
|
|
||||||
:group 'org-roam)
|
|
||||||
|
|
||||||
(defcustom org-roam-buffer-height 0.27
|
|
||||||
"Height of `org-roam' buffer.
|
|
||||||
Has an effect if and only if `org-roam-buffer-position' is `top' or `bottom'."
|
|
||||||
:type 'number
|
|
||||||
:group 'org-roam)
|
|
||||||
|
|
||||||
|
|
||||||
(defcustom org-roam-buffer "*org-roam*"
|
|
||||||
"Org-roam buffer name."
|
|
||||||
:type 'string
|
|
||||||
:group 'org-roam)
|
|
||||||
|
|
||||||
(defcustom org-roam-buffer-prepare-hook '(org-roam-buffer--insert-title
|
|
||||||
org-roam-buffer--insert-backlinks
|
|
||||||
org-roam-buffer--insert-ref-links)
|
|
||||||
"Hook run in the `org-roam-buffer' before it is displayed."
|
|
||||||
:type 'hook
|
|
||||||
:group 'org-roam)
|
|
||||||
|
|
||||||
(defcustom org-roam-buffer-window-parameters nil
|
|
||||||
"Additional window parameters for the `org-roam-buffer' side window.
|
|
||||||
For example: (setq org-roam-buffer-window-parameters '((no-other-window . t)))"
|
|
||||||
:type '(alist)
|
|
||||||
:group 'org-roam)
|
|
||||||
|
|
||||||
(defvar org-roam-buffer--current nil
|
|
||||||
"Currently displayed file in `org-roam' buffer.")
|
|
||||||
|
|
||||||
(defun org-roam-buffer--find-file (file)
|
|
||||||
"Open FILE in the window `org-roam' was called from."
|
|
||||||
(if (and org-roam-last-window (window-valid-p org-roam-last-window))
|
|
||||||
(progn (with-selected-window org-roam-last-window
|
|
||||||
(org-roam--find-file file))
|
|
||||||
(select-window org-roam-last-window))
|
|
||||||
(org-roam--find-file file)))
|
|
||||||
|
|
||||||
(defun org-roam-buffer--insert-title ()
|
|
||||||
"Insert the org-roam-buffer title."
|
|
||||||
(insert (propertize (org-roam--get-title-or-slug
|
|
||||||
(buffer-file-name org-roam-buffer--current))
|
|
||||||
'font-lock-face
|
|
||||||
'org-document-title)))
|
|
||||||
|
|
||||||
(defun org-roam-buffer--pluralize (string number)
|
|
||||||
"Conditionally pluralize STRING if NUMBER is above 1."
|
|
||||||
(let ((l (pcase number
|
|
||||||
((pred (listp)) (length number))
|
|
||||||
((pred (integerp)) number)
|
|
||||||
(wrong-type (signal 'wrong-type-argument
|
|
||||||
`((listp integerp)
|
|
||||||
,wrong-type))))))
|
|
||||||
(concat string (when (> l 1) "s"))))
|
|
||||||
|
|
||||||
(defun org-roam-buffer--insert-ref-links ()
|
|
||||||
"Insert ref backlinks for the current buffer."
|
|
||||||
(when-let ((ref (cdr (with-temp-buffer
|
|
||||||
(insert-buffer-substring org-roam-buffer--current)
|
|
||||||
(org-roam--extract-ref)))))
|
|
||||||
(if-let* ((key-backlinks (org-roam--get-backlinks ref))
|
|
||||||
(grouped-backlinks (--group-by (nth 0 it) key-backlinks)))
|
|
||||||
(progn
|
|
||||||
(insert (let ((l (length key-backlinks)))
|
|
||||||
(format "\n\n* %d %s\n"
|
|
||||||
l (org-roam-buffer--pluralize "Ref Backlink" l))))
|
|
||||||
(dolist (group grouped-backlinks)
|
|
||||||
(let ((file-from (car group))
|
|
||||||
(bls (cdr group)))
|
|
||||||
(insert (format "** [[file:%s][%s]]\n"
|
|
||||||
file-from
|
|
||||||
(org-roam--get-title-or-slug file-from)))
|
|
||||||
(dolist (backlink bls)
|
|
||||||
(pcase-let ((`(,file-from _ ,props) backlink))
|
|
||||||
(insert (propertize (plist-get props :content)
|
|
||||||
'help-echo "mouse-1: visit backlinked note"
|
|
||||||
'file-from file-from
|
|
||||||
'file-from-point (plist-get props :point)))
|
|
||||||
(insert "\n\n"))))))
|
|
||||||
(insert "\n\n* No ref backlinks!"))))
|
|
||||||
|
|
||||||
(defun org-roam-buffer--insert-backlinks ()
|
|
||||||
"Insert the org-roam-buffer backlinks string for the current buffer."
|
|
||||||
(if-let* ((file-path (buffer-file-name org-roam-buffer--current))
|
|
||||||
(backlinks (org-roam--get-backlinks file-path))
|
|
||||||
(grouped-backlinks (--group-by (nth 0 it) backlinks)))
|
|
||||||
(progn
|
|
||||||
(insert (let ((l (length backlinks)))
|
|
||||||
(format "\n\n* %d %s\n"
|
|
||||||
l (org-roam-buffer--pluralize "Backlink" l))))
|
|
||||||
(dolist (group grouped-backlinks)
|
|
||||||
(let ((file-from (car group))
|
|
||||||
(bls (cdr group)))
|
|
||||||
(insert (format "** [[file:%s][%s]]\n"
|
|
||||||
file-from
|
|
||||||
(org-roam--get-title-or-slug file-from)))
|
|
||||||
(dolist (backlink bls)
|
|
||||||
(pcase-let ((`(,file-from _ ,props) backlink))
|
|
||||||
(insert "*** "
|
|
||||||
(if-let ((outline (plist-get props :outline)))
|
|
||||||
(string-join outline " > ")
|
|
||||||
"Top")
|
|
||||||
"\n"
|
|
||||||
(propertize
|
|
||||||
(s-trim (s-replace "\n" " "
|
|
||||||
(plist-get props :content)))
|
|
||||||
'help-echo "mouse-1: visit backlinked note"
|
|
||||||
'file-from file-from
|
|
||||||
'file-from-point (plist-get props :point))
|
|
||||||
"\n\n"))))))
|
|
||||||
(insert "\n\n* No backlinks!")))
|
|
||||||
|
|
||||||
(defun org-roam-buffer-update ()
|
|
||||||
"Update the `org-roam-buffer'."
|
|
||||||
(org-roam-db--ensure-built)
|
|
||||||
(let* ((source-org-roam-directory org-roam-directory))
|
|
||||||
(with-current-buffer org-roam-buffer
|
|
||||||
;; When dir-locals.el is used to override org-roam-directory,
|
|
||||||
;; org-roam-buffer should have a different local org-roam-directory and
|
|
||||||
;; default-directory, as relative links are relative from the overridden
|
|
||||||
;; org-roam-directory.
|
|
||||||
(setq-local org-roam-directory source-org-roam-directory)
|
|
||||||
(setq-local default-directory source-org-roam-directory)
|
|
||||||
;; Locally overwrite the file opening function to re-use the
|
|
||||||
;; last window org-roam was called from
|
|
||||||
(setq-local org-link-frame-setup
|
|
||||||
(cons '(file . org-roam--find-file) org-link-frame-setup))
|
|
||||||
(let ((inhibit-read-only t))
|
|
||||||
(erase-buffer)
|
|
||||||
(unless (eq major-mode 'org-mode)
|
|
||||||
(org-mode))
|
|
||||||
(unless org-roam-backlinks-mode
|
|
||||||
(org-roam-backlinks-mode))
|
|
||||||
(make-local-variable 'org-return-follows-link)
|
|
||||||
(setq org-return-follows-link t)
|
|
||||||
(run-hooks 'org-roam-buffer-prepare-hook)
|
|
||||||
(read-only-mode 1)))))
|
|
||||||
|
|
||||||
|
|
||||||
(cl-defun org-roam-buffer--update-maybe (&key redisplay)
|
|
||||||
"Reconstructs `org-roam-buffer'.
|
|
||||||
This needs to be quick or infrequent, because this is run at
|
|
||||||
`post-command-hook'. If REDISPLAY, force an update of
|
|
||||||
`org-roam-buffer'."
|
|
||||||
(let ((buffer (window-buffer)))
|
|
||||||
(when (and (or redisplay
|
|
||||||
(not (eq org-roam-buffer--current buffer)))
|
|
||||||
(eq 'visible (org-roam-buffer--visibility))
|
|
||||||
(buffer-local-value 'buffer-file-truename buffer))
|
|
||||||
(setq org-roam-buffer--current buffer)
|
|
||||||
(org-roam-buffer-update))))
|
|
||||||
|
|
||||||
;;;; Toggling the org-roam buffer
|
|
||||||
(define-inline org-roam-buffer--visibility ()
|
|
||||||
"Return whether the current visibility state of the org-roam buffer.
|
|
||||||
Valid states are 'visible, 'exists and 'none."
|
|
||||||
(declare (side-effect-free t))
|
|
||||||
(inline-quote
|
|
||||||
(cond
|
|
||||||
((get-buffer-window org-roam-buffer) 'visible)
|
|
||||||
((get-buffer org-roam-buffer) 'exists)
|
|
||||||
(t 'none))))
|
|
||||||
|
|
||||||
(defun org-roam-buffer--set-width (width)
|
|
||||||
"Set the width of `org-roam-buffer' to `WIDTH'."
|
|
||||||
(unless (one-window-p)
|
|
||||||
(let ((window-size-fixed)
|
|
||||||
(w (max width window-min-width)))
|
|
||||||
(cond
|
|
||||||
((> (window-width) w)
|
|
||||||
(shrink-window-horizontally (- (window-width) w)))
|
|
||||||
((< (window-width) w)
|
|
||||||
(enlarge-window-horizontally (- w (window-width))))))))
|
|
||||||
|
|
||||||
(defun org-roam-buffer--set-height (height)
|
|
||||||
"Set the height of `org-roam-buffer' to `HEIGHT'."
|
|
||||||
(unless (one-window-p)
|
|
||||||
(let ((window-size-fixed)
|
|
||||||
(h (max height window-min-height)))
|
|
||||||
(cond
|
|
||||||
((> (window-height) h)
|
|
||||||
(shrink-window (- (window-height) h)))
|
|
||||||
((< (window-height) h)
|
|
||||||
(enlarge-window (- h (window-height))))))))
|
|
||||||
|
|
||||||
(defun org-roam-buffer--get-create ()
|
|
||||||
"Set up the `org-roam' buffer at `org-roam-buffer-position'."
|
|
||||||
(let ((position
|
|
||||||
(if (member org-roam-buffer-position '(right left top bottom))
|
|
||||||
org-roam-buffer-position
|
|
||||||
(let ((text-quoting-style 'grave))
|
|
||||||
(lwarn '(org-roam) :error
|
|
||||||
"Invalid org-roam-buffer-position: %s. Defaulting to \\='right"
|
|
||||||
org-roam-buffer-position))
|
|
||||||
'right)))
|
|
||||||
(save-selected-window
|
|
||||||
(-> (get-buffer-create org-roam-buffer)
|
|
||||||
(display-buffer-in-side-window
|
|
||||||
`((side . ,position)
|
|
||||||
(window-parameters . ,org-roam-buffer-window-parameters)))
|
|
||||||
(select-window))
|
|
||||||
(pcase position
|
|
||||||
((or 'right 'left)
|
|
||||||
(org-roam-buffer--set-width
|
|
||||||
(round (* (frame-width) org-roam-buffer-width))))
|
|
||||||
((or 'top 'bottom)
|
|
||||||
(org-roam-buffer--set-height
|
|
||||||
(round (* (frame-height) org-roam-buffer-height))))))))
|
|
||||||
|
|
||||||
(defun org-roam-buffer-activate ()
|
|
||||||
"Activate display of the `org-roam-buffer'."
|
|
||||||
(interactive)
|
|
||||||
(unless org-roam-mode (org-roam-mode))
|
|
||||||
(setq org-roam-last-window (get-buffer-window))
|
|
||||||
(org-roam-buffer--get-create))
|
|
||||||
|
|
||||||
(defun org-roam-buffer-deactivate ()
|
|
||||||
"Deactivate display of the `org-roam-buffer'."
|
|
||||||
(interactive)
|
|
||||||
(setq org-roam-last-window (get-buffer-window))
|
|
||||||
(delete-window (get-buffer-window org-roam-buffer)))
|
|
||||||
|
|
||||||
(defun org-roam-buffer-toggle-display ()
|
|
||||||
"Toggle display of the `org-roam-buffer'."
|
|
||||||
(interactive)
|
|
||||||
(pcase (org-roam-buffer--visibility)
|
|
||||||
('visible (org-roam-buffer-deactivate))
|
|
||||||
((or 'exists 'none) (org-roam-buffer-activate))))
|
|
||||||
|
|
||||||
(provide 'org-roam-buffer)
|
|
||||||
|
|
||||||
;;; org-roam-buffer.el ends here
|
|
1100
org-roam-capture.el
1100
org-roam-capture.el
File diff suppressed because it is too large
Load Diff
@ -5,8 +5,8 @@
|
|||||||
;; Author: Jethro Kuan <jethrokuan95@gmail.com>
|
;; Author: Jethro Kuan <jethrokuan95@gmail.com>
|
||||||
;; URL: https://github.com/org-roam/org-roam
|
;; URL: https://github.com/org-roam/org-roam
|
||||||
;; Keywords: org-mode, roam, convenience
|
;; Keywords: org-mode, roam, convenience
|
||||||
;; Version: 1.2.1
|
;; Version: 2.0.0
|
||||||
;; Package-Requires: ((emacs "26.1") (dash "2.13") (f "0.17.2") (s "1.12.0") (org "9.3") (emacsql "3.0.0") (emacsql-sqlite3 "1.0.0"))
|
;; Package-Requires: ((emacs "26.1") (dash "2.13") (f "0.17.2") (org "9.4") (emacsql "3.0.0") (emacsql-sqlite "1.0.0") (magit-section "2.90.1"))
|
||||||
|
|
||||||
;; This file is NOT part of GNU Emacs.
|
;; This file is NOT part of GNU Emacs.
|
||||||
|
|
||||||
@ -34,74 +34,7 @@
|
|||||||
;;;; Library Requires
|
;;;; Library Requires
|
||||||
|
|
||||||
;;; Obsolete aliases (remove after next major release)
|
;;; Obsolete aliases (remove after next major release)
|
||||||
;;;; Functions
|
;;; Obsolete functions
|
||||||
(define-obsolete-function-alias 'org-roam--capture-get-point 'org-roam-capture--get-point
|
|
||||||
"org-roam 1.0.0")
|
|
||||||
(define-obsolete-function-alias 'org-roam-build-cache 'org-roam-db-build-cache
|
|
||||||
"org-roam 1.0.0")
|
|
||||||
(define-obsolete-function-alias 'org-roam-sql 'org-roam-db-query
|
|
||||||
"org-roam 1.0.0")
|
|
||||||
(define-obsolete-function-alias 'org-roam--get-db 'org-roam-db--get
|
|
||||||
"org-roam 1.0.0")
|
|
||||||
(define-obsolete-function-alias 'org-roam--db-clear 'org-roam-db--clear
|
|
||||||
"org-roam 1.0.0")
|
|
||||||
(define-obsolete-function-alias 'org-roam-show-graph 'org-roam-graph-show
|
|
||||||
"org-roam 1.0.0")
|
|
||||||
(define-obsolete-function-alias 'org-roam--maybe-update-buffer
|
|
||||||
'org-roam-buffer--update-maybe "org-roam 1.0.0")
|
|
||||||
(define-obsolete-function-alias 'org-roam--current-visibility
|
|
||||||
'org-roam-buffer--visibility "org-roam 1.0.0")
|
|
||||||
(define-obsolete-function-alias 'org-roam-update 'org-roam-buffer-update
|
|
||||||
"org-roam 1.0.0")
|
|
||||||
(define-obsolete-function-alias 'org-roam--set-width 'org-roam-buffer--set-width
|
|
||||||
"org-roam 1.0.0")
|
|
||||||
(define-obsolete-function-alias 'org-roam--set-height 'org-roam-buffer--set-height
|
|
||||||
"org-roam 1.0.0")
|
|
||||||
(define-obsolete-function-alias 'org-roam--set-up-buffer 'org-roam-buffer--get-create
|
|
||||||
"org-roam 1.0.0")
|
|
||||||
(define-obsolete-function-alias 'org-roam-today 'org-roam-dailies-today
|
|
||||||
"org-roam 1.0.0")
|
|
||||||
(define-obsolete-function-alias 'org-roam-tomorrow 'org-roam-dailies-tomorrow
|
|
||||||
"org-roam 1.0.0")
|
|
||||||
(define-obsolete-function-alias 'org-roam-yesterday 'org-roam-dailies-yesterday
|
|
||||||
"org-roam 1.0.0")
|
|
||||||
(define-obsolete-function-alias 'org-roam-date 'org-roam-dailies-date
|
|
||||||
"org-roam 1.0.0")
|
|
||||||
(define-obsolete-function-alias 'org-roam-graph-show 'org-roam-graph
|
|
||||||
"org-roam 1.0.0")
|
|
||||||
(define-obsolete-function-alias 'org-roam-graph-build 'org-roam-graph
|
|
||||||
"org-roam 1.0.0")
|
|
||||||
(define-obsolete-function-alias 'org-roam-find-index 'org-roam-jump-to-index
|
|
||||||
"org-roam 1.1.0")
|
|
||||||
(define-obsolete-function-alias 'org-roam--pluralize 'org-roam-buffer--pluralize
|
|
||||||
"org-roam 1.1.0")
|
|
||||||
(define-obsolete-function-alias 'org-roam--capture 'org-roam-capture--capture
|
|
||||||
"org-roam 1.1.0")
|
|
||||||
(define-obsolete-function-alias 'org-roam-db--maybe-update 'org-roam-db--update-maybe
|
|
||||||
"org-roam 1.1.0")
|
|
||||||
(define-obsolete-function-alias 'org-roam-db--clear 'org-roam-db-clear
|
|
||||||
"org-roam 1.2.0")
|
|
||||||
|
|
||||||
(when (version< (org-version) "9.3")
|
|
||||||
(defalias 'org-link-make-string 'org-make-link-string))
|
|
||||||
|
|
||||||
;;;; Variables
|
|
||||||
(define-obsolete-variable-alias 'org-roam-graphviz-extra-options
|
|
||||||
'org-roam-graph-extra-config "org-roam 1.0.0")
|
|
||||||
(define-obsolete-variable-alias 'org-roam-grapher-extra-options
|
|
||||||
'org-roam-graph-extra-config "org-roam 1.0.0")
|
|
||||||
(define-obsolete-variable-alias 'org-roam-graph-node-shape
|
|
||||||
'org-roam-graph-node-extra-config "org-roam 1.0.0")
|
|
||||||
(define-obsolete-variable-alias 'org-roam--db-connection
|
|
||||||
'org-roam-db--connection "org-roam 1.0.0")
|
|
||||||
(define-obsolete-variable-alias 'org-roam--current-buffer
|
|
||||||
'org-roam-buffer--current "org-roam 1.0.0")
|
|
||||||
(define-obsolete-variable-alias 'org-roam-date-title-format
|
|
||||||
'org-roam-dailies-capture-templates "org-roam 1.0.0")
|
|
||||||
(define-obsolete-variable-alias 'org-roam-date-filename-format
|
|
||||||
'org-roam-dailies-capture-templates "org-roam 1.0.0")
|
|
||||||
(make-obsolete-variable 'org-roam-buffer-no-delete-other-windows
|
|
||||||
'org-roam-buffer-window-parameters "org-roam 1.1.1")
|
|
||||||
|
|
||||||
(provide 'org-roam-compat)
|
(provide 'org-roam-compat)
|
||||||
|
|
||||||
|
@ -5,9 +5,8 @@
|
|||||||
;; Author: Jethro Kuan <jethrokuan95@gmail.com>
|
;; Author: Jethro Kuan <jethrokuan95@gmail.com>
|
||||||
;; URL: https://github.com/org-roam/org-roam
|
;; URL: https://github.com/org-roam/org-roam
|
||||||
;; Keywords: org-mode, roam, convenience
|
;; Keywords: org-mode, roam, convenience
|
||||||
;; Version: 1.2.1
|
;; Version: 2.0.0
|
||||||
;; Package-Requires: ((emacs "26.1") (dash "2.13") (f "0.17.2") (s "1.12.0") (org "9.3") (emacsql "3.0.0") (emacsql-sqlite3 "1.0.0"))
|
;; Package-Requires: ((emacs "26.1") (dash "2.13") (f "0.17.2") (org "9.4") (emacsql "3.0.0") (emacsql-sqlite "1.0.0") (magit-section "2.90.1"))
|
||||||
|
|
||||||
;; This file is NOT part of GNU Emacs.
|
;; This file is NOT part of GNU Emacs.
|
||||||
|
|
||||||
;; This program is free software; you can redistribute it and/or modify
|
;; This program is free software; you can redistribute it and/or modify
|
||||||
@ -27,84 +26,81 @@
|
|||||||
|
|
||||||
;;; Commentary:
|
;;; Commentary:
|
||||||
;;
|
;;
|
||||||
;; This library provides completion for org-roam.
|
;; This library provides completion-at-point functions for Org-roam.
|
||||||
|
;;
|
||||||
|
;; The two main functions provided to capf are:
|
||||||
|
;;
|
||||||
|
;; `org-roam-complete-link-at-point' provides completions to nodes
|
||||||
|
;; within link brackets
|
||||||
|
;;
|
||||||
|
;; `org-roam-complete-everywhere' provides completions for nodes everywhere,
|
||||||
|
;; matching the symbol at point
|
||||||
|
;;
|
||||||
;;; Code:
|
;;; Code:
|
||||||
;;;; Library Requires
|
|
||||||
(require 'cl-lib)
|
(require 'cl-lib)
|
||||||
(require 's)
|
(require 'org-element)
|
||||||
|
|
||||||
(defvar helm-pattern)
|
(declare-function org-roam--get-titles "org-roam")
|
||||||
(declare-function helm "ext:helm")
|
|
||||||
(declare-function helm-make-source "ext:helm-source" (name class &rest args) t)
|
|
||||||
|
|
||||||
(defcustom org-roam-completion-system 'default
|
(defcustom org-roam-completion-everywhere nil
|
||||||
"The completion system to be used by `org-roam'."
|
"When non-nil, provide link completion matching outside of Org links."
|
||||||
:type '(radio
|
:group 'org-roam
|
||||||
(const :tag "Default" default)
|
:type 'boolean)
|
||||||
(const :tag "Ido" ido)
|
|
||||||
(const :tag "Ivy" ivy)
|
|
||||||
(const :tag "Helm" helm)
|
|
||||||
(function :tag "Custom function"))
|
|
||||||
:group 'org-roam)
|
|
||||||
|
|
||||||
(defun org-roam-completion--helm-candidate-transformer (candidates _source)
|
(defvar org-roam-completion-functions (list #'org-roam-complete-link-at-point
|
||||||
"Transforms CANDIDATES for Helm-based completing read.
|
#'org-roam-complete-everywhere)
|
||||||
SOURCE is not used."
|
"List of functions to be used with `completion-at-point' for Org-roam.")
|
||||||
(let ((prefix (propertize "[?] "
|
|
||||||
'face 'helm-ff-prefix)))
|
|
||||||
(cons (propertize helm-pattern
|
|
||||||
'display (concat prefix helm-pattern))
|
|
||||||
candidates)))
|
|
||||||
|
|
||||||
(cl-defun org-roam-completion--completing-read (prompt choices &key
|
(defconst org-roam-bracket-completion-re
|
||||||
require-match initial-input
|
"\\[\\[\\(\\(?:roam:\\)?\\)\\([^z-a]*\\)]]"
|
||||||
action)
|
"Regex for completion within link brackets.
|
||||||
"Present a PROMPT with CHOICES and optional INITIAL-INPUT.
|
We use this as a substitute for `org-link-bracket-re', because
|
||||||
If REQUIRE-MATCH is t, the user must select one of the CHOICES.
|
`org-link-bracket-re' requires content within the brackets for a match.")
|
||||||
Return user choice."
|
|
||||||
(let (res)
|
(defun org-roam-complete-everywhere ()
|
||||||
(setq res
|
"Provides completions for links for any word at point.
|
||||||
(cond
|
This is a `completion-at-point' function, and is active when
|
||||||
((eq org-roam-completion-system 'ido)
|
`org-roam-completion-everywhere' is non-nil."
|
||||||
(let ((candidates (mapcar #'car choices)))
|
(when (and org-roam-completion-everywhere
|
||||||
(ido-completing-read prompt candidates nil require-match initial-input)))
|
(thing-at-point 'word)
|
||||||
((eq org-roam-completion-system 'default)
|
(not (save-match-data (org-in-regexp org-link-any-re))))
|
||||||
(completing-read prompt choices nil require-match initial-input))
|
(let ((bounds (bounds-of-thing-at-point 'word)))
|
||||||
((eq org-roam-completion-system 'ivy)
|
(list (car bounds) (cdr bounds)
|
||||||
(if (fboundp 'ivy-read)
|
(completion-table-dynamic
|
||||||
(ivy-read prompt choices
|
(lambda (_)
|
||||||
:initial-input initial-input
|
(funcall #'org-roam--get-titles)))
|
||||||
:require-match require-match
|
:exit-function
|
||||||
:action (prog1 action
|
(lambda (str _status)
|
||||||
(setq action nil))
|
(delete-char (- (length str)))
|
||||||
:caller 'org-roam--completing-read)
|
(insert "[[roam:" str "]]"))))))
|
||||||
(user-error "Please install ivy from \
|
|
||||||
https://github.com/abo-abo/swiper")))
|
(defun org-roam-complete-link-at-point ()
|
||||||
((eq org-roam-completion-system 'helm)
|
"Do appropriate completion for the link at point."
|
||||||
(unless (and (fboundp 'helm)
|
(let (roam-p start end)
|
||||||
(fboundp 'helm-make-source))
|
(when (org-in-regexp org-roam-bracket-completion-re 1)
|
||||||
(user-error "Please install helm from \
|
(setq roam-p (not (string-blank-p (match-string 1)))
|
||||||
https://github.com/emacs-helm/helm"))
|
start (match-beginning 2)
|
||||||
(let ((source (helm-make-source prompt 'helm-source-sync
|
end (match-end 2))
|
||||||
:candidates (mapcar #'car choices)
|
(list start end
|
||||||
:filtered-candidate-transformer
|
(completion-table-dynamic
|
||||||
(and (not require-match)
|
(lambda (_)
|
||||||
#'org-roam-completion--helm-candidate-transformer)))
|
(funcall #'org-roam--get-titles)))
|
||||||
(buf (concat "*org-roam "
|
:exit-function
|
||||||
(s-downcase (s-chop-suffix ":" (s-trim prompt)))
|
(lambda (str &rest _)
|
||||||
"*")))
|
(delete-char (- 0 (length str)))
|
||||||
(or (helm :sources source
|
(insert (concat (unless roam-p "roam:")
|
||||||
:action (if action
|
str))
|
||||||
(prog1 action
|
(forward-char 2))))))
|
||||||
(setq action nil))
|
|
||||||
#'identity)
|
(defun org-roam-complete-at-point ()
|
||||||
:prompt prompt
|
"."
|
||||||
:input initial-input
|
(run-hook-with-args-until-success 'org-roam-completion-functions))
|
||||||
:buffer buf)
|
|
||||||
(keyboard-quit))))))
|
(defun org-roam--register-completion-functions ()
|
||||||
(if action
|
"."
|
||||||
(funcall action res)
|
(add-hook 'completion-at-point-functions #'org-roam-complete-at-point nil t))
|
||||||
res)))
|
|
||||||
|
(add-hook 'org-roam-find-file-hook #'org-roam--register-completion-functions)
|
||||||
|
|
||||||
(provide 'org-roam-completion)
|
(provide 'org-roam-completion)
|
||||||
|
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
;;; org-roam-dailies.el --- Daily notes for Org-roam -*- coding: utf-8; lexical-binding: t; -*-
|
;;; org-roam-dailies.el --- Daily-notes for Org-roam -*- coding: utf-8; lexical-binding: t; -*-
|
||||||
;;;
|
;;;
|
||||||
;; Copyright © 2020 Jethro Kuan <jethrokuan95@gmail.com>
|
;; Copyright © 2020 Jethro Kuan <jethrokuan95@gmail.com>
|
||||||
|
;; Copyright © 2020 Leo Vivier <leo.vivier+dev@gmail.com>
|
||||||
|
|
||||||
;; Author: Jethro Kuan <jethrokuan95@gmail.com>
|
;; Author: Jethro Kuan <jethrokuan95@gmail.com>
|
||||||
|
;; Leo Vivier <leo.vivier+dev@gmail.com>
|
||||||
;; URL: https://github.com/org-roam/org-roam
|
;; URL: https://github.com/org-roam/org-roam
|
||||||
;; Keywords: org-mode, roam, convenience
|
;; Keywords: org-mode, roam, convenience
|
||||||
;; Version: 1.2.1
|
;; Version: 2.0.0
|
||||||
;; Package-Requires: ((emacs "26.1") (dash "2.13") (f "0.17.2") (s "1.12.0") (org "9.3") (emacsql "3.0.0") (emacsql-sqlite3 "1.0.0"))
|
;; Package-Requires: ((emacs "26.1") (dash "2.13") (f "0.17.2") (org "9.4") (emacsql "3.0.0") (emacsql-sqlite "1.0.0") (magit-section "2.90.1"))
|
||||||
|
|
||||||
;; This file is NOT part of GNU Emacs.
|
;; This file is NOT part of GNU Emacs.
|
||||||
|
|
||||||
@ -27,111 +29,322 @@
|
|||||||
|
|
||||||
;;; Commentary:
|
;;; Commentary:
|
||||||
;;
|
;;
|
||||||
;; This library provides functionality for creating daily notes. This is a
|
;; This library provides functionality for creating daily-notes. This is a
|
||||||
;; concept borrowed from Roam Research.
|
;; concept borrowed from Roam Research.
|
||||||
;;
|
;;
|
||||||
;;; Code:
|
;;; Code:
|
||||||
;;; Library Requires
|
;;; Library Requires
|
||||||
(require 'org-capture)
|
(require 'org-capture)
|
||||||
(require 'org-roam-capture)
|
(require 'org-roam-capture)
|
||||||
(require 'org-roam-macs)
|
(require 'f)
|
||||||
|
|
||||||
|
;;;; Declarations
|
||||||
|
(defvar org-roam-directory)
|
||||||
|
(defvar org-roam-file-extensions)
|
||||||
|
(declare-function org-roam-file-p "org-roam")
|
||||||
|
|
||||||
|
;;;; Faces
|
||||||
|
(defface org-roam-dailies-calendar-note
|
||||||
|
'((t :inherit (org-link) :underline nil))
|
||||||
|
"Face for dates with a daily-note in the calendar."
|
||||||
|
:group 'org-roam-faces)
|
||||||
|
|
||||||
|
;;;; Customizable variables
|
||||||
|
(defcustom org-roam-dailies-directory "daily/"
|
||||||
|
"Path to daily-notes.
|
||||||
|
This path is relative to `org-roam-directory'."
|
||||||
|
:group 'org-roam
|
||||||
|
:type 'string)
|
||||||
|
|
||||||
|
(defcustom org-roam-dailies-find-file-hook nil
|
||||||
|
"Hook that is run right after navigating to a daily-note."
|
||||||
|
:group 'org-roam
|
||||||
|
:type 'hook)
|
||||||
|
|
||||||
(defcustom org-roam-dailies-capture-templates
|
(defcustom org-roam-dailies-capture-templates
|
||||||
'(("d" "daily" plain (function org-roam-capture--get-point)
|
`(("d" "default" entry
|
||||||
""
|
"* %?"
|
||||||
:immediate-finish t
|
:if-new (file+head "%<%Y-%m-%d>.org"
|
||||||
:file-name "%<%Y-%m-%d>"
|
"#+title: %<%Y-%m-%d>\n")))
|
||||||
:head "#+title: %<%Y-%m-%d>"))
|
"Capture templates for daily-notes in Org-roam.
|
||||||
"Capture templates for daily notes in Org-roam."
|
See `org-roam-capture-templates' for the template documentation."
|
||||||
:group 'org-roam
|
:group 'org-roam
|
||||||
;; Adapted from `org-capture-templates'
|
:type '(repeat
|
||||||
:type
|
(choice (list :tag "Multikey description"
|
||||||
'(repeat
|
(string :tag "Keys ")
|
||||||
(choice :value ("d" "daily" plain (function org-roam-capture--get-point)
|
(string :tag "Description"))
|
||||||
""
|
(list :tag "Template entry"
|
||||||
:immediate-finish t
|
(string :tag "Keys ")
|
||||||
:file-name "%<%Y-%m-%d>"
|
(string :tag "Description ")
|
||||||
:head "#+title: %<%Y-%m-%d>")
|
(choice :tag "Capture Type " :value entry
|
||||||
(list :tag "Multikey description"
|
(const :tag "Org entry" entry)
|
||||||
(string :tag "Keys ")
|
(const :tag "Plain list item" item)
|
||||||
(string :tag "Description"))
|
(const :tag "Checkbox item" checkitem)
|
||||||
(list :tag "Template entry"
|
(const :tag "Plain text" plain)
|
||||||
(string :tag "Keys ")
|
(const :tag "Table line" table-line))
|
||||||
(string :tag "Description ")
|
(choice :tag "Template "
|
||||||
(const :format "" plain)
|
(string)
|
||||||
(const :format "" (function org-roam-capture--get-point))
|
(list :tag "File"
|
||||||
(choice :tag "Template "
|
(const :format "" file)
|
||||||
(string :tag "String"
|
(file :tag "Template file"))
|
||||||
:format "String:\n \
|
(list :tag "Function"
|
||||||
Template string :\n%v")
|
(const :format "" function)
|
||||||
(list :tag "File"
|
(function :tag "Template function")))
|
||||||
(const :format "" file)
|
(plist :inline t
|
||||||
(file :tag "Template file "))
|
;; Give the most common options as checkboxes
|
||||||
(list :tag "Function"
|
:options (((const :format "%v " :if-new)
|
||||||
(const :format "" function)
|
(choice :tag "Node location"
|
||||||
(function :tag "Template function ")))
|
(list :tag "File"
|
||||||
(const :format "" :immediate-finish) (const :format "" t)
|
(const :format "" file)
|
||||||
(const :format "File name format :" :file-name)
|
(string :tag " File"))
|
||||||
(string :format " %v" :value "#+title: ${title}\n")
|
(list :tag "File & Head Content"
|
||||||
(const :format "Header format :" :head)
|
(const :format "" file+head)
|
||||||
(string :format "\n%v" :value "%<%Y%m%d%H%M%S>-${slug}")
|
(string :tag " File")
|
||||||
(plist :inline t
|
(string :tag " Head Content"))
|
||||||
:tag "Options"
|
(list :tag "File & Outline path"
|
||||||
;; Give the most common options as checkboxes
|
(const :format "" file+olp)
|
||||||
:options
|
(string :tag " File")
|
||||||
(((const :format "%v " :prepend) (const t))
|
(list :tag "Outline path"
|
||||||
((const :format "%v " :jump-to-captured) (const t))
|
(repeat (string :tag "Headline"))))
|
||||||
((const :format "%v " :empty-lines) (const 1))
|
(list :tag "File & Head Content & Outline path"
|
||||||
((const :format "%v " :empty-lines-before) (const 1))
|
(const :format "" file+head+olp)
|
||||||
((const :format "%v " :empty-lines-after) (const 1))
|
(string :tag " File")
|
||||||
((const :format "%v " :clock-in) (const t))
|
(string :tag " Head Content")
|
||||||
((const :format "%v " :clock-keep) (const t))
|
(list :tag "Outline path"
|
||||||
((const :format "%v " :clock-resume) (const t))
|
(repeat (string :tag "Headline"))))))
|
||||||
((const :format "%v " :time-prompt) (const t))
|
((const :format "%v " :prepend) (const t))
|
||||||
((const :format "%v " :tree-type) (const week))
|
((const :format "%v " :immediate-finish) (const t))
|
||||||
((const :format "%v " :table-line-pos) (string))
|
((const :format "%v " :jump-to-captured) (const t))
|
||||||
((const :format "%v " :kill-buffer) (const t))
|
((const :format "%v " :empty-lines) (const 1))
|
||||||
((const :format "%v " :unnarrowed) (const t))))))))
|
((const :format "%v " :empty-lines-before) (const 1))
|
||||||
|
((const :format "%v " :empty-lines-after) (const 1))
|
||||||
|
((const :format "%v " :clock-in) (const t))
|
||||||
|
((const :format "%v " :clock-keep) (const t))
|
||||||
|
((const :format "%v " :clock-resume) (const t))
|
||||||
|
((const :format "%v " :time-prompt) (const t))
|
||||||
|
((const :format "%v " :tree-type) (const week))
|
||||||
|
((const :format "%v " :unnarrowed) (const t))
|
||||||
|
((const :format "%v " :table-line-pos) (string))
|
||||||
|
((const :format "%v " :kill-buffer) (const t))))))))
|
||||||
|
|
||||||
;; Declarations
|
;;;###autoload
|
||||||
(defvar org-roam-mode)
|
(defun org-roam-dailies-find-directory ()
|
||||||
(declare-function org-roam--file-path-from-id "org-roam")
|
"Find and open `org-roam-dailies-directory'."
|
||||||
(declare-function org-roam-mode "org-roam")
|
|
||||||
|
|
||||||
(defun org-roam-dailies--file-for-time (time)
|
|
||||||
"Create and find file for TIME."
|
|
||||||
(let ((org-roam-capture-templates org-roam-dailies-capture-templates)
|
|
||||||
(org-roam-capture--info (list (cons 'time time)))
|
|
||||||
(org-roam-capture--context 'dailies))
|
|
||||||
(setq org-roam-capture-additional-template-props (list :finalize 'find-file))
|
|
||||||
(org-roam--with-template-error 'org-roam-dailies-capture-templates
|
|
||||||
(org-roam-capture--capture))))
|
|
||||||
|
|
||||||
(defun org-roam-dailies-today ()
|
|
||||||
"Create and find the daily note for today."
|
|
||||||
(interactive)
|
(interactive)
|
||||||
(unless org-roam-mode (org-roam-mode))
|
(find-file (expand-file-name org-roam-dailies-directory org-roam-directory)))
|
||||||
(org-roam-dailies--file-for-time (current-time)))
|
|
||||||
|
|
||||||
(defun org-roam-dailies-tomorrow (n)
|
(defun org-roam-dailies--daily-note-p (&optional file)
|
||||||
"Create and find the daily note for tomorrow.
|
"Return t if FILE is an Org-roam daily-note, nil otherwise.
|
||||||
With numeric argument N, use N days in the future."
|
If FILE is not specified, use the current buffer's file-path."
|
||||||
(interactive "p")
|
(when-let ((path (expand-file-name
|
||||||
(unless org-roam-mode (org-roam-mode))
|
(or file
|
||||||
(org-roam-dailies--file-for-time (time-add (* n 86400) (current-time))))
|
(buffer-file-name (buffer-base-buffer)))))
|
||||||
|
(directory (expand-file-name org-roam-dailies-directory org-roam-directory)))
|
||||||
|
(setq path (expand-file-name path))
|
||||||
|
(save-match-data
|
||||||
|
(and
|
||||||
|
(org-roam-file-p path)
|
||||||
|
(f-descendant-of-p path directory)))))
|
||||||
|
|
||||||
(defun org-roam-dailies-yesterday (n)
|
(defun org-roam-dailies--capture (time &optional goto)
|
||||||
"Create and find the file for yesterday.
|
"Capture an entry in a daily-note for TIME, creating it if necessary.
|
||||||
With numeric argument N, use N days in the past."
|
When GOTO is non-nil, go the note without creating an entry."
|
||||||
(interactive "p")
|
(let ((org-roam-directory (expand-file-name org-roam-dailies-directory org-roam-directory)))
|
||||||
(unless org-roam-mode (org-roam-mode))
|
(org-roam-capture- :goto (when goto '(4))
|
||||||
(org-roam-dailies-tomorrow (- n)))
|
:node (org-roam-node-create)
|
||||||
|
:templates org-roam-dailies-capture-templates
|
||||||
|
:props (list :override-default-time time)))
|
||||||
|
(when goto (run-hooks 'org-roam-dailies-find-file-hook)))
|
||||||
|
|
||||||
(defun org-roam-dailies-date ()
|
;;;; Commands
|
||||||
"Create the file for any date using the calendar interface."
|
;;; Today
|
||||||
|
;;;###autoload
|
||||||
|
(defun org-roam-dailies-capture-today (&optional goto)
|
||||||
|
"Create an entry in the daily-note for today.
|
||||||
|
When GOTO is non-nil, go the note without creating an entry."
|
||||||
|
(interactive "P")
|
||||||
|
(org-roam-dailies--capture (current-time) goto))
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(defun org-roam-dailies-goto-today ()
|
||||||
|
"Find the daily-note for today, creating it if necessary."
|
||||||
(interactive)
|
(interactive)
|
||||||
(let ((time (org-read-date nil 'to-time nil "Date: ")))
|
(org-roam-dailies-capture-today t))
|
||||||
(org-roam-dailies--file-for-time time)))
|
|
||||||
|
;;; Tomorrow
|
||||||
|
;;;###autoload
|
||||||
|
(defun org-roam-dailies-capture-tomorrow (n &optional goto)
|
||||||
|
"Create an entry in the daily-note for tomorrow.
|
||||||
|
|
||||||
|
With numeric argument N, use the daily-note N days in the future.
|
||||||
|
|
||||||
|
With a `C-u' prefix or when GOTO is non-nil, go the note without
|
||||||
|
creating an entry."
|
||||||
|
(interactive "p")
|
||||||
|
(org-roam-dailies--capture (time-add (* n 86400) (current-time)) goto))
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(defun org-roam-dailies-goto-tomorrow (n)
|
||||||
|
"Find the daily-note for tomorrow, creating it if necessary.
|
||||||
|
|
||||||
|
With numeric argument N, use the daily-note N days in the
|
||||||
|
future."
|
||||||
|
(interactive "p")
|
||||||
|
(org-roam-dailies-capture-tomorrow n t))
|
||||||
|
|
||||||
|
;;; Yesterday
|
||||||
|
;;;###autoload
|
||||||
|
(defun org-roam-dailies-capture-yesterday (n &optional goto)
|
||||||
|
"Create an entry in the daily-note for yesteday.
|
||||||
|
|
||||||
|
With numeric argument N, use the daily-note N days in the past.
|
||||||
|
|
||||||
|
When GOTO is non-nil, go the note without creating an entry."
|
||||||
|
(interactive "p")
|
||||||
|
(org-roam-dailies-capture-tomorrow (- n) goto))
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(defun org-roam-dailies-goto-yesterday (n)
|
||||||
|
"Find the daily-note for yesterday, creating it if necessary.
|
||||||
|
|
||||||
|
With numeric argument N, use the daily-note N days in the
|
||||||
|
future."
|
||||||
|
(interactive "p")
|
||||||
|
(org-roam-dailies-capture-tomorrow (- n) t))
|
||||||
|
|
||||||
|
;;; Calendar
|
||||||
|
(defun org-roam-dailies-calendar--file-to-date (&optional file)
|
||||||
|
"Convert FILE to date.
|
||||||
|
Return (MONTH DAY YEAR)."
|
||||||
|
(let ((file (or file
|
||||||
|
(buffer-base-buffer (buffer-file-name)))))
|
||||||
|
(cl-destructuring-bind (_ _ _ d m y _ _ _)
|
||||||
|
(org-parse-time-string
|
||||||
|
(file-name-sans-extension
|
||||||
|
(file-name-nondirectory file)))
|
||||||
|
(list m d y))))
|
||||||
|
|
||||||
|
(defun org-roam-dailies-calendar--date-to-time (date)
|
||||||
|
"Convert DATE as returned from then calendar (MONTH DAY YEAR) to a time."
|
||||||
|
(encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date)))
|
||||||
|
|
||||||
|
(defun org-roam-dailies-calendar-mark-entries ()
|
||||||
|
"Mark days in the calendar for which a daily-note is present."
|
||||||
|
(when (file-exists-p (expand-file-name org-roam-dailies-directory org-roam-directory))
|
||||||
|
(dolist (date (mapcar #'org-roam-dailies-calendar--file-to-date
|
||||||
|
(org-roam-dailies--list-files)))
|
||||||
|
(when (calendar-date-is-visible-p date)
|
||||||
|
(calendar-mark-visible-date date 'org-roam-dailies-calendar-note)))))
|
||||||
|
|
||||||
|
;;; Date
|
||||||
|
;;;###autoload
|
||||||
|
(defun org-roam-dailies-capture-date (&optional goto prefer-future)
|
||||||
|
"Create an entry in the daily-note for a date using the calendar.
|
||||||
|
Prefer past dates, unless PREFER-FUTURE is non-nil.
|
||||||
|
With a `C-u' prefix or when GOTO is non-nil, go the note without
|
||||||
|
creating an entry."
|
||||||
|
(interactive "P")
|
||||||
|
(let ((time (let ((org-read-date-prefer-future prefer-future))
|
||||||
|
(org-read-date t t nil (if goto
|
||||||
|
"Find daily-note: "
|
||||||
|
"Capture to daily-note: ")))))
|
||||||
|
(org-roam-dailies--capture time goto)))
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(defun org-roam-dailies-goto-date (&optional prefer-future)
|
||||||
|
"Find the daily-note for a date using the calendar, creating it if necessary.
|
||||||
|
Prefer past dates, unless PREFER-FUTURE is non-nil."
|
||||||
|
(interactive)
|
||||||
|
(org-roam-dailies-capture-date t prefer-future))
|
||||||
|
|
||||||
|
;;; Navigation
|
||||||
|
(defun org-roam-dailies--list-files (&rest extra-files)
|
||||||
|
"List all files in `org-roam-dailies-directory'.
|
||||||
|
EXTRA-FILES can be used to append extra files to the list."
|
||||||
|
(let ((dir (expand-file-name org-roam-dailies-directory org-roam-directory))
|
||||||
|
(regexp (rx-to-string `(and "." (or ,@org-roam-file-extensions)))))
|
||||||
|
(append (--remove (let ((file (file-name-nondirectory it)))
|
||||||
|
(when (or (auto-save-file-name-p file)
|
||||||
|
(backup-file-name-p file)
|
||||||
|
(string-match "^\\." file))
|
||||||
|
it))
|
||||||
|
(directory-files-recursively dir regexp))
|
||||||
|
extra-files)))
|
||||||
|
|
||||||
|
(defun org-roam-dailies-goto-next-note (&optional n)
|
||||||
|
"Find next daily-note.
|
||||||
|
|
||||||
|
With numeric argument N, find note N days in the future. If N is
|
||||||
|
negative, find note N days in the past."
|
||||||
|
(interactive "p")
|
||||||
|
(unless (org-roam-dailies--daily-note-p)
|
||||||
|
(user-error "Not in a daily-note"))
|
||||||
|
(setq n (or n 1))
|
||||||
|
(let* ((dailies (org-roam-dailies--list-files))
|
||||||
|
(position
|
||||||
|
(cl-position-if (lambda (candidate)
|
||||||
|
(string= (buffer-file-name (buffer-base-buffer)) candidate))
|
||||||
|
dailies))
|
||||||
|
note)
|
||||||
|
(unless position
|
||||||
|
(user-error "Can't find current note file - have you saved it yet?"))
|
||||||
|
(pcase n
|
||||||
|
((pred (natnump))
|
||||||
|
(when (eq position (- (length dailies) 1))
|
||||||
|
(user-error "Already at newest note")))
|
||||||
|
((pred (integerp))
|
||||||
|
(when (eq position 0)
|
||||||
|
(user-error "Already at oldest note"))))
|
||||||
|
(setq note (nth (+ position n) dailies))
|
||||||
|
(find-file note)
|
||||||
|
(run-hooks 'org-roam-dailies-find-file-hook)))
|
||||||
|
|
||||||
|
(defun org-roam-dailies-goto-previous-note (&optional n)
|
||||||
|
"Find previous daily-note.
|
||||||
|
|
||||||
|
With numeric argument N, find note N days in the past. If N is
|
||||||
|
negative, find note N days in the future."
|
||||||
|
(interactive "p")
|
||||||
|
(let ((n (if n (- n) -1)))
|
||||||
|
(org-roam-dailies-goto-next-note n)))
|
||||||
|
|
||||||
|
(add-hook 'calendar-today-visible-hook #'org-roam-dailies-calendar-mark-entries)
|
||||||
|
(add-hook 'calendar-today-invisible-hook #'org-roam-dailies-calendar-mark-entries)
|
||||||
|
|
||||||
|
;;;; Bindings
|
||||||
|
(defvar org-roam-dailies-map (make-sparse-keymap)
|
||||||
|
"Keymap for `org-roam-dailies'.")
|
||||||
|
|
||||||
|
(define-prefix-command 'org-roam-dailies-map)
|
||||||
|
|
||||||
|
(define-key org-roam-dailies-map (kbd "d") #'org-roam-dailies-goto-today)
|
||||||
|
(define-key org-roam-dailies-map (kbd "y") #'org-roam-dailies-goto-yesterday)
|
||||||
|
(define-key org-roam-dailies-map (kbd "t") #'org-roam-dailies-goto-tomorrow)
|
||||||
|
(define-key org-roam-dailies-map (kbd "n") #'org-roam-dailies-capture-today)
|
||||||
|
(define-key org-roam-dailies-map (kbd "f") #'org-roam-dailies-goto-next-note)
|
||||||
|
(define-key org-roam-dailies-map (kbd "b") #'org-roam-dailies-goto-previous-note)
|
||||||
|
(define-key org-roam-dailies-map (kbd "c") #'org-roam-dailies-goto-date)
|
||||||
|
(define-key org-roam-dailies-map (kbd "v") #'org-roam-dailies-capture-date)
|
||||||
|
(define-key org-roam-dailies-map (kbd ".") #'org-roam-dailies-find-directory)
|
||||||
|
|
||||||
|
(define-obsolete-function-alias
|
||||||
|
'org-roam-dailies-find-today
|
||||||
|
'org-roam-dailies-goto-today "org-roam 2.0")
|
||||||
|
(define-obsolete-function-alias
|
||||||
|
'org-roam-dailies-find-yesterday
|
||||||
|
'org-roam-dailies-goto-yesterday "org-roam 2.0")
|
||||||
|
(define-obsolete-function-alias
|
||||||
|
'org-roam-dailies-find-tomorrow
|
||||||
|
'org-roam-dailies-goto-tomorrow "org-roam 2.0")
|
||||||
|
(define-obsolete-function-alias
|
||||||
|
'org-roam-dailies-find-next-note
|
||||||
|
'org-roam-dailies-goto-next-note "org-roam 2.0")
|
||||||
|
(define-obsolete-function-alias
|
||||||
|
'org-roam-dailies-find-previous-note
|
||||||
|
'org-roam-dailies-goto-previous-note "org-roam 2.0")
|
||||||
|
(define-obsolete-function-alias
|
||||||
|
'org-roam-dailies-find-date
|
||||||
|
'org-roam-dailies-goto-date "org-roam 2.0")
|
||||||
|
|
||||||
(provide 'org-roam-dailies)
|
(provide 'org-roam-dailies)
|
||||||
|
|
||||||
|
740
org-roam-db.el
740
org-roam-db.el
@ -5,8 +5,8 @@
|
|||||||
;; Author: Jethro Kuan <jethrokuan95@gmail.com>
|
;; Author: Jethro Kuan <jethrokuan95@gmail.com>
|
||||||
;; URL: https://github.com/org-roam/org-roam
|
;; URL: https://github.com/org-roam/org-roam
|
||||||
;; Keywords: org-mode, roam, convenience
|
;; Keywords: org-mode, roam, convenience
|
||||||
;; Version: 1.2.1
|
;; Version: 2.0.0
|
||||||
;; Package-Requires: ((emacs "26.1") (dash "2.13") (f "0.17.2") (s "1.12.0") (org "9.3") (emacsql "3.0.0") (emacsql-sqlite3 "1.0.0"))
|
;; Package-Requires: ((emacs "26.1") (dash "2.13") (f "0.17.2") (org "9.4") (emacsql "3.0.0") (emacsql-sqlite "1.0.0") (magit-section "2.90.1"))
|
||||||
|
|
||||||
;; This file is NOT part of GNU Emacs.
|
;; This file is NOT part of GNU Emacs.
|
||||||
|
|
||||||
@ -27,33 +27,34 @@
|
|||||||
|
|
||||||
;;; Commentary:
|
;;; Commentary:
|
||||||
;;
|
;;
|
||||||
;; This library is provides the underlying database api to org-roam
|
;; This library provides the underlying database api to org-roam.
|
||||||
;;
|
;;
|
||||||
;;; Code:
|
;;; Code:
|
||||||
;;;; Library Requires
|
;;;; Library Requires
|
||||||
(eval-when-compile (require 'subr-x))
|
(eval-when-compile (require 'subr-x))
|
||||||
(require 'emacsql)
|
(require 'emacsql)
|
||||||
(require 'emacsql-sqlite3)
|
(require 'emacsql-sqlite)
|
||||||
(require 'seq)
|
(require 'seq)
|
||||||
(require 'org-roam-macs)
|
|
||||||
|
|
||||||
|
(eval-and-compile
|
||||||
|
(require 'org-roam-macs)
|
||||||
|
;; For `org-with-wide-buffer'
|
||||||
|
(require 'org-macs))
|
||||||
|
(require 'org)
|
||||||
|
(require 'ol)
|
||||||
|
(require 'org-roam-utils)
|
||||||
|
|
||||||
|
(defvar org-roam-find-file-hook)
|
||||||
(defvar org-roam-directory)
|
(defvar org-roam-directory)
|
||||||
(defvar org-roam-verbose)
|
(defvar org-roam-verbose)
|
||||||
(defvar org-roam-file-name)
|
(defvar org-agenda-files)
|
||||||
|
|
||||||
(declare-function org-roam--org-roam-file-p "org-roam")
|
(declare-function org-roam-id-at-point "org-roam")
|
||||||
(declare-function org-roam--extract-titles "org-roam")
|
(declare-function org-roam--list-all-files "org-roam")
|
||||||
(declare-function org-roam--extract-ref "org-roam")
|
(declare-function org-roam-node-at-point "org-roam")
|
||||||
(declare-function org-roam--extract-tags "org-roam")
|
|
||||||
(declare-function org-roam--extract-headlines "org-roam")
|
|
||||||
(declare-function org-roam--extract-links "org-roam")
|
|
||||||
(declare-function org-roam--list-all-files "org-roam")
|
|
||||||
(declare-function org-roam--path-to-slug "org-roam")
|
|
||||||
(declare-function org-roam--file-name-extension "org-roam")
|
|
||||||
(declare-function org-roam-buffer--update-maybe "org-roam-buffer")
|
|
||||||
|
|
||||||
;;;; Options
|
;;;; Options
|
||||||
(defcustom org-roam-db-location nil
|
(defcustom org-roam-db-location (expand-file-name "org-roam.db" user-emacs-directory)
|
||||||
"The full path to file where the Org-roam database is stored.
|
"The full path to file where the Org-roam database is stored.
|
||||||
If this is non-nil, the Org-roam sqlite database is saved here.
|
If this is non-nil, the Org-roam sqlite database is saved here.
|
||||||
|
|
||||||
@ -64,7 +65,7 @@ when used with multiple Org-roam instances."
|
|||||||
|
|
||||||
(defcustom org-roam-db-gc-threshold gc-cons-threshold
|
(defcustom org-roam-db-gc-threshold gc-cons-threshold
|
||||||
"The value to temporarily set the `gc-cons-threshold' threshold to.
|
"The value to temporarily set the `gc-cons-threshold' threshold to.
|
||||||
During large, heavy operations like `org-roam-db-build-cache',
|
During large, heavy operations like `org-roam-db-sync',
|
||||||
many GC operations happen because of the large number of
|
many GC operations happen because of the large number of
|
||||||
temporary structures generated (e.g. parsed ASTs). Temporarily
|
temporary structures generated (e.g. parsed ASTs). Temporarily
|
||||||
increasing `gc-cons-threshold' will help reduce the number of GC
|
increasing `gc-cons-threshold' will help reduce the number of GC
|
||||||
@ -77,20 +78,25 @@ value like `most-positive-fixnum'."
|
|||||||
:type 'int
|
:type 'int
|
||||||
:group 'org-roam)
|
:group 'org-roam)
|
||||||
|
|
||||||
(defconst org-roam-db--version 7)
|
(defcustom org-roam-db-node-include-function (lambda () t)
|
||||||
|
"A custom function to check if the headline at point is a node."
|
||||||
|
:type 'function
|
||||||
|
:group 'org-roam)
|
||||||
|
|
||||||
|
(defconst org-roam-db-version 16)
|
||||||
|
(defconst org-roam--sqlite-available-p
|
||||||
|
(with-demoted-errors "Org-roam initialization: %S"
|
||||||
|
(emacsql-sqlite-ensure-binary)
|
||||||
|
t))
|
||||||
|
|
||||||
(defvar org-roam-db--connection (make-hash-table :test #'equal)
|
(defvar org-roam-db--connection (make-hash-table :test #'equal)
|
||||||
"Database connection to Org-roam database.")
|
"Database connection to Org-roam database.")
|
||||||
|
|
||||||
;;;; Core Functions
|
;;;; Core Functions
|
||||||
(defun org-roam-db--get ()
|
|
||||||
"Return the sqlite db file."
|
|
||||||
(or org-roam-db-location
|
|
||||||
(expand-file-name "org-roam.db" org-roam-directory)))
|
|
||||||
|
|
||||||
(defun org-roam-db--get-connection ()
|
(defun org-roam-db--get-connection ()
|
||||||
"Return the database connection, if any."
|
"Return the database connection, if any."
|
||||||
(gethash (file-truename org-roam-directory)
|
(gethash (expand-file-name org-roam-directory)
|
||||||
org-roam-db--connection))
|
org-roam-db--connection))
|
||||||
|
|
||||||
(defun org-roam-db ()
|
(defun org-roam-db ()
|
||||||
@ -99,84 +105,115 @@ Initializes and stores the database, and the database connection.
|
|||||||
Performs a database upgrade when required."
|
Performs a database upgrade when required."
|
||||||
(unless (and (org-roam-db--get-connection)
|
(unless (and (org-roam-db--get-connection)
|
||||||
(emacsql-live-p (org-roam-db--get-connection)))
|
(emacsql-live-p (org-roam-db--get-connection)))
|
||||||
(let* ((db-file (org-roam-db--get))
|
(let ((init-db (not (file-exists-p org-roam-db-location))))
|
||||||
(init-db (not (file-exists-p db-file))))
|
(make-directory (file-name-directory org-roam-db-location) t)
|
||||||
(make-directory (file-name-directory db-file) t)
|
(let ((conn (emacsql-sqlite org-roam-db-location)))
|
||||||
(let ((conn (emacsql-sqlite3 db-file)))
|
|
||||||
(set-process-query-on-exit-flag (emacsql-process conn) nil)
|
(set-process-query-on-exit-flag (emacsql-process conn) nil)
|
||||||
(puthash (file-truename org-roam-directory)
|
(puthash (expand-file-name org-roam-directory)
|
||||||
conn
|
conn
|
||||||
org-roam-db--connection)
|
org-roam-db--connection)
|
||||||
(when init-db
|
(when init-db
|
||||||
(org-roam-db--init conn))
|
(org-roam-db--init conn))
|
||||||
(let* ((version (caar (emacsql conn "PRAGMA user_version")))
|
(let* ((version (caar (emacsql conn "PRAGMA user_version")))
|
||||||
(version (org-roam-db--update-maybe conn version)))
|
(version (org-roam-db--upgrade-maybe conn version)))
|
||||||
(cond
|
(cond
|
||||||
((> version org-roam-db--version)
|
((> version org-roam-db-version)
|
||||||
(emacsql-close conn)
|
(emacsql-close conn)
|
||||||
(user-error
|
(user-error
|
||||||
"The Org-roam database was created with a newer Org-roam version. "
|
"The Org-roam database was created with a newer Org-roam version. "
|
||||||
"You need to update the Org-roam package"))
|
"You need to update the Org-roam package"))
|
||||||
((< version org-roam-db--version)
|
((< version org-roam-db-version)
|
||||||
(emacsql-close conn)
|
(emacsql-close conn)
|
||||||
(error "BUG: The Org-roam database scheme changed %s"
|
(error "BUG: The Org-roam database scheme changed %s"
|
||||||
"and there is no upgrade path")))))))
|
"and there is no upgrade path")))))))
|
||||||
(org-roam-db--get-connection))
|
(org-roam-db--get-connection))
|
||||||
|
|
||||||
;;;; Entrypoint: (org-roam-db-query)
|
;;;; Entrypoint: (org-roam-db-query)
|
||||||
|
(define-error 'emacsql-constraint "SQL constraint violation")
|
||||||
(defun org-roam-db-query (sql &rest args)
|
(defun org-roam-db-query (sql &rest args)
|
||||||
"Run SQL query on Org-roam database with ARGS.
|
"Run SQL query on Org-roam database with ARGS.
|
||||||
SQL can be either the emacsql vector representation, or a string."
|
SQL can be either the emacsql vector representation, or a string."
|
||||||
(if (stringp sql)
|
(apply #'emacsql (org-roam-db) sql args))
|
||||||
(emacsql (org-roam-db) (apply #'format sql args))
|
|
||||||
(apply #'emacsql (org-roam-db) sql args)))
|
(defun org-roam-db-query! (handler sql &rest args)
|
||||||
|
"Run SQL query on Org-roam database with ARGS.
|
||||||
|
SQL can be either the emacsql vector representation, or a string.
|
||||||
|
The query is expected to be able to fail, in this situation, run HANDLER."
|
||||||
|
(condition-case err
|
||||||
|
(org-roam-db-query sql args)
|
||||||
|
(emacsql-constraint
|
||||||
|
(funcall handler err))))
|
||||||
|
|
||||||
;;;; Schemata
|
;;;; Schemata
|
||||||
(defconst org-roam-db--table-schemata
|
(defconst org-roam-db--table-schemata
|
||||||
'((files
|
'((files
|
||||||
[(file :unique :primary-key)
|
[(file :unique :primary-key)
|
||||||
(hash :not-null)
|
(hash :not-null)
|
||||||
(meta :not-null)])
|
(atime :not-null)
|
||||||
|
(mtime :not-null)])
|
||||||
|
|
||||||
(headlines
|
(nodes
|
||||||
[(id :unique :primary-key)
|
([(id :not-null :primary-key)
|
||||||
(file :not-null)])
|
(file :not-null)
|
||||||
|
(level :not-null)
|
||||||
|
(pos :not-null)
|
||||||
|
todo
|
||||||
|
priority
|
||||||
|
(scheduled text)
|
||||||
|
(deadline text)
|
||||||
|
title
|
||||||
|
properties
|
||||||
|
olp]
|
||||||
|
(:foreign-key [file] :references files [file] :on-delete :cascade)))
|
||||||
|
|
||||||
(links
|
(aliases
|
||||||
[(from :not-null)
|
([(node-id :not-null)
|
||||||
(to :not-null)
|
alias]
|
||||||
(type :not-null)
|
(:foreign-key [node-id] :references nodes [id] :on-delete :cascade)))
|
||||||
(properties :not-null)])
|
|
||||||
|
|
||||||
(tags
|
|
||||||
[(file :unique :primary-key)
|
|
||||||
(tags)])
|
|
||||||
|
|
||||||
(titles
|
|
||||||
[(file :not-null)
|
|
||||||
title])
|
|
||||||
|
|
||||||
(refs
|
(refs
|
||||||
[(ref :unique :not-null)
|
([(node-id :not-null)
|
||||||
(file :not-null)
|
(ref :not-null)
|
||||||
(type :not-null)])))
|
(type :not-null)]
|
||||||
|
(:foreign-key [node-id] :references nodes [id] :on-delete :cascade)))
|
||||||
|
|
||||||
|
(tags
|
||||||
|
([(node-id :not-null)
|
||||||
|
tag]
|
||||||
|
(:foreign-key [node-id] :references nodes [id] :on-delete :cascade)))
|
||||||
|
|
||||||
|
(links
|
||||||
|
([(pos :not-null)
|
||||||
|
(source :not-null)
|
||||||
|
(dest :not-null)
|
||||||
|
(type :not-null)
|
||||||
|
(properties :not-null)]
|
||||||
|
(:foreign-key [source] :references nodes [id] :on-delete :cascade)))))
|
||||||
|
|
||||||
|
(defconst org-roam-db--table-indices
|
||||||
|
'((alias-node-id aliases [node-id])
|
||||||
|
(refs-node-id refs [node-id])
|
||||||
|
(tags-node-id tags [node-id])))
|
||||||
|
|
||||||
(defun org-roam-db--init (db)
|
(defun org-roam-db--init (db)
|
||||||
"Initialize database DB with the correct schema and user version."
|
"Initialize database DB with the correct schema and user version."
|
||||||
(emacsql-with-transaction db
|
(emacsql-with-transaction db
|
||||||
(pcase-dolist (`(,table . ,schema) org-roam-db--table-schemata)
|
(emacsql db "PRAGMA foreign_keys = ON")
|
||||||
|
(pcase-dolist (`(,table ,schema) org-roam-db--table-schemata)
|
||||||
(emacsql db [:create-table $i1 $S2] table schema))
|
(emacsql db [:create-table $i1 $S2] table schema))
|
||||||
(emacsql db (format "PRAGMA user_version = %s" org-roam-db--version))))
|
(pcase-dolist (`(,index-name ,table ,columns) org-roam-db--table-indices)
|
||||||
|
(emacsql db [:create-index $i1 :on $i2 $S3] index-name table columns))
|
||||||
|
(emacsql db (format "PRAGMA user_version = %s" org-roam-db-version))))
|
||||||
|
|
||||||
(defun org-roam-db--update-maybe (db version)
|
(defun org-roam-db--upgrade-maybe (db version)
|
||||||
"Upgrades the database schema for DB, if VERSION is old."
|
"Upgrades the database schema for DB, if VERSION is old."
|
||||||
(emacsql-with-transaction db
|
(emacsql-with-transaction db
|
||||||
'ignore
|
'ignore
|
||||||
(if (< version org-roam-db--version)
|
(if (< version org-roam-db-version)
|
||||||
(progn
|
(progn
|
||||||
(org-roam-message (format "Upgrading the Org-roam database from version %d to version %d"
|
(org-roam-message (format "Upgrading the Org-roam database from version %d to version %d"
|
||||||
version org-roam-db--version))
|
version org-roam-db-version))
|
||||||
(org-roam-db-build-cache t))))
|
(org-roam-db-sync t))))
|
||||||
version)
|
version)
|
||||||
|
|
||||||
(defun org-roam-db--close (&optional db)
|
(defun org-roam-db--close (&optional db)
|
||||||
@ -194,352 +231,293 @@ the current `org-roam-directory'."
|
|||||||
(org-roam-db--close conn)))
|
(org-roam-db--close conn)))
|
||||||
|
|
||||||
;;;; Database API
|
;;;; Database API
|
||||||
;;;;; Initialization
|
|
||||||
(defun org-roam-db--initialized-p ()
|
|
||||||
"Whether the Org-roam cache has been initialized."
|
|
||||||
(and (file-exists-p (org-roam-db--get))
|
|
||||||
(> (caar (org-roam-db-query [:select (funcall count) :from titles]))
|
|
||||||
0)))
|
|
||||||
|
|
||||||
(defun org-roam-db--ensure-built ()
|
|
||||||
"Ensures that Org-roam cache is built."
|
|
||||||
(unless (org-roam-db--initialized-p)
|
|
||||||
(error "[Org-roam] your cache isn't built yet! Please run org-roam-db-build-cache")))
|
|
||||||
|
|
||||||
;;;;; Clearing
|
;;;;; Clearing
|
||||||
(defun org-roam-db-clear ()
|
(defun org-roam-db-clear-all ()
|
||||||
"Clears all entries in the Org-roam cache."
|
"Clears all entries in the Org-roam cache."
|
||||||
(interactive)
|
(interactive)
|
||||||
(when (file-exists-p (org-roam-db--get))
|
(when (file-exists-p org-roam-db-location)
|
||||||
(dolist (table (mapcar #'car org-roam-db--table-schemata))
|
(dolist (table (mapcar #'car org-roam-db--table-schemata))
|
||||||
(org-roam-db-query `[:delete :from ,table]))))
|
(org-roam-db-query `[:delete :from ,table]))))
|
||||||
|
|
||||||
(defun org-roam-db--clear-file (&optional filepath)
|
(defun org-roam-db-clear-file (&optional file)
|
||||||
"Remove any related links to the file at FILEPATH.
|
"Remove any related links to the FILE.
|
||||||
This is equivalent to removing the node from the graph."
|
This is equivalent to removing the node from the graph.
|
||||||
(let ((file (file-truename (or filepath
|
If FILE is nil, clear the current buffer."
|
||||||
(buffer-file-name (buffer-base-buffer))))))
|
(setq file (or file (buffer-file-name (buffer-base-buffer))))
|
||||||
(dolist (table (mapcar #'car org-roam-db--table-schemata))
|
(org-roam-db-query [:delete :from files
|
||||||
(org-roam-db-query `[:delete :from ,table
|
:where (= file $s1)]
|
||||||
:where (= ,(if (eq table 'links) 'from 'file) $s1)]
|
file))
|
||||||
file))))
|
|
||||||
|
|
||||||
;;;;; Insertion
|
;;;;; Updating tables
|
||||||
(defun org-roam-db--insert-meta (file hash meta)
|
(defun org-roam-db-insert-file ()
|
||||||
"Insert HASH and META for a FILE into the Org-roam cache."
|
"Update the files table for the current buffer.
|
||||||
(org-roam-db-query
|
If UPDATE-P is non-nil, first remove the file in the database."
|
||||||
[:insert :into files
|
(let* ((file (buffer-file-name))
|
||||||
:values $v1]
|
|
||||||
(list (vector file hash meta))))
|
|
||||||
|
|
||||||
(defun org-roam-db--insert-links (links)
|
|
||||||
"Insert LINKS into the Org-roam cache."
|
|
||||||
(org-roam-db-query
|
|
||||||
[:insert :into links
|
|
||||||
:values $v1]
|
|
||||||
links))
|
|
||||||
|
|
||||||
(defun org-roam-db--insert-titles (file titles)
|
|
||||||
"Insert TITLES for a FILE into the Org-roam cache."
|
|
||||||
(org-roam-db-query
|
|
||||||
[:insert :into titles
|
|
||||||
:values $v1]
|
|
||||||
(mapcar (lambda (title)
|
|
||||||
(vector file title)) titles)))
|
|
||||||
|
|
||||||
(defun org-roam-db--insert-headlines (headlines)
|
|
||||||
"Insert HEADLINES into the Org-roam cache.
|
|
||||||
Returns t if the insertion was successful, nil otherwise.
|
|
||||||
Insertions can fail when there is an ID conflict."
|
|
||||||
(condition-case nil
|
|
||||||
(progn
|
|
||||||
(org-roam-db-query
|
|
||||||
[:insert :into headlines
|
|
||||||
:values $v1]
|
|
||||||
headlines)
|
|
||||||
t)
|
|
||||||
(error
|
|
||||||
(unless (listp headlines)
|
|
||||||
(setq headlines (list headlines)))
|
|
||||||
(lwarn '(org-roam) :error
|
|
||||||
(format "Duplicate IDs in %s, one of:\n\n%s\n\nskipping..."
|
|
||||||
(aref (car headlines) 1)
|
|
||||||
(string-join (mapcar (lambda (hl)
|
|
||||||
(aref hl 0)) headlines) "\n")))
|
|
||||||
nil)))
|
|
||||||
|
|
||||||
(defun org-roam-db--insert-tags (file tags)
|
|
||||||
"Insert TAGS for a FILE into the Org-roam cache."
|
|
||||||
(org-roam-db-query
|
|
||||||
[:insert :into tags
|
|
||||||
:values $v1]
|
|
||||||
(list (vector file tags))))
|
|
||||||
|
|
||||||
(defun org-roam-db--insert-ref (file ref)
|
|
||||||
"Insert REF for FILE into the Org-roam cache.
|
|
||||||
Returns t if successful, and nil otherwise.
|
|
||||||
Insertions can fail if the key is already in the database."
|
|
||||||
(let ((key (cdr ref))
|
|
||||||
(type (car ref)))
|
|
||||||
(condition-case nil
|
|
||||||
(progn
|
|
||||||
(org-roam-db-query
|
|
||||||
[:insert :into refs :values $v1]
|
|
||||||
(list (vector key file type)))
|
|
||||||
t)
|
|
||||||
(error
|
|
||||||
(lwarn '(org-roam) :error
|
|
||||||
(format "Duplicate ref %s in:\n\nA: %s\nB: %s\n\nskipping..."
|
|
||||||
key
|
|
||||||
file
|
|
||||||
(caar (org-roam-db-query
|
|
||||||
[:select file :from refs
|
|
||||||
:where (= ref $v1)]
|
|
||||||
(vector key)))))
|
|
||||||
nil))))
|
|
||||||
|
|
||||||
;;;;; Fetching
|
|
||||||
(defun org-roam-db--get-current-files ()
|
|
||||||
"Return a hash-table of file to the hash of its file contents."
|
|
||||||
(let* ((current-files (org-roam-db-query [:select * :from files]))
|
|
||||||
(ht (make-hash-table :test #'equal)))
|
|
||||||
(dolist (row current-files)
|
|
||||||
(puthash (car row) (cadr row) ht))
|
|
||||||
ht))
|
|
||||||
|
|
||||||
(defun org-roam-db--get-titles (file)
|
|
||||||
"Return the titles of FILE from the cache."
|
|
||||||
(caar (org-roam-db-query [:select [title] :from titles
|
|
||||||
:where (= file $s1)
|
|
||||||
:limit 1]
|
|
||||||
file)))
|
|
||||||
|
|
||||||
(defun org-roam-db--connected-component (file)
|
|
||||||
"Return all files reachable from/connected to FILE, including the file itself.
|
|
||||||
If the file does not have any connections, nil is returned."
|
|
||||||
(let* ((query "WITH RECURSIVE
|
|
||||||
links_of(file, link) AS
|
|
||||||
(WITH filelinks AS (SELECT * FROM links WHERE \"type\" = '\"file\"'),
|
|
||||||
citelinks AS (SELECT * FROM links
|
|
||||||
JOIN refs ON links.\"to\" = refs.\"ref\"
|
|
||||||
AND links.\"type\" = '\"cite\"')
|
|
||||||
SELECT \"from\", \"to\" FROM filelinks UNION
|
|
||||||
SELECT \"to\", \"from\" FROM filelinks UNION
|
|
||||||
SELECT \"file\", \"from\" FROM citelinks UNION
|
|
||||||
SELECT \"from\", \"file\" FROM citelinks),
|
|
||||||
connected_component(file) AS
|
|
||||||
(SELECT link FROM links_of WHERE file = $s1
|
|
||||||
UNION
|
|
||||||
SELECT link FROM links_of JOIN connected_component USING(file))
|
|
||||||
SELECT * FROM connected_component;")
|
|
||||||
(files (mapcar 'car-safe (emacsql (org-roam-db) query file))))
|
|
||||||
files))
|
|
||||||
|
|
||||||
(defun org-roam-db--links-with-max-distance (file max-distance)
|
|
||||||
"Return all files connected to FILE in at most MAX-DISTANCE steps.
|
|
||||||
This includes the file itself. If the file does not have any
|
|
||||||
connections, nil is returned."
|
|
||||||
(let* ((query "WITH RECURSIVE
|
|
||||||
links_of(file, link) AS
|
|
||||||
(WITH filelinks AS (SELECT * FROM links WHERE \"type\" = '\"file\"'),
|
|
||||||
citelinks AS (SELECT * FROM links
|
|
||||||
JOIN refs ON links.\"to\" = refs.\"ref\"
|
|
||||||
AND links.\"type\" = '\"cite\"')
|
|
||||||
SELECT \"from\", \"to\" FROM filelinks UNION
|
|
||||||
SELECT \"to\", \"from\" FROM filelinks UNION
|
|
||||||
SELECT \"file\", \"from\" FROM citelinks UNION
|
|
||||||
SELECT \"from\", \"file\" FROM citelinks),
|
|
||||||
-- Links are traversed in a breadth-first search. In order to calculate the
|
|
||||||
-- distance of nodes and to avoid following cyclic links, the visited nodes
|
|
||||||
-- are tracked in 'trace'.
|
|
||||||
connected_component(file, trace) AS
|
|
||||||
(VALUES($s1, json_array($s1))
|
|
||||||
UNION
|
|
||||||
SELECT lo.link, json_insert(cc.trace, '$[' || json_array_length(cc.trace) || ']', lo.link) FROM
|
|
||||||
connected_component AS cc JOIN links_of AS lo USING(file)
|
|
||||||
WHERE (
|
|
||||||
-- Avoid cycles by only visiting each file once.
|
|
||||||
(SELECT count(*) FROM json_each(cc.trace) WHERE json_each.value == lo.link) == 0
|
|
||||||
-- Note: BFS is cut off early here.
|
|
||||||
AND json_array_length(cc.trace) < ($s2 + 1)))
|
|
||||||
SELECT DISTINCT file, min(json_array_length(trace)) AS distance
|
|
||||||
FROM connected_component GROUP BY file ORDER BY distance;")
|
|
||||||
;; In principle the distance would be available in the second column.
|
|
||||||
(files (mapcar 'car-safe (emacsql (org-roam-db) query file max-distance))))
|
|
||||||
files))
|
|
||||||
|
|
||||||
(defun org-roam-db--file-hash (&optional file-path)
|
|
||||||
"Compute the hash of FILE-PATH, a file or current buffer."
|
|
||||||
(let* ((file-p (and file-path))
|
|
||||||
(file-path (or file-path
|
|
||||||
(buffer-file-name (current-buffer))))
|
|
||||||
(encrypted-p (and file-path
|
|
||||||
(string= (org-roam--file-name-extension file-path)
|
|
||||||
"gpg"))))
|
|
||||||
(cond ((and encrypted-p file-p)
|
|
||||||
(with-temp-buffer
|
|
||||||
(set-buffer-multibyte nil)
|
|
||||||
(insert-file-contents-literally file-path)
|
|
||||||
(secure-hash 'sha1 (current-buffer))))
|
|
||||||
(file-p
|
|
||||||
(with-temp-buffer
|
|
||||||
(insert-file-contents file-path)
|
|
||||||
(secure-hash 'sha1 (current-buffer))))
|
|
||||||
(t
|
|
||||||
(secure-hash 'sha1 (current-buffer))))))
|
|
||||||
|
|
||||||
;;;;; Updating
|
|
||||||
(defun org-roam-db--update-meta ()
|
|
||||||
"Update the metadata of the current buffer into the cache."
|
|
||||||
(let* ((file (file-truename (buffer-file-name)))
|
|
||||||
(attr (file-attributes file))
|
(attr (file-attributes file))
|
||||||
(atime (file-attribute-access-time attr))
|
(atime (file-attribute-access-time attr))
|
||||||
(mtime (file-attribute-modification-time attr))
|
(mtime (file-attribute-modification-time attr))
|
||||||
(hash (org-roam-db--file-hash)))
|
(hash (org-roam-db--file-hash)))
|
||||||
(org-roam-db-query [:delete :from files
|
(org-roam-db-query
|
||||||
:where (= file $s1)]
|
[:insert :into files
|
||||||
file)
|
:values $v1]
|
||||||
(org-roam-db--insert-meta file hash (list :atime atime :mtime mtime))))
|
(list (vector file hash atime mtime)))))
|
||||||
|
|
||||||
(defun org-roam-db--update-titles ()
|
(defun org-roam-db-get-scheduled-time ()
|
||||||
"Update the title of the current buffer into the cache."
|
"Return the scheduled time at point in ISO8601 format."
|
||||||
(let* ((file (file-truename (buffer-file-name)))
|
(when-let ((time (org-get-scheduled-time (point))))
|
||||||
(titles (or (org-roam--extract-titles)
|
(org-format-time-string "%FT%T%z" time)))
|
||||||
(list (org-roam--path-to-slug file)))))
|
|
||||||
(org-roam-db-query [:delete :from titles
|
|
||||||
:where (= file $s1)]
|
|
||||||
file)
|
|
||||||
(org-roam-db--insert-titles file titles)))
|
|
||||||
|
|
||||||
(defun org-roam-db--update-tags ()
|
(defun org-roam-db-get-deadline-time ()
|
||||||
"Update the tags of the current buffer into the cache."
|
"Return the deadline time at point in ISO8601 format."
|
||||||
(let ((file (file-truename (buffer-file-name)))
|
(when-let ((time (org-get-deadline-time (point))))
|
||||||
(tags (org-roam--extract-tags)))
|
(org-format-time-string "%FT%T%z" time)))
|
||||||
(org-roam-db-query [:delete :from tags
|
|
||||||
:where (= file $s1)]
|
|
||||||
file)
|
|
||||||
(when tags
|
|
||||||
(org-roam-db--insert-tags file tags))))
|
|
||||||
|
|
||||||
(defun org-roam-db--update-refs ()
|
(defun org-roam-db-node-p ()
|
||||||
"Update the ref of the current buffer into the cache."
|
"Return t if headline at point is a node, else return nil."
|
||||||
(let ((file (file-truename (buffer-file-name))))
|
(and (org-id-get)
|
||||||
(org-roam-db-query [:delete :from refs
|
(not (cdr (assoc "ROAM_EXCLUDE" (org-entry-properties))))
|
||||||
:where (= file $s1)]
|
(funcall org-roam-db-node-include-function)))
|
||||||
file)
|
|
||||||
(when-let ((ref (org-roam--extract-ref)))
|
|
||||||
(org-roam-db--insert-ref file ref))))
|
|
||||||
|
|
||||||
(defun org-roam-db--update-links ()
|
(defun org-roam-db-map-nodes (fns)
|
||||||
"Update the file links of the current buffer in the cache."
|
"Run FNS over all nodes in the current buffer."
|
||||||
(let ((file (file-truename (buffer-file-name))))
|
(org-with-point-at 1
|
||||||
(org-roam-db-query [:delete :from links
|
(org-map-entries
|
||||||
:where (= from $s1)]
|
(lambda ()
|
||||||
file)
|
(when (org-roam-db-node-p)
|
||||||
(when-let ((links (org-roam--extract-links)))
|
(dolist (fn fns)
|
||||||
(org-roam-db--insert-links links))))
|
(funcall fn)))))))
|
||||||
|
|
||||||
(defun org-roam-db--update-headlines ()
|
(defun org-roam-db-map-links (fns)
|
||||||
"Update the file headlines of the current buffer into the cache."
|
"Run FNS over all links in the current buffer."
|
||||||
(let* ((file (file-truename (buffer-file-name))))
|
(org-with-point-at 1
|
||||||
(org-roam-db-query [:delete :from headlines
|
(org-element-map (org-element-parse-buffer) 'link
|
||||||
:where (= file $s1)]
|
(lambda (link)
|
||||||
file)
|
(dolist (fn fns)
|
||||||
(when-let ((headlines (org-roam--extract-headlines)))
|
(funcall fn link))))))
|
||||||
(org-roam-db--insert-headlines headlines))))
|
|
||||||
|
|
||||||
(defun org-roam-db--update-file (&optional file-path)
|
(defun org-roam-db-insert-file-node ()
|
||||||
"Update Org-roam cache for FILE-PATH."
|
"Insert the file-level node into the Org-roam cache."
|
||||||
(when (org-roam--org-roam-file-p file-path)
|
(org-with-point-at 1
|
||||||
(let ((buf (or (and file-path
|
(when (and (= (org-outline-level) 0)
|
||||||
(find-file-noselect file-path t))
|
(org-roam-db-node-p))
|
||||||
(current-buffer))))
|
(when-let ((id (org-id-get)))
|
||||||
(with-current-buffer buf
|
(let* ((file (buffer-file-name (buffer-base-buffer)))
|
||||||
(save-excursion
|
(title (org-link-display-format
|
||||||
(emacsql-with-transaction (org-roam-db)
|
(or (cadr (assoc "TITLE" (org-collect-keywords '("title"))
|
||||||
(org-roam-db--update-meta)
|
#'string-equal))
|
||||||
(org-roam-db--update-tags)
|
(file-relative-name file org-roam-directory))))
|
||||||
(org-roam-db--update-titles)
|
(pos (point))
|
||||||
(org-roam-db--update-refs)
|
(todo nil)
|
||||||
(org-roam-db--update-headlines)
|
(priority nil)
|
||||||
(org-roam-db--update-links))
|
(scheduled nil)
|
||||||
(org-roam-buffer--update-maybe :redisplay t))))))
|
(deadline nil)
|
||||||
|
(level 0)
|
||||||
|
(aliases (org-entry-get (point) "ROAM_ALIASES"))
|
||||||
|
(tags org-file-tags)
|
||||||
|
(refs (org-entry-get (point) "ROAM_REFS"))
|
||||||
|
(properties (org-entry-properties))
|
||||||
|
(olp (org-get-outline-path)))
|
||||||
|
(org-roam-db-query!
|
||||||
|
(lambda (err)
|
||||||
|
(lwarn 'org-roam :warning "%s for %s (%s) in %s"
|
||||||
|
(error-message-string err)
|
||||||
|
title id file))
|
||||||
|
[:insert :into nodes
|
||||||
|
:values $v1]
|
||||||
|
(vector id file level pos todo priority
|
||||||
|
scheduled deadline title properties olp))
|
||||||
|
(when tags
|
||||||
|
(org-roam-db-query
|
||||||
|
[:insert :into tags
|
||||||
|
:values $v1]
|
||||||
|
(mapcar (lambda (tag)
|
||||||
|
(vector id (substring-no-properties tag)))
|
||||||
|
tags)))
|
||||||
|
(when aliases
|
||||||
|
(org-roam-db-query
|
||||||
|
[:insert :into aliases
|
||||||
|
:values $v1]
|
||||||
|
(mapcar (lambda (alias)
|
||||||
|
(vector id alias))
|
||||||
|
(split-string-and-unquote aliases))))
|
||||||
|
(when refs
|
||||||
|
(setq refs (split-string-and-unquote refs))
|
||||||
|
(let (rows)
|
||||||
|
(dolist (ref refs)
|
||||||
|
(if (string-match org-link-plain-re ref)
|
||||||
|
(progn
|
||||||
|
(push (vector id (match-string 2 ref)
|
||||||
|
(match-string 1 ref)) rows))
|
||||||
|
(lwarn '(org-roam) :warning
|
||||||
|
"%s:%s\tInvalid ref %s, skipping..."
|
||||||
|
(buffer-file-name) (point) ref)))
|
||||||
|
(when rows
|
||||||
|
(org-roam-db-query
|
||||||
|
[:insert :into refs
|
||||||
|
:values $v1]
|
||||||
|
rows)))))))))
|
||||||
|
|
||||||
(defun org-roam-db-build-cache (&optional force)
|
(defun org-roam-db-insert-node-data ()
|
||||||
"Build the cache for `org-roam-directory'.
|
"Insert node data for headline at point into the Org-roam cache."
|
||||||
|
(when-let ((id (org-id-get)))
|
||||||
|
(let* ((file (buffer-file-name (buffer-base-buffer)))
|
||||||
|
(heading-components (org-heading-components))
|
||||||
|
(pos (point))
|
||||||
|
(todo (nth 2 heading-components))
|
||||||
|
(priority (nth 3 heading-components))
|
||||||
|
(level (nth 1 heading-components))
|
||||||
|
(scheduled (org-roam-db-get-scheduled-time))
|
||||||
|
(deadline (org-roam-db-get-deadline-time))
|
||||||
|
(title (org-link-display-format (nth 4 heading-components)))
|
||||||
|
(properties (org-entry-properties))
|
||||||
|
(olp (org-get-outline-path)))
|
||||||
|
(org-roam-db-query!
|
||||||
|
(lambda (err)
|
||||||
|
(lwarn 'org-roam :warning "%s for %s (%s) in %s"
|
||||||
|
(error-message-string err)
|
||||||
|
title id file))
|
||||||
|
[:insert :into nodes
|
||||||
|
:values $v1]
|
||||||
|
(vector id file level pos todo priority
|
||||||
|
scheduled deadline title properties olp)))))
|
||||||
|
|
||||||
|
(defun org-roam-db-insert-aliases ()
|
||||||
|
"Insert aliases for node at point into Org-roam cache."
|
||||||
|
(when-let ((node-id (org-id-get))
|
||||||
|
(aliases (org-entry-get (point) "ROAM_ALIASES")))
|
||||||
|
(org-roam-db-query [:insert :into aliases
|
||||||
|
:values $v1]
|
||||||
|
(mapcar (lambda (alias)
|
||||||
|
(vector node-id alias))
|
||||||
|
(split-string-and-unquote aliases)))))
|
||||||
|
|
||||||
|
(defun org-roam-db-insert-tags ()
|
||||||
|
"Insert tags for node at point into Org-roam cache."
|
||||||
|
(when-let ((node-id (org-id-get))
|
||||||
|
(tags (org-get-tags)))
|
||||||
|
(org-roam-db-query [:insert :into tags
|
||||||
|
:values $v1]
|
||||||
|
(mapcar (lambda (tag)
|
||||||
|
(vector node-id (substring-no-properties tag))) tags))))
|
||||||
|
|
||||||
|
(defun org-roam-db-insert-refs ()
|
||||||
|
"Insert refs for node at point into Org-roam cache."
|
||||||
|
(when-let* ((node-id (org-id-get))
|
||||||
|
(refs (org-entry-get (point) "ROAM_REFS"))
|
||||||
|
(refs (split-string-and-unquote refs)))
|
||||||
|
(let (rows)
|
||||||
|
(dolist (ref refs)
|
||||||
|
(save-match-data
|
||||||
|
(if (string-match org-link-plain-re ref)
|
||||||
|
(progn
|
||||||
|
(push (vector node-id (match-string 2 ref) (match-string 1 ref)) rows))
|
||||||
|
(lwarn '(org-roam) :warning
|
||||||
|
"%s:%s\tInvalid ref %s, skipping..." (buffer-file-name) (point) ref))))
|
||||||
|
(org-roam-db-query [:insert :into refs
|
||||||
|
:values $v1]
|
||||||
|
rows))))
|
||||||
|
|
||||||
|
(defun org-roam-db-insert-link (link)
|
||||||
|
"Insert link data for LINK at current point into the Org-roam cache."
|
||||||
|
(save-excursion
|
||||||
|
(goto-char (org-element-property :begin link))
|
||||||
|
(let ((type (org-element-property :type link))
|
||||||
|
(dest (org-element-property :path link))
|
||||||
|
(properties (list :outline (org-get-outline-path)))
|
||||||
|
(source (org-roam-id-at-point)))
|
||||||
|
(when source
|
||||||
|
(org-roam-db-query
|
||||||
|
[:insert :into links
|
||||||
|
:values $v1]
|
||||||
|
(vector (point) source dest type properties))))))
|
||||||
|
|
||||||
|
;;;;; Fetching
|
||||||
|
(defun org-roam-db--get-current-files ()
|
||||||
|
"Return a hash-table of file to the hash of its file contents."
|
||||||
|
(let ((current-files (org-roam-db-query [:select [file hash] :from files]))
|
||||||
|
(ht (make-hash-table :test #'equal)))
|
||||||
|
(dolist (row current-files)
|
||||||
|
(puthash (car row) (cadr row) ht))
|
||||||
|
ht))
|
||||||
|
|
||||||
|
(defun org-roam-db--file-hash (&optional file-path)
|
||||||
|
"Compute the hash of FILE-PATH, a file or current buffer."
|
||||||
|
(if file-path
|
||||||
|
(with-temp-buffer
|
||||||
|
(set-buffer-multibyte nil)
|
||||||
|
(insert-file-contents-literally file-path)
|
||||||
|
(secure-hash 'sha1 (current-buffer)))
|
||||||
|
(org-with-wide-buffer
|
||||||
|
(secure-hash 'sha1 (current-buffer)))))
|
||||||
|
|
||||||
|
;;;;; Updating
|
||||||
|
;;;###autoload
|
||||||
|
(defun org-roam-db-sync (&optional force)
|
||||||
|
"Synchronize the cache state with the current Org files on-disk.
|
||||||
If FORCE, force a rebuild of the cache from scratch."
|
If FORCE, force a rebuild of the cache from scratch."
|
||||||
(interactive "P")
|
(interactive "P")
|
||||||
(when force (delete-file (org-roam-db--get)))
|
(when force (delete-file org-roam-db-location))
|
||||||
(org-roam-db--close) ;; Force a reconnect
|
(org-roam-db--close) ;; Force a reconnect
|
||||||
(org-roam-db) ;; To initialize the database, no-op if already initialized
|
(org-roam-db) ;; To initialize the database, no-op if already initialized
|
||||||
(let* ((gc-cons-threshold org-roam-db-gc-threshold)
|
(let* ((gc-cons-threshold org-roam-db-gc-threshold)
|
||||||
|
(org-agenda-files nil)
|
||||||
(org-roam-files (org-roam--list-all-files))
|
(org-roam-files (org-roam--list-all-files))
|
||||||
(current-files (org-roam-db--get-current-files))
|
(current-files (org-roam-db--get-current-files))
|
||||||
(file-count 0)
|
(modified-files nil))
|
||||||
(headline-count 0)
|
(dolist (file org-roam-files)
|
||||||
(link-count 0)
|
(let ((contents-hash (org-roam-db--file-hash file)))
|
||||||
(tag-count 0)
|
(unless (string= (gethash file current-files)
|
||||||
(title-count 0)
|
contents-hash)
|
||||||
(ref-count 0)
|
(push file modified-files)))
|
||||||
(deleted-count 0))
|
(remhash file current-files))
|
||||||
(emacsql-with-transaction (org-roam-db)
|
(emacsql-with-transaction (org-roam-db)
|
||||||
;; Two-step building
|
(if (fboundp 'dolist-with-progress-reporter)
|
||||||
;; First step: Rebuild files and headlines
|
(dolist-with-progress-reporter (file (hash-table-keys current-files))
|
||||||
(dolist (file org-roam-files)
|
"Clearing removed files..."
|
||||||
(let* ((attr (file-attributes file))
|
(org-roam-db-clear-file file))
|
||||||
(atime (file-attribute-access-time attr))
|
(dolist (file (hash-table-keys current-files))
|
||||||
(mtime (file-attribute-modification-time attr)))
|
(org-roam-db-clear-file file)))
|
||||||
(let ((contents-hash (org-roam-db--file-hash file)))
|
(if (fboundp 'dolist-with-progress-reporter)
|
||||||
(unless (string= (gethash file current-files)
|
(dolist-with-progress-reporter (file modified-files)
|
||||||
contents-hash)
|
"Processing modified files..."
|
||||||
(org-roam--with-temp-buffer file
|
(org-roam-db-update-file file))
|
||||||
(org-roam-db--clear-file file)
|
(dolist (file modified-files)
|
||||||
(org-roam-db-query
|
(org-roam-db-update-file file))))))
|
||||||
[:insert :into files
|
|
||||||
:values $v1]
|
(defun org-roam-db-update-file (&optional file-path)
|
||||||
(vector file contents-hash (list :atime atime :mtime mtime)))
|
"Update Org-roam cache for FILE-PATH.
|
||||||
(setq file-count (1+ file-count))
|
If the file does not exist anymore, remove it from the cache.
|
||||||
(when-let ((headlines (org-roam--extract-headlines file)))
|
If the file exists, update the cache with information."
|
||||||
(when (org-roam-db--insert-headlines headlines)
|
(setq file-path (or file-path (buffer-file-name (buffer-base-buffer))))
|
||||||
(setq headline-count (1+ headline-count)))))))))
|
(let ((content-hash (org-roam-db--file-hash file-path))
|
||||||
;; Second step: Rebuild the rest
|
(db-hash (caar (org-roam-db-query [:select hash :from files
|
||||||
(dolist (file org-roam-files)
|
:where (= file $s1)] file-path))))
|
||||||
(let ((contents-hash (org-roam-db--file-hash file)))
|
(unless (string= content-hash db-hash)
|
||||||
(unless (string= (gethash file current-files)
|
(org-roam-with-file file-path nil
|
||||||
contents-hash)
|
(save-excursion
|
||||||
(org-roam--with-temp-buffer file
|
(org-set-regexps-and-options 'tags-only)
|
||||||
(when-let (links (org-roam--extract-links file))
|
(org-roam-db-clear-file)
|
||||||
(org-roam-db-query
|
(org-roam-db-insert-file)
|
||||||
[:insert :into links
|
(org-roam-db-insert-file-node)
|
||||||
:values $v1]
|
(org-roam-db-map-nodes
|
||||||
links)
|
(list #'org-roam-db-insert-node-data
|
||||||
(setq link-count (1+ link-count)))
|
#'org-roam-db-insert-aliases
|
||||||
(when-let (tags (org-roam--extract-tags file))
|
#'org-roam-db-insert-tags
|
||||||
(org-roam-db-query
|
#'org-roam-db-insert-refs))
|
||||||
[:insert :into tags
|
(org-roam-db-map-links
|
||||||
:values $v1]
|
(list #'org-roam-db-insert-link)))))))
|
||||||
(vector file tags))
|
|
||||||
(setq tag-count (1+ tag-count)))
|
(defun org-roam-db--update-on-save-h ()
|
||||||
(let ((titles (or (org-roam--extract-titles)
|
"."
|
||||||
(list (org-roam--path-to-slug file)))))
|
(add-hook 'after-save-hook #'org-roam-db-update-file nil t))
|
||||||
(org-roam-db--insert-titles file titles)
|
|
||||||
(setq title-count (+ title-count (length titles))))
|
(add-hook 'org-roam-find-file-hook #'org-roam-db--update-on-save-h)
|
||||||
(when-let* ((ref (org-roam--extract-ref)))
|
|
||||||
(when (org-roam-db--insert-ref file ref)
|
;; Diagnostic Interactives
|
||||||
(setq ref-count (1+ ref-count))))))
|
(defun org-roam-db-diagnose-node ()
|
||||||
(remhash file current-files)))
|
"Print information about node at point."
|
||||||
(dolist (file (hash-table-keys current-files))
|
(interactive)
|
||||||
;; These files are no longer around, remove from cache...
|
(prin1 (org-roam-node-at-point)))
|
||||||
(org-roam-db--clear-file file)
|
|
||||||
(setq deleted-count (1+ deleted-count))))
|
|
||||||
(org-roam-message "files: Δ%s, headlines: Δ%s, links: Δ%s, tags: Δ%s, titles: Δ%s, refs: Δ%s, deleted: Δ%s"
|
|
||||||
file-count
|
|
||||||
headline-count
|
|
||||||
link-count
|
|
||||||
tag-count
|
|
||||||
title-count
|
|
||||||
ref-count
|
|
||||||
deleted-count)))
|
|
||||||
|
|
||||||
(provide 'org-roam-db)
|
(provide 'org-roam-db)
|
||||||
|
|
||||||
|
@ -1,46 +0,0 @@
|
|||||||
;;; org-roam-dev.el --- Org-roam development code -mode -*- coding: utf-8; lexical-binding: t; -*-
|
|
||||||
|
|
||||||
;; Copyright © 2020 Jethro Kuan <jethrokuan95@gmail.com>
|
|
||||||
|
|
||||||
;; Author: Jethro Kuan <jethrokuan95@gmail.com>
|
|
||||||
;; URL: https://github.com/org-roam/org-roam
|
|
||||||
;; Keywords: org-mode, roam, convenience
|
|
||||||
;; Version: 1.2.1
|
|
||||||
;; Package-Requires: ((emacs "26.1") (dash "2.13") (f "0.17.2") (s "1.12.0") (org "9.3") (emacsql "3.0.0") (emacsql-sqlite3 "1.0.0"))
|
|
||||||
|
|
||||||
;; This file is NOT part of GNU Emacs.
|
|
||||||
|
|
||||||
;; This program is free software; you can redistribute it and/or modify
|
|
||||||
;; it under the terms of the GNU General Public License as published by
|
|
||||||
;; the Free Software Foundation; either version 3, or (at your option)
|
|
||||||
;; any later version.
|
|
||||||
;;
|
|
||||||
;; This program is distributed in the hope that it will be useful,
|
|
||||||
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
;; GNU General Public License for more details.
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the GNU General Public License
|
|
||||||
;; along with GNU Emacs; see the file COPYING. If not, write to the
|
|
||||||
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
||||||
;; Boston, MA 02110-1301, USA.
|
|
||||||
|
|
||||||
;;; Commentary:
|
|
||||||
;;
|
|
||||||
;; This library provides code for org-roam developers.
|
|
||||||
;; It is intended to be loaded before editing org-roam source files.
|
|
||||||
;; It ensures consistent application of various developer settings.
|
|
||||||
;;
|
|
||||||
;;; Code:
|
|
||||||
(require 'emacsql)
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(define-minor-mode org-roam-dev-mode
|
|
||||||
"Minor mode for setting the dev environment of Org-roam."
|
|
||||||
:lighter " ORD"
|
|
||||||
(when org-roam-dev-mode
|
|
||||||
(emacsql-fix-vector-indentation)
|
|
||||||
(setq-local sentence-end-double-space nil)))
|
|
||||||
|
|
||||||
(provide 'org-roam-dev)
|
|
||||||
;;; org-roam-dev.el ends here
|
|
@ -1,308 +0,0 @@
|
|||||||
;;; org-roam-doctor.el --- Linter for Org-roam files -*- coding: utf-8; lexical-binding: t; -*-
|
|
||||||
;;
|
|
||||||
;; Copyright © 2020 Jethro Kuan <jethrokuan95@gmail.com>
|
|
||||||
|
|
||||||
;; Author: Jethro Kuan <jethrokuan95@gmail.com>
|
|
||||||
;; URL: https://github.com/jethrokuan/org-roam
|
|
||||||
;; Keywords: org-mode, roam, convenience
|
|
||||||
;; Version: 1.2.1
|
|
||||||
;; Package-Requires: ((emacs "26.1") (dash "2.13") (f "0.17.2") (s "1.12.0") (org "9.3") (emacsql "3.0.0") (emacsql-sqlite3 "1.0.0"))
|
|
||||||
|
|
||||||
;; This file is NOT part of GNU Emacs.
|
|
||||||
|
|
||||||
;; This program is free software; you can redistribute it and/or modify
|
|
||||||
;; it under the terms of the GNU General Public License as published by
|
|
||||||
;; the Free Software Foundation; either version 3, or (at your option)
|
|
||||||
;; any later version.
|
|
||||||
;;
|
|
||||||
;; This program is distributed in the hope that it will be useful,
|
|
||||||
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
;; GNU General Public License for more details.
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the GNU General Public License
|
|
||||||
;; along with GNU Emacs; see the file COPYING. If not, write to the
|
|
||||||
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
||||||
;; Boston, MA 02110-1301, USA.
|
|
||||||
|
|
||||||
|
|
||||||
;;; Commentary:
|
|
||||||
;;
|
|
||||||
;; This library provides `org-roam-doctor', a utility for diagnosing and fixing
|
|
||||||
;; Org-roam files. Running `org-roam-doctor' launches a list of checks defined
|
|
||||||
;; by `org-roam-doctor--checkers'. Every checker is an instance of
|
|
||||||
;; `org-roam-doctor-checker'.
|
|
||||||
;;
|
|
||||||
;; Each checker is given the Org parse tree (AST), and is expected to return a
|
|
||||||
;; list of errors. The checker can also provide "actions" for auto-fixing errors
|
|
||||||
;; (see `org-roam-doctor--remove-link' for an example).
|
|
||||||
;;
|
|
||||||
;; The UX experience is inspired by both org-lint and checkdoc, and their code
|
|
||||||
;; is heavily referenced.
|
|
||||||
;;
|
|
||||||
;;; Code:
|
|
||||||
;; Library Requires
|
|
||||||
(require 'cl-lib)
|
|
||||||
(require 'org)
|
|
||||||
(require 'org-element)
|
|
||||||
(require 's)
|
|
||||||
(require 'dash)
|
|
||||||
(require 'org-roam-macs)
|
|
||||||
|
|
||||||
(declare-function org-roam-insert "org-roam")
|
|
||||||
(declare-function org-roam--get-roam-buffers "org-roam")
|
|
||||||
(declare-function org-roam--list-all-files "org-roam")
|
|
||||||
(declare-function org-roam--org-roam-file-p "org-roam")
|
|
||||||
(declare-function org-roam--str-to-list "org-roam")
|
|
||||||
(declare-function org-roam-mode "org-roam")
|
|
||||||
|
|
||||||
(defvar org-roam-verbose)
|
|
||||||
(defvar org-roam-mode)
|
|
||||||
|
|
||||||
(cl-defstruct (org-roam-doctor-checker (:copier nil))
|
|
||||||
(name 'missing-checker-name)
|
|
||||||
(description "")
|
|
||||||
(actions nil))
|
|
||||||
|
|
||||||
(defconst org-roam-doctor--checkers
|
|
||||||
(list
|
|
||||||
(make-org-roam-doctor-checker
|
|
||||||
:name 'org-roam-doctor-broken-links
|
|
||||||
:description "Fix broken links."
|
|
||||||
:actions '(("d" . ("Unlink" . org-roam-doctor--remove-link))
|
|
||||||
("r" . ("Replace link" . org-roam-doctor--replace-link))
|
|
||||||
("R" . ("Replace link (keep label)" . org-roam-doctor--replace-link-keep-label))))
|
|
||||||
(make-org-roam-doctor-checker
|
|
||||||
:name 'org-roam-doctor-check-roam-props
|
|
||||||
:description "Check #+roam_* properties.")
|
|
||||||
(make-org-roam-doctor-checker
|
|
||||||
:name 'org-roam-doctor-check-tags
|
|
||||||
:description "Check #+roam_tags.")
|
|
||||||
(make-org-roam-doctor-checker
|
|
||||||
:name 'org-roam-doctor-check-alias
|
|
||||||
:description "Check #+roam_alias.")))
|
|
||||||
|
|
||||||
(defconst org-roam-doctor--supported-roam-properties
|
|
||||||
'("roam_tags" "roam_alias" "roam_key")
|
|
||||||
"List of supported Org-roam properties.")
|
|
||||||
|
|
||||||
(defun org-roam-doctor-check-roam-props (ast)
|
|
||||||
"Checker for detecting invalid #+roam_* properties.
|
|
||||||
AST is the org-element parse tree."
|
|
||||||
(let (reports)
|
|
||||||
(org-element-map ast 'keyword
|
|
||||||
(lambda (kw)
|
|
||||||
(let ((key (org-element-property :key kw)))
|
|
||||||
(when (and (string-prefix-p "ROAM_" key t)
|
|
||||||
(not (member (downcase key) org-roam-doctor--supported-roam-properties)))
|
|
||||||
(push
|
|
||||||
`(,(org-element-property :begin kw)
|
|
||||||
,(concat "Possible mispelled key: "
|
|
||||||
(prin1-to-string key)
|
|
||||||
"\nOrg-roam supports the following keys: "
|
|
||||||
(s-join ", " org-roam-doctor--supported-roam-properties)))
|
|
||||||
reports)))))
|
|
||||||
reports))
|
|
||||||
|
|
||||||
(defun org-roam-doctor-check-tags (ast)
|
|
||||||
"Checker for detecting invalid #+roam_tags.
|
|
||||||
AST is the org-element parse tree."
|
|
||||||
(let (reports)
|
|
||||||
(org-element-map ast 'keyword
|
|
||||||
(lambda (kw)
|
|
||||||
(when (string-collate-equalp (org-element-property :key kw) "roam_tags" nil t)
|
|
||||||
(let ((tags (org-element-property :value kw)))
|
|
||||||
(condition-case nil
|
|
||||||
(org-roam--str-to-list tags)
|
|
||||||
(error
|
|
||||||
(push
|
|
||||||
`(,(org-element-property :begin kw)
|
|
||||||
,(concat "Unable to parse tags: "
|
|
||||||
tags
|
|
||||||
(when (s-contains? "," tags)
|
|
||||||
"\nCheck that your tags are not comma-separated.")))
|
|
||||||
reports)))))))
|
|
||||||
reports))
|
|
||||||
|
|
||||||
(defun org-roam-doctor-check-alias (ast)
|
|
||||||
"Checker for detecting invalid #+roam_alias.
|
|
||||||
AST is the org-element parse tree."
|
|
||||||
(let (reports)
|
|
||||||
(org-element-map ast 'keyword
|
|
||||||
(lambda (kw)
|
|
||||||
(when (string-collate-equalp (org-element-property :key kw) "roam_alias" nil t)
|
|
||||||
(let ((aliases (org-element-property :value kw)))
|
|
||||||
(condition-case nil
|
|
||||||
(org-roam--str-to-list aliases)
|
|
||||||
(error
|
|
||||||
(push
|
|
||||||
`(,(org-element-property :begin kw)
|
|
||||||
,(concat "Unable to parse aliases: "
|
|
||||||
aliases
|
|
||||||
(when (s-contains? "," aliases)
|
|
||||||
"\nCheck that your aliases are not comma-separated.")))
|
|
||||||
reports)))))))
|
|
||||||
reports))
|
|
||||||
|
|
||||||
(defun org-roam-doctor-broken-links (ast)
|
|
||||||
"Checker for detecting broken links.
|
|
||||||
AST is the org-element parse tree."
|
|
||||||
(let (reports)
|
|
||||||
(org-element-map ast 'link
|
|
||||||
(lambda (l)
|
|
||||||
(when (equal "file" (org-element-property :type l))
|
|
||||||
(let ((file (org-element-property :path l)))
|
|
||||||
(or (file-exists-p file)
|
|
||||||
(file-remote-p file)
|
|
||||||
(push
|
|
||||||
`(,(org-element-property :begin l)
|
|
||||||
,(format (if (org-element-lineage l '(link))
|
|
||||||
"Link to non-existent image file \"%s\"\
|
|
||||||
in link description"
|
|
||||||
"Link to non-existent local file \"%s\"")
|
|
||||||
file))
|
|
||||||
reports))))))
|
|
||||||
reports))
|
|
||||||
|
|
||||||
(defun org-roam-doctor--check (buffer checkers)
|
|
||||||
"Check BUFFER for errors.
|
|
||||||
CHECKERS is the list of checkers used."
|
|
||||||
(with-current-buffer buffer
|
|
||||||
(save-excursion
|
|
||||||
(goto-char (point-min))
|
|
||||||
(let* ((ast (org-element-parse-buffer))
|
|
||||||
(errors (sort (cl-mapcan
|
|
||||||
(lambda (c)
|
|
||||||
(mapcar
|
|
||||||
(lambda (report)
|
|
||||||
(list (set-marker (make-marker) (car report))
|
|
||||||
(nth 1 report) c))
|
|
||||||
(save-excursion
|
|
||||||
(funcall
|
|
||||||
(org-roam-doctor-checker-name c)
|
|
||||||
ast))))
|
|
||||||
checkers)
|
|
||||||
#'car-less-than-car)))
|
|
||||||
(dolist (e errors)
|
|
||||||
(pcase-let ((`(,m ,msg ,checker) e))
|
|
||||||
(switch-to-buffer buffer)
|
|
||||||
(goto-char m)
|
|
||||||
(org-reveal)
|
|
||||||
(undo-boundary)
|
|
||||||
(org-roam-doctor--resolve msg checker)
|
|
||||||
(set-marker m nil)))
|
|
||||||
errors))))
|
|
||||||
|
|
||||||
;;; Actions
|
|
||||||
(defun org-roam-doctor--recursive-edit ()
|
|
||||||
"Launch into a recursive edit."
|
|
||||||
(message "When you're done editing press C-M-c to continue.")
|
|
||||||
(recursive-edit))
|
|
||||||
|
|
||||||
(defun org-roam-doctor--skip ()
|
|
||||||
"Skip the current error."
|
|
||||||
(org-roam-message "Skipping..."))
|
|
||||||
|
|
||||||
(defun org-roam-doctor--replace-link ()
|
|
||||||
"Replace the current link with a new link."
|
|
||||||
(save-match-data
|
|
||||||
(unless (org-in-regexp org-link-bracket-re 1)
|
|
||||||
(user-error "No link at point"))
|
|
||||||
(let ((orig (buffer-string))
|
|
||||||
(p (point)))
|
|
||||||
(condition-case nil
|
|
||||||
(save-excursion
|
|
||||||
(replace-match "")
|
|
||||||
(org-roam-insert))
|
|
||||||
(quit (progn
|
|
||||||
(replace-buffer-contents orig)
|
|
||||||
(goto-char p)))))))
|
|
||||||
|
|
||||||
(defun org-roam-doctor--replace-link-keep-label ()
|
|
||||||
"Replace the current link with a new link, keeping the current link's label."
|
|
||||||
(save-match-data
|
|
||||||
(unless (org-in-regexp org-link-bracket-re 1)
|
|
||||||
(user-error "No link at point"))
|
|
||||||
(let ((orig (buffer-string))
|
|
||||||
(p (point)))
|
|
||||||
(condition-case nil
|
|
||||||
(save-excursion
|
|
||||||
(let ((label (if (match-end 2)
|
|
||||||
(match-string-no-properties 2)
|
|
||||||
(org-link-unescape (match-string-no-properties 1)))))
|
|
||||||
(replace-match "")
|
|
||||||
(org-roam-insert nil nil label)))
|
|
||||||
(quit (progn
|
|
||||||
(replace-buffer-contents orig)
|
|
||||||
(goto-char p)))))))
|
|
||||||
|
|
||||||
(defun org-roam-doctor--remove-link ()
|
|
||||||
"Unlink the text at point."
|
|
||||||
(unless (org-in-regexp org-link-bracket-re 1)
|
|
||||||
(user-error "No link at point"))
|
|
||||||
(save-excursion
|
|
||||||
(let ((label (if (match-end 2)
|
|
||||||
(match-string-no-properties 2)
|
|
||||||
(org-link-unescape (match-string-no-properties 1)))))
|
|
||||||
(delete-region (match-beginning 0) (match-end 0))
|
|
||||||
(insert label))))
|
|
||||||
|
|
||||||
(defun org-roam-doctor--resolve (msg checker)
|
|
||||||
"Resolve an error.
|
|
||||||
MSG is the error that was found, which is displayed in a help buffer.
|
|
||||||
CHECKER is a org-roam-doctor checker instance."
|
|
||||||
(let ((actions (org-roam-doctor-checker-actions checker))
|
|
||||||
c)
|
|
||||||
(push '("e" . ("Edit" . org-roam-doctor--recursive-edit)) actions)
|
|
||||||
(push '("s" . ("Skip" . org-roam-doctor--skip)) actions)
|
|
||||||
(with-output-to-temp-buffer "*Org-roam-doctor Help*"
|
|
||||||
(mapc #'princ
|
|
||||||
(list "Error message:\n " msg "\n\n"))
|
|
||||||
(dolist (action actions)
|
|
||||||
(princ (format "[%s]: %s\n"
|
|
||||||
(car action)
|
|
||||||
(cadr action))))
|
|
||||||
(princ "\n\n"))
|
|
||||||
(shrink-window-if-larger-than-buffer
|
|
||||||
(get-buffer-window "*Org-roam-doctor Help*"))
|
|
||||||
(message "Press key for command:")
|
|
||||||
(unwind-protect
|
|
||||||
(progn
|
|
||||||
(cl-loop
|
|
||||||
do (setq c (char-to-string (read-char-exclusive)))
|
|
||||||
until (assoc c actions)
|
|
||||||
do (message "Please enter a valid key for command:"))
|
|
||||||
(funcall (cddr (assoc c actions)))
|
|
||||||
(redisplay))
|
|
||||||
(when (get-buffer-window "*Org-roam-doctor Help*")
|
|
||||||
(delete-window (get-buffer-window "*Org-roam-doctor Help*"))
|
|
||||||
(kill-buffer "*Org-roam-doctor Help*")))))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun org-roam-doctor (&optional checkall)
|
|
||||||
"Perform a check on the current buffer to ensure cleanliness.
|
|
||||||
If CHECKALL, run the check for all Org-roam files."
|
|
||||||
(interactive "P")
|
|
||||||
(unless org-roam-mode (org-roam-mode))
|
|
||||||
(let ((files (if checkall
|
|
||||||
(org-roam--list-all-files)
|
|
||||||
(unless (org-roam--org-roam-file-p)
|
|
||||||
(user-error "Not in an org-roam file"))
|
|
||||||
`(,(buffer-file-name)))))
|
|
||||||
(org-roam-doctor-start files org-roam-doctor--checkers)))
|
|
||||||
|
|
||||||
(defun org-roam-doctor-start (files checkers)
|
|
||||||
"Lint FILES using CHECKERS."
|
|
||||||
(save-window-excursion
|
|
||||||
(let ((existing-buffers (org-roam--get-roam-buffers)))
|
|
||||||
(dolist (f files)
|
|
||||||
(let ((buf (find-file-noselect f)))
|
|
||||||
(org-roam-doctor--check buf checkers)
|
|
||||||
(unless (memq buf existing-buffers)
|
|
||||||
(save-buffer buf)
|
|
||||||
(kill-buffer buf))))))
|
|
||||||
(org-roam-message "Linting completed."))
|
|
||||||
|
|
||||||
(provide 'org-roam-doctor)
|
|
||||||
|
|
||||||
;;; org-roam-doctor.el ends here
|
|
@ -1,12 +1,12 @@
|
|||||||
;;; org-roam-graph.el --- Graphing API -*- coding: utf-8; lexical-binding: t; -*-
|
;;; org-roam-graph.el --- Graphing API -*- coding: utf-8; lexical-binding: t; -*-
|
||||||
|
|
||||||
;; Copyright © 2020 Jethro Kuan <jethrokuan95@gmail.com>
|
;; Copyright © 2020-2021 Jethro Kuan <jethrokuan95@gmail.com>
|
||||||
|
|
||||||
;; Author: Jethro Kuan <jethrokuan95@gmail.com>
|
;; Author: Jethro Kuan <jethrokuan95@gmail.com>
|
||||||
;; URL: https://github.com/org-roam/org-roam
|
;; URL: https://github.com/org-roam/org-roam
|
||||||
;; Keywords: org-mode, roam, convenience
|
;; Keywords: org-mode, roam, convenience
|
||||||
;; Version: 1.2.1
|
;; Version: 2.0.0
|
||||||
;; Package-Requires: ((emacs "26.1") (dash "2.13") (f "0.17.2") (s "1.12.0") (org "9.3") (emacsql "3.0.0") (emacsql-sqlite3 "1.0.0"))
|
;; Package-Requires: ((emacs "26.1") (dash "2.13") (f "0.17.2") (org "9.4") (emacsql "3.0.0") (emacsql-sqlite "1.0.0") (magit-section "2.90.1"))
|
||||||
|
|
||||||
;; This file is NOT part of GNU Emacs.
|
;; This file is NOT part of GNU Emacs.
|
||||||
|
|
||||||
@ -31,16 +31,12 @@
|
|||||||
;;
|
;;
|
||||||
;;; Code:
|
;;; Code:
|
||||||
(require 'xml) ;xml-escape-string
|
(require 'xml) ;xml-escape-string
|
||||||
(require 's) ;s-truncate, s-replace
|
(eval-and-compile
|
||||||
(require 'org-roam-macs)
|
(require 'org-roam-macs))
|
||||||
(require 'org-roam-db)
|
(require 'org-roam-db)
|
||||||
|
|
||||||
;;;; Declarations
|
;;;; Declarations
|
||||||
(defvar org-roam-directory)
|
(defvar org-roam-directory)
|
||||||
(defvar org-roam-mode)
|
|
||||||
(declare-function org-roam--org-roam-file-p "org-roam")
|
|
||||||
(declare-function org-roam--path-to-slug "org-roam")
|
|
||||||
(declare-function org-roam-mode "org-roam")
|
|
||||||
|
|
||||||
;;;; Options
|
;;;; Options
|
||||||
(defcustom org-roam-graph-viewer (executable-find "firefox")
|
(defcustom org-roam-graph-viewer (executable-find "firefox")
|
||||||
@ -60,6 +56,12 @@ It may be one of the following:
|
|||||||
:type 'string
|
:type 'string
|
||||||
:group 'org-roam)
|
:group 'org-roam)
|
||||||
|
|
||||||
|
(defcustom org-roam-graph-filetype "svg"
|
||||||
|
"File type to generate when producing graphs."
|
||||||
|
:type 'string
|
||||||
|
:group 'org-roam)
|
||||||
|
|
||||||
|
|
||||||
(defcustom org-roam-graph-extra-config nil
|
(defcustom org-roam-graph-extra-config nil
|
||||||
"Extra options passed to graphviz.
|
"Extra options passed to graphviz.
|
||||||
Example:
|
Example:
|
||||||
@ -67,31 +69,34 @@ Example:
|
|||||||
:type '(alist)
|
:type '(alist)
|
||||||
:group 'org-roam)
|
:group 'org-roam)
|
||||||
|
|
||||||
|
(defcustom org-roam-graph-edge-extra-config nil
|
||||||
|
"Extra edge options passed to graphviz.
|
||||||
|
Example:
|
||||||
|
'((\"dir\" . \"back\"))"
|
||||||
|
:type '(alist)
|
||||||
|
:group 'org-roam)
|
||||||
|
|
||||||
(defcustom org-roam-graph-node-extra-config
|
(defcustom org-roam-graph-node-extra-config
|
||||||
'(("shape" . "underline")
|
'(("id" . (("style" . "bold,rounded,filled")
|
||||||
("style" . "rounded,filled")
|
("fillcolor" . "#EEEEEE")
|
||||||
("fillcolor" . "#EEEEEE")
|
("color" . "#C9C9C9")
|
||||||
("color" . "#C9C9C9")
|
("fontcolor" . "#111111")))
|
||||||
("fontcolor" . "#111111"))
|
("http" . (("style" . "rounded,filled")
|
||||||
"Extra options for graphviz nodes.
|
("fillcolor" . "#EEEEEE")
|
||||||
Example:
|
("color" . "#C9C9C9")
|
||||||
'((\"color\" . \"skyblue\"))"
|
("fontcolor" . "#0A97A6")))
|
||||||
|
("https" . (("shape" . "rounded,filled")
|
||||||
|
("fillcolor" . "#EEEEEE")
|
||||||
|
("color" . "#C9C9C9")
|
||||||
|
("fontcolor" . "#0A97A6"))))
|
||||||
|
"Extra options for graphviz nodes."
|
||||||
:type '(alist)
|
:type '(alist)
|
||||||
:group 'org-roam)
|
:group 'org-roam)
|
||||||
|
|
||||||
(defcustom org-roam-graph-edge-extra-config
|
(defcustom org-roam-graph-link-hidden-types
|
||||||
'(("color" . "#333333"))
|
'("file")
|
||||||
"Extra options for graphviz edges.
|
"What sort of links to hide from the Org-roam graph."
|
||||||
Example:
|
:type '(repeat string)
|
||||||
'((\"dir\" . \"back\"))"
|
|
||||||
:type '(alist)
|
|
||||||
:group 'org-roam)
|
|
||||||
|
|
||||||
(defcustom org-roam-graph-edge-cites-extra-config '(("color" . "red"))
|
|
||||||
"Extra options for graphviz edges for citation links.
|
|
||||||
Example:
|
|
||||||
'((\"dir\" . \"back\"))"
|
|
||||||
:type '(alist)
|
|
||||||
:group 'org-roam)
|
:group 'org-roam)
|
||||||
|
|
||||||
(defcustom org-roam-graph-max-title-length 100
|
(defcustom org-roam-graph-max-title-length 100
|
||||||
@ -112,45 +117,6 @@ All other values including nil will have no effect."
|
|||||||
(const :tag "no" nil))
|
(const :tag "no" nil))
|
||||||
:group 'org-roam)
|
:group 'org-roam)
|
||||||
|
|
||||||
(defcustom org-roam-graph-exclude-matcher nil
|
|
||||||
"Matcher for excluding nodes from the generated graph.
|
|
||||||
Any nodes and links for file paths matching this string is
|
|
||||||
excluded from the graph.
|
|
||||||
|
|
||||||
If value is a string, the string is the only matcher.
|
|
||||||
|
|
||||||
If value is a list, all file paths matching any of the strings
|
|
||||||
are excluded."
|
|
||||||
:type '(choice
|
|
||||||
(string :tag "Matcher")
|
|
||||||
(list :tag "Matchers"))
|
|
||||||
:group 'org-roam)
|
|
||||||
|
|
||||||
;;;; Functions
|
|
||||||
(defun org-roam-graph--expand-matcher (col &optional negate where)
|
|
||||||
"Return the exclusion regexp from `org-roam-graph-exclude-matcher'.
|
|
||||||
COL is the symbol to be matched against. if NEGATE, add :not to sql query.
|
|
||||||
set WHERE to true if WHERE query already exists."
|
|
||||||
(let ((matchers (pcase org-roam-graph-exclude-matcher
|
|
||||||
('nil nil)
|
|
||||||
((pred stringp) `(,(concat "%" org-roam-graph-exclude-matcher "%")))
|
|
||||||
((pred listp) (mapcar (lambda (m)
|
|
||||||
(concat "%" m "%"))
|
|
||||||
org-roam-graph-exclude-matcher))
|
|
||||||
(_ (error "Invalid org-roam-graph-exclude-matcher"))))
|
|
||||||
res)
|
|
||||||
(dolist (match matchers)
|
|
||||||
(if where
|
|
||||||
(push :and res)
|
|
||||||
(push :where res)
|
|
||||||
(setq where t))
|
|
||||||
(push col res)
|
|
||||||
(when negate
|
|
||||||
(push :not res))
|
|
||||||
(push :like res)
|
|
||||||
(push match res))
|
|
||||||
(nreverse res)))
|
|
||||||
|
|
||||||
(defun org-roam-graph--dot-option (option &optional wrap-key wrap-val)
|
(defun org-roam-graph--dot-option (option &optional wrap-key wrap-val)
|
||||||
"Return dot string of form KEY=VAL for OPTION cons.
|
"Return dot string of form KEY=VAL for OPTION cons.
|
||||||
If WRAP-KEY is non-nil it wraps the KEY.
|
If WRAP-KEY is non-nil it wraps the KEY.
|
||||||
@ -159,71 +125,104 @@ If WRAP-VAL is non-nil it wraps the VAL."
|
|||||||
"="
|
"="
|
||||||
wrap-val (cdr option) wrap-val))
|
wrap-val (cdr option) wrap-val))
|
||||||
|
|
||||||
(defun org-roam-graph--dot (node-query)
|
(defun org-roam-graph--connected-component (id distance)
|
||||||
"Build the graphviz dot string for NODE-QUERY.
|
"Return the edges for all nodes reachable from/connected to ID.
|
||||||
The Org-roam database titles table is read, to obtain the list of titles.
|
DISTANCE is the maximum distance away from the root node."
|
||||||
The links table is then read to obtain all directed links, and formatted
|
(let* ((query
|
||||||
into a digraph."
|
(if (= distance 0)
|
||||||
(org-roam-db--ensure-built)
|
"
|
||||||
(org-roam--with-temp-buffer nil
|
WITH RECURSIVE
|
||||||
(let* ((nodes (org-roam-db-query node-query))
|
links_of(source, dest) AS
|
||||||
(edges-query
|
(SELECT source, dest FROM links UNION
|
||||||
`[:with selected :as [:select [file] :from ,node-query]
|
SELECT dest, source FROM links),
|
||||||
:select :distinct [to from] :from links
|
connected_component(source) AS
|
||||||
:where (and (in to selected) (in from selected))])
|
(SELECT dest FROM links_of WHERE source = $s1 UNION
|
||||||
(edges-cites-query
|
SELECT dest FROM links_of JOIN connected_component USING(source))
|
||||||
`[:with selected :as [:select [file] :from ,node-query]
|
SELECT source, dest, type FROM links WHERE source IN connected_component OR dest IN connected_component;"
|
||||||
:select :distinct [file from]
|
"
|
||||||
:from links :inner :join refs :on (and (= links:to refs:ref)
|
WITH RECURSIVE
|
||||||
(= links:type "cite")
|
links_of(source, dest) AS
|
||||||
(= refs:type "cite"))
|
(SELECT source, dest FROM links UNION
|
||||||
:where (and (in file selected) (in from selected))])
|
SELECT dest, source FROM links),
|
||||||
(edges (org-roam-db-query edges-query))
|
connected_component(source, trace) AS
|
||||||
(edges-cites (org-roam-db-query edges-cites-query)))
|
(VALUES ($s1 , json_array($s1)) UNION
|
||||||
|
SELECT lo.dest, json_insert(cc.trace, '$[' || json_array_length(cc.trace) || ']', lo.dest) FROM
|
||||||
|
connected_component AS cc JOIN links_of AS lo USING(source)
|
||||||
|
WHERE (
|
||||||
|
-- Avoid cycles by only visiting each node once.
|
||||||
|
(SELECT count(*) FROM json_each(cc.trace) WHERE json_each.value == lo.dest) == 0
|
||||||
|
-- Note: BFS is cut off early here.
|
||||||
|
AND json_array_length(cc.trace) < $s2)),
|
||||||
|
nodes(source) as (SELECT DISTINCT source
|
||||||
|
FROM connected_component GROUP BY source ORDER BY min(json_array_length(trace)))
|
||||||
|
SELECT source, dest, type FROM links WHERE source IN nodes OR dest IN nodes;")))
|
||||||
|
(org-roam-db-query query id distance)))
|
||||||
|
|
||||||
|
(defun org-roam-graph--dot (&optional edges all-nodes)
|
||||||
|
"Build the graphviz given the EDGES of the graph.
|
||||||
|
If ALL-NODES, include also nodes without edges."
|
||||||
|
(let ((org-roam-directory-temp org-roam-directory)
|
||||||
|
(nodes-table (org-roam--nodes-table))
|
||||||
|
(seen-nodes (list))
|
||||||
|
(edges (or edges (org-roam-db-query [:select :distinct [source dest type] :from links]))))
|
||||||
|
(with-temp-buffer
|
||||||
|
(setq-local org-roam-directory org-roam-directory-temp)
|
||||||
(insert "digraph \"org-roam\" {\n")
|
(insert "digraph \"org-roam\" {\n")
|
||||||
(dolist (option org-roam-graph-extra-config)
|
(dolist (option org-roam-graph-extra-config)
|
||||||
(insert (org-roam-graph--dot-option option) ";\n"))
|
(insert (org-roam-graph--dot-option option) ";\n"))
|
||||||
(dolist (attribute '("node" "edge"))
|
(insert (format " edge [%s];\n"
|
||||||
(insert (format " %s [%s];\n" attribute
|
(mapconcat (lambda (var)
|
||||||
(mapconcat (lambda (var)
|
(org-roam-graph--dot-option var nil "\""))
|
||||||
(org-roam-graph--dot-option var nil "\""))
|
org-roam-graph-edge-extra-config
|
||||||
(symbol-value
|
",")))
|
||||||
(intern (concat "org-roam-graph-" attribute "-extra-config")))
|
(pcase-dolist (`(,source ,dest ,type) edges)
|
||||||
","))))
|
(unless (member type org-roam-graph-link-hidden-types)
|
||||||
(dolist (node nodes)
|
(pcase-dolist (`(,node ,node-type) `((,source "id")
|
||||||
(let* ((file (xml-escape-string (car node)))
|
(,dest ,type)))
|
||||||
(title (or (cadr node)
|
(unless (member node seen-nodes)
|
||||||
(org-roam--path-to-slug file)))
|
(insert (org-roam-graph--format-node
|
||||||
(shortened-title (pcase org-roam-graph-shorten-titles
|
(or (gethash node nodes-table) node) node-type))
|
||||||
(`truncate (s-truncate org-roam-graph-max-title-length title))
|
(push node seen-nodes)))
|
||||||
(`wrap (s-word-wrap org-roam-graph-max-title-length title))
|
(insert (format " \"%s\" -> \"%s\";\n"
|
||||||
(_ title)))
|
(xml-escape-string source)
|
||||||
(shortened-title (org-roam-string-quote shortened-title))
|
(xml-escape-string dest)))))
|
||||||
(title (org-roam-string-quote title))
|
(when all-nodes
|
||||||
(node-properties
|
(maphash (lambda (id node)
|
||||||
`(("label" . ,shortened-title)
|
(unless (member id seen-nodes)
|
||||||
("URL" . ,(concat "org-protocol://roam-file?file=" (url-hexify-string file)))
|
(insert (org-roam-graph--format-node node "id"))))
|
||||||
("tooltip" . ,(xml-escape-string title)))))
|
nodes-table))
|
||||||
(insert
|
|
||||||
(format " \"%s\" [%s];\n" file
|
|
||||||
(mapconcat (lambda (n)
|
|
||||||
(org-roam-graph--dot-option n nil "\""))
|
|
||||||
node-properties ",")))))
|
|
||||||
(dolist (edge edges)
|
|
||||||
(insert (apply #'format `(" \"%s\" -> \"%s\";\n"
|
|
||||||
,@(mapcar #'xml-escape-string edge)))))
|
|
||||||
(insert (format " edge [%s];\n"
|
|
||||||
(mapconcat #'org-roam-graph--dot-option
|
|
||||||
org-roam-graph-edge-cites-extra-config ",")))
|
|
||||||
(dolist (edge edges-cites)
|
|
||||||
(insert (apply #'format `(" \"%s\" -> \"%s\";\n"
|
|
||||||
,@(mapcar #'xml-escape-string edge)))))
|
|
||||||
(insert "}")
|
(insert "}")
|
||||||
(buffer-string))))
|
(buffer-string))))
|
||||||
|
|
||||||
(defun org-roam-graph--build (&optional node-query callback)
|
(defun org-roam-graph--format-node (node type)
|
||||||
"Generate a graph showing the relations between nodes in NODE-QUERY.
|
"Return a graphviz NODE with TYPE.
|
||||||
Execute CALLBACK when process exits successfully.
|
Handles both Org-roam nodes, and string nodes (e.g. urls)."
|
||||||
|
(let (node-id node-properties)
|
||||||
|
(if (org-roam-node-p node)
|
||||||
|
(let* ((title (org-roam-quote-string (org-roam-node-title node)))
|
||||||
|
(shortened-title (org-roam-quote-string
|
||||||
|
(pcase org-roam-graph-shorten-titles
|
||||||
|
(`truncate (org-roam-truncate org-roam-graph-max-title-length title))
|
||||||
|
(`wrap (s-word-wrap org-roam-graph-max-title-length title))
|
||||||
|
(_ title)))))
|
||||||
|
(setq node-id (org-roam-node-id node)
|
||||||
|
node-properties `(("label" . ,shortened-title)
|
||||||
|
("URL" . ,(concat "org-protocol://roam-node?node="
|
||||||
|
(url-hexify-string (org-roam-node-id node))))
|
||||||
|
("tooltip" . ,(xml-escape-string title)))))
|
||||||
|
(setq node-id node
|
||||||
|
node-properties (append `(("label" . ,(concat type ":" node)))
|
||||||
|
(when (member type (list "http" "https"))
|
||||||
|
`(("URL" . ,(xml-escape-string (concat type ":" node))))))))
|
||||||
|
(format "\"%s\" [%s];\n"
|
||||||
|
node-id
|
||||||
|
(mapconcat (lambda (n)
|
||||||
|
(org-roam-graph--dot-option n nil "\""))
|
||||||
|
(append (cdr (assoc type org-roam-graph-node-extra-config))
|
||||||
|
node-properties) ","))))
|
||||||
|
|
||||||
|
(defun org-roam-graph--build (graph &optional callback)
|
||||||
|
"Generate the GRAPH, and execute CALLBACK when process exits successfully.
|
||||||
CALLBACK is passed the graph file as its sole argument."
|
CALLBACK is passed the graph file as its sole argument."
|
||||||
(unless (stringp org-roam-graph-executable)
|
(unless (stringp org-roam-graph-executable)
|
||||||
(user-error "`org-roam-graph-executable' is not a string"))
|
(user-error "`org-roam-graph-executable' is not a string"))
|
||||||
@ -231,18 +230,13 @@ CALLBACK is passed the graph file as its sole argument."
|
|||||||
(user-error (concat "Cannot find executable \"%s\" to generate the graph. "
|
(user-error (concat "Cannot find executable \"%s\" to generate the graph. "
|
||||||
"Please adjust `org-roam-graph-executable'")
|
"Please adjust `org-roam-graph-executable'")
|
||||||
org-roam-graph-executable))
|
org-roam-graph-executable))
|
||||||
(let* ((node-query (or node-query
|
(let* ((temp-dot (make-temp-file "graph." nil ".dot" graph))
|
||||||
`[:select [file title] :from titles
|
(temp-graph (make-temp-file "graph." nil (concat "." org-roam-graph-filetype))))
|
||||||
,@(org-roam-graph--expand-matcher 'file t)
|
|
||||||
:group :by file]))
|
|
||||||
(graph (org-roam-graph--dot node-query))
|
|
||||||
(temp-dot (make-temp-file "graph." nil ".dot" graph))
|
|
||||||
(temp-graph (make-temp-file "graph." nil ".svg")))
|
|
||||||
(org-roam-message "building graph")
|
(org-roam-message "building graph")
|
||||||
(make-process
|
(make-process
|
||||||
:name "*org-roam-graph--build-process*"
|
:name "*org-roam-graph--build-process*"
|
||||||
:buffer "*org-roam-graph--build-process*"
|
:buffer "*org-roam-graph--build-process*"
|
||||||
:command `(,org-roam-graph-executable ,temp-dot "-Tsvg" "-o" ,temp-graph)
|
:command `(,org-roam-graph-executable ,temp-dot "-T" ,org-roam-graph-filetype "-o" ,temp-graph)
|
||||||
:sentinel (when callback
|
:sentinel (when callback
|
||||||
(lambda (process _event)
|
(lambda (process _event)
|
||||||
(when (= 0 (process-exit-status process))
|
(when (= 0 (process-exit-status process))
|
||||||
@ -261,47 +255,26 @@ CALLBACK is passed the graph file as its sole argument."
|
|||||||
('nil (view-file file))
|
('nil (view-file file))
|
||||||
(_ (signal 'wrong-type-argument `((functionp stringp null) ,org-roam-graph-viewer)))))
|
(_ (signal 'wrong-type-argument `((functionp stringp null) ,org-roam-graph-viewer)))))
|
||||||
|
|
||||||
(defun org-roam-graph--build-connected-component (file &optional max-distance callback)
|
|
||||||
"Build a graph of nodes connected to FILE.
|
|
||||||
If MAX-DISTANCE is non-nil, limit nodes to MAX-DISTANCE steps.
|
|
||||||
CALLBACK is passed to `org-roam-graph--build'."
|
|
||||||
(let* ((file (file-truename file))
|
|
||||||
(files (or (if (and max-distance (>= max-distance 0))
|
|
||||||
(org-roam-db--links-with-max-distance file max-distance)
|
|
||||||
(org-roam-db--connected-component file))
|
|
||||||
(list file)))
|
|
||||||
(query `[:select [file title]
|
|
||||||
:from titles
|
|
||||||
:where (in file [,@files])]))
|
|
||||||
(org-roam-graph--build query callback)))
|
|
||||||
|
|
||||||
;;;; Commands
|
;;;; Commands
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun org-roam-graph (&optional arg file node-query)
|
(defun org-roam-graph (&optional arg node)
|
||||||
"Build and possibly display a graph for FILE from NODE-QUERY.
|
"Build and possibly display a graph for NODE.
|
||||||
If FILE is nil, default to current buffer's file name.
|
|
||||||
ARG may be any of the following values:
|
ARG may be any of the following values:
|
||||||
- nil show the graph.
|
- nil show the graph.
|
||||||
- `\\[universal-argument]' show the graph for FILE.
|
- `\\[universal-argument]' show the graph for NODE.
|
||||||
- `\\[universal-argument]' N show the graph for FILE limiting nodes to N steps.
|
- `\\[universal-argument]' N show the graph for NODE limiting nodes to N steps."
|
||||||
- `\\[universal-argument] \\[universal-argument]' build the graph.
|
(interactive
|
||||||
- `\\[universal-argument]' - build the graph for FILE.
|
(list current-prefix-arg
|
||||||
- `\\[universal-argument]' -N build the graph for FILE limiting nodes to N steps."
|
(and current-prefix-arg
|
||||||
(interactive "P")
|
(org-roam-node-at-point 'assert))))
|
||||||
(unless org-roam-mode (org-roam-mode))
|
(let ((graph (cl-typecase arg
|
||||||
(let ((file (or file (buffer-file-name (buffer-base-buffer)))))
|
(null (org-roam-graph--dot nil 'all-nodes))
|
||||||
(unless (or (not arg) (equal arg '(16)))
|
(cons (org-roam-graph--dot (org-roam-graph--connected-component
|
||||||
(unless file
|
(org-roam-node-id node) 0)))
|
||||||
(user-error "Cannot build graph for nil file. Is current buffer visiting a file?"))
|
(integer (org-roam-graph--dot (org-roam-graph--connected-component
|
||||||
(unless (org-roam--org-roam-file-p file)
|
(org-roam-node-id node) (abs arg)))))))
|
||||||
(user-error "\"%s\" is not an org-roam file" file)))
|
(org-roam-graph--build graph #'org-roam-graph--open)))
|
||||||
(pcase arg
|
|
||||||
('nil (org-roam-graph--build node-query #'org-roam-graph--open))
|
|
||||||
('(4) (org-roam-graph--build-connected-component file nil #'org-roam-graph--open))
|
|
||||||
((pred integerp) (org-roam-graph--build-connected-component file (abs arg) (when (>= arg 0) #'org-roam-graph--open)))
|
|
||||||
('(16) (org-roam-graph--build node-query))
|
|
||||||
('- (org-roam-graph--build-connected-component file))
|
|
||||||
(_ (user-error "Unrecognized ARG: %s" arg)))))
|
|
||||||
|
|
||||||
(provide 'org-roam-graph)
|
(provide 'org-roam-graph)
|
||||||
|
|
||||||
|
@ -5,8 +5,8 @@
|
|||||||
;; Author: Jethro Kuan <jethrokuan95@gmail.com>
|
;; Author: Jethro Kuan <jethrokuan95@gmail.com>
|
||||||
;; URL: https://github.com/org-roam/org-roam
|
;; URL: https://github.com/org-roam/org-roam
|
||||||
;; Keywords: org-mode, roam, convenience
|
;; Keywords: org-mode, roam, convenience
|
||||||
;; Version: 1.2.1
|
;; Version: 2.0.0
|
||||||
;; Package-Requires: ((emacs "26.1") (dash "2.13") (f "0.17.2") (s "1.12.0") (org "9.3") (emacsql "3.0.0") (emacsql-sqlite3 "1.0.0"))
|
;; Package-Requires: ((emacs "26.1") (dash "2.13") (f "0.17.2") (org "9.4") (emacsql "3.0.0") (emacsql-sqlite "1.0.0") (magit-section "2.90.1"))
|
||||||
|
|
||||||
;; This file is NOT part of GNU Emacs.
|
;; This file is NOT part of GNU Emacs.
|
||||||
|
|
||||||
@ -27,56 +27,64 @@
|
|||||||
|
|
||||||
;;; Commentary:
|
;;; Commentary:
|
||||||
;;
|
;;
|
||||||
;; This library implements macros and utility functions used throughout
|
;; This library implements macros used throughout org-roam.
|
||||||
;; org-roam.
|
|
||||||
;;
|
|
||||||
;;
|
;;
|
||||||
;;; Code:
|
;;; Code:
|
||||||
;;;; Library Requires
|
(defmacro org-roam-plist-map! (fn plist)
|
||||||
(require 'dash)
|
"Map FN over PLIST, modifying it in-place."
|
||||||
|
(declare (indent 1))
|
||||||
|
(let ((plist-var (make-symbol "plist"))
|
||||||
|
(k (make-symbol "k"))
|
||||||
|
(v (make-symbol "v")))
|
||||||
|
`(let ((,plist-var (copy-sequence ,plist)))
|
||||||
|
(while ,plist-var
|
||||||
|
(setq ,k (pop ,plist-var))
|
||||||
|
(setq ,v (pop ,plist-var))
|
||||||
|
(setq ,plist (plist-put ,plist ,k (funcall ,fn ,k ,v)))))))
|
||||||
|
|
||||||
(defvar org-roam-verbose)
|
(defmacro org-roam-with-file (file keep-buf-p &rest body)
|
||||||
|
"Execute BODY within FILE.
|
||||||
|
If FILE is nil, execute BODY in the current buffer.
|
||||||
|
Kills the buffer if KEEP-BUF-P is nil, and FILE is not yet visited."
|
||||||
|
(declare (indent 2) (debug t))
|
||||||
|
`(let* (new-buf
|
||||||
|
(auto-mode-alist nil)
|
||||||
|
(buf (or (and (not ,file)
|
||||||
|
(current-buffer)) ;If FILE is nil, use current buffer
|
||||||
|
(find-buffer-visiting ,file) ; If FILE is already visited, find buffer
|
||||||
|
(progn
|
||||||
|
(setq new-buf t)
|
||||||
|
(find-file-noselect ,file)))) ; Else, visit FILE and return buffer
|
||||||
|
res)
|
||||||
|
(with-current-buffer buf
|
||||||
|
(unless (equal major-mode 'org-mode)
|
||||||
|
(delay-mode-hooks
|
||||||
|
(let ((org-inhibit-startup t)
|
||||||
|
(org-agenda-files nil))
|
||||||
|
(org-mode))))
|
||||||
|
(setq res (progn ,@body))
|
||||||
|
(unless (and new-buf (not ,keep-buf-p))
|
||||||
|
(save-buffer)))
|
||||||
|
(if (and new-buf (not ,keep-buf-p))
|
||||||
|
(when (find-buffer-visiting ,file)
|
||||||
|
(kill-buffer (find-buffer-visiting ,file))))
|
||||||
|
res))
|
||||||
|
|
||||||
(defmacro org-roam--with-temp-buffer (file &rest body)
|
(defmacro org-roam-with-temp-buffer (file &rest body)
|
||||||
"Execute BODY within a temp buffer.
|
"Execute BODY within a temp buffer.
|
||||||
Like `with-temp-buffer', but propagates `org-roam-directory'.
|
Like `with-temp-buffer', but propagates `org-roam-directory'.
|
||||||
If FILE, set `org-roam-temp-file-name' to file and insert its contents."
|
If FILE, set `default-directory' to FILE's directory and insert its contents."
|
||||||
(declare (indent 1) (debug t))
|
(declare (indent 1) (debug t))
|
||||||
(let ((current-org-roam-directory (make-symbol "current-org-roam-directory")))
|
(let ((current-org-roam-directory (make-symbol "current-org-roam-directory")))
|
||||||
`(let ((,current-org-roam-directory org-roam-directory))
|
`(let ((,current-org-roam-directory org-roam-directory))
|
||||||
(with-temp-buffer
|
(with-temp-buffer
|
||||||
(let ((org-roam-directory ,current-org-roam-directory)
|
(let ((org-roam-directory ,current-org-roam-directory))
|
||||||
(org-mode-hook nil))
|
(delay-mode-hooks (org-mode))
|
||||||
(org-mode)
|
|
||||||
(when ,file
|
(when ,file
|
||||||
(insert-file-contents ,file)
|
(insert-file-contents ,file)
|
||||||
(setq-local org-roam-file-name ,file))
|
(setq-local default-directory (file-name-directory ,file)))
|
||||||
,@body)))))
|
,@body)))))
|
||||||
|
|
||||||
(defmacro org-roam--with-template-error (templates &rest body)
|
|
||||||
"Eval BODY, and point to TEMPLATES on error.
|
|
||||||
Provides more informative error messages so that users know where
|
|
||||||
to look.
|
|
||||||
|
|
||||||
\(fn TEMPLATES BODY...)"
|
|
||||||
(declare (debug (form body)) (indent 1))
|
|
||||||
`(condition-case err
|
|
||||||
,@body
|
|
||||||
(error (user-error "%s. Please adjust `%s'"
|
|
||||||
(error-message-string err)
|
|
||||||
,templates))))
|
|
||||||
|
|
||||||
(defun org-roam-message (format-string &rest args)
|
|
||||||
"Pass FORMAT-STRING and ARGS to `message' when `org-roam-verbose' is t."
|
|
||||||
(when org-roam-verbose
|
|
||||||
(apply #'message `(,(concat "(org-roam) " format-string) ,@args))))
|
|
||||||
|
|
||||||
(defun org-roam-string-quote (str)
|
|
||||||
"Quote STR."
|
|
||||||
(->> str
|
|
||||||
(s-replace "\\" "\\\\")
|
|
||||||
(s-replace "\"" "\\\"")))
|
|
||||||
|
|
||||||
(provide 'org-roam-macs)
|
(provide 'org-roam-macs)
|
||||||
|
|
||||||
;;; org-roam-macs.el ends here
|
;;; org-roam-macs.el ends here
|
||||||
|
192
org-roam-migrate.el
Normal file
192
org-roam-migrate.el
Normal file
@ -0,0 +1,192 @@
|
|||||||
|
;;; org-roam-migrate.el --- Migration utilities from v1 to v2 -*- coding: utf-8; lexical-binding: t; -*-
|
||||||
|
|
||||||
|
;; Copyright © 2020-2021 Jethro Kuan <jethrokuan95@gmail.com>
|
||||||
|
|
||||||
|
;; Author: Jethro Kuan <jethrokuan95@gmail.com>
|
||||||
|
;; URL: https://github.com/org-roam/org-roam
|
||||||
|
;; Keywords: org-mode, roam, convenience
|
||||||
|
;; Version: 2.0.0
|
||||||
|
;; Package-Requires: ((emacs "26.1") (dash "2.13") (f "0.17.2") (org "9.4") (emacsql "3.0.0") (emacsql-sqlite "1.0.0") (magit-section "2.90.1"))
|
||||||
|
|
||||||
|
;; This file is NOT part of GNU Emacs.
|
||||||
|
|
||||||
|
;; This program is free software; you can redistribute it and/or modify
|
||||||
|
;; it under the terms of the GNU General Public License as published by
|
||||||
|
;; the Free Software Foundation; either version 3, or (at your option)
|
||||||
|
;; any later version.
|
||||||
|
;;
|
||||||
|
;; This program is distributed in the hope that it will be useful,
|
||||||
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
;; GNU General Public License for more details.
|
||||||
|
;;
|
||||||
|
;; You should have received a copy of the GNU General Public License
|
||||||
|
;; along with GNU Emacs; see the file COPYING. If not, write to the
|
||||||
|
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||||
|
;; Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
|
;;; Commentary:
|
||||||
|
;;
|
||||||
|
;; To ease transition from v1 to v2, we provide various migration utilities.
|
||||||
|
;; This library helps convert v1 notes to v2, and informs the user.
|
||||||
|
;;
|
||||||
|
;;; Code:
|
||||||
|
;;;; Dependencies
|
||||||
|
;;;;
|
||||||
|
;;; v1 breaking warning
|
||||||
|
(require 'org-roam-db)
|
||||||
|
|
||||||
|
(defvar org-roam-v2-ack nil)
|
||||||
|
|
||||||
|
(unless org-roam-v2-ack
|
||||||
|
(lwarn 'org-roam :error "
|
||||||
|
------------------------------------
|
||||||
|
WARNING: You're now on Org-roam v2!
|
||||||
|
------------------------------------
|
||||||
|
|
||||||
|
You may have arrived here from a package upgrade. Please read the
|
||||||
|
wiki entry at
|
||||||
|
https://github.com/org-roam/org-roam/wiki/Hitchhiker's-Rough-Guide-to-Org-roam-V2
|
||||||
|
for an overview of the major changes.
|
||||||
|
|
||||||
|
Notes taken in v1 are incompatible with v1, but you can upgrade
|
||||||
|
them to the v2 format via a simple command. To migrate your
|
||||||
|
notes, run:
|
||||||
|
|
||||||
|
M-x org-roam-migrate-wizard
|
||||||
|
|
||||||
|
If you wish to stay on v1, v1 is unfortunately not distributed on
|
||||||
|
MELPA. See org-roam/org-roam-v1 on GitHub on how to install v1.
|
||||||
|
|
||||||
|
If you've gone through the migration steps (if necessary), and
|
||||||
|
know what you're doing set `org-roam-v2-ack' to `t' to disable
|
||||||
|
this warning. You can do so by adding:
|
||||||
|
|
||||||
|
(setq org-roam-v2-ack t)
|
||||||
|
|
||||||
|
To your init file.
|
||||||
|
|
||||||
|
"))
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(defun org-roam-migrate-wizard ()
|
||||||
|
"Migrate all notes from to be compatible with Org-roam v2.
|
||||||
|
1. Convert all notes from v1 format to v2.
|
||||||
|
2. Rebuild the cache.
|
||||||
|
3. Replace all file links with ID links."
|
||||||
|
(interactive)
|
||||||
|
(when (yes-or-no-p "Org-roam will now convert all your notes from v1 to v2.
|
||||||
|
This will take a while. Are you sure you want to do this?")
|
||||||
|
;; Back up notes
|
||||||
|
(let ((backup-dir (expand-file-name "org-roam.bak"
|
||||||
|
(file-name-directory (directory-file-name org-roam-directory)))))
|
||||||
|
(message "Backing up files to %s" backup-dir)
|
||||||
|
(copy-directory org-roam-directory backup-dir))
|
||||||
|
|
||||||
|
;; Convert v1 to v2
|
||||||
|
(dolist (f (org-roam--list-all-files))
|
||||||
|
(org-roam-with-file f nil
|
||||||
|
(org-roam-migrate-v1-to-v2)))
|
||||||
|
;; Rebuild cache
|
||||||
|
(org-roam-db-sync 'force)
|
||||||
|
|
||||||
|
;;Replace all file links with ID links
|
||||||
|
(dolist (f (org-roam--list-all-files))
|
||||||
|
(org-roam-with-file f nil
|
||||||
|
(org-roam-migrate-replace-file-links-with-id)
|
||||||
|
(save-buffer)))))
|
||||||
|
|
||||||
|
(defun org-roam-migrate-v1-to-v2 ()
|
||||||
|
"Convert the current buffer to v2 format."
|
||||||
|
;; Create file level ID
|
||||||
|
(org-with-point-at 1
|
||||||
|
(org-id-get-create))
|
||||||
|
;; Replace roam_key into properties drawer roam_ref
|
||||||
|
(when-let* ((refs (mapcan #'split-string-and-unquote
|
||||||
|
(cdar (org-collect-keywords '("roam_key"))))))
|
||||||
|
(let ((case-fold-search t))
|
||||||
|
(org-with-point-at 1
|
||||||
|
(dolist (ref refs)
|
||||||
|
(org-roam-ref-add ref))
|
||||||
|
(while (re-search-forward "^#\\+roam_key:" (point-max) t)
|
||||||
|
(beginning-of-line)
|
||||||
|
(kill-line 1)))))
|
||||||
|
|
||||||
|
;; Replace roam_alias into properties drawer roam_aliases
|
||||||
|
(when-let* ((aliases (mapcan #'split-string-and-unquote
|
||||||
|
(cdar (org-collect-keywords '("roam_alias"))))))
|
||||||
|
(let ((case-fold-search t))
|
||||||
|
(org-with-point-at 1
|
||||||
|
(dolist (alias aliases)
|
||||||
|
(org-roam-alias-add alias))
|
||||||
|
(while (re-search-forward "^#\\+roam_alias:" (point-max) t)
|
||||||
|
(beginning-of-line)
|
||||||
|
(kill-line 1)))))
|
||||||
|
|
||||||
|
;; Replace #+roam_tags into #+filetags
|
||||||
|
(org-with-point-at 1
|
||||||
|
(let* ((roam-tags (org-roam-migrate-get-prop-list "ROAM_TAGS"))
|
||||||
|
(file-tags (org-roam-migrate-get-prop-list "FILETAGS"))
|
||||||
|
(tags (append roam-tags file-tags))
|
||||||
|
(tags (seq-map (lambda (tag)
|
||||||
|
(replace-regexp-in-string
|
||||||
|
"[^[:alnum:]_@#%]"
|
||||||
|
"_"
|
||||||
|
tag)) tags))
|
||||||
|
(tags (seq-uniq tags)))
|
||||||
|
(when tags
|
||||||
|
(org-roam-migrate-prop-set "filetags" (string-join tags " "))))
|
||||||
|
(let ((case-fold-search t))
|
||||||
|
(org-with-point-at 1
|
||||||
|
(while (re-search-forward "^#\\+roam_tags:" (point-max) t)
|
||||||
|
(beginning-of-line)
|
||||||
|
(kill-line 1)))))
|
||||||
|
(save-buffer))
|
||||||
|
|
||||||
|
(defun org-roam-migrate-get-prop-list (keyword)
|
||||||
|
"Return prop list for KEYWORD."
|
||||||
|
(let ((re (format "^#\\+%s:[ \t]*\\([^\n]+\\)" (upcase keyword)))
|
||||||
|
lst)
|
||||||
|
(goto-char (point-min))
|
||||||
|
(while (re-search-forward re 2048 t)
|
||||||
|
(setq lst (append lst (split-string-and-unquote
|
||||||
|
(buffer-substring-no-properties
|
||||||
|
(match-beginning 1) (match-end 1))))))
|
||||||
|
lst))
|
||||||
|
|
||||||
|
(defun org-roam-migrate-prop-set (name value)
|
||||||
|
"Set a file property called NAME to VALUE in buffer file.
|
||||||
|
If the property is already set, replace its value."
|
||||||
|
(setq name (downcase name))
|
||||||
|
(org-with-point-at 1
|
||||||
|
(let ((case-fold-search t))
|
||||||
|
(if (re-search-forward (concat "^#\\+" name ":\\(.*\\)")
|
||||||
|
(point-max) t)
|
||||||
|
(replace-match (concat "#+" name ": " value) 'fixedcase)
|
||||||
|
(while (and (not (eobp))
|
||||||
|
(looking-at "^[#:]"))
|
||||||
|
(if (save-excursion (end-of-line) (eobp))
|
||||||
|
(progn
|
||||||
|
(end-of-line)
|
||||||
|
(insert "\n"))
|
||||||
|
(forward-line)
|
||||||
|
(beginning-of-line)))
|
||||||
|
(insert "#+" name ": " value "\n")))))
|
||||||
|
|
||||||
|
(defun org-roam-migrate-replace-file-links-with-id ()
|
||||||
|
"Replace all file: links with ID links in current buffer."
|
||||||
|
(org-with-point-at 1
|
||||||
|
(while (re-search-forward org-link-bracket-re nil t)
|
||||||
|
(let* ((mdata (match-data))
|
||||||
|
(path (match-string 1))
|
||||||
|
(desc (match-string 2)))
|
||||||
|
(when (string-prefix-p "file:" path)
|
||||||
|
(setq path (expand-file-name (substring path 5)))
|
||||||
|
(when-let ((node-id (caar (org-roam-db-query [:select [id] :from nodes
|
||||||
|
:where (= file $s1)
|
||||||
|
:and (= level 0)] path))))
|
||||||
|
(set-match-data mdata)
|
||||||
|
(replace-match (org-link-make-string (concat "id:" node-id) desc))))))))
|
||||||
|
|
||||||
|
(provide 'org-roam-migrate)
|
||||||
|
;;; org-roam-migrate.el ends here
|
468
org-roam-mode.el
Normal file
468
org-roam-mode.el
Normal file
@ -0,0 +1,468 @@
|
|||||||
|
;;; org-roam-mode.el --- create and refresh Org-roam buffers -*- lexical-binding: t -*-
|
||||||
|
;; Copyright © 2020 Jethro Kuan <jethrokuan95@gmail.com>
|
||||||
|
|
||||||
|
;; Author: Jethro Kuan <jethrokuan95@gmail.com>
|
||||||
|
;; URL: https://github.com/org-roam/org-roam
|
||||||
|
;; Keywords: org-mode, roam, convenience
|
||||||
|
;; Version: 2.0.0
|
||||||
|
;; Package-Requires: ((emacs "26.1") (dash "2.13") (f "0.17.2") (org "9.4") (emacsql "3.0.0") (emacsql-sqlite "1.0.0") (magit-section "2.90.1"))
|
||||||
|
|
||||||
|
;; This file is NOT part of GNU Emacs.
|
||||||
|
|
||||||
|
;; This program is free software; you can redistribute it and/or modify
|
||||||
|
;; it under the terms of the GNU General Public License as published by
|
||||||
|
;; the Free Software Foundation; either version 3, or (at your option)
|
||||||
|
;; any later version.
|
||||||
|
;;
|
||||||
|
;; This program is distributed in the hope that it will be useful,
|
||||||
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
;; GNU General Public License for more details.
|
||||||
|
;;
|
||||||
|
;; You should have received a copy of the GNU General Public License
|
||||||
|
;; along with GNU Emacs; see the file COPYING. If not, write to the
|
||||||
|
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||||
|
;; Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
|
;;; Commentary:
|
||||||
|
;;
|
||||||
|
;; This library implements the abstract major-mode `org-roam-mode', from which
|
||||||
|
;; almost all other Org-roam major-modes derive.
|
||||||
|
;;
|
||||||
|
;;; Code:
|
||||||
|
(require 'magit-section)
|
||||||
|
|
||||||
|
(require 'org-roam-utils)
|
||||||
|
|
||||||
|
(defvar org-roam-directory)
|
||||||
|
(defvar org-roam-find-file-hook)
|
||||||
|
|
||||||
|
(declare-function org-roam-node-at-point "org-roam")
|
||||||
|
|
||||||
|
;;; Faces
|
||||||
|
(defface org-roam-header-line
|
||||||
|
`((((class color) (background light))
|
||||||
|
,@(and (>= emacs-major-version 27) '(:extend t))
|
||||||
|
:foreground "DarkGoldenrod4"
|
||||||
|
:weight bold)
|
||||||
|
(((class color) (background dark))
|
||||||
|
,@(and (>= emacs-major-version 27) '(:extend t))
|
||||||
|
:foreground "LightGoldenrod2"
|
||||||
|
:weight bold))
|
||||||
|
"Face for the `header-line' in some Org-roam modes."
|
||||||
|
:group 'org-roam-faces)
|
||||||
|
|
||||||
|
(defface org-roam-title
|
||||||
|
'((t :weight bold))
|
||||||
|
"Face for Org-roam titles."
|
||||||
|
:group 'org-roam-faces)
|
||||||
|
|
||||||
|
(defface org-roam-olp
|
||||||
|
'((((class color) (background light)) :foreground "grey60")
|
||||||
|
(((class color) (background dark)) :foreground "grey40"))
|
||||||
|
"Face for the OLP of the node."
|
||||||
|
:group 'org-roam-faces)
|
||||||
|
|
||||||
|
(defface org-roam-preview-heading
|
||||||
|
`((((class color) (background light))
|
||||||
|
,@(and (>= emacs-major-version 27) '(:extend t))
|
||||||
|
:background "grey80"
|
||||||
|
:foreground "grey30")
|
||||||
|
(((class color) (background dark))
|
||||||
|
,@(and (>= emacs-major-version 27) '(:extend t))
|
||||||
|
:background "grey25"
|
||||||
|
:foreground "grey70"))
|
||||||
|
"Face for preview headings."
|
||||||
|
:group 'org-roam-faces)
|
||||||
|
|
||||||
|
(defface org-roam-preview-heading-highlight
|
||||||
|
`((((class color) (background light))
|
||||||
|
,@(and (>= emacs-major-version 27) '(:extend t))
|
||||||
|
:background "grey75"
|
||||||
|
:foreground "grey30")
|
||||||
|
(((class color) (background dark))
|
||||||
|
,@(and (>= emacs-major-version 27) '(:extend t))
|
||||||
|
:background "grey35"
|
||||||
|
:foreground "grey70"))
|
||||||
|
"Face for current preview headings."
|
||||||
|
:group 'org-roam-faces)
|
||||||
|
|
||||||
|
(defface org-roam-preview-heading-selection
|
||||||
|
`((((class color) (background light))
|
||||||
|
,@(and (>= emacs-major-version 27) '(:extend t))
|
||||||
|
:inherit org-roam-preview-heading-highlight
|
||||||
|
:foreground "salmon4")
|
||||||
|
(((class color) (background dark))
|
||||||
|
,@(and (>= emacs-major-version 27) '(:extend t))
|
||||||
|
:inherit org-roam-preview-heading-highlight
|
||||||
|
:foreground "LightSalmon3"))
|
||||||
|
"Face for selected preview headings."
|
||||||
|
:group 'org-roam-faces)
|
||||||
|
|
||||||
|
(defface org-roam-preview-region
|
||||||
|
`((t :inherit bold
|
||||||
|
,@(and (>= emacs-major-version 27)
|
||||||
|
(list :extend (ignore-errors (face-attribute 'region :extend))))))
|
||||||
|
"Face used by `org-roam-highlight-preview-region-using-face'.
|
||||||
|
|
||||||
|
This face is overlaid over text that uses other hunk faces,
|
||||||
|
and those normally set the foreground and background colors.
|
||||||
|
The `:foreground' and especially the `:background' properties
|
||||||
|
should be avoided here. Setting the latter would cause the
|
||||||
|
loss of information. Good properties to set here are `:weight'
|
||||||
|
and `:slant'."
|
||||||
|
:group 'org-roam-faces)
|
||||||
|
|
||||||
|
(defface org-roam-dim
|
||||||
|
'((((class color) (background light)) :foreground "grey60")
|
||||||
|
(((class color) (background dark)) :foreground "grey40"))
|
||||||
|
"Face for the dimmer part of the widgets."
|
||||||
|
:group 'org-roam-faces)
|
||||||
|
|
||||||
|
;;; Variables
|
||||||
|
(defvar org-roam-current-node nil
|
||||||
|
"The current node at point.")
|
||||||
|
|
||||||
|
(defvar org-roam-current-directory nil
|
||||||
|
"The `org-roam-directory' value for the current node.")
|
||||||
|
|
||||||
|
(defcustom org-roam-mode-section-functions (list #'org-roam-backlinks-section
|
||||||
|
#'org-roam-reflinks-section)
|
||||||
|
"Functions which insert sections of the `org-roam-buffer'.
|
||||||
|
Each function is called with one argument, which is the current org-roam node at point."
|
||||||
|
:group 'org-roam
|
||||||
|
:type 'hook)
|
||||||
|
|
||||||
|
;;; The mode
|
||||||
|
(defvar org-roam-mode-map
|
||||||
|
(let ((map (make-sparse-keymap)))
|
||||||
|
(set-keymap-parent map magit-section-mode-map)
|
||||||
|
(define-key map [C-return] 'org-roam-visit-thing)
|
||||||
|
(define-key map (kbd "C-m") 'org-roam-visit-thing)
|
||||||
|
(define-key map [remap revert-buffer] 'org-roam-buffer-render)
|
||||||
|
map)
|
||||||
|
"Parent keymap for all keymaps of modes derived from `org-roam-mode'.")
|
||||||
|
|
||||||
|
(define-derived-mode org-roam-mode magit-section-mode "Org-roam"
|
||||||
|
"Major mode for Org-roam's buffer."
|
||||||
|
:group 'org-roam
|
||||||
|
(face-remap-add-relative 'header-line 'org-roam-header-line))
|
||||||
|
|
||||||
|
;;; Key functions
|
||||||
|
(defun org-roam-visit-thing ()
|
||||||
|
"This is a placeholder command.
|
||||||
|
Where applicable, section-specific keymaps bind another command
|
||||||
|
which visits the thing at point."
|
||||||
|
(interactive)
|
||||||
|
(user-error "There is no thing at point that could be visited"))
|
||||||
|
|
||||||
|
(defun org-roam-buffer-render ()
|
||||||
|
"Render the current node at point."
|
||||||
|
(interactive)
|
||||||
|
(when (derived-mode-p 'org-roam-mode)
|
||||||
|
(let ((inhibit-read-only t))
|
||||||
|
(erase-buffer)
|
||||||
|
(setq-local default-directory org-roam-current-directory)
|
||||||
|
(setq-local org-roam-directory org-roam-current-directory)
|
||||||
|
(org-roam-set-header-line-format (org-roam-node-title org-roam-current-node))
|
||||||
|
(magit-insert-section (org-roam)
|
||||||
|
(magit-insert-heading)
|
||||||
|
(run-hook-with-args 'org-roam-mode-section-functions org-roam-current-node)))))
|
||||||
|
|
||||||
|
(defun org-roam-buffer ()
|
||||||
|
"Launch an Org-roam buffer for the current node at point."
|
||||||
|
(interactive)
|
||||||
|
(if-let ((node (org-roam-node-at-point))
|
||||||
|
(source-org-roam-directory org-roam-directory))
|
||||||
|
(progn
|
||||||
|
(let ((buffer (get-buffer-create
|
||||||
|
(concat "org-roam: "
|
||||||
|
(file-relative-name (buffer-file-name) org-roam-directory)))))
|
||||||
|
(with-current-buffer buffer
|
||||||
|
(org-roam-mode)
|
||||||
|
(setq-local org-roam-current-node node)
|
||||||
|
(setq-local org-roam-current-directory source-org-roam-directory)
|
||||||
|
(org-roam-buffer-render))
|
||||||
|
(switch-to-buffer-other-window buffer)))
|
||||||
|
(user-error "No node at point")))
|
||||||
|
|
||||||
|
;;; Persistent buffer
|
||||||
|
(defvar org-roam-buffer "*org-roam*"
|
||||||
|
"The persistent Org-roam buffer name.")
|
||||||
|
|
||||||
|
(defun org-roam-buffer--post-command-h ()
|
||||||
|
"Reconstructs the Org-roam buffer.
|
||||||
|
This needs to be quick or infrequent, because this is run at
|
||||||
|
`post-command-hook'. If REDISPLAY, force an update of
|
||||||
|
the Org-roam buffer."
|
||||||
|
(when (get-buffer-window org-roam-buffer)
|
||||||
|
(when-let ((node (org-roam-node-at-point)))
|
||||||
|
(unless (equal node org-roam-current-node)
|
||||||
|
(setq org-roam-current-node node)
|
||||||
|
(setq org-roam-current-directory org-roam-directory)
|
||||||
|
(org-roam-buffer-persistent-redisplay)))))
|
||||||
|
|
||||||
|
(define-inline org-roam-buffer--visibility ()
|
||||||
|
"Return whether the current visibility state of the org-roam buffer.
|
||||||
|
Valid states are 'visible, 'exists and 'none."
|
||||||
|
(declare (side-effect-free t))
|
||||||
|
(inline-quote
|
||||||
|
(cond
|
||||||
|
((get-buffer-window org-roam-buffer) 'visible)
|
||||||
|
((get-buffer org-roam-buffer) 'exists)
|
||||||
|
(t 'none))))
|
||||||
|
|
||||||
|
(defun org-roam-buffer-toggle ()
|
||||||
|
"Toggle display of the Org-roam buffer."
|
||||||
|
(interactive)
|
||||||
|
(pcase (org-roam-buffer--visibility)
|
||||||
|
('visible
|
||||||
|
(progn
|
||||||
|
(delete-window (get-buffer-window org-roam-buffer))
|
||||||
|
(remove-hook 'post-command-hook #'org-roam-buffer--post-command-h)))
|
||||||
|
((or 'exists 'none)
|
||||||
|
(progn
|
||||||
|
(setq org-roam-current-node (org-roam-node-at-point)
|
||||||
|
org-roam-current-directory org-roam-directory)
|
||||||
|
(display-buffer (get-buffer-create org-roam-buffer))
|
||||||
|
(org-roam-buffer-persistent-redisplay)))))
|
||||||
|
|
||||||
|
(defun org-roam-buffer-persistent-redisplay ()
|
||||||
|
"Recompute contents of the persistent Org-roam buffer.
|
||||||
|
Has no effect when `org-roam-current-node' is nil."
|
||||||
|
(when org-roam-current-node
|
||||||
|
(with-current-buffer (get-buffer-create org-roam-buffer)
|
||||||
|
(let ((inhibit-read-only t))
|
||||||
|
(erase-buffer)
|
||||||
|
(org-roam-mode)
|
||||||
|
(setq-local default-directory org-roam-current-directory)
|
||||||
|
(setq-local org-roam-directory org-roam-current-directory)
|
||||||
|
(org-roam-set-header-line-format (org-roam-node-title org-roam-current-node))
|
||||||
|
(magit-insert-section (org-roam)
|
||||||
|
(magit-insert-heading)
|
||||||
|
(dolist (fn org-roam-mode-section-functions)
|
||||||
|
(funcall fn org-roam-current-node)))))))
|
||||||
|
|
||||||
|
(defun org-roam-buffer--redisplay ()
|
||||||
|
"."
|
||||||
|
(add-hook 'post-command-hook #'org-roam-buffer--post-command-h nil t))
|
||||||
|
|
||||||
|
(add-hook 'org-roam-find-file-hook #'org-roam-buffer--redisplay)
|
||||||
|
|
||||||
|
;;; Sections
|
||||||
|
;;;; Backlinks
|
||||||
|
(cl-defstruct (org-roam-backlink (:constructor org-roam-backlink-create)
|
||||||
|
(:copier nil))
|
||||||
|
source-node target-node
|
||||||
|
point properties)
|
||||||
|
|
||||||
|
(cl-defmethod org-roam-populate ((backlink org-roam-backlink))
|
||||||
|
"Populate BACKLINK from database."
|
||||||
|
(setf (org-roam-backlink-source-node backlink)
|
||||||
|
(org-roam-populate (org-roam-backlink-source-node backlink))
|
||||||
|
(org-roam-backlink-target-node backlink)
|
||||||
|
(org-roam-populate (org-roam-backlink-target-node backlink)))
|
||||||
|
backlink)
|
||||||
|
|
||||||
|
(defun org-roam-backlinks-get (node)
|
||||||
|
"Return the backlinks for NODE."
|
||||||
|
(let ((backlinks (org-roam-db-query
|
||||||
|
[:select [source dest pos properties]
|
||||||
|
:from links
|
||||||
|
:where (= dest $s1)
|
||||||
|
:and (= type "id")]
|
||||||
|
(org-roam-node-id node))))
|
||||||
|
(cl-loop for backlink in backlinks
|
||||||
|
collect (pcase-let ((`(,source-id ,dest-id ,pos ,properties) backlink))
|
||||||
|
(org-roam-populate
|
||||||
|
(org-roam-backlink-create
|
||||||
|
:source-node (org-roam-node-create :id source-id)
|
||||||
|
:target-node (org-roam-node-create :id dest-id)
|
||||||
|
:point pos
|
||||||
|
:properties properties))))))
|
||||||
|
|
||||||
|
(defun org-roam-backlinks-sort (a b)
|
||||||
|
"Default sorting function for backlinks A and B.
|
||||||
|
Sorts by title."
|
||||||
|
(string< (org-roam-node-title (org-roam-backlink-source-node a))
|
||||||
|
(org-roam-node-title (org-roam-backlink-source-node b))))
|
||||||
|
|
||||||
|
(defun org-roam-backlinks-section (node)
|
||||||
|
"The backlinks section for NODE."
|
||||||
|
(when-let ((backlinks (seq-sort #'org-roam-backlinks-sort (org-roam-backlinks-get node))))
|
||||||
|
(magit-insert-section (org-roam-backlinks)
|
||||||
|
(magit-insert-heading "Backlinks:")
|
||||||
|
(dolist (backlink backlinks)
|
||||||
|
(org-roam-node-insert-section
|
||||||
|
:source-node (org-roam-backlink-source-node backlink)
|
||||||
|
:point (org-roam-backlink-point backlink)
|
||||||
|
:properties (org-roam-backlink-properties backlink)))
|
||||||
|
(insert ?\n))))
|
||||||
|
|
||||||
|
;;;; Reflinks
|
||||||
|
(cl-defstruct (org-roam-reflink (:constructor org-roam-reflink-create)
|
||||||
|
(:copier nil))
|
||||||
|
source-node ref
|
||||||
|
point properties)
|
||||||
|
|
||||||
|
(cl-defmethod org-roam-populate ((reflink org-roam-reflink))
|
||||||
|
"Populate REFLINK from database."
|
||||||
|
(setf (org-roam-reflink-source-node reflink)
|
||||||
|
(org-roam-populate (org-roam-reflink-source-node reflink)))
|
||||||
|
reflink)
|
||||||
|
|
||||||
|
(defun org-roam-reflinks-get (node)
|
||||||
|
"Return the reflinks for NODE."
|
||||||
|
(let ((refs (org-roam-db-query [:select [ref] :from refs
|
||||||
|
:where (= node-id $s1)]
|
||||||
|
(org-roam-node-id node)))
|
||||||
|
links)
|
||||||
|
(pcase-dolist (`(,ref) refs)
|
||||||
|
(pcase-dolist (`(,source-id ,pos ,properties) (org-roam-db-query
|
||||||
|
[:select [source pos properties]
|
||||||
|
:from links
|
||||||
|
:where (= dest $s1)]
|
||||||
|
ref))
|
||||||
|
(push (org-roam-populate
|
||||||
|
(org-roam-reflink-create
|
||||||
|
:source-node (org-roam-node-create :id source-id)
|
||||||
|
:ref ref
|
||||||
|
:point pos
|
||||||
|
:properties properties)) links)))
|
||||||
|
links))
|
||||||
|
|
||||||
|
(defun org-roam-reflinks-sort (a b)
|
||||||
|
"Default sorting function for reflinks A and B.
|
||||||
|
Sorts by title."
|
||||||
|
(string< (org-roam-node-title (org-roam-reflink-source-node a))
|
||||||
|
(org-roam-node-title (org-roam-reflink-source-node b))))
|
||||||
|
|
||||||
|
(defun org-roam-reflinks-section (node)
|
||||||
|
"The reflinks section for NODE."
|
||||||
|
(when (org-roam-node-refs node)
|
||||||
|
(let* ((reflinks (seq-sort #'org-roam-reflinks-sort (org-roam-reflinks-get node))))
|
||||||
|
(magit-insert-section (org-roam-reflinks)
|
||||||
|
(magit-insert-heading "Reflinks:")
|
||||||
|
(dolist (reflink reflinks)
|
||||||
|
(org-roam-node-insert-section
|
||||||
|
:source-node (org-roam-reflink-source-node reflink)
|
||||||
|
:point (org-roam-reflink-point reflink)
|
||||||
|
:properties (org-roam-reflink-properties reflink)))
|
||||||
|
(insert ?\n)))))
|
||||||
|
|
||||||
|
;;;; Unlinked references
|
||||||
|
(defvar org-roam-grep-map
|
||||||
|
(let ((map (make-sparse-keymap)))
|
||||||
|
(set-keymap-parent map org-roam-mode-map)
|
||||||
|
(define-key map [remap org-roam-visit-thing] 'org-roam-file-visit)
|
||||||
|
map)
|
||||||
|
"Keymap for Org-roam grep result sections.")
|
||||||
|
|
||||||
|
(defclass org-roam-grep-section (magit-section)
|
||||||
|
((keymap :initform 'org-roam-grep-map)
|
||||||
|
(file :initform nil)
|
||||||
|
(row :initform nil)
|
||||||
|
(col :initform nil)))
|
||||||
|
|
||||||
|
(defun org-roam-file-at-point (&optional assert)
|
||||||
|
"Return the file at point.
|
||||||
|
If ASSERT, throw an error."
|
||||||
|
(if-let ((file (magit-section-case
|
||||||
|
(org-roam-node-section (org-roam-node-file (oref it node)))
|
||||||
|
(org-roam-grep-section (oref it file))
|
||||||
|
(org-roam-preview-section (oref it file)))))
|
||||||
|
file
|
||||||
|
(when assert
|
||||||
|
(user-error "No file at point"))))
|
||||||
|
|
||||||
|
(defun org-roam-file-visit (file &optional other-window row col)
|
||||||
|
"Visits FILE.
|
||||||
|
With a prefix argument OTHER-WINDOW, display the buffer in
|
||||||
|
another window instead.
|
||||||
|
If ROW, move to the row, and if COL move to the COL."
|
||||||
|
(interactive (list (org-roam-file-at-point t)
|
||||||
|
current-prefix-arg
|
||||||
|
(oref (magit-current-section) row)
|
||||||
|
(oref (magit-current-section) col)))
|
||||||
|
(let ((buf (find-file-noselect file)))
|
||||||
|
(with-current-buffer buf
|
||||||
|
(widen)
|
||||||
|
(goto-char (point-min))
|
||||||
|
(when row
|
||||||
|
(forward-line (1- row)))
|
||||||
|
(when col
|
||||||
|
(forward-char (1- col))))
|
||||||
|
(funcall (if other-window
|
||||||
|
#'switch-to-buffer-other-window
|
||||||
|
#'pop-to-buffer-same-window) buf)))
|
||||||
|
|
||||||
|
(defvar org-roam-unlinked-references-result-re
|
||||||
|
(rx (group (one-or-more anything))
|
||||||
|
":"
|
||||||
|
(group (one-or-more digit))
|
||||||
|
":"
|
||||||
|
(group (one-or-more digit))
|
||||||
|
":"
|
||||||
|
(group (zero-or-more anything)))
|
||||||
|
"Regex for the return result of a ripgrep query.")
|
||||||
|
|
||||||
|
(defun org-roam-unlinked-references-preview-line (file row)
|
||||||
|
"Return the preview line from FILE.
|
||||||
|
This is the ROW within FILE."
|
||||||
|
(with-temp-buffer
|
||||||
|
(insert-file-contents-literally file)
|
||||||
|
(forward-line (1- row))
|
||||||
|
(buffer-substring-no-properties
|
||||||
|
(save-excursion
|
||||||
|
(beginning-of-line)
|
||||||
|
(point))
|
||||||
|
(save-excursion
|
||||||
|
(end-of-line)
|
||||||
|
(point)))))
|
||||||
|
|
||||||
|
(defun org-roam-unlinked-references-section (node)
|
||||||
|
"The unlinked references section for NODE.
|
||||||
|
References from FILE are excluded."
|
||||||
|
(when (and (executable-find "rg")
|
||||||
|
(not (string-match "PCRE2 is not available"
|
||||||
|
(shell-command-to-string "rg --pcre2-version"))))
|
||||||
|
(let* ((titles (cons (org-roam-node-title node)
|
||||||
|
(org-roam-node-aliases node)))
|
||||||
|
(rg-command (concat "rg -o --vimgrep -P -i "
|
||||||
|
(mapconcat (lambda (glob) (concat "-g " glob))
|
||||||
|
(org-roam--list-files-search-globs org-roam-file-extensions)
|
||||||
|
" ")
|
||||||
|
(format " '\\[([^[]]++|(?R))*\\]%s' "
|
||||||
|
(mapconcat (lambda (title)
|
||||||
|
(format "|(\\b%s\\b)" (shell-quote-argument title)))
|
||||||
|
titles ""))
|
||||||
|
org-roam-directory))
|
||||||
|
(results (split-string (shell-command-to-string rg-command) "\n"))
|
||||||
|
f row col match)
|
||||||
|
(magit-insert-section (unlinked-references)
|
||||||
|
(magit-insert-heading "Unlinked References:")
|
||||||
|
(dolist (line results)
|
||||||
|
(save-match-data
|
||||||
|
(when (string-match org-roam-unlinked-references-result-re line)
|
||||||
|
(setq f (match-string 1 line)
|
||||||
|
row (string-to-number (match-string 2 line))
|
||||||
|
col (string-to-number (match-string 3 line))
|
||||||
|
match (match-string 4 line))
|
||||||
|
(when (and match
|
||||||
|
(not (f-equal-p (org-roam-node-file node) f))
|
||||||
|
(member (downcase match) (mapcar #'downcase titles)))
|
||||||
|
(magit-insert-section section (org-roam-grep-section)
|
||||||
|
(oset section file f)
|
||||||
|
(oset section row row)
|
||||||
|
(oset section col col)
|
||||||
|
(insert (propertize (format "%s:%s:%s"
|
||||||
|
(truncate-string-to-width (file-name-base f) 15 nil nil "...")
|
||||||
|
row col) 'font-lock-face 'org-roam-dim)
|
||||||
|
" "
|
||||||
|
(org-roam-fontify-like-in-org-mode
|
||||||
|
(org-roam-unlinked-references-preview-line f row))
|
||||||
|
"\n"))))))
|
||||||
|
(insert ?\n)))))
|
||||||
|
|
||||||
|
(provide 'org-roam-mode)
|
||||||
|
;;; org-roam-mode.el ends here
|
98
org-roam-overlay.el
Normal file
98
org-roam-overlay.el
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
;;; org-roam-overlay.el --- Link overlay for Org-roam nodes -*- coding: utf-8; lexical-binding: t; -*-
|
||||||
|
|
||||||
|
;; Copyright © 2020-2021 Jethro Kuan <jethrokuan95@gmail.com>
|
||||||
|
|
||||||
|
;; Author: Jethro Kuan <jethrokuan95@gmail.com>
|
||||||
|
;; URL: https://github.com/org-roam/org-roam
|
||||||
|
;; Keywords: org-mode, roam, convenience
|
||||||
|
;; Version: 2.0.0
|
||||||
|
;; Package-Requires: ((emacs "26.1") (dash "2.13") (f "0.17.2") (org "9.4") (emacsql "3.0.0") (emacsql-sqlite "1.0.0") (magit-section "2.90.1"))
|
||||||
|
|
||||||
|
;; This file is NOT part of GNU Emacs.
|
||||||
|
|
||||||
|
;; This program is free software; you can redistribute it and/or modify
|
||||||
|
;; it under the terms of the GNU General Public License as published by
|
||||||
|
;; the Free Software Foundation; either version 3, or (at your option)
|
||||||
|
;; any later version.
|
||||||
|
;;
|
||||||
|
;; This program is distributed in the hope that it will be useful,
|
||||||
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
;; GNU General Public License for more details.
|
||||||
|
;;
|
||||||
|
;; You should have received a copy of the GNU General Public License
|
||||||
|
;; along with GNU Emacs; see the file COPYING. If not, write to the
|
||||||
|
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||||
|
;; Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
|
;;; Commentary:
|
||||||
|
;;
|
||||||
|
;; This library is an attempt at injecting Roam functionality into Org-mode.
|
||||||
|
;; This is achieved primarily through building caches for forward links,
|
||||||
|
;; backward links, and file titles.
|
||||||
|
;;
|
||||||
|
;;
|
||||||
|
;;; Code:
|
||||||
|
;;;; Dependencies
|
||||||
|
|
||||||
|
(defface org-roam-overlay
|
||||||
|
'((((class color) (background light))
|
||||||
|
:background "grey90" :box (:line-width -1 :color "black"))
|
||||||
|
(((class color) (background dark))
|
||||||
|
:background "grey10" :box (:line-width -1 :color "white")))
|
||||||
|
"Face for the Org-roam overlay."
|
||||||
|
:group 'org-roam-faces)
|
||||||
|
|
||||||
|
(defun org-roam-overlay--make (l r &rest props)
|
||||||
|
"Make an overlay from L to R with PROPS."
|
||||||
|
(let ((o (make-overlay l (or r l))))
|
||||||
|
(overlay-put o 'category 'org-roam)
|
||||||
|
(while props (overlay-put o (pop props) (pop props)))
|
||||||
|
o))
|
||||||
|
|
||||||
|
(defun org-roam-overlay-make-link-overlay (link)
|
||||||
|
"Create overlay for LINK."
|
||||||
|
(save-excursion
|
||||||
|
(save-match-data
|
||||||
|
(let* ((type (org-element-property :type link))
|
||||||
|
(id (org-element-property :path link))
|
||||||
|
(pos (org-element-property :end link))
|
||||||
|
(desc-p (org-element-property :contents-begin link))
|
||||||
|
node)
|
||||||
|
(when (and (string-equal type "id")
|
||||||
|
(setq node (org-roam-node-from-id id))
|
||||||
|
(not desc-p))
|
||||||
|
(org-roam-overlay--make
|
||||||
|
pos pos
|
||||||
|
'after-string (format "%s "
|
||||||
|
(propertize (org-roam-node-title node)
|
||||||
|
'face 'org-roam-overlay))))))))
|
||||||
|
|
||||||
|
(defun org-roam-overlay-enable ()
|
||||||
|
"Enable Org-roam overlays."
|
||||||
|
(org-roam-db-map-links
|
||||||
|
(list #'org-roam-overlay-make-link-overlay)))
|
||||||
|
|
||||||
|
(defun org-roam-overlay-disable ()
|
||||||
|
"Disable Org-roam overlays."
|
||||||
|
(remove-overlays nil nil 'category 'org-roam))
|
||||||
|
|
||||||
|
(defun org-roam-overlay-redisplay ()
|
||||||
|
"Redisplay Org-roam overlays."
|
||||||
|
(org-roam-overlay-disable)
|
||||||
|
(org-roam-overlay-enable))
|
||||||
|
|
||||||
|
(define-minor-mode org-roam-overlay-mode
|
||||||
|
"Overlays for Org-roam ID links.
|
||||||
|
Org-roam overlay mode is a minor mode. When enabled,
|
||||||
|
overlay displaying the node's title is displayed."
|
||||||
|
:lighter " org-roam-overlay"
|
||||||
|
(if org-roam-overlay-mode
|
||||||
|
(progn
|
||||||
|
(org-roam-overlay-enable)
|
||||||
|
(add-hook 'after-save-hook #'org-roam-overlay-redisplay nil t))
|
||||||
|
(org-roam-overlay-disable)
|
||||||
|
(remove-hook 'after-save-hook #'org-roam-overlay-redisplay t)))
|
||||||
|
|
||||||
|
(provide 'org-roam-overlay)
|
||||||
|
;;; org-roam-overlay.el ends here
|
@ -4,8 +4,8 @@
|
|||||||
;; Author: Jethro Kuan <jethrokuan95@gmail.com>
|
;; Author: Jethro Kuan <jethrokuan95@gmail.com>
|
||||||
;; URL: https://github.com/org-roam/org-roam
|
;; URL: https://github.com/org-roam/org-roam
|
||||||
;; Keywords: org-mode, roam, convenience
|
;; Keywords: org-mode, roam, convenience
|
||||||
;; Version: 1.2.1
|
;; Version: 2.0.0
|
||||||
;; Package-Requires: ((emacs "26.1") (org "9.3"))
|
;; Package-Requires: ((emacs "26.1") (dash "2.13") (f "0.17.2") (org "9.4") (emacsql "3.0.0") (emacsql-sqlite "1.0.0") (magit-section "2.90.1"))
|
||||||
|
|
||||||
;; This file is NOT part of GNU Emacs.
|
;; This file is NOT part of GNU Emacs.
|
||||||
|
|
||||||
@ -31,12 +31,20 @@
|
|||||||
;;
|
;;
|
||||||
;; We define 2 protocols:
|
;; We define 2 protocols:
|
||||||
;;
|
;;
|
||||||
;; 1. "roam-file": This protocol simply opens the file given by the FILE key
|
;; 1. "roam-node": This protocol simply opens the node given by the node ID
|
||||||
;; 2. "roam-ref": This protocol creates or opens a note with the given REF
|
;; 2. "roam-ref": This protocol creates or opens a note with the given REF
|
||||||
;;
|
;;
|
||||||
;;; Code:
|
;;; Code:
|
||||||
(require 'org-protocol)
|
(require 'org-protocol)
|
||||||
(require 'org-roam)
|
(require 'org-roam)
|
||||||
|
(eval-when-compile
|
||||||
|
(require 'org-roam-macs))
|
||||||
|
(require 'ol) ;; for org-link-decode
|
||||||
|
|
||||||
|
(defcustom org-roam-protocol-store-links nil
|
||||||
|
"Whether to store links when capturing websites with `org-roam-protocol'."
|
||||||
|
:type 'boolean
|
||||||
|
:group 'org-roam)
|
||||||
|
|
||||||
;;;; Functions
|
;;;; Functions
|
||||||
(defun org-roam-protocol-open-ref (info)
|
(defun org-roam-protocol-open-ref (info)
|
||||||
@ -45,29 +53,37 @@
|
|||||||
It opens or creates a note with the given ref.
|
It opens or creates a note with the given ref.
|
||||||
|
|
||||||
javascript:location.href = \\='org-protocol://roam-ref?template=r&ref=\\='+ \\
|
javascript:location.href = \\='org-protocol://roam-ref?template=r&ref=\\='+ \\
|
||||||
encodeURIComponent(location.href) + \\='&title=\\=' \\
|
encodeURIComponent(location.href) + \\='&title=\\=' + \\
|
||||||
encodeURIComponent(document.title) + \\='&body=\\=' + \\
|
encodeURIComponent(document.title) + \\='&body=\\=' + \\
|
||||||
encodeURIComponent(window.getSelection())"
|
encodeURIComponent(window.getSelection())"
|
||||||
(when-let* ((alist (org-roam--plist-to-alist info))
|
(unless (plist-get info :ref)
|
||||||
(decoded-alist (mapcar (lambda (k.v)
|
(user-error "No ref key provided"))
|
||||||
(let ((key (car k.v))
|
(org-roam-plist-map! (lambda (k v)
|
||||||
(val (cdr k.v)))
|
(org-link-decode
|
||||||
(cons key (org-link-decode val)))) alist)))
|
(if (equal k :ref)
|
||||||
(unless (assoc 'ref decoded-alist)
|
(org-protocol-sanitize-uri v)
|
||||||
(error "No ref key provided"))
|
v))) info)
|
||||||
(when-let ((title (cdr (assoc 'title decoded-alist))))
|
(when org-roam-protocol-store-links
|
||||||
(push (cons 'slug (funcall org-roam-title-to-slug-function title)) decoded-alist))
|
(push (list (plist-get info :ref)
|
||||||
(let* ((org-roam-capture-templates org-roam-capture-ref-templates)
|
(plist-get info :title)) org-stored-links))
|
||||||
(org-roam-capture--context 'ref)
|
(org-link-store-props :type (and (string-match org-link-plain-re
|
||||||
(org-roam-capture--info decoded-alist)
|
(plist-get info :ref))
|
||||||
(template (cdr (assoc 'template decoded-alist))))
|
(match-string 1 (plist-get info :ref)))
|
||||||
(raise-frame)
|
:link (plist-get info :ref)
|
||||||
(org-roam--with-template-error 'org-roam-capture-ref-templates
|
:annotation (org-link-make-string (plist-get info :ref)
|
||||||
(org-roam-capture--capture nil template))
|
(or (plist-get info :title)
|
||||||
(org-roam-message "Item captured.")))
|
(plist-get info :ref)))
|
||||||
|
:initial (or (plist-get info :body) ""))
|
||||||
|
(raise-frame)
|
||||||
|
(org-roam-capture-
|
||||||
|
:keys (plist-get info :template)
|
||||||
|
:node (org-roam-node-create :title (plist-get info :title))
|
||||||
|
:info (list :ref (plist-get info :ref)
|
||||||
|
:body (plist-get info :body))
|
||||||
|
:templates org-roam-capture-ref-templates)
|
||||||
nil)
|
nil)
|
||||||
|
|
||||||
(defun org-roam-protocol-open-file (info)
|
(defun org-roam-protocol-open-node (info)
|
||||||
"This handler simply opens the file with emacsclient.
|
"This handler simply opens the file with emacsclient.
|
||||||
|
|
||||||
INFO is an alist containing additional information passed by the protocol URL.
|
INFO is an alist containing additional information passed by the protocol URL.
|
||||||
@ -75,15 +91,15 @@ It should contain the FILE key, pointing to the path of the file to open.
|
|||||||
|
|
||||||
Example protocol string:
|
Example protocol string:
|
||||||
|
|
||||||
org-protocol://roam-file?file=/path/to/file.org"
|
org-protocol://roam-node?node=uuid"
|
||||||
(when-let ((file (plist-get info :file)))
|
(when-let ((node (plist-get info :node)))
|
||||||
(raise-frame)
|
(raise-frame)
|
||||||
(org-roam--find-file file))
|
(org-roam-node-visit (org-roam-populate (org-roam-node-create :id node))))
|
||||||
nil)
|
nil)
|
||||||
|
|
||||||
(push '("org-roam-ref" :protocol "roam-ref" :function org-roam-protocol-open-ref)
|
(push '("org-roam-ref" :protocol "roam-ref" :function org-roam-protocol-open-ref)
|
||||||
org-protocol-protocol-alist)
|
org-protocol-protocol-alist)
|
||||||
(push '("org-roam-file" :protocol "roam-file" :function org-roam-protocol-open-file)
|
(push '("org-roam-node" :protocol "roam-node" :function org-roam-protocol-open-node)
|
||||||
org-protocol-protocol-alist)
|
org-protocol-protocol-alist)
|
||||||
|
|
||||||
(provide 'org-roam-protocol)
|
(provide 'org-roam-protocol)
|
||||||
|
296
org-roam-utils.el
Normal file
296
org-roam-utils.el
Normal file
@ -0,0 +1,296 @@
|
|||||||
|
;;; org-roam-utils.el --- Utilities for Org-roam -*- coding: utf-8; lexical-binding: t; -*-
|
||||||
|
|
||||||
|
;; Copyright © 2020 Jethro Kuan <jethrokuan95@gmail.com>
|
||||||
|
|
||||||
|
;; Author: Jethro Kuan <jethrokuan95@gmail.com>
|
||||||
|
;; URL: https://github.com/org-roam/org-roam
|
||||||
|
;; Keywords: org-mode, roam, convenience
|
||||||
|
;; Version: 2.0.0
|
||||||
|
;; Package-Requires: ((emacs "26.1") (dash "2.13") (f "0.17.2") (org "9.4") (emacsql "3.0.0") (emacsql-sqlite "1.0.0") (magit-section "2.90.1"))
|
||||||
|
|
||||||
|
;; This file is NOT part of GNU Emacs.
|
||||||
|
|
||||||
|
;; This program is free software; you can redistribute it and/or modify
|
||||||
|
;; it under the terms of the GNU General Public License as published by
|
||||||
|
;; the Free Software Foundation; either version 3, or (at your option)
|
||||||
|
;; any later version.
|
||||||
|
;;
|
||||||
|
;; This program is distributed in the hope that it will be useful,
|
||||||
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
;; GNU General Public License for more details.
|
||||||
|
;;
|
||||||
|
;; You should have received a copy of the GNU General Public License
|
||||||
|
;; along with GNU Emacs; see the file COPYING. If not, write to the
|
||||||
|
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||||
|
;; Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
|
;;; Commentary:
|
||||||
|
;;
|
||||||
|
;; This library implements utility functions used throughout
|
||||||
|
;; Org-roam.
|
||||||
|
;;
|
||||||
|
;;
|
||||||
|
;;; Code:
|
||||||
|
;;;; Library Requires
|
||||||
|
(require 'dash)
|
||||||
|
|
||||||
|
(eval-when-compile
|
||||||
|
(require 'org-roam-macs)
|
||||||
|
(require 'org-macs))
|
||||||
|
|
||||||
|
(defvar org-roam-verbose)
|
||||||
|
|
||||||
|
;; This is necessary to ensure all dependents on this module see
|
||||||
|
;; `org-mode-hook' and `org-inhibit-startup' as dynamic variables,
|
||||||
|
;; regardless of whether Org is loaded before their compilation.
|
||||||
|
(require 'org)
|
||||||
|
|
||||||
|
;;;; String Utilities
|
||||||
|
(defun org-roam-truncate (len s &optional ellipsis)
|
||||||
|
"If S is longer than LEN, cut it down and add ELLIPSIS to the end.
|
||||||
|
|
||||||
|
The resulting string, including ellipsis, will be LEN characters
|
||||||
|
long.
|
||||||
|
|
||||||
|
When not specified, ELLIPSIS defaults to ‘...’."
|
||||||
|
(declare (pure t) (side-effect-free t))
|
||||||
|
(unless ellipsis
|
||||||
|
(setq ellipsis "..."))
|
||||||
|
(if (> (length s) len)
|
||||||
|
(format "%s%s" (substring s 0 (- len (length ellipsis))) ellipsis)
|
||||||
|
s))
|
||||||
|
|
||||||
|
(defun org-roam-replace (old new s)
|
||||||
|
"Replace OLD with NEW in S."
|
||||||
|
(declare (pure t) (side-effect-free t))
|
||||||
|
(replace-regexp-in-string (regexp-quote old) new s t t))
|
||||||
|
|
||||||
|
(defun org-roam-quote-string (s)
|
||||||
|
"Quotes string S."
|
||||||
|
(->> s
|
||||||
|
(org-roam-replace "\\" "\\\\")
|
||||||
|
(org-roam-replace "\"" "\\\"")))
|
||||||
|
|
||||||
|
;;;; Utility Functions
|
||||||
|
(defun org-roam--list-interleave (lst separator)
|
||||||
|
"Interleaves elements in LST with SEPARATOR."
|
||||||
|
(when lst
|
||||||
|
(let ((new-lst (list (pop lst))))
|
||||||
|
(dolist (it lst)
|
||||||
|
(nconc new-lst (list separator it)))
|
||||||
|
new-lst)))
|
||||||
|
|
||||||
|
(defun org-roam-up-heading-or-point-min ()
|
||||||
|
"Fixed version of Org's `org-up-heading-or-point-min'."
|
||||||
|
(ignore-errors (org-back-to-heading t))
|
||||||
|
(let ((p (point)))
|
||||||
|
(if (< 1 (funcall outline-level))
|
||||||
|
(progn
|
||||||
|
(org-up-heading-safe)
|
||||||
|
(when (= (point) p)
|
||||||
|
(goto-char (point-min))))
|
||||||
|
(unless (bobp) (goto-char (point-min))))))
|
||||||
|
|
||||||
|
(defun org-roam-message (format-string &rest args)
|
||||||
|
"Pass FORMAT-STRING and ARGS to `message' when `org-roam-verbose' is t."
|
||||||
|
(when org-roam-verbose
|
||||||
|
(apply #'message `(,(concat "(org-roam) " format-string) ,@args))))
|
||||||
|
|
||||||
|
(defvar org-ref-buffer-hacked)
|
||||||
|
|
||||||
|
(defun org-roam-fontify-like-in-org-mode (s)
|
||||||
|
"Fontify string S like in Org mode.
|
||||||
|
Like `org-fontify-like-in-org-mode', but supports `org-ref'."
|
||||||
|
;; NOTE: pretend that the temporary buffer created by `org-fontify-like-in-org-mode' to
|
||||||
|
;; fontify a `cite:' reference has been hacked by org-ref, whatever that means;
|
||||||
|
;;
|
||||||
|
;; `org-ref-cite-link-face-fn', which is used to supply a face for `cite:' links, calls
|
||||||
|
;; `hack-dir-local-variables' rationalizing that `bibtex-completion' would throw some warnings
|
||||||
|
;; otherwise. This doesn't seem to be the case and calling this function just before
|
||||||
|
;; `org-font-lock-ensure' (alias of `font-lock-ensure') actually instead of fixing the alleged
|
||||||
|
;; warnings messes the things so badly that `font-lock-ensure' crashes with error and doesn't let
|
||||||
|
;; org-roam to proceed further. I don't know what's happening there exactly but disabling this hackery
|
||||||
|
;; fixes the crashing. Fortunately, org-ref provides the `org-ref-buffer-hacked' switch, which we use
|
||||||
|
;; here to make it believe that the buffer was hacked.
|
||||||
|
;;
|
||||||
|
;; This is a workaround for `cite:' links and does not have any effect on other ref types.
|
||||||
|
;;
|
||||||
|
;; `org-ref-buffer-hacked' is a buffer-local variable, therefore we inline
|
||||||
|
;; `org-fontify-like-in-org-mode' here
|
||||||
|
(with-temp-buffer
|
||||||
|
(insert s)
|
||||||
|
(let ((org-ref-buffer-hacked t))
|
||||||
|
(org-mode)
|
||||||
|
(org-font-lock-ensure)
|
||||||
|
(buffer-string))))
|
||||||
|
|
||||||
|
(defun org-roam-set-header-line-format (string)
|
||||||
|
"Set the header-line using STRING.
|
||||||
|
If the `face' property of any part of STRING is already set, then
|
||||||
|
that takes precedence. Also pad the left side of STRING so that
|
||||||
|
it aligns with the text area."
|
||||||
|
(setq-local header-line-format
|
||||||
|
(concat (propertize " " 'display '(space :align-to 0))
|
||||||
|
string)))
|
||||||
|
|
||||||
|
;;; Keywords
|
||||||
|
(defun org-roam--get-keyword (name &optional bound)
|
||||||
|
"Return keyword property NAME in current buffer.
|
||||||
|
If BOUND, scan up to BOUND bytes of the buffer."
|
||||||
|
(save-excursion
|
||||||
|
(let ((re (format "^#\\+%s:[ \t]*\\([^\n]+\\)" (upcase name))))
|
||||||
|
(goto-char (point-min))
|
||||||
|
(when (re-search-forward re bound t)
|
||||||
|
(buffer-substring-no-properties (match-beginning 1) (match-end 1))))))
|
||||||
|
|
||||||
|
(defun org-roam-get-keyword (name &optional file bound)
|
||||||
|
"Return keyword property NAME from an org FILE.
|
||||||
|
FILE defaults to current file.
|
||||||
|
Only scans up to BOUND bytes of the document."
|
||||||
|
(unless bound
|
||||||
|
(setq bound 1024))
|
||||||
|
(if file
|
||||||
|
(with-temp-buffer
|
||||||
|
(insert-file-contents-literally file nil 0 bound)
|
||||||
|
(org-roam--get-keyword name))
|
||||||
|
(org-roam--get-keyword name bound)))
|
||||||
|
|
||||||
|
;;; Shielding regions
|
||||||
|
(defface org-roam-shielded
|
||||||
|
'((t :inherit (warning)))
|
||||||
|
"Face for regions that are shielded (marked as read-only).
|
||||||
|
This face is used on the region target by org-roam-insertion
|
||||||
|
during an `org-roam-capture'."
|
||||||
|
:group 'org-roam-faces)
|
||||||
|
|
||||||
|
(defun org-roam-shield-region (beg end)
|
||||||
|
"Shield region against modifications.
|
||||||
|
BEG and END are markers for the beginning and end regions.
|
||||||
|
REGION must be a cons-cell containing the marker to the region
|
||||||
|
beginning and maximum values."
|
||||||
|
(add-text-properties beg end
|
||||||
|
'(font-lock-face org-roam-shielded
|
||||||
|
read-only t)
|
||||||
|
(marker-buffer beg)))
|
||||||
|
|
||||||
|
(defun org-roam-unshield-region (beg end)
|
||||||
|
"Unshield the shielded REGION.
|
||||||
|
BEG and END are markers for the beginning and end regions."
|
||||||
|
(let ((inhibit-read-only t))
|
||||||
|
(remove-text-properties beg end
|
||||||
|
'(font-lock-face org-roam-shielded
|
||||||
|
read-only t)
|
||||||
|
(marker-buffer beg))))
|
||||||
|
|
||||||
|
;;; Formatting
|
||||||
|
(defun org-roam-format (template replacer)
|
||||||
|
"Format TEMPLATE with the function REPLACER.
|
||||||
|
REPLACER takes an argument of the format variable and optionally
|
||||||
|
an extra argument which is the EXTRA value from the call to
|
||||||
|
`org-roam-format'.
|
||||||
|
Adapted from `s-format'."
|
||||||
|
(let ((saved-match-data (match-data)))
|
||||||
|
(unwind-protect
|
||||||
|
(replace-regexp-in-string
|
||||||
|
"\\${\\([^}]+\\)}"
|
||||||
|
(lambda (md)
|
||||||
|
(let ((var (match-string 1 md))
|
||||||
|
(replacer-match-data (match-data)))
|
||||||
|
(unwind-protect
|
||||||
|
(let ((v (progn
|
||||||
|
(set-match-data saved-match-data)
|
||||||
|
(funcall replacer var))))
|
||||||
|
(if v (format "%s" v) (signal 'org-roam-format-resolve md)))
|
||||||
|
(set-match-data replacer-match-data)))) template
|
||||||
|
;; Need literal to make sure it works
|
||||||
|
t t)
|
||||||
|
(set-match-data saved-match-data))))
|
||||||
|
|
||||||
|
(defvar org-roam--cached-display-format nil)
|
||||||
|
|
||||||
|
(defun org-roam--process-display-format (format)
|
||||||
|
"Pre-calculate minimal widths needed by the FORMAT string."
|
||||||
|
(or org-roam--cached-display-format
|
||||||
|
(setq org-roam--cached-display-format
|
||||||
|
(let* ((fields-width 0)
|
||||||
|
(string-width
|
||||||
|
(string-width
|
||||||
|
(org-roam-format
|
||||||
|
format
|
||||||
|
(lambda (field)
|
||||||
|
(setq fields-width
|
||||||
|
(+ fields-width
|
||||||
|
(string-to-number
|
||||||
|
(or (cadr (split-string field ":"))
|
||||||
|
"")))))))))
|
||||||
|
(cons format (+ fields-width string-width))))))
|
||||||
|
|
||||||
|
;;; for org-roam-demote-entire-buffer in org-roam-refile.el
|
||||||
|
(defun org-roam--file-keyword-get (keyword)
|
||||||
|
"Pull a KEYWORD setting from the top of the file.
|
||||||
|
|
||||||
|
Keyword must be specified in ALL CAPS."
|
||||||
|
(cadr (assoc keyword
|
||||||
|
(org-collect-keywords (list keyword)))))
|
||||||
|
|
||||||
|
(defun org-roam--file-keyword-kill (keyword)
|
||||||
|
"Erase KEYWORD setting line from the top of the file."
|
||||||
|
(let ((case-fold-search t))
|
||||||
|
(org-with-point-at 1
|
||||||
|
(when (re-search-forward (concat "^#\\+" keyword ":") nil t)
|
||||||
|
(beginning-of-line)
|
||||||
|
(delete-region (point) (line-end-position))
|
||||||
|
(delete-char 1)))))
|
||||||
|
|
||||||
|
(defun org-roam--kill-empty-buffer ()
|
||||||
|
"If the source buffer has been emptied, kill it.
|
||||||
|
|
||||||
|
If the buffer is associated with a file, delete the file.
|
||||||
|
|
||||||
|
If the buffer is associated with an in-process capture operation, abort the operation."
|
||||||
|
(when (eq (buffer-size) 0)
|
||||||
|
(if (buffer-file-name)
|
||||||
|
(delete-file (buffer-file-name)))
|
||||||
|
(set-buffer-modified-p nil)
|
||||||
|
(when (and org-capture-mode
|
||||||
|
(buffer-base-buffer (current-buffer)))
|
||||||
|
(org-capture-kill))
|
||||||
|
(kill-buffer (current-buffer))))
|
||||||
|
|
||||||
|
;;; Diagnostics
|
||||||
|
;;;###autoload
|
||||||
|
(defun org-roam-version (&optional message)
|
||||||
|
"Return `org-roam' version.
|
||||||
|
Interactively, or when MESSAGE is non-nil, show in the echo area."
|
||||||
|
(interactive)
|
||||||
|
(let* ((version
|
||||||
|
(with-temp-buffer
|
||||||
|
(insert-file-contents-literally (locate-library "org-roam.el"))
|
||||||
|
(goto-char (point-min))
|
||||||
|
(save-match-data
|
||||||
|
(if (re-search-forward "\\(?:;; Version: \\([^z-a]*?$\\)\\)" nil nil)
|
||||||
|
(substring-no-properties (match-string 1))
|
||||||
|
"N/A")))))
|
||||||
|
(if (or message (called-interactively-p 'interactive))
|
||||||
|
(message "%s" version)
|
||||||
|
version)))
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(defun org-roam-diagnostics ()
|
||||||
|
"Collect and print info for `org-roam' issues."
|
||||||
|
(interactive)
|
||||||
|
(with-current-buffer (switch-to-buffer-other-window (get-buffer-create "*org-roam diagnostics*"))
|
||||||
|
(erase-buffer)
|
||||||
|
(insert (propertize "Copy info below this line into issue:\n" 'face '(:weight bold)))
|
||||||
|
(insert (format "- Emacs: %s\n" (emacs-version)))
|
||||||
|
(insert (format "- Framework: %s\n"
|
||||||
|
(condition-case _
|
||||||
|
(completing-read "I'm using the following Emacs framework:"
|
||||||
|
'("Doom" "Spacemacs" "N/A" "I don't know"))
|
||||||
|
(quit "N/A"))))
|
||||||
|
(insert (format "- Org: %s\n" (org-version nil 'full)))
|
||||||
|
(insert (format "- Org-roam: %s" (org-roam-version)))))
|
||||||
|
|
||||||
|
(provide 'org-roam-utils)
|
||||||
|
;;; org-roam-utils.el ends here
|
2318
org-roam.el
2318
org-roam.el
File diff suppressed because it is too large
Load Diff
@ -1,2 +0,0 @@
|
|||||||
#+roam_alias: "a1" "a 2"
|
|
||||||
#+title: t1
|
|
@ -1,3 +1,6 @@
|
|||||||
|
:PROPERTIES:
|
||||||
|
:ID: 440795d0-70c1-4165-993d-aebd5eef7a24
|
||||||
|
:END:
|
||||||
#+title: Bar
|
#+title: Bar
|
||||||
|
|
||||||
This is file bar. Bar links to [[file:nested/bar.org][Nested Bar]].
|
[[id:884b2341-b7fe-434d-848c-5282c0727861][Foo]]
|
||||||
|
@ -1 +0,0 @@
|
|||||||
#+title: Base
|
|
@ -1,8 +1,4 @@
|
|||||||
|
:PROPERTIES:
|
||||||
|
:ID: 884b2341-b7fe-434d-848c-5282c0727861
|
||||||
|
:END:
|
||||||
#+title: Foo
|
#+title: Foo
|
||||||
|
|
||||||
This is the foo file. It contains a link to [[file:bar.org][Bar]].
|
|
||||||
|
|
||||||
To make the tests more robust, here are some arbitrary links:
|
|
||||||
|
|
||||||
- [[https:google.com][Google]]
|
|
||||||
- [[mailto:foo@john.com][mail to foo]]
|
|
||||||
|
@ -1,14 +0,0 @@
|
|||||||
#+TITLE: Headline
|
|
||||||
|
|
||||||
* Headline 1
|
|
||||||
:PROPERTIES:
|
|
||||||
:ID: e84d0630-efad-4017-9059-5ef917908823
|
|
||||||
:END:
|
|
||||||
|
|
||||||
* No headline here
|
|
||||||
Oops.
|
|
||||||
|
|
||||||
* Headline 2
|
|
||||||
:PROPERTIES:
|
|
||||||
:ID: 801b58eb-97e2-435f-a33e-ff59a2f0c213
|
|
||||||
:END:
|
|
@ -1,3 +0,0 @@
|
|||||||
#+title: Nested Bar
|
|
||||||
|
|
||||||
This file is nested, 1 level deeper. It links to both [[file:../foo.org][Foo]] and [[file:foo.org][Nested Foo]].
|
|
@ -1 +0,0 @@
|
|||||||
#+title: Deeply Nested File
|
|
@ -1,3 +0,0 @@
|
|||||||
#+title: Nested Foo
|
|
||||||
|
|
||||||
This file has no links.
|
|
@ -1,5 +0,0 @@
|
|||||||
no title in this file :O
|
|
||||||
|
|
||||||
links to itself, with no title: [[file:no-title.org][no-title]]
|
|
||||||
|
|
||||||
* Headline title
|
|
@ -1,3 +0,0 @@
|
|||||||
#+title: Tagless File
|
|
||||||
|
|
||||||
This file has no tags, and should not yield any tags on extracting via ~#+roam_tags~.
|
|
@ -1,4 +0,0 @@
|
|||||||
#+roam_tags: "t1" "t2 with space" t3
|
|
||||||
#+title: Tags
|
|
||||||
|
|
||||||
This file is used to test functionality for =(org-roam--extract-tags)=
|
|
@ -1 +0,0 @@
|
|||||||
#+roam_alias: "roam" "alias"
|
|
@ -1,4 +0,0 @@
|
|||||||
#+title: TITLE PROP
|
|
||||||
#+roam_alias: "roam" "alias"
|
|
||||||
|
|
||||||
* Headline
|
|
@ -1 +0,0 @@
|
|||||||
* Headline
|
|
@ -1 +0,0 @@
|
|||||||
#+title: Title
|
|
@ -1,3 +0,0 @@
|
|||||||
#+title: Unlinked
|
|
||||||
|
|
||||||
Nothing links here :(
|
|
@ -1 +0,0 @@
|
|||||||
#+roam_key: https://google.com/
|
|
@ -1,53 +0,0 @@
|
|||||||
;;; test-org-roam-perf.el --- Performance Tests for Org-roam -*- lexical-binding: t; -*-
|
|
||||||
|
|
||||||
;; Copyright (C) 2020 Jethro Kuan
|
|
||||||
|
|
||||||
;; Author: Jethro Kuan <jethrokuan95@gmail.com>
|
|
||||||
;; Package-Requires: ((buttercup))
|
|
||||||
|
|
||||||
;; This program is free software; you can redistribute it and/or modify
|
|
||||||
;; it under the terms of the GNU General Public License as published by
|
|
||||||
;; the Free Software Foundation, either version 3 of the License, or
|
|
||||||
;; (at your option) any later version.
|
|
||||||
|
|
||||||
;; This program is distributed in the hope that it will be useful,
|
|
||||||
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
;; GNU General Public License for more details.
|
|
||||||
|
|
||||||
;; You should have received a copy of the GNU General Public License
|
|
||||||
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
;;; Commentary:
|
|
||||||
;;; Code:
|
|
||||||
|
|
||||||
(require 'buttercup)
|
|
||||||
(require 'org-roam)
|
|
||||||
|
|
||||||
(defconst test-org-roam-perf-zip-url "https://github.com/org-roam/test-org-files/archive/master.zip"
|
|
||||||
"Path to zip for test org-roam files.")
|
|
||||||
|
|
||||||
(defun test-org-roam-perf--abs-path (file-path)
|
|
||||||
"Get absolute FILE-PATH from `org-roam-directory'."
|
|
||||||
(file-truename (expand-file-name file-path org-roam-directory)))
|
|
||||||
|
|
||||||
(defun test-org-roam-perf--init ()
|
|
||||||
"."
|
|
||||||
(let* ((temp-loc (expand-file-name (make-temp-name "test-org-files-") temporary-file-directory))
|
|
||||||
(zip-file-loc (concat temp-loc ".zip"))
|
|
||||||
(_ (url-copy-file test-org-roam-perf-zip-url zip-file-loc))
|
|
||||||
(_ (shell-command (format "mkdir -p %s && unzip -j -qq %s -d %s" temp-loc zip-file-loc temp-loc))))
|
|
||||||
(setq org-roam-directory temp-loc)))
|
|
||||||
|
|
||||||
(describe "Cache Build"
|
|
||||||
(it "cache build from scratch time to be acceptable"
|
|
||||||
(test-org-roam-perf--init)
|
|
||||||
(pcase (benchmark-run 1 (org-roam-db-build-cache t))
|
|
||||||
(`(,time ,gcs ,time-in-gc)
|
|
||||||
(message "Elapsed time: %fs (%fs in %d GCs)" time time-in-gc gcs)
|
|
||||||
(expect time :to-be-less-than 100))))
|
|
||||||
(it "builds quickly without change"
|
|
||||||
(pcase (benchmark-run 1 (org-roam-db-build-cache))
|
|
||||||
(`(,time ,gcs ,time-in-gc)
|
|
||||||
(message "Elapsed time: %fs (%fs in %d GCs)" time time-in-gc gcs)
|
|
||||||
(expect time :to-be-less-than 5)))))
|
|
@ -23,304 +23,31 @@
|
|||||||
|
|
||||||
(require 'buttercup)
|
(require 'buttercup)
|
||||||
(require 'org-roam)
|
(require 'org-roam)
|
||||||
(require 'dash)
|
|
||||||
|
|
||||||
(defun test-org-roam--abs-path (file-path)
|
(describe "org-roam-db-sync"
|
||||||
"Get absolute FILE-PATH from `org-roam-directory'."
|
|
||||||
(file-truename (expand-file-name file-path org-roam-directory)))
|
|
||||||
|
|
||||||
(defun test-org-roam--find-file (path)
|
|
||||||
"PATH."
|
|
||||||
(let ((path (test-org-roam--abs-path path)))
|
|
||||||
(make-directory (file-name-directory path) t)
|
|
||||||
(find-file path)))
|
|
||||||
|
|
||||||
(defvar test-org-roam-directory (file-truename (concat default-directory "tests/roam-files"))
|
|
||||||
"Directory containing org-roam test org files.")
|
|
||||||
|
|
||||||
(defun test-org-roam--init ()
|
|
||||||
"."
|
|
||||||
(let ((original-dir test-org-roam-directory)
|
|
||||||
(new-dir (expand-file-name (make-temp-name "org-roam") temporary-file-directory)))
|
|
||||||
(copy-directory original-dir new-dir)
|
|
||||||
(setq org-roam-directory new-dir)
|
|
||||||
(org-roam-mode +1)
|
|
||||||
(sleep-for 2)))
|
|
||||||
|
|
||||||
(defun test-org-roam--teardown ()
|
|
||||||
(org-roam-mode -1)
|
|
||||||
(delete-file (org-roam-db--get))
|
|
||||||
(org-roam-db--close))
|
|
||||||
|
|
||||||
(describe "org-roam--str-to-list"
|
|
||||||
(it "nil"
|
|
||||||
(expect (org-roam--str-to-list nil)
|
|
||||||
:to-be
|
|
||||||
nil))
|
|
||||||
(it "\"multi word\" prop 123"
|
|
||||||
(expect (org-roam--str-to-list "\"multi word\" prop 123")
|
|
||||||
:to-equal
|
|
||||||
'("multi word" "prop" "123")))
|
|
||||||
(it "prop \"multi word\" 123"
|
|
||||||
(expect (org-roam--str-to-list "\"multi word\" prop 123")
|
|
||||||
:to-equal
|
|
||||||
'("multi word" "prop" "123")))
|
|
||||||
(it "errors on bad input"
|
|
||||||
(expect (org-roam--str-to-list 1)
|
|
||||||
:to-throw)
|
|
||||||
(expect (org-roam--str-to-list "\"hello")
|
|
||||||
:to-throw)))
|
|
||||||
|
|
||||||
(describe "Title extraction"
|
|
||||||
:var (org-roam-title-sources)
|
|
||||||
(before-all
|
(before-all
|
||||||
(test-org-roam--init))
|
(setq org-roam-directory (expand-file-name "tests/roam-files")
|
||||||
|
org-roam-db-location (expand-file-name "org-roam.db" temporary-file-directory))
|
||||||
|
(org-roam-setup))
|
||||||
|
|
||||||
(after-all
|
(after-all
|
||||||
(test-org-roam--teardown))
|
(org-roam-teardown)
|
||||||
|
(delete-file org-roam-db-location))
|
||||||
|
|
||||||
(cl-flet
|
(it "has the correct number of files"
|
||||||
((test (fn file)
|
(expect (caar (org-roam-db-query [:select (funcall count) :from files]))
|
||||||
(let ((buf (find-file-noselect
|
|
||||||
(test-org-roam--abs-path file))))
|
|
||||||
(with-current-buffer buf
|
|
||||||
(funcall fn)))))
|
|
||||||
(it "extracts title from title property"
|
|
||||||
(expect (test #'org-roam--extract-titles-title
|
|
||||||
"titles/title.org")
|
|
||||||
:to-equal
|
|
||||||
'("Title"))
|
|
||||||
(expect (test #'org-roam--extract-titles-title
|
|
||||||
"titles/aliases.org")
|
|
||||||
:to-equal
|
|
||||||
nil)
|
|
||||||
(expect (test #'org-roam--extract-titles-title
|
|
||||||
"titles/headline.org")
|
|
||||||
:to-equal
|
|
||||||
nil)
|
|
||||||
(expect (test #'org-roam--extract-titles-title
|
|
||||||
"titles/combination.org")
|
|
||||||
:to-equal
|
|
||||||
'("TITLE PROP")))
|
|
||||||
|
|
||||||
(it "extracts alias"
|
|
||||||
(expect (test #'org-roam--extract-titles-alias
|
|
||||||
"titles/title.org")
|
|
||||||
:to-equal
|
|
||||||
nil)
|
|
||||||
(expect (test #'org-roam--extract-titles-alias
|
|
||||||
"titles/aliases.org")
|
|
||||||
:to-equal
|
|
||||||
'("roam" "alias"))
|
|
||||||
(expect (test #'org-roam--extract-titles-alias
|
|
||||||
"titles/headline.org")
|
|
||||||
:to-equal
|
|
||||||
nil)
|
|
||||||
(expect (test #'org-roam--extract-titles-alias
|
|
||||||
"titles/combination.org")
|
|
||||||
:to-equal
|
|
||||||
'("roam" "alias")))
|
|
||||||
|
|
||||||
(it "extracts headlines"
|
|
||||||
(expect (test #'org-roam--extract-titles-alias
|
|
||||||
"titles/title.org")
|
|
||||||
:to-equal
|
|
||||||
nil)
|
|
||||||
(expect (test #'org-roam--extract-titles-headline
|
|
||||||
"titles/aliases.org")
|
|
||||||
:to-equal
|
|
||||||
nil)
|
|
||||||
(expect (test #'org-roam--extract-titles-headline
|
|
||||||
"titles/headline.org")
|
|
||||||
:to-equal
|
|
||||||
'("Headline"))
|
|
||||||
(expect (test #'org-roam--extract-titles-headline
|
|
||||||
"titles/combination.org")
|
|
||||||
:to-equal
|
|
||||||
'("Headline")))
|
|
||||||
|
|
||||||
(describe "uses org-roam-title-sources correctly"
|
|
||||||
(it "'((title headline) alias)"
|
|
||||||
(expect (let ((org-roam-title-sources '((title headline) alias)))
|
|
||||||
(test #'org-roam--extract-titles
|
|
||||||
"titles/combination.org"))
|
|
||||||
:to-equal
|
|
||||||
'("TITLE PROP" "roam" "alias")))
|
|
||||||
(it "'((headline title) alias)"
|
|
||||||
(expect (let ((org-roam-title-sources '((headline title) alias)))
|
|
||||||
(test #'org-roam--extract-titles
|
|
||||||
"titles/combination.org"))
|
|
||||||
:to-equal
|
|
||||||
'("Headline" "roam" "alias")))
|
|
||||||
(it "'(headline alias title)"
|
|
||||||
(expect (let ((org-roam-title-sources '(headline alias title)))
|
|
||||||
(test #'org-roam--extract-titles
|
|
||||||
"titles/combination.org"))
|
|
||||||
:to-equal
|
|
||||||
'("Headline" "roam" "alias" "TITLE PROP"))))))
|
|
||||||
|
|
||||||
(describe "Tag extraction"
|
|
||||||
:var (org-roam-tag-sources)
|
|
||||||
(before-all
|
|
||||||
(test-org-roam--init))
|
|
||||||
|
|
||||||
(after-all
|
|
||||||
(test-org-roam--teardown))
|
|
||||||
|
|
||||||
(cl-flet
|
|
||||||
((test (fn file)
|
|
||||||
(let* ((fname (test-org-roam--abs-path file))
|
|
||||||
(buf (find-file-noselect fname)))
|
|
||||||
(with-current-buffer buf
|
|
||||||
(funcall fn fname)))))
|
|
||||||
(it "extracts from prop"
|
|
||||||
(expect (test #'org-roam--extract-tags-prop
|
|
||||||
"tags/tag.org")
|
|
||||||
:to-equal
|
|
||||||
'("t1" "t2 with space" "t3"))
|
|
||||||
(expect (test #'org-roam--extract-tags-prop
|
|
||||||
"tags/no_tag.org")
|
|
||||||
:to-equal
|
|
||||||
nil))
|
|
||||||
|
|
||||||
(it "extracts from all directories"
|
|
||||||
(expect (test #'org-roam--extract-tags-all-directories
|
|
||||||
"base.org")
|
|
||||||
:to-equal
|
|
||||||
nil)
|
|
||||||
(expect (test #'org-roam--extract-tags-all-directories
|
|
||||||
"tags/tag.org")
|
|
||||||
:to-equal
|
|
||||||
'("tags"))
|
|
||||||
(expect (test #'org-roam--extract-tags-all-directories
|
|
||||||
"nested/deeply/deeply_nested_file.org")
|
|
||||||
:to-equal
|
|
||||||
'("nested" "deeply")))
|
|
||||||
|
|
||||||
(it "extracts from last directory"
|
|
||||||
(expect (test #'org-roam--extract-tags-last-directory
|
|
||||||
"base.org")
|
|
||||||
:to-equal
|
|
||||||
nil)
|
|
||||||
(expect (test #'org-roam--extract-tags-last-directory
|
|
||||||
"tags/tag.org")
|
|
||||||
:to-equal
|
|
||||||
'("tags"))
|
|
||||||
(expect (test #'org-roam--extract-tags-last-directory
|
|
||||||
"nested/deeply/deeply_nested_file.org")
|
|
||||||
:to-equal
|
|
||||||
'("deeply")))
|
|
||||||
|
|
||||||
(it "extracts from first directory"
|
|
||||||
(expect (test #'org-roam--extract-tags-first-directory
|
|
||||||
"base.org")
|
|
||||||
:to-equal
|
|
||||||
nil)
|
|
||||||
(expect (test #'org-roam--extract-tags-first-directory
|
|
||||||
"tags/tag.org")
|
|
||||||
:to-equal
|
|
||||||
'("tags"))
|
|
||||||
(expect (test #'org-roam--extract-tags-first-directory
|
|
||||||
"nested/deeply/deeply_nested_file.org")
|
|
||||||
:to-equal
|
|
||||||
'("nested")))
|
|
||||||
|
|
||||||
(describe "uses org-roam-tag-sources correctly"
|
|
||||||
(it "'(prop)"
|
|
||||||
(expect (let ((org-roam-tag-sources '(prop)))
|
|
||||||
(test #'org-roam--extract-tags
|
|
||||||
"tags/tag.org"))
|
|
||||||
:to-equal
|
|
||||||
'("t1" "t2 with space" "t3")))
|
|
||||||
(it "'(prop all-directories)"
|
|
||||||
(expect (let ((org-roam-tag-sources '(prop all-directories)))
|
|
||||||
(test #'org-roam--extract-tags
|
|
||||||
"tags/tag.org"))
|
|
||||||
:to-equal
|
|
||||||
'("t1" "t2 with space" "t3" "tags"))))))
|
|
||||||
|
|
||||||
(describe "Headline extraction"
|
|
||||||
(before-all
|
|
||||||
(test-org-roam--init))
|
|
||||||
|
|
||||||
(after-all
|
|
||||||
(test-org-roam--teardown))
|
|
||||||
|
|
||||||
(cl-flet
|
|
||||||
((test (fn file)
|
|
||||||
(let* ((fname (test-org-roam--abs-path file))
|
|
||||||
(buf (find-file-noselect fname)))
|
|
||||||
(with-current-buffer buf
|
|
||||||
(funcall fn fname)))))
|
|
||||||
(it "extracts headlines"
|
|
||||||
(expect (test #'org-roam--extract-headlines
|
|
||||||
"headlines/headline.org")
|
|
||||||
:to-equal
|
|
||||||
`(["e84d0630-efad-4017-9059-5ef917908823" ,(test-org-roam--abs-path "headlines/headline.org")]
|
|
||||||
["801b58eb-97e2-435f-a33e-ff59a2f0c213" ,(test-org-roam--abs-path "headlines/headline.org")])))))
|
|
||||||
|
|
||||||
;;; Tests
|
|
||||||
(xdescribe "org-roam-db-build-cache"
|
|
||||||
(before-each
|
|
||||||
(test-org-roam--init))
|
|
||||||
|
|
||||||
(after-each
|
|
||||||
(test-org-roam--teardown))
|
|
||||||
|
|
||||||
(it "initializes correctly"
|
|
||||||
;; Cache
|
|
||||||
(expect (caar (org-roam-db-query [:select (funcall count) :from files])) :to-be 8)
|
|
||||||
(expect (caar (org-roam-db-query [:select (funcall count) :from links])) :to-be 5)
|
|
||||||
(expect (caar (org-roam-db-query [:select (funcall count) :from titles])) :to-be 8)
|
|
||||||
(expect (caar (org-roam-db-query [:select (funcall count) :from titles
|
|
||||||
:where titles :is-null])) :to-be 1)
|
|
||||||
(expect (caar (org-roam-db-query [:select (funcall count) :from refs])) :to-be 1)
|
|
||||||
|
|
||||||
;; Links
|
|
||||||
(expect (caar (org-roam-db-query [:select (funcall count) :from links
|
|
||||||
:where (= from $s1)]
|
|
||||||
(test-org-roam--abs-path "foo.org"))) :to-be 1)
|
|
||||||
(expect (caar (org-roam-db-query [:select (funcall count) :from links
|
|
||||||
:where (= from $s1)]
|
|
||||||
(test-org-roam--abs-path "nested/bar.org"))) :to-be 2)
|
|
||||||
|
|
||||||
;; Links -- File-to
|
|
||||||
(expect (caar (org-roam-db-query [:select (funcall count) :from links
|
|
||||||
:where (= to $s1)]
|
|
||||||
(test-org-roam--abs-path "nested/foo.org"))) :to-be 1)
|
|
||||||
(expect (caar (org-roam-db-query [:select (funcall count) :from links
|
|
||||||
:where (= to $s1)]
|
|
||||||
(test-org-roam--abs-path "nested/bar.org"))) :to-be 1)
|
|
||||||
(expect (caar (org-roam-db-query [:select (funcall count) :from links
|
|
||||||
:where (= to $s1)]
|
|
||||||
(test-org-roam--abs-path "unlinked.org"))) :to-be 0)
|
|
||||||
;; TODO Test titles
|
|
||||||
(expect (org-roam-db-query [:select * :from titles])
|
|
||||||
:to-have-same-items-as
|
|
||||||
(list (list (test-org-roam--abs-path "alias.org")
|
|
||||||
(list "t1" "a1" "a 2"))
|
|
||||||
(list (test-org-roam--abs-path "bar.org")
|
|
||||||
(list "Bar"))
|
|
||||||
(list (test-org-roam--abs-path "foo.org")
|
|
||||||
(list "Foo"))
|
|
||||||
(list (test-org-roam--abs-path "nested/bar.org")
|
|
||||||
(list "Nested Bar"))
|
|
||||||
(list (test-org-roam--abs-path "nested/foo.org")
|
|
||||||
(list "Nested Foo"))
|
|
||||||
(list (test-org-roam--abs-path "no-title.org")
|
|
||||||
(list "Headline title"))
|
|
||||||
(list (test-org-roam--abs-path "web_ref.org") nil)
|
|
||||||
(list (test-org-roam--abs-path "unlinked.org")
|
|
||||||
(list "Unlinked"))))
|
|
||||||
|
|
||||||
(expect (org-roam-db-query [:select * :from refs])
|
|
||||||
:to-have-same-items-as
|
|
||||||
(list (list "https://google.com/" (test-org-roam--abs-path "web_ref.org") "website")))
|
|
||||||
|
|
||||||
;; Expect rebuilds to be really quick (nothing changed)
|
|
||||||
(expect (org-roam-db-build-cache)
|
|
||||||
:to-equal
|
:to-equal
|
||||||
(list :files 0 :links 0 :tags 0 :titles 0 :refs 0 :deleted 0))))
|
2))
|
||||||
|
|
||||||
|
(it "has the correct number of nodes"
|
||||||
|
(expect (caar (org-roam-db-query [:select (funcall count) :from nodes]))
|
||||||
|
:to-equal
|
||||||
|
2))
|
||||||
|
|
||||||
|
(it "has the correct number of links"
|
||||||
|
(expect (caar (org-roam-db-query [:select (funcall count) :from links]))
|
||||||
|
:to-equal
|
||||||
|
1)))
|
||||||
|
|
||||||
(provide 'test-org-roam)
|
(provide 'test-org-roam)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user