mirror of
https://github.com/org-roam/org-roam
synced 2025-08-03 12:27:23 -05:00
Compare commits
109 Commits
Author | SHA1 | Date | |
---|---|---|---|
38b5375354 | |||
aa755a8c77 | |||
49c048a177 | |||
741677869c | |||
9da45b54f3 | |||
1440802b8b | |||
0163461f87 | |||
c866275086 | |||
a37dd6afea | |||
3f31ff2cd9 | |||
20e021fdde | |||
5db30d8fdc | |||
b12bd4ea40 | |||
e6acc40e79 | |||
d53f0e60bf | |||
45aa3e6973 | |||
3c6e1b5194 | |||
be81a3a738 | |||
67b1562582 | |||
05d95abc2e | |||
d465ea0d72 | |||
6b98f4b836 | |||
3664d22fde | |||
f62c00ea73 | |||
597d3c6241 | |||
f43b24a5bf | |||
aa2b670cd7 | |||
6c34528837 | |||
bc7a4986d8 | |||
624ac77fe2 | |||
0697f376eb | |||
3615969b35 | |||
f52c3a47d4 | |||
517f18afb4 | |||
b1ebba4b9a | |||
bad71fb928 | |||
bbefa7c174 | |||
1773978dc3 | |||
4cddc21c02 | |||
121d08562d | |||
fbf15fe5f2 | |||
4d697dea8f | |||
e612b3f068 | |||
c9636d6551 | |||
eef1ed2873 | |||
a1710b41b3 | |||
a527560cf4 | |||
628d5dcfbe | |||
516d8dfbf8 | |||
866368bfee | |||
1c831dcd73 | |||
3a2df140cb | |||
de6477be17 | |||
6f233363c8 | |||
09b0d74359 | |||
1b1d2b2b76 | |||
9e4a943d03 | |||
9a6cfe56c4 | |||
45546ff6fa | |||
7a6b885b99 | |||
39bb939dc2 | |||
467b165678 | |||
d641ad4792 | |||
18083cc1ed | |||
5b0078e79d | |||
5a3363ac22 | |||
18aa3ac787 | |||
7a493d8549 | |||
50436a9b1c | |||
73a04a611a | |||
ca1080b349 | |||
4e5a21d7e3 | |||
fb27fc78bc | |||
a35b0e7c6d | |||
f883c3270f | |||
eec1edf8f5 | |||
3d61a76ecb | |||
49541298ba | |||
490901957e | |||
f681c51630 | |||
ae5a0c15ba | |||
732efc6262 | |||
537f167503 | |||
1ea5b029a5 | |||
486f3cac3d | |||
e62cf7f8aa | |||
a4ab83ea89 | |||
7bb61806ef | |||
6ac3a84057 | |||
47c3b024d7 | |||
e19c3d6273 | |||
6bcf164036 | |||
315e2dc447 | |||
2f77ae709d | |||
e238c6d766 | |||
9b0a45f105 | |||
843eacb80b | |||
6fae3aa74c | |||
d1dd75e3b2 | |||
be828e2c1d | |||
5c7027aece | |||
fb76f81423 | |||
121e969553 | |||
0c0d677631 | |||
dc0357b12e | |||
cbeaa4d92e | |||
302b2e3bc3 | |||
25c41a079a | |||
53dcf687ef |
@ -4,11 +4,7 @@
|
|||||||
(elisp-lint-ignored-validators . ("byte-compile" "package-lint"))
|
(elisp-lint-ignored-validators . ("byte-compile" "package-lint"))
|
||||||
(elisp-lint-indent-specs . ((describe . 1)
|
(elisp-lint-indent-specs . ((describe . 1)
|
||||||
(it . 1)
|
(it . 1)
|
||||||
(thread-first . 0)
|
|
||||||
(cl-flet . 1)
|
|
||||||
(cl-flet* . 1)
|
|
||||||
(org-element-map . defun)
|
(org-element-map . defun)
|
||||||
(org-roam-dolist-with-progress . 2)
|
|
||||||
(org-roam-with-temp-buffer . 1)
|
(org-roam-with-temp-buffer . 1)
|
||||||
(org-with-point-at . 1)
|
(org-with-point-at . 1)
|
||||||
(magit-insert-section . defun)
|
(magit-insert-section . defun)
|
||||||
|
2
.github/FUNDING.yml
vendored
2
.github/FUNDING.yml
vendored
@ -1,6 +1,6 @@
|
|||||||
# These are supported funding model platforms
|
# These are supported funding model platforms
|
||||||
|
|
||||||
github: [jethrokuan]
|
github: [jethrokuan, zaeph]
|
||||||
patreon: # Replace with a single Patreon username
|
patreon: # Replace with a single Patreon username
|
||||||
open_collective: # Replace with a single Open Collective username
|
open_collective: # Replace with a single Open Collective username
|
||||||
ko_fi: # Replace with a single Ko-fi username
|
ko_fi: # Replace with a single Ko-fi username
|
||||||
|
2
.github/ISSUE_TEMPLATE/bug_report.md
vendored
2
.github/ISSUE_TEMPLATE/bug_report.md
vendored
@ -39,3 +39,5 @@ Example:
|
|||||||
### Environment
|
### Environment
|
||||||
|
|
||||||
<!-- Please M-x org-roam-diagnostics and paste results here -->
|
<!-- Please M-x org-roam-diagnostics and paste results here -->
|
||||||
|
|
||||||
|
- Org-roam commit: https://github.com/jethrokuan/org-roam/commit/commithashhere
|
||||||
|
2
.github/workflows/docs.yml
vendored
2
.github/workflows/docs.yml
vendored
@ -4,7 +4,7 @@ name: "Docs"
|
|||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- master
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
|
10
.github/workflows/test.yml
vendored
10
.github/workflows/test.yml
vendored
@ -28,7 +28,7 @@ on:
|
|||||||
pull_request:
|
pull_request:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- master
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
@ -36,11 +36,7 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
emacs_version:
|
emacs_version:
|
||||||
# REVIEW: we do not yet have the bootstrapping in place to test
|
- 27.1
|
||||||
# versions of emacs without built-in sqlite (pre 29.1)
|
|
||||||
# - 27.2
|
|
||||||
# - 28.2
|
|
||||||
- 29.4
|
|
||||||
- snapshot
|
- snapshot
|
||||||
steps:
|
steps:
|
||||||
- uses: purcell/setup-emacs@master
|
- uses: purcell/setup-emacs@master
|
||||||
@ -50,7 +46,7 @@ jobs:
|
|||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
- name: Install Eldev
|
- name: Install Eldev
|
||||||
run: curl -fsSL https://raw.github.com/org-roam/org-roam/master/github-eldev | sh
|
run: curl -fsSL https://raw.github.com/doublep/eldev/master/webinstall/github-eldev | sh
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: make prepare
|
run: make prepare
|
||||||
|
93
.github/workflows/tidy-issues.yml
vendored
93
.github/workflows/tidy-issues.yml
vendored
@ -1,93 +0,0 @@
|
|||||||
name: 'Manage stale/dormant issues and PRs'
|
|
||||||
|
|
||||||
on:
|
|
||||||
schedule:
|
|
||||||
- cron: '0 1 * * *' # Daily at 1 AM UTC
|
|
||||||
workflow_dispatch: # Allow this to be run manually
|
|
||||||
inputs:
|
|
||||||
dry_run:
|
|
||||||
description: 'Dry run: Show what would happen without making changes'
|
|
||||||
required: false
|
|
||||||
default: 'false'
|
|
||||||
type: boolean
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
stale:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
# Handle stale issues/PRs
|
|
||||||
- name: Mark/close stale issues and PRs
|
|
||||||
uses: actions/stale@v9
|
|
||||||
with:
|
|
||||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
|
|
||||||
# Dry run setting
|
|
||||||
debug-only: ${{ github.event.inputs.dry_run == 'true' }}
|
|
||||||
|
|
||||||
# Messages
|
|
||||||
stale-issue-message: |
|
|
||||||
📅 **Stale Issue Notice**
|
|
||||||
|
|
||||||
This issue has been automatically marked as stale because it has not had recent activity for **6 months**.
|
|
||||||
|
|
||||||
**⏰ This issue will be closed in 2 weeks** if no further activity occurs.
|
|
||||||
|
|
||||||
**To keep this issue open:**
|
|
||||||
- Comment on this issue
|
|
||||||
- Reference it in a commit or PR
|
|
||||||
- Add new information or updates
|
|
||||||
|
|
||||||
Thank you for your contributions to org-roam! 🙏
|
|
||||||
|
|
||||||
close-issue-message: |
|
|
||||||
🔒 **Issue Automatically Closed**
|
|
||||||
|
|
||||||
This issue was automatically closed due to **6 months of inactivity** followed by 2 weeks notice.
|
|
||||||
|
|
||||||
**To reopen:**
|
|
||||||
- If still relevant, comment below and we'll reopen
|
|
||||||
- Or create a new issue with updated information
|
|
||||||
|
|
||||||
If this issue is not reopened in 2 weeks, it will be locked.
|
|
||||||
|
|
||||||
This helps keep our issue tracker focused and manageable.
|
|
||||||
|
|
||||||
stale-pr-message: |
|
|
||||||
📅 **Stale Pull Request Notice**
|
|
||||||
|
|
||||||
This pull request has been automatically marked as stale because it has not had recent activity for **6 months**.
|
|
||||||
|
|
||||||
**⏰ This PR will be closed in 2 weeks** if no further activity occurs.
|
|
||||||
|
|
||||||
**To keep this PR open:**
|
|
||||||
- Push new commits
|
|
||||||
- Comment with updates
|
|
||||||
- Rebase on latest main branch
|
|
||||||
|
|
||||||
Thank you for your contributions to org-roam! 🙏
|
|
||||||
|
|
||||||
close-pr-message: |
|
|
||||||
🔒 **Pull Request Automatically Closed**
|
|
||||||
|
|
||||||
This pull request was automatically closed due to **6 months of inactivity** followed by 2 weeks notice.
|
|
||||||
|
|
||||||
# Timing (6 months + 2 weeks)
|
|
||||||
days-before-stale: 182 # ~6 months
|
|
||||||
days-before-close: 14 # 2 weeks notice
|
|
||||||
|
|
||||||
# Performance
|
|
||||||
operations-per-run: 1000
|
|
||||||
|
|
||||||
# Show dry run summary
|
|
||||||
- name: Dry run summary
|
|
||||||
if: github.event.inputs.dry_run == 'true'
|
|
||||||
run: |
|
|
||||||
echo "🧪 DRY RUN COMPLETED"
|
|
||||||
echo "This was a dry run - no actual changes were made."
|
|
||||||
echo "Check the action logs above to see what would have happened."
|
|
||||||
echo ""
|
|
||||||
echo "To run for real:"
|
|
||||||
echo "1. Go to Actions tab"
|
|
||||||
echo "2. Click 'Run workflow'"
|
|
||||||
echo "3. Leave 'Dry run mode' unchecked"
|
|
||||||
echo "4. Click 'Run workflow'"
|
|
225
CHANGELOG.md
225
CHANGELOG.md
@ -1,213 +1,9 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
## 2.3.1 (2025-06-26)
|
## 1.2.4 (TBD)
|
||||||
|
|
||||||
* (fix): Use correct type specifications to suppress warnings by @okomestudio in https://github.com/org-roam/org-roam/pull/2522
|
|
||||||
* perf: suppress extra org features in the temp buffer by @dustinfarris in https://github.com/org-roam/org-roam/pull/2524
|
|
||||||
|
|
||||||
## 2.3.0 (2025-05-24)
|
|
||||||
|
|
||||||
* (perf)node-read: filter before map to candidate by @russmatney in https://github.com/org-roam/org-roam/pull/2168
|
|
||||||
* (chore): remove extraneous changelog line by @jethrokuan in https://github.com/org-roam/org-roam/pull/2172
|
|
||||||
* (fix)org-roam-file-p: don't exclude org-roam-directory by @toregilhk in https://github.com/org-roam/org-roam/pull/2178
|
|
||||||
* (chore) fix version numbers by @jethrokuan in https://github.com/org-roam/org-roam/pull/2182
|
|
||||||
* (fix) org-roam-file-p handle opening a buffer with no path by @jethrokuan in https://github.com/org-roam/org-roam/pull/2185
|
|
||||||
* (fix)db: update atime on file access by @jethrokuan in https://github.com/org-roam/org-roam/pull/2174
|
|
||||||
* Fix org-roam-extract-subtree by @ralfdoering in https://github.com/org-roam/org-roam/pull/2191
|
|
||||||
* (node): fix org-roam-node-at-point check by @jethrokuan in https://github.com/org-roam/org-roam/pull/2195
|
|
||||||
* (chore): reapply #2178 by @jethrokuan in https://github.com/org-roam/org-roam/pull/2197
|
|
||||||
* Solved issue #2192 (Respect blank lines in capture templates) by @alopezrivera in https://github.com/org-roam/org-roam/pull/2203
|
|
||||||
* (chore)ci: /s/master/main by @jethrokuan in https://github.com/org-roam/org-roam/pull/2204
|
|
||||||
* support custom minibuffer matching function by @cuttlefisch in https://github.com/org-roam/org-roam/pull/2177
|
|
||||||
* (db)fix: org-roam-db-connector group by @jethrokuan in https://github.com/org-roam/org-roam/pull/2209
|
|
||||||
* ensure unique candidates in `org-roam-ref-find` by @bdarcus in https://github.com/org-roam/org-roam/pull/2208
|
|
||||||
* (db)fix: FOREIGN KEY error in narrowed buffer by @psii in https://github.com/org-roam/org-roam/pull/2215
|
|
||||||
* (feat): org-roam-property-* code duplication removed (#2217) by @clanghans in https://github.com/org-roam/org-roam/pull/2218
|
|
||||||
* (db)fix: file modification detection failing in some edge cases by @kisaragi-hiu in https://github.com/org-roam/org-roam/pull/2221
|
|
||||||
* (fix): autoload org-roam-list-files by @jethrokuan in https://github.com/org-roam/org-roam/pull/2226
|
|
||||||
* (fix): links not displayed properly in org-roam-buffer by @ntharim in https://github.com/org-roam/org-roam/pull/2236
|
|
||||||
* (fix): remove use of deprecated org-font-lock-ensure by @jethrokuan in https://github.com/org-roam/org-roam/pull/2238
|
|
||||||
* was missing the FULL parameter to `org-end-of-meta-data` - fixes #2242 by @jmay in https://github.com/org-roam/org-roam/pull/2246
|
|
||||||
* (Docs): Fixed typos in the docs by @hnvy in https://github.com/org-roam/org-roam/pull/2256
|
|
||||||
* Fix space chars in roam refs by @hwiorn in https://github.com/org-roam/org-roam/pull/2285
|
|
||||||
* org-roam-tag-add: use tags separator as crm-separator by @Hugo-Heagren in https://github.com/org-roam/org-roam/pull/2282
|
|
||||||
* Support multi-line org titles by @FelixBrendel in https://github.com/org-roam/org-roam/pull/2264
|
|
||||||
* (Docs): orgmode.org/elpa has been shut down by @aviad in https://github.com/org-roam/org-roam/pull/2258
|
|
||||||
* Minor typo in the commented text of the definition of `org-roam-refile` by @apc in https://github.com/org-roam/org-roam/pull/2263
|
|
||||||
* fix outline of link in properties by @bhuztez in https://github.com/org-roam/org-roam/pull/2230
|
|
||||||
* (fix): update `org-roam-unlinked-references-section` check by @Elilif in https://github.com/org-roam/org-roam/pull/2254
|
|
||||||
* Add support for filtering backlinks. by @swflint in https://github.com/org-roam/org-roam/pull/2247
|
|
||||||
* (docs): update documentation on database-connectors by @jethrokuan in https://github.com/org-roam/org-roam/pull/2298
|
|
||||||
* (db): default to sqlite-builtin when possible by @jethrokuan in https://github.com/org-roam/org-roam/pull/2299
|
|
||||||
* don't complete org-roam nodes in source blocks by @ParetoOptimalDev in https://github.com/org-roam/org-roam/pull/2292
|
|
||||||
* (core): add org-roam-node-category by @jethrokuan in https://github.com/org-roam/org-roam/pull/2300
|
|
||||||
* add discoverability support for age encrypted org files by @anticomputer in https://github.com/org-roam/org-roam/pull/2302
|
|
||||||
* (minor): fix lints on main by @jethrokuan in https://github.com/org-roam/org-roam/pull/2320
|
|
||||||
* utils: descendant-of-p: Defend against nils by @qzdl in https://github.com/org-roam/org-roam/pull/2319
|
|
||||||
* Add customisable function for prompting when adding refs by @Hugo-Heagren in https://github.com/org-roam/org-roam/pull/2317
|
|
||||||
* Fix org-fold-core-style in org-roam-buffer by @hwiorn in https://github.com/org-roam/org-roam/pull/2325
|
|
||||||
* depend on snapshot of emacsql by @jethrokuan in https://github.com/org-roam/org-roam/pull/2327
|
|
||||||
* (node): org-roam-node-at-point: don't error in non-org buffers by @Hugo-Heagren in https://github.com/org-roam/org-roam/pull/2329
|
|
||||||
* (node) add optional NOCASE parameter to org-roam-node-from-title-or-alias by @nuthub in https://github.com/org-roam/org-roam/pull/2403
|
|
||||||
* (docs): update org-protocol instructions by @benthamite in https://github.com/org-roam/org-roam/pull/2401
|
|
||||||
* Fix some typos by @feltcat in https://github.com/org-roam/org-roam/pull/2430
|
|
||||||
* (docs): fix name of my-org-roam-show-backlink-p by @Delapouite in https://github.com/org-roam/org-roam/pull/2447
|
|
||||||
* Link Martin Edström's knowledge base by @meedstrom in https://github.com/org-roam/org-roam/pull/2394
|
|
||||||
* Update org-roam.org by @marcosbodio in https://github.com/org-roam/org-roam/pull/2441
|
|
||||||
* (chore): fix indent blocking ci lint execution by @Delapouite in https://github.com/org-roam/org-roam/pull/2448
|
|
||||||
* Fix Issue #2410 - Unlinked References doesnt work if the org-roam-directory has a space in it. by @vikram-mandyam in https://github.com/org-roam/org-roam/pull/2411
|
|
||||||
* (test): add "org-roam--list-files-search-globs" by @Delapouite in https://github.com/org-roam/org-roam/pull/2449
|
|
||||||
* Backlink heading by @toregilhk in https://github.com/org-roam/org-roam/pull/2333
|
|
||||||
* (test): add org-roam-id-find by @Delapouite in https://github.com/org-roam/org-roam/pull/2450
|
|
||||||
* (test): add org-roam-id-at-point by @Delapouite in https://github.com/org-roam/org-roam/pull/2451
|
|
||||||
* (test): add org-roam--buffer-promoteable-p by @Delapouite in https://github.com/org-roam/org-roam/pull/2452
|
|
||||||
* (test): add org-roam--get-titles by @Delapouite in https://github.com/org-roam/org-roam/pull/2453
|
|
||||||
* (test): add org-roam-node-from-{id|title-or-alias} by @Delapouite in https://github.com/org-roam/org-roam/pull/2454
|
|
||||||
* (test): add org-roam-alias-{add|remove} by @Delapouite in https://github.com/org-roam/org-roam/pull/2455
|
|
||||||
* (docs): add missing versions dates and obsolete notice by @Delapouite in https://github.com/org-roam/org-roam/pull/2456
|
|
||||||
* (docs): explain org-roam-file-exclude-regexp by @adamoudad in https://github.com/org-roam/org-roam/pull/2458
|
|
||||||
* (test): add org-roam-demote-entire-buffer by @Delapouite in https://github.com/org-roam/org-roam/pull/2459
|
|
||||||
* (test): add org-roam-file-p by @Delapouite in https://github.com/org-roam/org-roam/pull/2460
|
|
||||||
* (test): add org-roam-buffer-p by @Delapouite in https://github.com/org-roam/org-roam/pull/2461
|
|
||||||
* (fix): remove dead-code about org-roam-shield feature by @Delapouite in https://github.com/org-roam/org-roam/pull/2462
|
|
||||||
* (test): add org-roam-db--file-hash by @Delapouite in https://github.com/org-roam/org-roam/pull/2464
|
|
||||||
* (test): add org-roam-db-get-{scheduled|deadline}-time by @Delapouite in https://github.com/org-roam/org-roam/pull/2465
|
|
||||||
* Doc formatting: 2 fixes by @kevinrineer in https://github.com/org-roam/org-roam/pull/2475
|
|
||||||
* Take org-roam-node as argument to #'org-roam-refile by @pestctrl in https://github.com/org-roam/org-roam/pull/2388
|
|
||||||
* Compatibility with latest org-id version: advise org-id-find rather than overwriting id link by @ricklupton in https://github.com/org-roam/org-roam/pull/2432
|
|
||||||
* Depend on emacsql 4.0.0 by @bcc32 in https://github.com/org-roam/org-roam/pull/2466
|
|
||||||
* Use regexp match to replace hard-coded path equal test by @manphiz in https://github.com/org-roam/org-roam/pull/2497
|
|
||||||
* Align sqlite integration with emacsql 4.0 by @dustinfarris in https://github.com/org-roam/org-roam/pull/2503
|
|
||||||
* fix #2425 Prevent data loss when user has called org-roam-extract-subtree on folded org headline by @akashpal-21 in https://github.com/org-roam/org-roam/pull/2444
|
|
||||||
* Rely on emacsql-sqlite-open to pick the best available back-end by @tarsius in https://github.com/org-roam/org-roam/pull/2486
|
|
||||||
* Set org-roam-directory to a non-existent path to ensure robust test by @manphiz in https://github.com/org-roam/org-roam/pull/2499
|
|
||||||
* (perf): Deprecate link :outline properties by @meedstrom in https://github.com/org-roam/org-roam/pull/2509
|
|
||||||
* Bump DB version to avoid error by @meedstrom in https://github.com/org-roam/org-roam/pull/2514
|
|
||||||
|
|
||||||
|
|
||||||
## 2.2.2 (2022-04-25)
|
|
||||||
|
|
||||||
### Breaking
|
|
||||||
### Added
|
|
||||||
- [#2138](https://github.com/org-roam/org-roam/pull/2138) export: add new module
|
|
||||||
- [#2170](https://github.com/org-roam/org-roam/pull/2170) log: add new module for working with org logs
|
|
||||||
- [#2158](https://github.com/org-roam/org-roam/pull/2158) db: support emacsql-sqlite-builtin and emacsql-sqlite-module
|
|
||||||
- [#2160](https://github.com/org-roam/org-roam/pull/2160) core: support a list of `org-roam-file-exclude-regexp`
|
|
||||||
|
|
||||||
### Removed
|
|
||||||
### Fixed
|
|
||||||
- [#2091](https://github.com/org-roam/org-roam/pull/2091) node: fix org-roam-promote-entire-buffer structural errors
|
|
||||||
- [#2130](https://github.com/org-roam/org-roam/pull/2130) buffer: unlinked-references section now also searches within symlinked directories
|
|
||||||
- [#2152](https://github.com/org-roam/org-roam/pull/2152) org-roam-preview-default-function: doesn't copy copy content of next heading node when current node's content is empty
|
|
||||||
- [#2159](https://github.com/org-roam/org-roam/pull/2159) db: fix db syncs on narrowed buffers
|
|
||||||
- [#2156](https://github.com/org-roam/org-roam/pull/2157) capture: templates with functions are handled correctly to avoid signaling `char-or-string-p`
|
|
||||||
|
|
||||||
### Changed
|
|
||||||
- [#2160](https://github.com/org-roam/org-roam/pull/2160) core: ignore files in `org-attach-id-dir` by default
|
|
||||||
|
|
||||||
## 2.2.1 (2022-03-15)
|
|
||||||
|
|
||||||
### Breaking
|
|
||||||
- [#2054](https://github.com/org-roam/org-roam/pull/2054) node: simplify default `org-roam-node-display-template`.
|
|
||||||
This was done so completions work fine by default on all completion systems. To restore the tabular vertical completion interface, set this in your configuration:
|
|
||||||
|
|
||||||
```emacs-lisp
|
|
||||||
(setq org-roam-node-display-template
|
|
||||||
(concat "${title:*} "
|
|
||||||
(propertize "${tags:10}" 'face 'org-tag)))
|
|
||||||
```
|
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
- [#2042](https://github.com/org-roam/org-roam/pull/2042) db: add `org-roam-db-extra-links-elements` and `org-roam-db-extra-links-exclude-keys` for fine-grained control over additional link parsing
|
|
||||||
- [#2049](https://github.com/org-roam/org-roam/pull/2049) capture: allow ID to be used as part of `org-roam-capture-templates`
|
|
||||||
- [#2050](https://github.com/org-roam/org-roam/pull/2050) core: add `FILTER-FN` to `org-roam-node-random`
|
|
||||||
- [#2065](https://github.com/org-roam/org-roam/pull/2065) dailies: add `keys` argument to the remaining dailies functions `org-roam-dailies-goto-yesterday`/`-today`/`-tomorrow`/`-date` and `org-roam-dailies-capture-yesterday`/`-tomorrow`/`-date` to give the abilty to get into a capture buffer bypassing the selection screen in all dailies commands. Extension of #2055
|
|
||||||
- [#2079](https://github.com/org-roam/org-roam/pull/2079) capture: ensure that `:ref` info captured in all cases.
|
|
||||||
- [#2121](https://github.com/org-roam/org-roam/pull/2121) buffer: add unique option to `org-roam-backlinks-section`
|
|
||||||
|
|
||||||
### Removed
|
|
||||||
### Fixed
|
|
||||||
- [#2086](https://github.com/org-roam/org-roam/pull/2086) capture: correctly update org-id-locations on capture
|
|
||||||
- [#2082](https://github.com/org-roam/org-roam/pull/2082) buffer: don't destroy window if `org-roam-node-toggle` reuses window
|
|
||||||
- [#2080](https://github.com/org-roam/org-roam/pull/2080) dailies: prevent multiple "dailies/" subdir expansions
|
|
||||||
- [#2055](https://github.com/org-roam/org-roam/pull/2055) dailies: removed stray f require, which was causing require and compilation errors
|
|
||||||
- [#2117](https://github.com/org-roam/org-roam/pull/2117) capture: preserve trailing whitespace content in capture templates
|
|
||||||
|
|
||||||
### Changed
|
|
||||||
- [#2060](https://github.com/org-roam/org-roam/pull/2060) node: added double acute accent normalization for Unicode characters in titles
|
|
||||||
- [#2040](https://github.com/org-roam/org-roam/pull/2040) completions: fix completions display-width for Helm users
|
|
||||||
- [#2025](https://github.com/org-roam/org-roam/pull/2025) chore: removed the dependencies on f.el and s.el
|
|
||||||
- [#2109](https://github.com/org-roam/org-roam/pull/2109) capture: `org-roam-node-insert` places cursor after inserted link where appropriate
|
|
||||||
- [#2123](https://github.com/org-roam/org-roam/pull/2123), [#2124](https://github.com/org-roam/org-roam/pull/2124) buffer: `org-roam-mode-section-functions` renamed to `org-roam-mode-sections`, supports passing args into the section-rendering function
|
|
||||||
|
|
||||||
## 2.2.0 (2022-01-14)
|
|
||||||
|
|
||||||
### Added
|
|
||||||
- [#1806](https://github.com/org-roam/org-roam/pull/1806), [#2017](https://github.com/org-roam/org-roam/pull/2017) db: support caching and usage of Org 9.5's in-built citations
|
|
||||||
- [#1963](https://github.com/org-roam/org-roam/pull/1963) db: cache file title into files table
|
|
||||||
- [#1977](https://github.com/org-roam/org-roam/pull/1977) db: support Org-ref v3 citations
|
|
||||||
- [#1907](https://github.com/org-roam/org-roam/pull/1907), [#2009](https://github.com/org-roam/org-roam/pull/2009), [#2018](https://github.com/org-roam/org-roam/pull/2018) db: support sqlite3
|
|
||||||
- [#2028](https://github.com/org-roam/org-roam/pull/2028) dailies: add `keys` argument to `org-roam-dailies-capture-today` and `org-roam-dailies--capture` functions to give the abilty to get into a capture buffer bypassing the selection screen
|
|
||||||
|
|
||||||
### Removed
|
|
||||||
### Changed
|
|
||||||
- [#1795](https://github.com/org-roam/org-roam/pull/1795) buffer: optimized reflinks fetch
|
|
||||||
- [#1809](https://github.com/org-roam/org-roam/pull/1809) capture: the mandatory `:if-new` property of each capture template is now renamed to `:target`
|
|
||||||
- [#1829](https://github.com/org-roam/org-roam/pull/1829) perf: file sql updates are now wrapped in a transaction
|
|
||||||
- [#1877](https://github.com/org-roam/org-roam/pull/1877) dailies: stop asking for time, only date
|
|
||||||
- [#1949](https://github.com/org-roam/org-roam/pull/1949) db: check for property drawers are now case-insensitive
|
|
||||||
|
|
||||||
### Fixed
|
|
||||||
- [#1798](https://github.com/org-roam/org-roam/pull/1798) org-roam-node-at-point: do not skip invisible headings
|
|
||||||
- [#1807](https://github.com/org-roam/org-roam/pull/1807) capture: always trigger `:if-new` template for existing nodes
|
|
||||||
- [#1813](https://github.com/org-roam/org-roam/pull/1813) db: prevent empty ROAM_ALIASES from crashing db updates
|
|
||||||
- [#1816](https://github.com/org-roam/org-roam/pull/1816) db: prevent invalid ROAM_REFS from crashing db updates
|
|
||||||
- [#1893](https://github.com/org-roam/org-roam/pull/1893), [#1896](https://github.com/org-roam/org-roam/pull/1896), [#1901](https://github.com/org-roam/org-roam/pull/1901), [#1895](https://github.com/org-roam/org-roam/pull/1895), [#1904](https://github.com/org-roam/org-roam/pull/1904) completions: various mini-buffer related completion fixes
|
|
||||||
- [#1931](https://github.com/org-roam/org-roam/pull/1931) utils: org-roam-set-keyword now skips over all drawers
|
|
||||||
- [#1947](https://github.com/org-roam/org-roam/pull/1947) db: links in ROAM_REFS are no longer considered as links
|
|
||||||
- [#1948](https://github.com/org-roam/org-roam/pull/1948) completions: fix same-line completions
|
|
||||||
- [#1953](https://github.com/org-roam/org-roam/pull/1953) db: refresh CATEGORY before writing to db
|
|
||||||
- [#1946](https://github.com/org-roam/org-roam/pull/1946), [#1946](https://github.com/org-roam/org-roam/pull/1946), [#1958](https://github.com/org-roam/org-roam/pull/1958) various performance improvements
|
|
||||||
- [#1980](https://github.com/org-roam/org-roam/pull/1980) utils: fix org-roam-with-file changing the minor-mode
|
|
||||||
- [#2016](https://github.com/org-roam/org-roam/pull/2016) db: fix node caching being affected by agenda variables
|
|
||||||
- [#2033](https://github.com/org-roam/org-roam/pull/2023) db: respect local variables during db parsing
|
|
||||||
|
|
||||||
## 2.1.0 (2021-08-20)
|
|
||||||
|
|
||||||
### Added
|
|
||||||
- [#1693](https://github.com/org-roam/org-roam/pull/1693) added `filter-fn` and `templates` parameter to `org-roam-capture`, `org-roam-node-find`, and `org-roam-node-insert`
|
|
||||||
- [#1709](https://github.com/org-roam/org-roam/pull/1709) added ability to specify default value in org-roam capture templates
|
|
||||||
- [#1710](https://github.com/org-roam/org-roam/pull/1710) added `org-roam-extract-subtree`
|
|
||||||
- [#1720](https://github.com/org-roam/org-roam/pull/1720) added `org-roam-db-update-on-save`
|
|
||||||
- [#1758](https://github.com/org-roam/org-roam/pull/1758) added `org-roam-db-autosync-mode`, replacing `org-roam-setup` and `org-roam-teardown`
|
|
||||||
|
|
||||||
### Removed
|
|
||||||
- [#1716](https://github.com/org-roam/org-roam/pull/1716) helper function `org-roam-get-keyword` is now obsolete: prefer `org-collect-keywords`
|
|
||||||
|
|
||||||
### Changed
|
|
||||||
- [#1595](https://github.com/org-roam/org-roam/pull/1595), [#1724](https://github.com/org-roam/org-roam/pull/1724) Major refactoring and restructuring of the codebase
|
|
||||||
- [#1655](https://github.com/org-roam/org-roam/pull/1655) improved org-roam contents preview
|
|
||||||
- [#1741](https://github.com/org-roam/org-roam/pull/1741) expose `org-roam-capture-` keys in interactive commands
|
|
||||||
- [#1786](https://github.com/org-roam/org-roam/pull/1786) org-roam-version now outputs commit hash if found
|
|
||||||
- [#1788](https://github.com/org-roam/org-roam/pull/1788) the point is not moved if the node is already visited
|
|
||||||
|
|
||||||
### Fixed
|
|
||||||
- [#1608](https://github.com/org-roam/org-roam/pull/1608) migration: empty ROAM_REFS are now removed
|
|
||||||
- [#1609](https://github.com/org-roam/org-roam/pull/1609) migration: fixed file-link replacement
|
|
||||||
- [#1653](https://github.com/org-roam/org-roam/pull/1653) migration: fixed tags migration
|
|
||||||
- [#1694](https://github.com/org-roam/org-roam/pull/1694) core: nodes with no title are now skipped
|
|
||||||
- [#1637](https://github.com/org-roam/org-roam/pull/1637) core: fix org-ref multi-cite links not being split
|
|
||||||
- [#1651](https://github.com/org-roam/org-roam/pull/1651) core: fix org-roam-file-p crashing when there is no corresponding file
|
|
||||||
- [#1705](https://github.com/org-roam/org-roam/pull/1705) core: fix for add/remove of file-level tags
|
|
||||||
- [#1769](https://github.com/org-roam/org-roam/pull/1769) core: gracefully handle absence of `org-id-locations-file`
|
|
||||||
- [#1713](https://github.com/org-roam/org-roam/pull/1713) capture: check for file-existence before template insertion
|
|
||||||
- [#1725](https://github.com/org-roam/org-roam/pull/1725) db: always compute hash of encrypted file to prevent re-processing of encrypted files
|
|
||||||
|
|
||||||
## 2.0.0 (2021-07-17)
|
|
||||||
|
|
||||||
A few symbols have been marked as obsolete. Have a look at the content of [org-roam-compat.el](https://github.com/org-roam/org-roam/blob/f819720c510185af713522c592833ec9f2934251/org-roam-compat.el#L159)
|
|
||||||
|
|
||||||
### 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
|
- [#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`.
|
- [#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
|
- [#1353](https://github.com/org-roam/org-roam/pull/1353) support file-level property drawers
|
||||||
@ -215,8 +11,6 @@ A few symbols have been marked as obsolete. Have a look at the content of [org-r
|
|||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
- [#1352](https://github.com/org-roam/org-roam/pull/1352) prefer lower-case for roam_tag and roam_alias in interactive commands
|
- [#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
|
### Fixed
|
||||||
|
|
||||||
@ -231,9 +25,8 @@ A few symbols have been marked as obsolete. Have a look at the content of [org-r
|
|||||||
- [#1375](https://github.com/org-roam/org-roam/pull/1375) fix org-roam-protocol to use existing ref file
|
- [#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
|
- [#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`
|
- [#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 (2020-11-13)
|
## 1.2.3 (13-11-2020)
|
||||||
|
|
||||||
Primarily a stabilization and bug-fix release.
|
Primarily a stabilization and bug-fix release.
|
||||||
|
|
||||||
@ -264,7 +57,7 @@ Org-roam-dailies has also been revamped to include new features, see [this video
|
|||||||
- [#1233](https://github.com/org-roam/org-roam/issues/1233) fixes bug where descriptive file links become plain links during update for relative paths
|
- [#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
|
- [#1252](https://github.com/org-roam/org-roam/issues/1252) respect original link type during automatic replacement
|
||||||
|
|
||||||
## 1.2.2 (2020-10-06)
|
## 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`.
|
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`.
|
||||||
|
|
||||||
@ -302,7 +95,7 @@ This change requires you to set `org-roam-directory` to the resolved path of a f
|
|||||||
- [#1057](https://github.com/org-roam/org-roam/pull/1057) Improve performance of database builds by preventing generation of LaTeX and image previews.
|
- [#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
|
- [#1103](https://github.com/org-roam/org-roam/pull/1103) Fix long build-times for Windows on files with URL links
|
||||||
|
|
||||||
## 1.2.1 (2020-07-27)
|
## 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.
|
||||||
|
|
||||||
@ -335,7 +128,7 @@ We also added some new features that had been a long time coming:
|
|||||||
- [#894](https://github.com/org-roam/org-roam/pull/894) Perform link fixes on all Org-roam files
|
- [#894](https://github.com/org-roam/org-roam/pull/894) Perform link fixes on all Org-roam files
|
||||||
- [#952](https://github.com/org-roam/org-roam/pull/952) Cache `${foo}` template variables so they do not need to be re-entered twice
|
- [#952](https://github.com/org-roam/org-roam/pull/952) Cache `${foo}` template variables so they do not need to be re-entered twice
|
||||||
|
|
||||||
## 1.2.0 (2020-06-12)
|
## 1.2.0 (12-06-2020)
|
||||||
|
|
||||||
In this release, we improved the linking process by achieving feature parity between links to files and links to headlines. Before, we used the `file:foo::*bar` format to link to the headline `bar` in file `foo`, but this was prone to breakage upon renaming the file or modifying the headline. This is not the case anymore. Now, we use `org-id` to create IDs for those headlines, which are then stored in our database to compute the relationships and jump around. Note that this will work even if you’re not using `org-id` in your global configuration for Org-mode.
|
In this release, we improved the linking process by achieving feature parity between links to files and links to headlines. Before, we used the `file:foo::*bar` format to link to the headline `bar` in file `foo`, but this was prone to breakage upon renaming the file or modifying the headline. This is not the case anymore. Now, we use `org-id` to create IDs for those headlines, which are then stored in our database to compute the relationships and jump around. Note that this will work even if you’re not using `org-id` in your global configuration for Org-mode.
|
||||||
|
|
||||||
@ -363,7 +156,7 @@ We also add `org-roam-unlinked-references`, which naively finds text that could
|
|||||||
- [#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
|
||||||
|
|
||||||
## 1.1.1 (2020-05-18)
|
## 1.1.1 (18-05-2020)
|
||||||
|
|
||||||
In this release, we added two new features:
|
In this release, we added two new features:
|
||||||
|
|
||||||
@ -403,7 +196,7 @@ As usual, this release comes with a multitude of bug-fixes and refactorings.
|
|||||||
- [#606](https://github.com/org-roam/org-roam/pull/606) Added `org-roam-dev.el` for developer coding standards
|
- [#606](https://github.com/org-roam/org-roam/pull/606) Added `org-roam-dev.el` for developer coding standards
|
||||||
- [#622](https://github.com/org-roam/org-roam/pull/622) Online documentation now points to the Org-based documentation
|
- [#622](https://github.com/org-roam/org-roam/pull/622) Online documentation now points to the Org-based documentation
|
||||||
|
|
||||||
## 1.1.0 (2020-04-21)
|
## 1.1.0 (21-04-2020)
|
||||||
|
|
||||||
To the average user, this release is mainly a bugfix release with additional options to customize. However, the changes made to the source is significant. Most notably, in this release:
|
To the average user, this release is mainly a bugfix release with additional options to customize. However, the changes made to the source is significant. Most notably, in this release:
|
||||||
|
|
||||||
@ -441,7 +234,7 @@ In the coming months, you can expect work on bigger projects (e.g. revamping the
|
|||||||
- [#363](https://github.com/org-roam/org-roam/pull/363), [#473](https://github.com/org-roam/org-roam/pull/473) Modularize org-roam features.
|
- [#363](https://github.com/org-roam/org-roam/pull/363), [#473](https://github.com/org-roam/org-roam/pull/473) Modularize org-roam features.
|
||||||
- [#497](https://github.com/org-roam/org-roam/pull/497) Simplify `org-roam--list-files` implementation
|
- [#497](https://github.com/org-roam/org-roam/pull/497) Simplify `org-roam--list-files` implementation
|
||||||
|
|
||||||
## 1.0.0 (2020-03-23)
|
## 1.0.0 (23-03-2020)
|
||||||
|
|
||||||
Org-roam is now on MELPA! We have squashed most of the bugs, and Org-roam has
|
Org-roam is now on MELPA! We have squashed most of the bugs, and Org-roam has
|
||||||
been stable for the most part.
|
been stable for the most part.
|
||||||
@ -460,7 +253,7 @@ been stable for the most part.
|
|||||||
- [#293](https://github.com/org-roam/org-roam/pull/293) Fix capture templates not working as expected for `org-roam-find-file`
|
- [#293](https://github.com/org-roam/org-roam/pull/293) Fix capture templates not working as expected for `org-roam-find-file`
|
||||||
- [#275](https://github.com/org-roam/org-roam/pull/275) Fix database rebuild when `org-roam-directory` is set locally
|
- [#275](https://github.com/org-roam/org-roam/pull/275) Fix database rebuild when `org-roam-directory` is set locally
|
||||||
|
|
||||||
## 1.0.0-rc1 (2020-03-06)
|
## 1.0.0-rc1 (06-03-2020)
|
||||||
|
|
||||||
This is a pre-release before the push to MELPA. It contains large
|
This is a pre-release before the push to MELPA. It contains large
|
||||||
internal changes, with little user-facing changes. Most notably, the
|
internal changes, with little user-facing changes. Most notably, the
|
||||||
|
186
README.md
186
README.md
@ -33,180 +33,32 @@ solution for anyone already using Org-mode for their personal wiki.
|
|||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
Down below you will find basic installation instructions for how to quickly
|
You can install `org-roam` using `package.el`:
|
||||||
install `org-roam` using various environments for various purposes. For more
|
|
||||||
detailed information, please read the [manual][docs].
|
|
||||||
|
|
||||||
### Using `package.el`
|
|
||||||
<details>
|
|
||||||
<summary>Toggle instructions</summary>
|
|
||||||
|
|
||||||
You can install `org-roam` from [MELPA](https://melpa.org/) or [MELPA
|
|
||||||
Stable](https://stable.melpa.org/) using `package.el`:
|
|
||||||
|
|
||||||
```
|
```
|
||||||
M-x package-install RET org-roam RET
|
M-x package-install RET org-roam RET
|
||||||
```
|
```
|
||||||
</details>
|
|
||||||
|
|
||||||
### Using `straight.el`
|
Here's a sample configuration with `use-package`:
|
||||||
<details>
|
|
||||||
<summary>Toggle instructions</summary>
|
|
||||||
|
|
||||||
Installation from MELPA or MELPA Stable using `straight.el`:
|
|
||||||
|
|
||||||
```emacs-lisp
|
|
||||||
(straight-use-package 'org-roam)
|
|
||||||
```
|
|
||||||
|
|
||||||
Or with `use-package`:
|
|
||||||
|
|
||||||
```emacs-lisp
|
```emacs-lisp
|
||||||
(use-package org-roam
|
(use-package org-roam
|
||||||
:straight t
|
:ensure t
|
||||||
...)
|
:hook
|
||||||
|
(after-init . org-roam-mode)
|
||||||
|
:custom
|
||||||
|
(org-roam-directory "/path/to/org-files/")
|
||||||
|
:bind (:map org-roam-mode-map
|
||||||
|
(("C-c n l" . org-roam)
|
||||||
|
("C-c n f" . org-roam-find-file)
|
||||||
|
("C-c n g" . org-roam-graph))
|
||||||
|
:map org-mode-map
|
||||||
|
(("C-c n i" . org-roam-insert))))
|
||||||
```
|
```
|
||||||
|
|
||||||
If you need to install the package directly from the source repository, instead
|
Org-roam requires sqlite to function. Org-roam optionally uses Graphviz for
|
||||||
of from MELPA, the next sample shows how to do so:
|
graph-related functionality. It is recommended to install PCRE-enabled ripgrep
|
||||||
|
for better performance and extended functionality.
|
||||||
```emacs-lisp
|
|
||||||
(use-package org-roam
|
|
||||||
:straight (:host github :repo "org-roam/org-roam"
|
|
||||||
:files (:defaults "extensions/*"))
|
|
||||||
...)
|
|
||||||
```
|
|
||||||
|
|
||||||
If you plan to use your own local fork for the development and contribution, the
|
|
||||||
next sample will get you there:
|
|
||||||
|
|
||||||
```emacs-lisp
|
|
||||||
(use-package org-roam
|
|
||||||
:straight (:local-repo "/path/to/org-roam-fork"
|
|
||||||
:files (:defaults "extensions/*")
|
|
||||||
:build (:not compile))
|
|
||||||
...)
|
|
||||||
```
|
|
||||||
</details>
|
|
||||||
|
|
||||||
### Using Doom Emacs
|
|
||||||
<details>
|
|
||||||
<summary>Toggle instructions</summary>
|
|
||||||
|
|
||||||
Doom's `:lang org` module comes with support for `org-roam`, but it's not
|
|
||||||
enabled by default. To activate it pass `+roam2` flag to `org` module in your
|
|
||||||
`$DOOMDIR/init.el` (e.g. `(org +roam2)`), save the file and run `doom sync -u`
|
|
||||||
in your shell.
|
|
||||||
|
|
||||||
To provide better stability, Doom pins the package to a specific commit. If you
|
|
||||||
need to unpin it *(not recommended doing that, request Doom to bump the package
|
|
||||||
instead)* use the next in your `packages.el`:
|
|
||||||
|
|
||||||
```emacs-lisp
|
|
||||||
(unpin! org-roam)
|
|
||||||
```
|
|
||||||
|
|
||||||
If for some reasons you want to use a different recipe for `org-roam`, you can
|
|
||||||
use the next form in your `packages.el` to install the package from a recipe
|
|
||||||
repository (e.g. MELPA):
|
|
||||||
|
|
||||||
```emacs-lisp
|
|
||||||
(package! org-roam)
|
|
||||||
```
|
|
||||||
|
|
||||||
You can pass `:pin "commit hash"` to pin the package to a specific commit.
|
|
||||||
|
|
||||||
With the next sample you can install the package directly from the source
|
|
||||||
repository:
|
|
||||||
|
|
||||||
```emacs-lisp
|
|
||||||
(package! org-roam
|
|
||||||
:recipe (:host github :repo "org-roam/org-roam"
|
|
||||||
:files (:defaults "extensions/*")))
|
|
||||||
```
|
|
||||||
|
|
||||||
And if you plan to use your own local fork for the development or contribution,
|
|
||||||
the next sample will get you there:
|
|
||||||
|
|
||||||
```emacs-lisp
|
|
||||||
(package! org-roam
|
|
||||||
:recipe (:local-repo "/path/to/org-roam-fork"
|
|
||||||
:files (:defaults "extensions/*")
|
|
||||||
:build (:not compile)))
|
|
||||||
```
|
|
||||||
</details>
|
|
||||||
|
|
||||||
### Without a package manager
|
|
||||||
<details>
|
|
||||||
<summary>Toggle instructions</summary>
|
|
||||||
|
|
||||||
To install the package without using a package manager you have the next two
|
|
||||||
options:
|
|
||||||
|
|
||||||
1. Install the package by cloning it with `git` from the source repository.
|
|
||||||
2. Or install the package by downloading the latest [release
|
|
||||||
version](https://github.com/org-roam/org-roam/releases).
|
|
||||||
|
|
||||||
In both of the cases you will need to ensure that you have all the required
|
|
||||||
dependencies. These include:
|
|
||||||
|
|
||||||
- dash
|
|
||||||
- f
|
|
||||||
- s
|
|
||||||
- org (9.6 is the minimum required version!)
|
|
||||||
- emacsql
|
|
||||||
- magit-section
|
|
||||||
- filenotify-recursive
|
|
||||||
|
|
||||||
After installing the package, you will need to properly setup `load-path` to the
|
|
||||||
package:
|
|
||||||
|
|
||||||
``` emacs-lisp
|
|
||||||
(add-to-list 'load-path "/path/to/org-roam/")
|
|
||||||
(add-to-list 'load-path "/path/to-org-roam/extensions/")
|
|
||||||
```
|
|
||||||
|
|
||||||
After which you should be able to resolve `(require 'org-roam)` call without any
|
|
||||||
problems.
|
|
||||||
|
|
||||||
Org-roam also comes with `.texi` files to integrate with Emacs' built-in Info
|
|
||||||
system. Read the manual to find more details for how to install them manually.
|
|
||||||
</details>
|
|
||||||
|
|
||||||
## Configuration
|
|
||||||
|
|
||||||
Here's a very basic sample for configuration of `org-roam` using `use-package`:
|
|
||||||
|
|
||||||
```emacs-lisp
|
|
||||||
(use-package org-roam
|
|
||||||
:ensure t
|
|
||||||
:custom
|
|
||||||
(org-roam-directory (file-truename "/path/to/org-files/"))
|
|
||||||
:bind (("C-c n l" . org-roam-buffer-toggle)
|
|
||||||
("C-c n f" . org-roam-node-find)
|
|
||||||
("C-c n g" . org-roam-graph)
|
|
||||||
("C-c n i" . org-roam-node-insert)
|
|
||||||
("C-c n c" . org-roam-capture)
|
|
||||||
;; Dailies
|
|
||||||
("C-c n j" . org-roam-dailies-capture-today))
|
|
||||||
:config
|
|
||||||
;; If you're using a vertical completion framework, you might want a more informative completion interface
|
|
||||||
(setq org-roam-node-display-template (concat "${title:*} " (propertize "${tags:10}" 'face 'org-tag)))
|
|
||||||
(org-roam-db-autosync-mode)
|
|
||||||
;; If using org-roam-protocol
|
|
||||||
(require 'org-roam-protocol))
|
|
||||||
```
|
|
||||||
|
|
||||||
Note that the `file-truename` function is only necessary when you use symbolic
|
|
||||||
link to `org-roam-directory`. Org-roam won't automatically resolve symbolic link
|
|
||||||
to the directory.
|
|
||||||
## Getting Started
|
|
||||||
|
|
||||||
[David Wilson](https://github.com/daviwil) of [System
|
|
||||||
Crafters](https://www.youtube.com/c/SystemCrafters) has produced an introductory
|
|
||||||
video that covers the basic commands:
|
|
||||||
|
|
||||||
[](https://www.youtube.com/watch?v=AyhPmypHDEw)
|
|
||||||
|
|
||||||
## Getting Help
|
## Getting Help
|
||||||
|
|
||||||
@ -227,9 +79,7 @@ it has not already been addressed on [GitHub][issues] or on
|
|||||||
|
|
||||||
- [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://www.alexeyshmalko.com/)
|
- [Alexey Shmalko](https://braindump.rasen.dev/)
|
||||||
- [Sidharth Arya](https://sidhartharya.github.io/braindump/index.html)
|
|
||||||
- [Martin Edström](https://edstrom.dev/)
|
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
@ -252,6 +102,6 @@ General Public License, Version 3.
|
|||||||
[release]: https://github.com/org-roam/org-roam/releases
|
[release]: https://github.com/org-roam/org-roam/releases
|
||||||
[docs]: https://www.orgroam.com/manual.html
|
[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-wuoize1z-x3UyQnQ0WHF0RhuEQ2NLnQ
|
[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
|
[faq]: https://www.orgroam.com/manual.html#FAQ
|
||||||
|
15
default.mk
15
default.mk
@ -44,17 +44,16 @@ HTMLDIRS = $(PACKAGES)
|
|||||||
PDFFILES = $(addsuffix .pdf,$(PACKAGES))
|
PDFFILES = $(addsuffix .pdf,$(PACKAGES))
|
||||||
EPUBFILES = $(addsuffix .epub,$(PACKAGES))
|
EPUBFILES = $(addsuffix .epub,$(PACKAGES))
|
||||||
|
|
||||||
ELS = org-roam.el
|
ELS = org-roam-buffer.el
|
||||||
ELS += org-roam-capture.el
|
ELS += org-roam-capture.el
|
||||||
ELS += org-roam-compat.el
|
ELS += org-roam-compat.el
|
||||||
|
ELS += org-roam-completion.el
|
||||||
|
ELS += org-roam-dailies.el
|
||||||
ELS += org-roam-db.el
|
ELS += org-roam-db.el
|
||||||
ELS += org-roam-mode.el
|
ELS += org-roam.el
|
||||||
ELS += org-roam-node.el
|
ELS += org-roam-graph.el
|
||||||
ELS += org-roam-utils.el
|
ELS += org-roam-macs.el
|
||||||
ELS += extensions/org-roam-dailies.el
|
ELS += org-roam-protocol.el
|
||||||
ELS += extensions/org-roam-graph.el
|
|
||||||
ELS += extensions/org-roam-overlay.el
|
|
||||||
ELS += extensions/org-roam-protocol.el
|
|
||||||
ELCS = $(ELS:.el=.elc)
|
ELCS = $(ELS:.el=.elc)
|
||||||
ELMS = org-roam.el $(filter-out $(addsuffix .el,$(PACKAGES)),$(ELS))
|
ELMS = org-roam.el $(filter-out $(addsuffix .el,$(PACKAGES)),$(ELS))
|
||||||
ELGS = org-roam-autoloads.el org-roam-version.el
|
ELGS = org-roam-autoloads.el org-roam-version.el
|
||||||
|
@ -95,7 +95,7 @@
|
|||||||
<ul>
|
<ul>
|
||||||
<li>Read our documentation within Emacs, or on the <a href="https://www.orgroam.com/manual.html">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-wuoize1z-x3UyQnQ0WHF0RhuEQ2NLnQ">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>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
@ -116,8 +116,8 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<a
|
<a
|
||||||
class="content footer-links"
|
class="content footer-links"
|
||||||
href="https://github.com/org-roam/org-roam-ui"
|
href="https://github.com/org-roam/org-roam-server"
|
||||||
>org-roam-ui</a
|
>org-roam-server</a
|
||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -151,7 +151,7 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<a
|
<a
|
||||||
class="content footer-links"
|
class="content footer-links"
|
||||||
href="https://join.slack.com/t/orgroam/shared_invite/zt-wuoize1z-x3UyQnQ0WHF0RhuEQ2NLnQ"
|
href="https://join.slack.com/t/orgroam/shared_invite/zt-deoqamys-043YQ~s5Tay3iJ5QRI~Lxg"
|
||||||
>Slack</a
|
>Slack</a
|
||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
|
1883
doc/org-roam.org
1883
doc/org-roam.org
File diff suppressed because it is too large
Load Diff
2525
doc/org-roam.texi
2525
doc/org-roam.texi
File diff suppressed because it is too large
Load Diff
@ -1,75 +0,0 @@
|
|||||||
;;; org-roam-export.el --- Org-roam org-export tweaks -*- coding: utf-8; lexical-binding: t; -*-
|
|
||||||
|
|
||||||
;; Copyright © 2020-2025 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.3.1
|
|
||||||
;; Package-Requires: ((emacs "26.1") (org "9.6") (org-roam "2.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 package provides the necessary changes required to make org-export work out-of-the-box.
|
|
||||||
;;
|
|
||||||
;; To enable it, run:
|
|
||||||
;;
|
|
||||||
;; (require 'org-roam-export)
|
|
||||||
;;
|
|
||||||
;; The key issue Org's export-to-html functionality has is that it does not respect the ID property, which
|
|
||||||
;; Org-roam relies heavily on. This patches the necessary function in ox-html to export ID links correctly,
|
|
||||||
;; pointing to the correct place.
|
|
||||||
;;
|
|
||||||
;;; Code:
|
|
||||||
(require 'ox-html)
|
|
||||||
|
|
||||||
(defun org-roam-export--org-html--reference (datum info &optional named-only)
|
|
||||||
"Org-roam's patch for `org-html--reference' to support ID link export.
|
|
||||||
See `org-html--reference' for DATUM, INFO and NAMED-ONLY."
|
|
||||||
(let* ((type (org-element-type datum))
|
|
||||||
(user-label
|
|
||||||
(org-element-property
|
|
||||||
(pcase type
|
|
||||||
((or `headline `inlinetask) :CUSTOM_ID)
|
|
||||||
((or `radio-target `target) :value)
|
|
||||||
(_ :name))
|
|
||||||
datum))
|
|
||||||
(user-label
|
|
||||||
(or user-label
|
|
||||||
(when-let ((path (org-element-property :ID datum)))
|
|
||||||
;; see `org-html-link' for why we use "ID-"
|
|
||||||
;; (search for "ID-" in ox-html.el)
|
|
||||||
(concat "ID-" path)))))
|
|
||||||
(cond
|
|
||||||
((and user-label
|
|
||||||
(or (plist-get info :html-prefer-user-labels)
|
|
||||||
(memq type '(headline inlinetask))))
|
|
||||||
user-label)
|
|
||||||
((and named-only
|
|
||||||
(not (memq type '(headline inlinetask radio-target target)))
|
|
||||||
(not user-label))
|
|
||||||
nil)
|
|
||||||
(t
|
|
||||||
(org-export-get-reference datum info)))))
|
|
||||||
|
|
||||||
(advice-add 'org-html--reference :override #'org-roam-export--org-html--reference)
|
|
||||||
|
|
||||||
(provide 'org-roam-export)
|
|
||||||
;;; org-roam-export.el ends here
|
|
@ -1,302 +0,0 @@
|
|||||||
;;; org-roam-graph.el --- Basic graphing functionality for Org-roam -*- coding: utf-8; lexical-binding: t; -*-
|
|
||||||
|
|
||||||
;; Copyright © 2020-2025 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.3.1
|
|
||||||
;; Package-Requires: ((emacs "26.1") (org "9.6") (org-roam "2.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 extension implements capability to build and generate graphs in Org-roam
|
|
||||||
;; with the help of Graphviz.
|
|
||||||
;;
|
|
||||||
;;; Code:
|
|
||||||
(require 'xml) ;xml-escape-string
|
|
||||||
(require 'org-roam)
|
|
||||||
|
|
||||||
;;; Options
|
|
||||||
(defcustom org-roam-graph-viewer (executable-find "firefox")
|
|
||||||
"Method to view the org-roam graph.
|
|
||||||
It may be one of the following:
|
|
||||||
- a string representing the path to the executable for viewing the graph.
|
|
||||||
- a function accepting a single argument: the graph file path.
|
|
||||||
- nil uses `view-file' to view the graph."
|
|
||||||
:type '(choice
|
|
||||||
(string :tag "Path to executable")
|
|
||||||
(function :tag "Function to display graph" eww-open-file)
|
|
||||||
(const :tag "view-file"))
|
|
||||||
:group 'org-roam)
|
|
||||||
|
|
||||||
(defcustom org-roam-graph-executable "dot"
|
|
||||||
"Path to graphing executable, or its name."
|
|
||||||
:type 'string
|
|
||||||
: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
|
|
||||||
"Extra options passed to graphviz.
|
|
||||||
Example:
|
|
||||||
'((\"rankdir\" . \"LR\"))"
|
|
||||||
:type '(alist)
|
|
||||||
: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
|
|
||||||
'(("id" . (("style" . "bold,rounded,filled")
|
|
||||||
("fillcolor" . "#EEEEEE")
|
|
||||||
("color" . "#C9C9C9")
|
|
||||||
("fontcolor" . "#111111")))
|
|
||||||
("http" . (("style" . "rounded,filled")
|
|
||||||
("fillcolor" . "#EEEEEE")
|
|
||||||
("color" . "#C9C9C9")
|
|
||||||
("fontcolor" . "#0A97A6")))
|
|
||||||
("https" . (("style" . "rounded,filled")
|
|
||||||
("fillcolor" . "#EEEEEE")
|
|
||||||
("color" . "#C9C9C9")
|
|
||||||
("fontcolor" . "#0A97A6"))))
|
|
||||||
"Extra options for graphviz nodes."
|
|
||||||
:type '(alist)
|
|
||||||
:group 'org-roam)
|
|
||||||
|
|
||||||
(defcustom org-roam-graph-link-hidden-types
|
|
||||||
'("file")
|
|
||||||
"What sort of links to hide from the Org-roam graph."
|
|
||||||
:type '(repeat string)
|
|
||||||
:group 'org-roam)
|
|
||||||
|
|
||||||
(defcustom org-roam-graph-max-title-length 100
|
|
||||||
"Maximum length of titles in graph nodes."
|
|
||||||
:type 'number
|
|
||||||
:group 'org-roam)
|
|
||||||
|
|
||||||
(defcustom org-roam-graph-shorten-titles 'truncate
|
|
||||||
"Determines how long titles appear in graph nodes.
|
|
||||||
Recognized values are the symbols `truncate' and `wrap', in which
|
|
||||||
cases the title will be truncated or wrapped, respectively, if it
|
|
||||||
is longer than `org-roam-graph-max-title-length'.
|
|
||||||
|
|
||||||
All other values including nil will have no effect."
|
|
||||||
:type '(choice
|
|
||||||
(const :tag "truncate" truncate)
|
|
||||||
(const :tag "wrap" wrap)
|
|
||||||
(const :tag "no" nil))
|
|
||||||
:group 'org-roam)
|
|
||||||
|
|
||||||
(defcustom org-roam-graph-link-builder 'org-roam-org-protocol-link-builder
|
|
||||||
"Function used to build the Org-roam graph links.
|
|
||||||
Given a node name, return a string to be used for the link fed to
|
|
||||||
the graph generation utility."
|
|
||||||
:type 'function
|
|
||||||
:group 'org-roam)
|
|
||||||
|
|
||||||
(defcustom org-roam-graph-generation-hook nil
|
|
||||||
"Functions to run after the graph has been generated.
|
|
||||||
Each function is called with two arguments: the filename
|
|
||||||
containing the graph generation tool, and the generated graph."
|
|
||||||
:type 'hook
|
|
||||||
:group 'org-roam)
|
|
||||||
|
|
||||||
(defun org-roam-org-protocol-link-builder (node)
|
|
||||||
"Default org-roam link builder. Generate an org-protocol link using NODE."
|
|
||||||
(concat "org-protocol://roam-node?node="
|
|
||||||
(url-hexify-string (org-roam-node-id node))))
|
|
||||||
|
|
||||||
;;; Interactive command
|
|
||||||
;;;###autoload
|
|
||||||
(defun org-roam-graph (&optional arg node)
|
|
||||||
"Build and possibly display a graph for NODE.
|
|
||||||
ARG may be any of the following values:
|
|
||||||
- nil show the graph.
|
|
||||||
- `\\[universal-argument]' show the graph for NODE.
|
|
||||||
- `\\[universal-argument]' N show the graph for NODE limiting nodes to N steps."
|
|
||||||
(interactive
|
|
||||||
(list current-prefix-arg
|
|
||||||
(and current-prefix-arg
|
|
||||||
(org-roam-node-at-point 'assert))))
|
|
||||||
(let ((graph (cl-typecase arg
|
|
||||||
(null (org-roam-graph--dot nil 'all-nodes))
|
|
||||||
(cons (org-roam-graph--dot (org-roam-graph--connected-component
|
|
||||||
(org-roam-node-id node) 0)))
|
|
||||||
(integer (org-roam-graph--dot (org-roam-graph--connected-component
|
|
||||||
(org-roam-node-id node) (abs arg)))))))
|
|
||||||
(org-roam-graph--build graph #'org-roam-graph--open)))
|
|
||||||
|
|
||||||
;;; Generation and Build process
|
|
||||||
(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."
|
|
||||||
(unless (stringp org-roam-graph-executable)
|
|
||||||
(user-error "`org-roam-graph-executable' is not a string"))
|
|
||||||
(unless (executable-find org-roam-graph-executable)
|
|
||||||
(user-error (concat "Cannot find executable \"%s\" to generate the graph. "
|
|
||||||
"Please adjust `org-roam-graph-executable'")
|
|
||||||
org-roam-graph-executable))
|
|
||||||
(let* ((temp-dot (make-temp-file "graph." nil ".dot" graph))
|
|
||||||
(temp-graph (make-temp-file "graph." nil (concat "." org-roam-graph-filetype))))
|
|
||||||
(org-roam-message "building graph")
|
|
||||||
(make-process
|
|
||||||
:name "*org-roam-graph*"
|
|
||||||
:buffer " *org-roam-graph*"
|
|
||||||
:command `(,org-roam-graph-executable ,temp-dot "-T" ,org-roam-graph-filetype "-o" ,temp-graph)
|
|
||||||
:sentinel (when callback
|
|
||||||
(lambda (process _event)
|
|
||||||
(when (= 0 (process-exit-status process))
|
|
||||||
(progn (funcall callback temp-graph)
|
|
||||||
(run-hook-with-args 'org-roam-graph-generation-hook temp-dot temp-graph))))))))
|
|
||||||
|
|
||||||
(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 (make-hash-table :test #'equal))
|
|
||||||
(seen-nodes (list))
|
|
||||||
(edges (or edges (org-roam-db-query [:select :distinct [source dest type] :from links]))))
|
|
||||||
(pcase-dolist (`(,id ,file ,title)
|
|
||||||
(org-roam-db-query [:select [id file title] :from nodes]))
|
|
||||||
(puthash id (org-roam-node-create :file file :id id :title title) nodes-table))
|
|
||||||
(with-temp-buffer
|
|
||||||
(setq-local org-roam-directory org-roam-directory-temp)
|
|
||||||
(insert "digraph \"org-roam\" {\n")
|
|
||||||
(dolist (option org-roam-graph-extra-config)
|
|
||||||
(insert (org-roam-graph--dot-option option) ";\n"))
|
|
||||||
(insert (format " edge [%s];\n"
|
|
||||||
(mapconcat (lambda (var)
|
|
||||||
(org-roam-graph--dot-option var nil "\""))
|
|
||||||
org-roam-graph-edge-extra-config
|
|
||||||
",")))
|
|
||||||
(pcase-dolist (`(,source ,dest ,type) edges)
|
|
||||||
(unless (member type org-roam-graph-link-hidden-types)
|
|
||||||
(pcase-dolist (`(,node ,node-type) `((,source "id")
|
|
||||||
(,dest ,type)))
|
|
||||||
(unless (member node seen-nodes)
|
|
||||||
(insert (org-roam-graph--format-node
|
|
||||||
(or (gethash node nodes-table) node) node-type))
|
|
||||||
(push node seen-nodes)))
|
|
||||||
(insert (format " \"%s\" -> \"%s\";\n"
|
|
||||||
(xml-escape-string source)
|
|
||||||
(xml-escape-string dest)))))
|
|
||||||
(when all-nodes
|
|
||||||
(maphash (lambda (id node)
|
|
||||||
(unless (member id seen-nodes)
|
|
||||||
(insert (org-roam-graph--format-node node "id"))))
|
|
||||||
nodes-table))
|
|
||||||
(insert "}")
|
|
||||||
(buffer-string))))
|
|
||||||
|
|
||||||
(defun org-roam-graph--connected-component (id distance)
|
|
||||||
"Return the edges for all nodes reachable from/connected to ID.
|
|
||||||
DISTANCE is the maximum distance away from the root node."
|
|
||||||
(let* ((query
|
|
||||||
(if (= distance 0)
|
|
||||||
"
|
|
||||||
WITH RECURSIVE
|
|
||||||
links_of(source, dest) AS
|
|
||||||
(SELECT source, dest FROM links UNION
|
|
||||||
SELECT dest, source FROM links),
|
|
||||||
connected_component(source) AS
|
|
||||||
(SELECT dest FROM links_of WHERE source = $s1 UNION
|
|
||||||
SELECT dest FROM links_of JOIN connected_component USING(source))
|
|
||||||
SELECT DISTINCT source, dest, type FROM links
|
|
||||||
WHERE source IN connected_component OR dest IN connected_component;"
|
|
||||||
"
|
|
||||||
WITH RECURSIVE
|
|
||||||
links_of(source, dest) AS
|
|
||||||
(SELECT source, dest FROM links UNION
|
|
||||||
SELECT dest, source FROM links),
|
|
||||||
connected_component(source, trace) AS
|
|
||||||
(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 DISTINCT 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-option (option &optional wrap-key wrap-val)
|
|
||||||
"Return dot string of form KEY=VAL for OPTION cons.
|
|
||||||
If WRAP-KEY is non-nil it wraps the KEY.
|
|
||||||
If WRAP-VAL is non-nil it wraps the VAL."
|
|
||||||
(concat wrap-key (car option) wrap-key
|
|
||||||
"="
|
|
||||||
wrap-val (cdr option) wrap-val))
|
|
||||||
|
|
||||||
(defun org-roam-graph--format-node (node type)
|
|
||||||
"Return a graphviz NODE with TYPE.
|
|
||||||
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 (truncate-string-to-width title org-roam-graph-max-title-length nil nil "..."))
|
|
||||||
(`wrap (org-roam-word-wrap org-roam-graph-max-title-length title))
|
|
||||||
(_ title)))))
|
|
||||||
(setq node-id (org-roam-node-id node)
|
|
||||||
node-properties `(("label" . ,shortened-title)
|
|
||||||
("URL" . ,(funcall org-roam-graph-link-builder 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--open (file)
|
|
||||||
"Open FILE using `org-roam-graph-viewer' with `view-file' as a fallback."
|
|
||||||
(pcase org-roam-graph-viewer
|
|
||||||
((pred stringp)
|
|
||||||
(if (executable-find org-roam-graph-viewer)
|
|
||||||
(condition-case err
|
|
||||||
(call-process org-roam-graph-viewer nil 0 nil file)
|
|
||||||
(error (user-error "Failed to open org-roam graph: %s" err)))
|
|
||||||
(user-error "Executable not found: \"%s\"" org-roam-graph-viewer)))
|
|
||||||
((pred functionp) (funcall org-roam-graph-viewer file))
|
|
||||||
('nil (view-file file))
|
|
||||||
(_ (signal 'wrong-type-argument `((functionp stringp null) ,org-roam-graph-viewer)))))
|
|
||||||
|
|
||||||
|
|
||||||
(provide 'org-roam-graph)
|
|
||||||
|
|
||||||
;;; org-roam-graph.el ends here
|
|
@ -1,96 +0,0 @@
|
|||||||
;;; org-roam-overlay.el --- Link overlay for [id:] links to Org-roam nodes -*- coding: utf-8; lexical-binding: t; -*-
|
|
||||||
|
|
||||||
;; Copyright © 2020-2025 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.3.1
|
|
||||||
;; Package-Requires: ((emacs "26.1") (org "9.6") (org-roam "2.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 extension allows to render [[id:]] links that don't have an associated
|
|
||||||
;; descriptor with an overlay that displays the node's current title.
|
|
||||||
;;
|
|
||||||
;;; Code:
|
|
||||||
(require 'org-roam)
|
|
||||||
|
|
||||||
(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
|
|
@ -1,174 +0,0 @@
|
|||||||
;;; org-roam-protocol.el --- Protocol handler for roam:// links -*- coding: utf-8; lexical-binding: t; -*-
|
|
||||||
|
|
||||||
;; Copyright © 2020-2025 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.3.1
|
|
||||||
;; Package-Requires: ((emacs "26.1") (org "9.6") (org-roam "2.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 extension extends `org-protocol', adding custom Org-roam handlers to it
|
|
||||||
;; to provide the next new protocols:
|
|
||||||
;;
|
|
||||||
;; 1. "roam-node": This protocol simply opens the node given by the node ID
|
|
||||||
;; 2. "roam-ref": This protocol creates or opens the node with the given REF
|
|
||||||
;;
|
|
||||||
;; You can find detailed instructions on how to setup the protocol in the
|
|
||||||
;; documentation for Org-roam.
|
|
||||||
;;
|
|
||||||
;;; Code:
|
|
||||||
(require 'org-protocol)
|
|
||||||
(require 'ol) ;; for org-link-decode
|
|
||||||
(require 'org-roam)
|
|
||||||
|
|
||||||
;;; Options
|
|
||||||
(defcustom org-roam-protocol-store-links nil
|
|
||||||
"Whether to store links when capturing websites with `org-roam-protocol'."
|
|
||||||
:type 'boolean
|
|
||||||
:group 'org-roam)
|
|
||||||
|
|
||||||
(defcustom org-roam-capture-ref-templates
|
|
||||||
'(("r" "ref" plain "%?"
|
|
||||||
:target (file+head "${slug}.org"
|
|
||||||
"#+title: ${title}")
|
|
||||||
:unnarrowed t))
|
|
||||||
"The Org-roam templates used during a capture from the roam-ref protocol.
|
|
||||||
See `org-roam-capture-templates' for the template documentation."
|
|
||||||
:group 'org-roam
|
|
||||||
:type '(repeat
|
|
||||||
(choice (list :tag "Multikey description"
|
|
||||||
(string :tag "Keys ")
|
|
||||||
(string :tag "Description"))
|
|
||||||
(list :tag "Template entry"
|
|
||||||
(string :tag "Keys ")
|
|
||||||
(string :tag "Description ")
|
|
||||||
(choice :tag "Capture Type " :value entry
|
|
||||||
(const :tag "Org entry" entry)
|
|
||||||
(const :tag "Plain list item" item)
|
|
||||||
(const :tag "Checkbox item" checkitem)
|
|
||||||
(const :tag "Plain text" plain)
|
|
||||||
(const :tag "Table line" table-line))
|
|
||||||
(choice :tag "Template "
|
|
||||||
(string)
|
|
||||||
(list :tag "File"
|
|
||||||
(const :format "" file)
|
|
||||||
(file :tag "Template file"))
|
|
||||||
(list :tag "Function"
|
|
||||||
(const :format "" function)
|
|
||||||
(function :tag "Template function")))
|
|
||||||
(plist :inline t
|
|
||||||
;; Give the most common options as checkboxes
|
|
||||||
:options (((const :format "%v " :target)
|
|
||||||
(choice :tag "Node location"
|
|
||||||
(list :tag "File"
|
|
||||||
(const :format "" file)
|
|
||||||
(string :tag " File"))
|
|
||||||
(list :tag "File & Head Content"
|
|
||||||
(const :format "" file+head)
|
|
||||||
(string :tag " File")
|
|
||||||
(string :tag " Head Content"))
|
|
||||||
(list :tag "File & Outline path"
|
|
||||||
(const :format "" file+olp)
|
|
||||||
(string :tag " File")
|
|
||||||
(list :tag "Outline path"
|
|
||||||
(repeat (string :tag "Headline"))))
|
|
||||||
(list :tag "File & Head Content & Outline path"
|
|
||||||
(const :format "" file+head+olp)
|
|
||||||
(string :tag " File")
|
|
||||||
(string :tag " Head Content")
|
|
||||||
(list :tag "Outline path"
|
|
||||||
(repeat (string :tag "Headline"))))))
|
|
||||||
((const :format "%v " :prepend) (const t))
|
|
||||||
((const :format "%v " :immediate-finish) (const t))
|
|
||||||
((const :format "%v " :jump-to-captured) (const t))
|
|
||||||
((const :format "%v " :empty-lines) (const 1))
|
|
||||||
((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))))))))
|
|
||||||
|
|
||||||
;;; Handlers
|
|
||||||
(defun org-roam-protocol-open-ref (info)
|
|
||||||
"Process an org-protocol://roam-ref?ref= style url with INFO.
|
|
||||||
|
|
||||||
It opens or creates a note with the given ref.
|
|
||||||
|
|
||||||
javascript:location.href = \\='org-protocol://roam-ref?template=r&ref=\\='+ \\
|
|
||||||
encodeURIComponent(location.href) + \\='&title=\\=' + \\
|
|
||||||
encodeURIComponent(document.title) + \\='&body=\\=' + \\
|
|
||||||
encodeURIComponent(window.getSelection())"
|
|
||||||
(unless (plist-get info :ref)
|
|
||||||
(user-error "No ref key provided"))
|
|
||||||
(org-roam-plist-map! (lambda (k v)
|
|
||||||
(org-link-decode
|
|
||||||
(if (equal k :ref)
|
|
||||||
(org-protocol-sanitize-uri v)
|
|
||||||
v))) info)
|
|
||||||
(when org-roam-protocol-store-links
|
|
||||||
(push (list (plist-get info :ref)
|
|
||||||
(plist-get info :title)) org-stored-links))
|
|
||||||
(org-link-store-props :type (and (string-match org-link-plain-re
|
|
||||||
(plist-get info :ref))
|
|
||||||
(match-string 1 (plist-get info :ref)))
|
|
||||||
:link (plist-get info :ref)
|
|
||||||
:annotation (org-link-make-string (plist-get info :ref)
|
|
||||||
(or (plist-get info :title)
|
|
||||||
(plist-get info :ref)))
|
|
||||||
:initial (or (plist-get info :body) ""))
|
|
||||||
(raise-frame)
|
|
||||||
(let ((org-capture-link-is-already-stored t))
|
|
||||||
(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)
|
|
||||||
|
|
||||||
(defun org-roam-protocol-open-node (info)
|
|
||||||
"This handler simply opens the file with emacsclient.
|
|
||||||
|
|
||||||
INFO is a plist containing additional information passed by the protocol URL.
|
|
||||||
It should contain the FILE key, pointing to the path of the file to open.
|
|
||||||
|
|
||||||
Example protocol string:
|
|
||||||
|
|
||||||
org-protocol://roam-node?node=uuid"
|
|
||||||
(when-let ((node (plist-get info :node)))
|
|
||||||
(raise-frame)
|
|
||||||
(org-roam-node-visit (org-roam-populate (org-roam-node-create :id node)) nil 'force))
|
|
||||||
nil)
|
|
||||||
|
|
||||||
(push '("org-roam-ref" :protocol "roam-ref" :function org-roam-protocol-open-ref)
|
|
||||||
org-protocol-protocol-alist)
|
|
||||||
(push '("org-roam-node" :protocol "roam-node" :function org-roam-protocol-open-node)
|
|
||||||
org-protocol-protocol-alist)
|
|
||||||
|
|
||||||
(provide 'org-roam-protocol)
|
|
||||||
|
|
||||||
;;; org-roam-protocol.el ends here
|
|
11
github-eldev
11
github-eldev
@ -1,11 +0,0 @@
|
|||||||
#! /bin/sh
|
|
||||||
set -e
|
|
||||||
|
|
||||||
ELDEV_BIN_DIR=~/.local/bin
|
|
||||||
|
|
||||||
# `$GITHUB_PATH' is a magic file which contents is translated to environment variable `$PATH'.
|
|
||||||
echo "$ELDEV_BIN_DIR" >> $GITHUB_PATH
|
|
||||||
|
|
||||||
mkdir -p $ELDEV_BIN_DIR
|
|
||||||
curl -fsSL https://raw.githubusercontent.com/doublep/eldev/f111d19cda305e5e8fcb70a5675b87173041cb68/bin/eldev > $ELDEV_BIN_DIR/eldev
|
|
||||||
chmod a+x $ELDEV_BIN_DIR/eldev
|
|
@ -1,12 +1,12 @@
|
|||||||
;;; org-roam-capture.el --- Capture functionality -*- coding: utf-8; lexical-binding: t; -*-
|
;;; org-roam-capture.el --- Capture functionality -*- coding: utf-8; lexical-binding: t; -*-
|
||||||
|
|
||||||
;; Copyright © 2020-2025 Jethro Kuan <jethrokuan95@gmail.com>
|
;; Copyright © 2020 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: 2.3.1
|
;; Version: 2.0.0
|
||||||
;; Package-Requires: ((emacs "26.1") (dash "2.13") (org "9.6") (emacsql "4.1.0") (magit-section "3.0.0"))
|
;; Package-Requires: ((emacs "26.1") (dash "2.13") (f "0.17.2") (s "1.12.0") (org "9.4") (emacsql "3.0.0") (emacsql-sqlite3 "1.0.2") (magit-section "2.90.1"))
|
||||||
|
|
||||||
;; This file is NOT part of GNU Emacs.
|
;; This file is NOT part of GNU Emacs.
|
||||||
|
|
||||||
@ -27,20 +27,38 @@
|
|||||||
|
|
||||||
;;; Commentary:
|
;;; Commentary:
|
||||||
;;
|
;;
|
||||||
;; This module provides `org-capture' functionality for Org-roam. With this
|
;; This library provides capture functionality for org-roam
|
||||||
;; module the user can capture new nodes or capture new content to existing
|
|
||||||
;; nodes.
|
|
||||||
;;
|
|
||||||
;;; Code:
|
;;; Code:
|
||||||
(require 'org-roam)
|
;;;
|
||||||
|
;;;; Library Requires
|
||||||
|
(require 'org-capture)
|
||||||
|
(eval-when-compile
|
||||||
|
(require 'org-roam-macs))
|
||||||
|
(require 'org-roam-db)
|
||||||
|
(require 'dash)
|
||||||
|
(require 'cl-lib)
|
||||||
|
|
||||||
;;;; Declarations
|
;; Declarations
|
||||||
(defvar org-end-time-was-given)
|
(declare-function org-roam-ref-add "org-roam" (ref))
|
||||||
|
|
||||||
|
(defvar org-roam-directory)
|
||||||
|
|
||||||
|
(defvar org-roam-capture--node nil
|
||||||
|
"The node passed during an Org-roam capture.
|
||||||
|
This variable is populated dynamically, and is only non-nil
|
||||||
|
during the Org-roam capture process.")
|
||||||
|
|
||||||
|
(defvar org-roam-capture--info nil
|
||||||
|
"A property-list of additional information passed to the Org-roam template.
|
||||||
|
This variable is populated dynamically, and is only non-nil
|
||||||
|
during the Org-roam capture process.")
|
||||||
|
|
||||||
|
(defconst org-roam-capture--template-keywords '(:if-new :id :link-description :call-location)
|
||||||
|
"Keywords used in `org-roam-capture-templates' specific to Org-roam.")
|
||||||
|
|
||||||
;;; Options
|
|
||||||
(defcustom org-roam-capture-templates
|
(defcustom org-roam-capture-templates
|
||||||
'(("d" "default" plain "%?"
|
'(("d" "default" plain "%?"
|
||||||
:target (file+head "%<%Y%m%d%H%M%S>-${slug}.org"
|
:if-new (file+head "%<%Y%m%d%H%M%S>-${slug}.org"
|
||||||
"#+title: ${title}\n")
|
"#+title: ${title}\n")
|
||||||
:unnarrowed t))
|
:unnarrowed t))
|
||||||
"Templates for the creation of new entries within Org-roam.
|
"Templates for the creation of new entries within Org-roam.
|
||||||
@ -92,45 +110,25 @@ template The template for creating the capture item.
|
|||||||
in order to get a template from a file, or dynamically
|
in order to get a template from a file, or dynamically
|
||||||
from a function.
|
from a function.
|
||||||
|
|
||||||
The template contains a compulsory :target property. The :target property
|
The template contains a compulsory :if-new property. This determines the
|
||||||
contains a list, where:
|
location of the new node. The :if-new property contains a list, supporting
|
||||||
- The first element indicates the type of the target.
|
the following options:
|
||||||
- The second element indicates the location of the captured node.
|
|
||||||
- And the rest of the list indicate the prefilled template, that will be
|
|
||||||
inserted and the position of the point will be adjusted for.
|
|
||||||
This behavior varies from type to type.
|
|
||||||
|
|
||||||
The following options are supported for the :target property:
|
|
||||||
|
|
||||||
(file \"path/to/file\")
|
(file \"path/to/file\")
|
||||||
The file will be created, and prescribed an ID.
|
The file will be created, and prescribed an ID.
|
||||||
|
|
||||||
(file+head \"path/to/file\" \"head content\")
|
(file+head \"path/to/file\" \"head content\")
|
||||||
The file will be created, prescribed an ID, and head content will be
|
The file will be created, prescribed an ID, and head content will be
|
||||||
inserted if the node is a newly captured one.
|
inserted into the file.
|
||||||
|
|
||||||
(file+olp \"path/to/file\" (\"h1\" \"h2\"))
|
(file+olp \"path/to/file\" '(\"h1\" \"h2\"))
|
||||||
The file will be created, prescribed an ID. If the file doesn't contain
|
The file will be created, prescribed an ID. The OLP (h1, h2) will be
|
||||||
the outline path (h1, h2), it will be automatically created. The point
|
created, and the point placed after.
|
||||||
will be adjusted to the last element in the OLP.
|
|
||||||
|
|
||||||
(file+head+olp \"path/to/file\" \"head content\" (\"h1\" \"h2\"))
|
(file+head+olp \"path/to/file\" \"head content\" '(\"h1\" \"h2\"))
|
||||||
The file will be created, prescribed an ID. Head content will be
|
The file will be created, prescribed an ID. Head content will be
|
||||||
inserted at the start of the file if the node is a newly captured one.
|
inserted at the start of the file. The OLP (h1, h2) will be created,
|
||||||
If the file doesn't contain the outline path (h1, h2), it will be
|
and the point placed after.
|
||||||
automatically created. The point will be adjusted to the last element in
|
|
||||||
the OLP.
|
|
||||||
|
|
||||||
(file+datetree \"path/to/file\" tree-type)
|
|
||||||
The file will be created, prescribed an ID. A date based outline path
|
|
||||||
will be created for today's date. The tree-type can be one of the
|
|
||||||
following symbols: day, week or month. The point will adjusted to the
|
|
||||||
last element in the tree. To prompt for date instead of using today's,
|
|
||||||
use the :time-prompt property.
|
|
||||||
|
|
||||||
(node \"title or alias or ID of an existing node\")
|
|
||||||
The point will be placed for an existing node, based on either, its
|
|
||||||
title, alias or ID.
|
|
||||||
|
|
||||||
The rest of the entry is a property list of additional options. Recognized
|
The rest of the entry is a property list of additional options. Recognized
|
||||||
properties are:
|
properties are:
|
||||||
@ -205,8 +203,7 @@ be replaced with content and expanded:
|
|||||||
introduced with %[pathname] are expanded this way. Since this
|
introduced with %[pathname] are expanded this way. Since this
|
||||||
happens after expanding non-interactive %-escapes, those can
|
happens after expanding non-interactive %-escapes, those can
|
||||||
be used to fill the expression.
|
be used to fill the expression.
|
||||||
%<...> The result of `format-time-string' on the ... format
|
%<...> The result of `format-time-string' on the ... format specification.
|
||||||
specification.
|
|
||||||
%t Time stamp, date only. The time stamp is the current time,
|
%t Time stamp, date only. The time stamp is the current time,
|
||||||
except when called from agendas with `\\[org-agenda-capture]' or
|
except when called from agendas with `\\[org-agenda-capture]' or
|
||||||
with `org-capture-use-agenda-date' set.
|
with `org-capture-use-agenda-date' set.
|
||||||
@ -301,7 +298,7 @@ streamlined user experience in Org-roam."
|
|||||||
(function :tag "Template function")))
|
(function :tag "Template function")))
|
||||||
(plist :inline t
|
(plist :inline t
|
||||||
;; Give the most common options as checkboxes
|
;; Give the most common options as checkboxes
|
||||||
:options (((const :format "%v " :target)
|
:options (((const :format "%v " :if-new)
|
||||||
(choice :tag "Node location"
|
(choice :tag "Node location"
|
||||||
(list :tag "File"
|
(list :tag "File"
|
||||||
(const :format "" file)
|
(const :format "" file)
|
||||||
@ -314,13 +311,13 @@ streamlined user experience in Org-roam."
|
|||||||
(const :format "" file+olp)
|
(const :format "" file+olp)
|
||||||
(string :tag " File")
|
(string :tag " File")
|
||||||
(list :tag "Outline path"
|
(list :tag "Outline path"
|
||||||
(repeat (string :tag "Headline"))))
|
(repeat string :tag "Headline")))
|
||||||
(list :tag "File & Head Content & Outline path"
|
(list :tag "File & Head Content & Outline path"
|
||||||
(const :format "" file+head+olp)
|
(const :format "" file+head+olp)
|
||||||
(string :tag " File")
|
(string :tag " File")
|
||||||
(string :tag " Head Content")
|
(string :tag " Head Content")
|
||||||
(list :tag "Outline path"
|
(list :tag "Outline path"
|
||||||
(repeat (string :tag "Headline"))))))
|
(repeat string :tag "Headline")))))
|
||||||
((const :format "%v " :prepend) (const t))
|
((const :format "%v " :prepend) (const t))
|
||||||
((const :format "%v " :immediate-finish) (const t))
|
((const :format "%v " :immediate-finish) (const t))
|
||||||
((const :format "%v " :jump-to-captured) (const t))
|
((const :format "%v " :jump-to-captured) (const t))
|
||||||
@ -336,106 +333,77 @@ streamlined user experience in Org-roam."
|
|||||||
((const :format "%v " :table-line-pos) (string))
|
((const :format "%v " :table-line-pos) (string))
|
||||||
((const :format "%v " :kill-buffer) (const t))))))))
|
((const :format "%v " :kill-buffer) (const t))))))))
|
||||||
|
|
||||||
(defcustom org-roam-capture-new-node-hook nil
|
(defvar org-roam-capture-new-node-hook (list #'org-roam-capture--insert-ref)
|
||||||
"Normal-mode hooks run when a new Org-roam node is created.
|
"Normal-mode hooks run when a new Org-roam node is created.
|
||||||
The current point is the point of the new node.
|
The current point is the point of the new node.
|
||||||
The hooks must not move the point."
|
The hooks must not move the point.")
|
||||||
|
|
||||||
|
(defcustom org-roam-capture-ref-templates
|
||||||
|
'(("r" "ref" plain "%?"
|
||||||
|
:if-new (file+head "${slug}.org"
|
||||||
|
"#+title: ${title}")
|
||||||
|
:unnarrowed t))
|
||||||
|
"The Org-roam templates used during a capture from the roam-ref protocol.
|
||||||
|
See `org-roam-capture-templates' for the template documentation."
|
||||||
:group 'org-roam
|
:group 'org-roam
|
||||||
:type 'hook)
|
:type '(repeat
|
||||||
|
(choice (list :tag "Multikey description"
|
||||||
|
(string :tag "Keys ")
|
||||||
|
(string :tag "Description"))
|
||||||
|
(list :tag "Template entry"
|
||||||
|
(string :tag "Keys ")
|
||||||
|
(string :tag "Description ")
|
||||||
|
(choice :tag "Capture Type " :value entry
|
||||||
|
(const :tag "Org entry" entry)
|
||||||
|
(const :tag "Plain list item" item)
|
||||||
|
(const :tag "Checkbox item" checkitem)
|
||||||
|
(const :tag "Plain text" plain)
|
||||||
|
(const :tag "Table line" table-line))
|
||||||
|
(choice :tag "Template "
|
||||||
|
(string)
|
||||||
|
(list :tag "File"
|
||||||
|
(const :format "" file)
|
||||||
|
(file :tag "Template file"))
|
||||||
|
(list :tag "Function"
|
||||||
|
(const :format "" function)
|
||||||
|
(function :tag "Template function")))
|
||||||
|
(plist :inline t
|
||||||
|
;; Give the most common options as checkboxes
|
||||||
|
:options (((const :format "%v " :if-new)
|
||||||
|
(choice :tag "Node location"
|
||||||
|
(list :tag "File"
|
||||||
|
(const :format "" file)
|
||||||
|
(string :tag " File"))
|
||||||
|
(list :tag "File & Head Content"
|
||||||
|
(const :format "" file+head)
|
||||||
|
(string :tag " File")
|
||||||
|
(string :tag " Head Content"))
|
||||||
|
(list :tag "File & Outline path"
|
||||||
|
(const :format "" file+olp)
|
||||||
|
(string :tag " File")
|
||||||
|
(list :tag "Outline path"
|
||||||
|
(repeat string :tag "Headline")))
|
||||||
|
(list :tag "File & Head Content & Outline path"
|
||||||
|
(const :format "" file+head+olp)
|
||||||
|
(string :tag " File")
|
||||||
|
(string :tag " Head Content")
|
||||||
|
(list :tag "Outline path"
|
||||||
|
(repeat string :tag "Headline")))))
|
||||||
|
((const :format "%v " :prepend) (const t))
|
||||||
|
((const :format "%v " :immediate-finish) (const t))
|
||||||
|
((const :format "%v " :jump-to-captured) (const t))
|
||||||
|
((const :format "%v " :empty-lines) (const 1))
|
||||||
|
((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))))))))
|
||||||
|
|
||||||
(defvar org-roam-capture-preface-hook nil
|
|
||||||
"Hook run when Org-roam tries to determine capture location of the node.
|
|
||||||
If any hook returns a value (which should be an ID), all hooks
|
|
||||||
after it are ignored.
|
|
||||||
|
|
||||||
With this hook you can hijack controls over the location of the
|
|
||||||
node for which the capture process is currently running for, or
|
|
||||||
use to just perform an arbitrary side effect, e.g. modify the
|
|
||||||
state related to the capture process. See `org-roam-protocol' and
|
|
||||||
`org-roam-dailies' as examples for what and how this hook is used
|
|
||||||
for.
|
|
||||||
|
|
||||||
If you're trying to perform the hijack, it's mandatory for you to:
|
|
||||||
1. Set the currently active buffer for editing operations using
|
|
||||||
`org-capture-target-buffer'.
|
|
||||||
2. Place the point in this buffer from where the location starts
|
|
||||||
from (e.g. if it's a file based node it should be the BOB,
|
|
||||||
otherwise it should be the position from where the heading
|
|
||||||
based node starts from).
|
|
||||||
3. Return the ID (as a string) of the capturing node.
|
|
||||||
|
|
||||||
If you use this hook for any other purpose, but not the hijack,
|
|
||||||
it's mandatory that you should return nil as the return value; so
|
|
||||||
the capture process would be able to setup the capture buffer.
|
|
||||||
|
|
||||||
If you need to do something when you capture new nodes, use
|
|
||||||
`org-roam-capture-new-node-hook' instead of this hook.
|
|
||||||
|
|
||||||
WARNING: This hook is primarily designed for the usage by the
|
|
||||||
extensions and packages, and requires understanding of the
|
|
||||||
internal capture process. If you don't understand it, you should
|
|
||||||
learn these internals before using this or use it at your own
|
|
||||||
risk breaking things.")
|
|
||||||
|
|
||||||
;;; Variables
|
|
||||||
|
|
||||||
(defvar org-roam-capture--node nil
|
|
||||||
"The node passed during an Org-roam capture.
|
|
||||||
This variable is populated dynamically, and is only non-nil
|
|
||||||
during the Org-roam capture process.")
|
|
||||||
|
|
||||||
(defvar org-roam-capture--info nil
|
|
||||||
"A property-list of additional information passed to the Org-roam template.
|
|
||||||
This variable is populated dynamically, and is only non-nil
|
|
||||||
during the Org-roam capture process.")
|
|
||||||
|
|
||||||
(defconst org-roam-capture--template-keywords (list :target :id :link-description :call-location
|
|
||||||
:region)
|
|
||||||
"Keywords used in `org-roam-capture-templates' specific to Org-roam.")
|
|
||||||
|
|
||||||
;;; Main entry point
|
|
||||||
;;;###autoload
|
|
||||||
(cl-defun org-roam-capture- (&key goto keys node info props templates)
|
|
||||||
"Main entry point of `org-roam-capture' module.
|
|
||||||
GOTO and KEYS correspond to `org-capture' arguments.
|
|
||||||
INFO is a plist for filling up Org-roam's capture templates.
|
|
||||||
NODE is an `org-roam-node' construct containing information about the node.
|
|
||||||
PROPS is a plist containing additional Org-roam properties for each template.
|
|
||||||
TEMPLATES is a list of org-roam templates."
|
|
||||||
(let* ((props (plist-put props :call-location (point-marker)))
|
|
||||||
(org-capture-templates
|
|
||||||
(mapcar (lambda (template)
|
|
||||||
(org-roam-capture--convert-template template props))
|
|
||||||
(or templates org-roam-capture-templates)))
|
|
||||||
(_ (setf (org-roam-node-id node) (or (org-roam-node-id node)
|
|
||||||
(org-id-new))))
|
|
||||||
(org-roam-capture--node node)
|
|
||||||
(org-roam-capture--info info))
|
|
||||||
(when (and (not keys)
|
|
||||||
(= (length org-capture-templates) 1))
|
|
||||||
(setq keys (caar org-capture-templates)))
|
|
||||||
(org-capture goto keys)))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(cl-defun org-roam-capture (&optional goto keys &key filter-fn templates info)
|
|
||||||
"Launches an `org-capture' process for a new or existing node.
|
|
||||||
This uses the templates defined at `org-roam-capture-templates'.
|
|
||||||
Arguments GOTO and KEYS see `org-capture'.
|
|
||||||
FILTER-FN is a function to filter out nodes: it takes an `org-roam-node',
|
|
||||||
and when nil is returned the node will be filtered out.
|
|
||||||
The TEMPLATES, if provided, override the list of capture templates (see
|
|
||||||
`org-roam-capture-'.)
|
|
||||||
The INFO, if provided, is passed along to the underlying `org-roam-capture-'."
|
|
||||||
(interactive "P")
|
|
||||||
(let ((node (org-roam-node-read nil filter-fn)))
|
|
||||||
(org-roam-capture- :goto goto
|
|
||||||
:info info
|
|
||||||
:keys keys
|
|
||||||
:templates templates
|
|
||||||
:node node
|
|
||||||
:props '(:immediate-finish nil))))
|
|
||||||
|
|
||||||
;;; Capture process
|
|
||||||
(defun org-roam-capture-p ()
|
(defun org-roam-capture-p ()
|
||||||
"Return t if the current capture process is an Org-roam capture.
|
"Return t if the current capture process is an Org-roam capture.
|
||||||
This function is to only be called when `org-capture-plist' is
|
This function is to only be called when `org-capture-plist' is
|
||||||
@ -447,160 +415,153 @@ the capture)."
|
|||||||
"Get the value for KEYWORD from the `org-roam-capture-template'."
|
"Get the value for KEYWORD from the `org-roam-capture-template'."
|
||||||
(plist-get (plist-get org-capture-plist :org-roam) keyword))
|
(plist-get (plist-get org-capture-plist :org-roam) keyword))
|
||||||
|
|
||||||
(defun org-roam-capture--put (prop value)
|
(defun org-roam-capture--put (&rest stuff)
|
||||||
"Set property PROP to VALUE in the `org-roam-capture-template'."
|
"Put properties from STUFF into the `org-roam-capture-template'."
|
||||||
(let ((p (plist-get org-capture-plist :org-roam)))
|
(let ((p (plist-get org-capture-plist :org-roam)))
|
||||||
|
(while stuff
|
||||||
|
(setq p (plist-put p (pop stuff) (pop stuff))))
|
||||||
(setq org-capture-plist
|
(setq org-capture-plist
|
||||||
(plist-put org-capture-plist
|
(plist-put org-capture-plist :org-roam p))))
|
||||||
:org-roam
|
|
||||||
(plist-put p prop value)))))
|
|
||||||
|
|
||||||
;;;; Capture target
|
;; FIXME: Pending upstream patch
|
||||||
(defun org-roam-capture--prepare-buffer ()
|
;; https://orgmode.org/list/87h7tv9pkm.fsf@hidden/T/#u
|
||||||
"Prepare the capture buffer for the current Org-roam based capture template.
|
;;
|
||||||
This function will initialize and setup the capture buffer,
|
;; Org-capture's behaviour right now is that `org-capture-plist' is valid only
|
||||||
position the point to the current :target (and if necessary,
|
;; during the initialization of the Org-capture buffer. The value of
|
||||||
create it if it doesn't exist), and place the point for further
|
;; `org-capture-plist' is saved into buffer-local `org-capture-current-plist'.
|
||||||
processing by `org-capture'.
|
;; However, the value for that particular capture is no longer accessible for
|
||||||
|
;; hooks in `org-capture-after-finalize-hook', since the capture buffer has been
|
||||||
|
;; cleaned up.
|
||||||
|
;;
|
||||||
|
;; This advice restores the global `org-capture-plist' during finalization, so
|
||||||
|
;; the plist is valid during both initialization and finalization of the
|
||||||
|
;; capture.
|
||||||
|
(defun org-roam-capture--update-plist (&optional _)
|
||||||
|
"Update global plist from local var."
|
||||||
|
(setq org-capture-plist org-capture-current-plist))
|
||||||
|
|
||||||
Note: During the capture process this function is run by
|
(advice-add 'org-capture-finalize :before #'org-roam-capture--update-plist)
|
||||||
`org-capture-set-target-location', as a (function ...) based
|
|
||||||
capture target."
|
|
||||||
(let ((id (cond ((run-hook-with-args-until-success 'org-roam-capture-preface-hook))
|
|
||||||
(t (org-roam-capture--setup-target-location)))))
|
|
||||||
(org-roam-capture--adjust-point-for-capture-type)
|
|
||||||
(let ((template (org-capture-get :template)))
|
|
||||||
(when (stringp template)
|
|
||||||
(org-capture-put
|
|
||||||
:template
|
|
||||||
(org-roam-capture--fill-template template))))
|
|
||||||
(org-roam-capture--put :id id)
|
|
||||||
(org-roam-capture--put :finalize (or (org-capture-get :finalize)
|
|
||||||
(org-roam-capture--get :finalize)))))
|
|
||||||
|
|
||||||
(defun org-roam-capture--setup-target-location ()
|
(defun org-roam-capture--finalize-find-file ()
|
||||||
|
"Visit the buffer after Org-capture is done.
|
||||||
|
This function is to be called in the Org-capture finalization process.
|
||||||
|
ID is unused."
|
||||||
|
(switch-to-buffer (org-capture-get :buffer)))
|
||||||
|
|
||||||
|
(defun org-roam-capture--finalize-insert-link ()
|
||||||
|
"Insert a link to ID into the buffer where Org-capture was called.
|
||||||
|
ID is the Org id of the newly captured content.
|
||||||
|
This function is to be called in the Org-capture finalization process."
|
||||||
|
(when-let* ((mkr (org-roam-capture--get :call-location))
|
||||||
|
(buf (marker-buffer mkr)))
|
||||||
|
(with-current-buffer buf
|
||||||
|
(when-let ((region (org-roam-capture--get :region)))
|
||||||
|
(org-roam-unshield-region (car region) (cdr region))
|
||||||
|
(delete-region (car region) (cdr region))
|
||||||
|
(set-marker (car region) nil)
|
||||||
|
(set-marker (cdr region) nil))
|
||||||
|
(org-with-point-at mkr
|
||||||
|
(insert (org-link-make-string (concat "id:" (org-roam-capture--get :id))
|
||||||
|
(org-roam-capture--get :link-description)))))))
|
||||||
|
|
||||||
|
(defun org-roam-capture--finalize ()
|
||||||
|
"Finalize the `org-roam-capture' process."
|
||||||
|
(when-let ((region (org-roam-capture--get :region)))
|
||||||
|
(org-roam-unshield-region (car region) (cdr region)))
|
||||||
|
(unless org-note-abort
|
||||||
|
(when-let ((finalize (org-roam-capture--get :finalize)))
|
||||||
|
(funcall (intern (concat "org-roam-capture--finalize-"
|
||||||
|
(symbol-name (org-roam-capture--get :finalize)))))))
|
||||||
|
(remove-hook 'org-capture-after-finalize-hook #'org-roam-capture--finalize))
|
||||||
|
|
||||||
|
(defun org-roam-capture--install-finalize ()
|
||||||
|
"Install `org-roam-capture--finalize' if the capture is an Org-roam capture."
|
||||||
|
(when (org-roam-capture-p)
|
||||||
|
(add-hook 'org-capture-after-finalize-hook #'org-roam-capture--finalize)))
|
||||||
|
|
||||||
|
(add-hook 'org-capture-prepare-finalize-hook #'org-roam-capture--install-finalize)
|
||||||
|
|
||||||
|
(defun org-roam-capture--fill-template (template &optional org-capture-p)
|
||||||
|
"Expand TEMPLATE and return it.
|
||||||
|
It expands ${var} occurrences in TEMPLATE. When ORG-CAPTURE-P,
|
||||||
|
also run Org-capture's template expansion."
|
||||||
|
(funcall (if org-capture-p #'org-capture-fill-template #'identity)
|
||||||
|
(org-roam-format
|
||||||
|
template
|
||||||
|
(lambda (key)
|
||||||
|
(let ((fn (intern (concat "org-roam-node-" key)))
|
||||||
|
(ksym (intern (concat ":" key))))
|
||||||
|
(cond
|
||||||
|
((fboundp fn)
|
||||||
|
(funcall fn org-roam-capture--node))
|
||||||
|
((plist-get org-roam-capture--info ksym)
|
||||||
|
(plist-get org-roam-capture--info ksym))
|
||||||
|
(t (let ((r (completing-read (format "%s: " key) nil)))
|
||||||
|
(plist-put org-roam-capture--info ksym r)
|
||||||
|
r))))))))
|
||||||
|
|
||||||
|
(defun org-roam-capture--insert-ref ()
|
||||||
|
"Insert the ref if any."
|
||||||
|
(when-let ((ref (plist-get org-roam-capture--info :ref)))
|
||||||
|
(org-roam-ref-add ref)))
|
||||||
|
|
||||||
|
(defun org-roam-capture--goto-location ()
|
||||||
"Initialize the buffer, and goto the location of the new capture.
|
"Initialize the buffer, and goto the location of the new capture.
|
||||||
Return the ID of the location."
|
Return the ID of the location."
|
||||||
(let (p new-file-p)
|
(let (p)
|
||||||
(pcase (org-roam-capture--get-target)
|
(pcase (or (org-roam-capture--get :if-new)
|
||||||
|
(user-error "Template needs to specify `:if-new'"))
|
||||||
(`(file ,path)
|
(`(file ,path)
|
||||||
(setq path (org-roam-capture--target-truepath path)
|
(setq path (expand-file-name
|
||||||
new-file-p (org-roam-capture--new-file-p path))
|
(string-trim (org-roam-capture--fill-template path t))
|
||||||
(when new-file-p (org-roam-capture--put :new-file path))
|
org-roam-directory))
|
||||||
(set-buffer (org-capture-target-buffer path))
|
(set-buffer (org-capture-target-buffer path))
|
||||||
(widen)
|
(widen)
|
||||||
(setq p (goto-char (point-min))))
|
(setq p (point)))
|
||||||
(`(file+olp ,path ,olp)
|
(`(file+olp ,path ,olp)
|
||||||
(setq path (org-roam-capture--target-truepath path)
|
(setq path (expand-file-name
|
||||||
new-file-p (org-roam-capture--new-file-p path))
|
(string-trim (org-roam-capture--fill-template path t))
|
||||||
(when new-file-p (org-roam-capture--put :new-file path))
|
org-roam-directory))
|
||||||
(set-buffer (org-capture-target-buffer path))
|
(set-buffer (org-capture-target-buffer path))
|
||||||
(setq p (point-min))
|
(setq p (point-min))
|
||||||
(let ((m (org-roam-capture-find-or-create-olp olp)))
|
(let ((m (org-roam-capture-find-or-create-olp olp)))
|
||||||
(goto-char m))
|
(goto-char m))
|
||||||
(widen))
|
(widen))
|
||||||
(`(file+head ,path ,head)
|
(`(file+head ,path ,head)
|
||||||
(setq path (org-roam-capture--target-truepath path)
|
(setq path (expand-file-name
|
||||||
new-file-p (org-roam-capture--new-file-p path))
|
(string-trim (org-roam-capture--fill-template path t))
|
||||||
(set-buffer (org-capture-target-buffer path))
|
org-roam-directory))
|
||||||
(when new-file-p
|
(let ((exists-p (file-exists-p path)))
|
||||||
(org-roam-capture--put :new-file path)
|
(set-buffer (org-capture-target-buffer path))
|
||||||
(insert (org-roam-capture--fill-template head 'ensure-newline)))
|
(unless exists-p
|
||||||
|
(insert (org-roam-capture--fill-template head t))))
|
||||||
(widen)
|
(widen)
|
||||||
(setq p (goto-char (point-min))))
|
(setq p (point-min)))
|
||||||
(`(file+head+olp ,path ,head ,olp)
|
(`(file+head+olp ,path ,head ,olp)
|
||||||
(setq path (org-roam-capture--target-truepath path)
|
(setq path (expand-file-name
|
||||||
new-file-p (org-roam-capture--new-file-p path))
|
(string-trim (org-roam-capture--fill-template path t))
|
||||||
(set-buffer (org-capture-target-buffer path))
|
org-roam-directory))
|
||||||
(widen)
|
(widen)
|
||||||
(when new-file-p
|
(let ((exists-p (file-exists-p path)))
|
||||||
(org-roam-capture--put :new-file path)
|
(set-buffer (org-capture-target-buffer path))
|
||||||
(insert (org-roam-capture--fill-template head 'ensure-newline)))
|
(unless exists-p
|
||||||
|
(insert (org-roam-capture--fill-template head t))))
|
||||||
(setq p (point-min))
|
(setq p (point-min))
|
||||||
(let ((m (org-roam-capture-find-or-create-olp olp)))
|
(let ((m (org-roam-capture-find-or-create-olp olp)))
|
||||||
(goto-char m)))
|
(goto-char m)))
|
||||||
(`(file+datetree ,path ,tree-type)
|
|
||||||
(setq path (org-roam-capture--target-truepath path))
|
|
||||||
(require 'org-datetree)
|
|
||||||
(widen)
|
|
||||||
(set-buffer (org-capture-target-buffer path))
|
|
||||||
(unless (file-exists-p path)
|
|
||||||
(org-roam-capture--put :new-file path))
|
|
||||||
(funcall
|
|
||||||
(pcase tree-type
|
|
||||||
(`week #'org-datetree-find-iso-week-create)
|
|
||||||
(`month #'org-datetree-find-month-create)
|
|
||||||
(_ #'org-datetree-find-date-create))
|
|
||||||
(calendar-gregorian-from-absolute
|
|
||||||
(cond
|
|
||||||
(org-overriding-default-time
|
|
||||||
;; Use the overriding default time.
|
|
||||||
(time-to-days org-overriding-default-time))
|
|
||||||
((org-capture-get :default-time)
|
|
||||||
(time-to-days (org-capture-get :default-time)))
|
|
||||||
((org-capture-get :time-prompt)
|
|
||||||
;; Prompt for date. Bind `org-end-time-was-given' so
|
|
||||||
;; that `org-read-date-analyze' handles the time range
|
|
||||||
;; case and returns `prompt-time' with the start value.
|
|
||||||
(let* ((org-time-was-given nil)
|
|
||||||
(org-end-time-was-given nil)
|
|
||||||
(prompt-time (org-read-date
|
|
||||||
nil t nil "Date for tree entry:")))
|
|
||||||
(org-capture-put
|
|
||||||
:default-time
|
|
||||||
(if (or org-time-was-given
|
|
||||||
(= (time-to-days prompt-time) (org-today)))
|
|
||||||
prompt-time
|
|
||||||
;; Use 00:00 when no time is given for another
|
|
||||||
;; date than today?
|
|
||||||
(apply #'encode-time 0 0
|
|
||||||
org-extend-today-until
|
|
||||||
(cl-cdddr (decode-time prompt-time)))))
|
|
||||||
(time-to-days prompt-time)))
|
|
||||||
(t
|
|
||||||
;; Current date, possibly corrected for late night
|
|
||||||
;; workers.
|
|
||||||
(org-today)))))
|
|
||||||
(setq p (point)))
|
|
||||||
(`(node ,title-or-id)
|
(`(node ,title-or-id)
|
||||||
;; first try to get ID, then try to get title/alias
|
;; first try to get ID, then try to get title/alias
|
||||||
(let ((node (or (org-roam-node-from-id title-or-id)
|
(let ((node (or (org-roam-node-from-id title-or-id)
|
||||||
(org-roam-node-from-title-or-alias title-or-id)
|
(org-roam-node-from-title-or-alias title-or-id)
|
||||||
(user-error "No node with title or id \"%s\"" title-or-id))))
|
(user-error "No node with title or id \"%s\" title-or-id"))))
|
||||||
(set-buffer (org-capture-target-buffer (org-roam-node-file node)))
|
(set-buffer (org-capture-target-buffer (org-roam-node-file node)))
|
||||||
(goto-char (org-roam-node-point node))
|
(goto-char (org-roam-node-point node))
|
||||||
(setq p (org-roam-node-point node)))))
|
(setq p (org-roam-node-point node))
|
||||||
;; Setup `org-id' for the current capture target and return it back to the
|
(org-end-of-subtree t t))))
|
||||||
;; caller.
|
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(goto-char p)
|
(goto-char p)
|
||||||
(if-let ((id (org-entry-get p "ID")))
|
(run-hooks 'org-roam-capture-new-node-hook)
|
||||||
(setf (org-roam-node-id org-roam-capture--node) id)
|
(org-id-get-create))))
|
||||||
(org-entry-put p "ID" (org-roam-node-id org-roam-capture--node)))
|
|
||||||
(prog1
|
|
||||||
(org-id-get)
|
|
||||||
(run-hooks 'org-roam-capture-new-node-hook)))))
|
|
||||||
|
|
||||||
(defun org-roam-capture--get-target ()
|
|
||||||
"Get the current capture :target for the capture template in use."
|
|
||||||
(or (org-roam-capture--get :target)
|
|
||||||
(user-error "Template needs to specify `:target'")))
|
|
||||||
|
|
||||||
(defun org-roam-capture--target-truepath (path)
|
|
||||||
"From PATH get the correct path to the current capture target and return it.
|
|
||||||
PATH is a string that can optionally contain templated text in
|
|
||||||
it."
|
|
||||||
(or (org-roam-node-file org-roam-capture--node)
|
|
||||||
(thread-first
|
|
||||||
path
|
|
||||||
(org-roam-capture--fill-template)
|
|
||||||
(string-trim)
|
|
||||||
(expand-file-name org-roam-directory))))
|
|
||||||
|
|
||||||
(defun org-roam-capture--new-file-p (path)
|
|
||||||
"Return t if PATH is for a new file with no visiting buffer."
|
|
||||||
(not (or (file-exists-p path)
|
|
||||||
(org-find-base-buffer-visiting path))))
|
|
||||||
|
|
||||||
(defun org-roam-capture-find-or-create-olp (olp)
|
(defun org-roam-capture-find-or-create-olp (olp)
|
||||||
"Return a marker pointing to the entry at OLP in the current buffer.
|
"Return a marker pointing to the entry at OLP in the current buffer.
|
||||||
@ -618,7 +579,6 @@ you can catch it with `condition-case'."
|
|||||||
(org-with-wide-buffer
|
(org-with-wide-buffer
|
||||||
(goto-char start)
|
(goto-char start)
|
||||||
(dolist (heading olp)
|
(dolist (heading olp)
|
||||||
(setq heading (org-roam-capture--fill-template heading))
|
|
||||||
(let ((re (format org-complex-heading-regexp-format
|
(let ((re (format org-complex-heading-regexp-format
|
||||||
(regexp-quote heading)))
|
(regexp-quote heading)))
|
||||||
(cnt 0))
|
(cnt 0))
|
||||||
@ -632,10 +592,8 @@ you can catch it with `condition-case'."
|
|||||||
;; Create heading if it doesn't exist
|
;; Create heading if it doesn't exist
|
||||||
(goto-char end)
|
(goto-char end)
|
||||||
(unless (bolp) (newline))
|
(unless (bolp) (newline))
|
||||||
(let (org-insert-heading-respect-content)
|
(org-insert-heading nil nil t)
|
||||||
(org-insert-heading nil nil t))
|
(unless (= lmax 1) (org-do-demote))
|
||||||
(unless (= lmax 1)
|
|
||||||
(dotimes (_ level) (org-do-demote)))
|
|
||||||
(insert heading)
|
(insert heading)
|
||||||
(setq end (point))
|
(setq end (point))
|
||||||
(goto-char start)
|
(goto-char start)
|
||||||
@ -647,161 +605,61 @@ you can catch it with `condition-case'."
|
|||||||
(setq lmin (1+ flevel) lmax (+ lmin (if org-odd-levels-only 1 0)))
|
(setq lmin (1+ flevel) lmax (+ lmin (if org-odd-levels-only 1 0)))
|
||||||
(setq start found
|
(setq start found
|
||||||
end (save-excursion (org-end-of-subtree t t))))
|
end (save-excursion (org-end-of-subtree t t))))
|
||||||
(point-marker))))
|
(copy-marker end))))
|
||||||
|
|
||||||
(defun org-roam-capture--adjust-point-for-capture-type (&optional pos)
|
(defun org-roam-capture--get-node-from-ref (ref)
|
||||||
"Reposition the point for template insertion dependently on the capture type.
|
"Return the node from reference REF."
|
||||||
Return the newly adjusted position of `point'.
|
(save-match-data
|
||||||
|
(when (string-match org-link-plain-re ref)
|
||||||
|
(let ((type (match-string 1 ref))
|
||||||
|
(path (match-string 2 ref)))
|
||||||
|
(when-let ((id (caar (org-roam-db-query
|
||||||
|
[:select [nodes:id]
|
||||||
|
:from refs
|
||||||
|
:left-join nodes
|
||||||
|
:on (= refs:node-id nodes:id)
|
||||||
|
:where (= refs:type $s1)
|
||||||
|
:and (= refs:ref $s2)
|
||||||
|
:limit 1]
|
||||||
|
type path))))
|
||||||
|
(org-roam-populate (org-roam-node-create :id id)))))))
|
||||||
|
|
||||||
POS is the current position of point (an integer) inside the
|
(defun org-roam-capture--get-point ()
|
||||||
currently active capture buffer, where the adjustment should
|
"Return exact point to file for org-capture-template.
|
||||||
start to begin from. If it's nil, then it will default to
|
This function is used solely in Org-roam's capture templates: see
|
||||||
the current value of `point'."
|
`org-roam-capture-templates'."
|
||||||
(or pos (setq pos (point)))
|
(let ((id (cond ((plist-get org-roam-capture--info :ref)
|
||||||
(goto-char pos)
|
(if-let ((node (org-roam-capture--get-node-from-ref
|
||||||
(let ((location-type (if (= pos 1) 'beginning-of-file 'heading-at-point)))
|
(plist-get org-roam-capture--info :ref))))
|
||||||
(and (eq location-type 'heading-at-point)
|
(progn
|
||||||
(cl-assert (org-at-heading-p)))
|
(set-buffer (org-capture-target-buffer (org-roam-node-file node)))
|
||||||
(pcase (org-capture-get :type)
|
(goto-char (org-roam-node-point node))
|
||||||
(`plain
|
(widen)
|
||||||
(cl-case location-type
|
(org-end-of-subtree t t))
|
||||||
(beginning-of-file
|
(org-roam-capture--goto-location)))
|
||||||
(if (org-capture-get :prepend)
|
((and (org-roam-node-file org-roam-capture--node)
|
||||||
(let ((el (org-element-at-point)))
|
(org-roam-node-point org-roam-capture--node))
|
||||||
(while (and (not (eobp))
|
(set-buffer (org-capture-target-buffer (org-roam-node-file org-roam-capture--node)))
|
||||||
(memq (org-element-type el)
|
(goto-char (org-roam-node-point org-roam-capture--node))
|
||||||
'(drawer property-drawer keyword comment comment-block horizontal-rule)))
|
(widen)
|
||||||
(goto-char (org-element-property :end el))
|
(org-end-of-subtree t t)
|
||||||
(setq el (org-element-at-point))))
|
(org-roam-node-id org-roam-capture--node))
|
||||||
(goto-char (org-entry-end-position))))
|
(t
|
||||||
(heading-at-point
|
(org-roam-capture--goto-location)))))
|
||||||
(if (org-capture-get :prepend)
|
(org-capture-put :template
|
||||||
(org-end-of-meta-data t)
|
(org-roam-capture--fill-template (org-capture-get :template)))
|
||||||
(goto-char (org-entry-end-position))))))))
|
(org-roam-capture--put :id id)
|
||||||
(point))
|
(org-roam-capture--put :finalize (or (org-capture-get :finalize)
|
||||||
|
(org-roam-capture--get :finalize)))))
|
||||||
;;; Capture implementation
|
|
||||||
(add-hook 'org-roam-capture-preface-hook #'org-roam-capture--try-capture-to-ref-h)
|
|
||||||
(defun org-roam-capture--try-capture-to-ref-h ()
|
|
||||||
"Try to capture to an existing node that match the ref."
|
|
||||||
(when-let ((node (and (plist-get org-roam-capture--info :ref)
|
|
||||||
(org-roam-node-from-ref
|
|
||||||
(plist-get org-roam-capture--info :ref)))))
|
|
||||||
(set-buffer (org-capture-target-buffer (org-roam-node-file node)))
|
|
||||||
(goto-char (org-roam-node-point node))
|
|
||||||
(widen)
|
|
||||||
(org-roam-node-id node)))
|
|
||||||
|
|
||||||
(add-hook 'org-roam-capture-new-node-hook #'org-roam-capture--insert-captured-ref-h)
|
|
||||||
(defun org-roam-capture--insert-captured-ref-h ()
|
|
||||||
"Insert the ref if any."
|
|
||||||
(when-let ((ref (plist-get org-roam-capture--info :ref)))
|
|
||||||
(org-roam-ref-add ref)))
|
|
||||||
|
|
||||||
;;;; Finalizers
|
|
||||||
(add-hook 'org-capture-prepare-finalize-hook #'org-roam-capture--install-finalize-h)
|
|
||||||
(defun org-roam-capture--install-finalize-h ()
|
|
||||||
"Install `org-roam-capture--finalize' if the capture is an Org-roam capture."
|
|
||||||
(when (org-roam-capture-p)
|
|
||||||
(add-hook 'org-capture-after-finalize-hook #'org-roam-capture--finalize)))
|
|
||||||
|
|
||||||
(defun org-roam-capture--finalize ()
|
|
||||||
"Finalize the `org-roam-capture' process."
|
|
||||||
(if org-note-abort
|
|
||||||
(when-let ((new-file (org-roam-capture--get :new-file))
|
|
||||||
(_ (yes-or-no-p "Delete file for aborted capture?")))
|
|
||||||
(when (find-buffer-visiting new-file)
|
|
||||||
(kill-buffer (find-buffer-visiting new-file)))
|
|
||||||
(delete-file new-file))
|
|
||||||
(when-let* ((buffer (plist-get org-capture-plist :buffer))
|
|
||||||
(file (buffer-file-name buffer)))
|
|
||||||
(org-id-add-location (org-roam-capture--get :id) file))
|
|
||||||
(when-let* ((finalize (org-roam-capture--get :finalize))
|
|
||||||
(org-roam-finalize-fn (intern (concat "org-roam-capture--finalize-"
|
|
||||||
(symbol-name finalize)))))
|
|
||||||
(if (functionp org-roam-finalize-fn)
|
|
||||||
(funcall org-roam-finalize-fn)
|
|
||||||
(funcall finalize))))
|
|
||||||
(remove-hook 'org-capture-after-finalize-hook #'org-roam-capture--finalize))
|
|
||||||
|
|
||||||
(defun org-roam-capture--finalize-find-file ()
|
|
||||||
"Visit the buffer after Org-capture is done.
|
|
||||||
This function is to be called in the Org-capture finalization process.
|
|
||||||
ID is unused."
|
|
||||||
(switch-to-buffer (org-capture-get :buffer)))
|
|
||||||
|
|
||||||
(defun org-roam-capture--finalize-insert-link ()
|
|
||||||
"Insert a link to ID into the buffer where Org-capture was called.
|
|
||||||
ID is the Org id of the newly captured content.
|
|
||||||
This function is to be called in the Org-capture finalization process."
|
|
||||||
(when-let* ((mkr (org-roam-capture--get :call-location))
|
|
||||||
(buf (marker-buffer mkr)))
|
|
||||||
(with-current-buffer buf
|
|
||||||
(when-let ((region (org-roam-capture--get :region)))
|
|
||||||
(delete-region (car region) (cdr region))
|
|
||||||
(set-marker (car region) nil)
|
|
||||||
(set-marker (cdr region) nil))
|
|
||||||
(let* ((id (org-roam-capture--get :id))
|
|
||||||
(description (org-roam-capture--get :link-description))
|
|
||||||
(link (org-link-make-string (concat "id:" id)
|
|
||||||
description)))
|
|
||||||
(if (eq (point) (marker-position mkr))
|
|
||||||
(insert link)
|
|
||||||
(org-with-point-at mkr
|
|
||||||
(insert link)))
|
|
||||||
(run-hook-with-args 'org-roam-post-node-insert-hook
|
|
||||||
id
|
|
||||||
description)))))
|
|
||||||
|
|
||||||
;;;; Processing of the capture templates
|
|
||||||
(defun org-roam-capture--fill-template (template &optional ensure-newline)
|
|
||||||
"Expand TEMPLATE and return it.
|
|
||||||
It expands ${var} occurrences in TEMPLATE, and then runs
|
|
||||||
org-capture's template expansion.
|
|
||||||
When ENSURE-NEWLINE, always ensure there's a newline behind."
|
|
||||||
(let* ((template (if (functionp template)
|
|
||||||
(funcall template)
|
|
||||||
template))
|
|
||||||
(template-whitespace-content (org-roam-whitespace-content template)))
|
|
||||||
(setq template
|
|
||||||
(org-roam-format-template
|
|
||||||
template
|
|
||||||
(lambda (key default-val)
|
|
||||||
(let ((fn (intern key))
|
|
||||||
(node-fn (intern (concat "org-roam-node-" key)))
|
|
||||||
(ksym (intern (concat ":" key))))
|
|
||||||
(cond
|
|
||||||
((fboundp fn)
|
|
||||||
(funcall fn org-roam-capture--node))
|
|
||||||
((fboundp node-fn)
|
|
||||||
(funcall node-fn org-roam-capture--node))
|
|
||||||
((plist-get org-roam-capture--info ksym)
|
|
||||||
(plist-get org-roam-capture--info ksym))
|
|
||||||
(t (let ((r (read-from-minibuffer (format "%s: " key) default-val)))
|
|
||||||
(plist-put org-roam-capture--info ksym r)
|
|
||||||
r)))))))
|
|
||||||
;; WARNING:
|
|
||||||
;; `org-capture-fill-template' fills the template, but post-processes whitespace such that the resultant
|
|
||||||
;; template does not start with any whitespace, and only ends with a single newline
|
|
||||||
;;
|
|
||||||
;; Instead, we restore the whitespace in the original template.
|
|
||||||
(setq template (replace-regexp-in-string "[\n]*\\'" "" (org-capture-fill-template template)))
|
|
||||||
(when (and ensure-newline
|
|
||||||
(string-equal template-whitespace-content ""))
|
|
||||||
(setq template-whitespace-content "\n"))
|
|
||||||
(setq template (concat template template-whitespace-content))
|
|
||||||
template))
|
|
||||||
|
|
||||||
(defun org-roam-capture--convert-template (template &optional props)
|
(defun org-roam-capture--convert-template (template &optional props)
|
||||||
"Convert TEMPLATE from Org-roam syntax to `org-capture-templates' syntax.
|
"Convert TEMPLATE from Org-roam syntax to `org-capture-templates' syntax.
|
||||||
PROPS is a plist containing additional Org-roam specific
|
PROPS is a plist containing additional Org-roam specific
|
||||||
properties to be added to the template."
|
properties to be added to the template."
|
||||||
(pcase template
|
(pcase template
|
||||||
(`(,_key ,_desc)
|
(`(,key ,desc)
|
||||||
template)
|
template)
|
||||||
((or `(,key ,desc ,type ignore ,body . ,rest)
|
(`(,key ,desc ,type ,body . ,rest)
|
||||||
`(,key ,desc ,type (function ignore) ,body . ,rest)
|
|
||||||
`(,key ,desc ,type ,body . ,rest))
|
|
||||||
(setq rest (append rest props))
|
(setq rest (append rest props))
|
||||||
(let (org-roam-plist options)
|
(let (org-roam-plist options)
|
||||||
(while rest
|
(while rest
|
||||||
@ -814,12 +672,43 @@ properties to be added to the template."
|
|||||||
(if custom
|
(if custom
|
||||||
(setq org-roam-plist (plist-put org-roam-plist key val))
|
(setq org-roam-plist (plist-put org-roam-plist key val))
|
||||||
(setq options (plist-put options key val)))))
|
(setq options (plist-put options key val)))))
|
||||||
(append `(,key ,desc ,type #'org-roam-capture--prepare-buffer ,body)
|
(append `(,key ,desc ,type #'org-roam-capture--get-point ,body)
|
||||||
options
|
options
|
||||||
(list :org-roam org-roam-plist))))
|
(list :org-roam org-roam-plist))))
|
||||||
(_
|
(_
|
||||||
(signal 'invalid-template template))))
|
(signal 'invalid-template template))))
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(cl-defun org-roam-capture- (&key goto keys node info props templates)
|
||||||
|
"Main entry point.
|
||||||
|
GOTO and KEYS correspond to `org-capture' arguments.
|
||||||
|
INFO is an alist for filling up Org-roam's capture templates.
|
||||||
|
NODE is an `org-roam-node' construct containing information about the node.
|
||||||
|
PROPS is a plist containing additional Org-roam properties for each template.
|
||||||
|
TEMPLATES is a list of org-roam templates."
|
||||||
|
(let* ((props (plist-put props :call-location (point-marker)))
|
||||||
|
(org-capture-templates
|
||||||
|
(mapcar (lambda (template)
|
||||||
|
(org-roam-capture--convert-template template props))
|
||||||
|
(or templates org-roam-capture-templates)))
|
||||||
|
(org-roam-capture--node node)
|
||||||
|
(org-roam-capture--info info))
|
||||||
|
(when (and (not keys)
|
||||||
|
(= (length org-capture-templates) 1))
|
||||||
|
(setq keys (caar org-capture-templates)))
|
||||||
|
(org-capture goto keys)))
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(defun org-roam-capture (&optional goto keys)
|
||||||
|
"Launches an `org-capture' process for a new or existing note.
|
||||||
|
This uses the templates defined at `org-roam-capture-templates'.
|
||||||
|
Arguments GOTO and KEYS see `org-capture'."
|
||||||
|
(interactive "P")
|
||||||
|
(let ((node (org-roam-node-read)))
|
||||||
|
(org-roam-capture- :goto goto
|
||||||
|
:keys keys
|
||||||
|
:node node
|
||||||
|
:props '(:immediate-finish nil))))
|
||||||
|
|
||||||
(provide 'org-roam-capture)
|
(provide 'org-roam-capture)
|
||||||
|
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
;;; org-roam-compat.el --- Backward compatibility code -*- coding: utf-8; lexical-binding: t; -*-
|
;;; org-roam-compat.el --- Compatibility Code -*- coding: utf-8; lexical-binding: t; -*-
|
||||||
|
|
||||||
;; Copyright © 2020-2025 Jethro Kuan <jethrokuan95@gmail.com>
|
;; Copyright © 2020 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: 2.3.1
|
;; Version: 2.0.0
|
||||||
;; Package-Requires: ((emacs "26.1"))
|
;; Package-Requires: ((emacs "26.1") (dash "2.13") (f "0.17.2") (org "9.4") (emacsql "3.0.0") (emacsql-sqlite3 "1.0.2") (magit-section "2.90.1"))
|
||||||
|
|
||||||
;; This file is NOT part of GNU Emacs.
|
;; This file is NOT part of GNU Emacs.
|
||||||
|
|
||||||
@ -27,214 +27,14 @@
|
|||||||
|
|
||||||
;;; Commentary:
|
;;; Commentary:
|
||||||
;;
|
;;
|
||||||
;; This file is dedicated to maintain backward compatibility with older older
|
;; This file contains code needed for backward compatibility with older Emacsen
|
||||||
;; Emacsen and Org-roam versions.
|
;; and previous versions of org-roam.
|
||||||
;;
|
;;
|
||||||
;;; Code:
|
;;; Code:
|
||||||
(require 'org-roam)
|
;;;; Library Requires
|
||||||
|
|
||||||
;;; Backports
|
|
||||||
;; REVIEW Remove when 26.x support is dropped. This is exact the same as
|
|
||||||
;; `directory-files-recursively' from Emacs 26, but with FOLLOW-SYMLINKS
|
|
||||||
;; parameter from Emacs 27.
|
|
||||||
(defun org-roam--directory-files-recursively (dir regexp
|
|
||||||
&optional include-directories predicate
|
|
||||||
follow-symlinks)
|
|
||||||
"Return list of all files under directory DIR whose names match REGEXP.
|
|
||||||
This function works recursively. Files are returned in \"depth
|
|
||||||
first\" order, and files from each directory are sorted in
|
|
||||||
alphabetical order. Each file name appears in the returned list
|
|
||||||
in its absolute form.
|
|
||||||
|
|
||||||
By default, the returned list excludes directories, but if
|
|
||||||
optional argument INCLUDE-DIRECTORIES is non-nil, they are
|
|
||||||
included.
|
|
||||||
|
|
||||||
PREDICATE can be either nil (which means that all subdirectories
|
|
||||||
of DIR are descended into), t (which means that subdirectories that
|
|
||||||
can't be read are ignored), or a function (which is called with
|
|
||||||
the name of each subdirectory, and should return non-nil if the
|
|
||||||
subdirectory is to be descended into).
|
|
||||||
|
|
||||||
If FOLLOW-SYMLINKS is non-nil, symbolic links that point to
|
|
||||||
directories are followed. Note that this can lead to infinite
|
|
||||||
recursion."
|
|
||||||
(let* ((result nil)
|
|
||||||
(files nil)
|
|
||||||
(dir (directory-file-name dir))
|
|
||||||
;; When DIR is "/", remote file names like "/method:" could
|
|
||||||
;; also be offered. We shall suppress them.
|
|
||||||
(tramp-mode (and tramp-mode (file-remote-p (expand-file-name dir)))))
|
|
||||||
(dolist (file (sort (file-name-all-completions "" dir)
|
|
||||||
'string<))
|
|
||||||
(unless (member file '("./" "../"))
|
|
||||||
(if (directory-name-p file)
|
|
||||||
(let* ((leaf (substring file 0 (1- (length file))))
|
|
||||||
(full-file (concat dir "/" leaf)))
|
|
||||||
;; Don't follow symlinks to other directories.
|
|
||||||
(when (and (or (not (file-symlink-p full-file))
|
|
||||||
(and (file-symlink-p full-file)
|
|
||||||
follow-symlinks))
|
|
||||||
;; Allow filtering subdirectories.
|
|
||||||
(or (eq predicate nil)
|
|
||||||
(eq predicate t)
|
|
||||||
(funcall predicate full-file)))
|
|
||||||
(let ((sub-files
|
|
||||||
(if (eq predicate t)
|
|
||||||
(condition-case nil
|
|
||||||
(org-roam--directory-files-recursively
|
|
||||||
full-file regexp include-directories
|
|
||||||
predicate follow-symlinks)
|
|
||||||
(file-error nil))
|
|
||||||
(org-roam--directory-files-recursively
|
|
||||||
full-file regexp include-directories
|
|
||||||
predicate follow-symlinks))))
|
|
||||||
(setq result (nconc result sub-files))))
|
|
||||||
(when (and include-directories
|
|
||||||
(string-match regexp leaf))
|
|
||||||
(setq result (nconc result (list full-file)))))
|
|
||||||
(when (string-match regexp file)
|
|
||||||
(push (concat dir "/" file) files)))))
|
|
||||||
(nconc result (nreverse files))))
|
|
||||||
|
|
||||||
;;; Compatibility hacks and patches
|
|
||||||
(advice-add #'org-id-add-location :around #'org-roam--handle-absent-org-id-locations-file-a)
|
|
||||||
(defun org-roam--handle-absent-org-id-locations-file-a (fn &rest args)
|
|
||||||
"Gracefully handle errors related to absence of `org-id-locations-file'.
|
|
||||||
FN is `org-id-add-location' that comes from advice and ARGS are
|
|
||||||
passed to it."
|
|
||||||
(condition-case err
|
|
||||||
(apply fn args)
|
|
||||||
;; `org-id' makes the assumption that `org-id-locations-file' will be stored in `user-emacs-directory'
|
|
||||||
;; which always exist if you have Emacs, so it uses `with-temp-file' to write to the file. However, the
|
|
||||||
;; users *do* change the path to this file and `with-temp-file' unable to create the file, if the path to
|
|
||||||
;; it consists of directories that don't exist. We'll have to handle this ourselves.
|
|
||||||
(error
|
|
||||||
(advice-remove 'org-id-add-location #'org-roam--handle-absent-org-id-locations-file-a)
|
|
||||||
(if (file-exists-p (file-truename org-id-locations-file))
|
|
||||||
(signal (car err) (cdr err))
|
|
||||||
;; Pre-allocate the hash table to avoid weird access related errors during the regeneration.
|
|
||||||
(or org-id-locations (setq org-id-locations (make-hash-table :test 'equal)))
|
|
||||||
;; If permissions allow that, try to create the user specified directory path to
|
|
||||||
;; `org-id-locations-file' ourselves.
|
|
||||||
(condition-case _err
|
|
||||||
(progn (org-roam-message (concat "`org-id-locations-file' (%s) doesn't exist. "
|
|
||||||
"Trying to regenerate it (this may take a while)...")
|
|
||||||
org-id-locations-file)
|
|
||||||
(make-directory (file-name-directory (file-truename org-id-locations-file)))
|
|
||||||
(org-roam-update-org-id-locations)
|
|
||||||
(apply fn args))
|
|
||||||
;; In case of failure (lack of permissions), we'll patch it to at least handle the current session
|
|
||||||
;; without errors.
|
|
||||||
(file-error (org-roam-message "Failed to regenerate `org-id-locations-file'")
|
|
||||||
(lwarn 'org-roam :error "
|
|
||||||
--------
|
|
||||||
WARNING: `org-id-locations-file' (%s) doesn't exist!
|
|
||||||
Org-roam is unable to create it for you.
|
|
||||||
--------
|
|
||||||
|
|
||||||
This happens when Emacs doesn't have permissions to create the
|
|
||||||
path to your `org-id-locations-file'. Org-roam will now fallback
|
|
||||||
storing the file in your current `org-roam-directory', but the
|
|
||||||
warning will keep popup with each new session.
|
|
||||||
|
|
||||||
To stop this warning from popping up, set `org-id-locations-file'
|
|
||||||
to the location you want and ensure that the path exists on your
|
|
||||||
filesystem, then run M-x `org-roam-update-org-id-locations'.
|
|
||||||
|
|
||||||
Note: While Org-roam doesn't depend on `org-id-locations-file' to
|
|
||||||
lookup IDs for the nodes that are stored in the database, it
|
|
||||||
still tries to keep it updated so IDs work across other files in
|
|
||||||
Org-mode, so the IDs used in your `org-roam-directory' would be
|
|
||||||
able to cross-reference outside of `org-roam-directory'. It also
|
|
||||||
allows to keep linking with \"id:\" links within the current
|
|
||||||
`org-roam-directory' to headings and files that are excluded from
|
|
||||||
identification (e.g. with \"ROAM_EXCLUDE\" property) as Org-roam
|
|
||||||
nodes." org-id-locations-file)
|
|
||||||
(setq org-id-locations-file
|
|
||||||
(expand-file-name ".orgids" (file-truename org-roam-directory)))
|
|
||||||
(apply fn args)))))))
|
|
||||||
|
|
||||||
;;;; Deprecated :if-new capture template keyword
|
|
||||||
(with-eval-after-load 'org-roam-capture
|
|
||||||
(add-to-list 'org-roam-capture--template-keywords :if-new)
|
|
||||||
|
|
||||||
(let ((inhibit-warning-p t)) ; REVIEW Set this to nil close to next major release
|
|
||||||
(advice-add 'org-roam-capture--get-target :around #'org-roam-capture--get-if-new-target-a)
|
|
||||||
(defun org-roam-capture--get-if-new-target-a (fn &rest args)
|
|
||||||
"Get the current capture target using deprecated :if-new property."
|
|
||||||
(if-let ((target (org-roam-capture--get :if-new)))
|
|
||||||
(prog1 target
|
|
||||||
(unless inhibit-warning-p
|
|
||||||
(lwarn 'org-roam-capture :warning
|
|
||||||
(mapconcat
|
|
||||||
#'identity
|
|
||||||
["`:if-new' property is deprecated in favor of `:target'."
|
|
||||||
"This warning will popup once per each session. In order to get"
|
|
||||||
"rid of it, rename all the references to the `:if-new' property"
|
|
||||||
"in your capture templates to `:target'."]
|
|
||||||
"\n"))
|
|
||||||
;; Don't irritate the user too much. Displaying the warning once per session should be enough.
|
|
||||||
(setq inhibit-warning-p t)))
|
|
||||||
(apply fn args)))))
|
|
||||||
|
|
||||||
;;; Obsolete aliases (remove after next major release)
|
;;; Obsolete aliases (remove after next major release)
|
||||||
(define-obsolete-function-alias
|
|
||||||
'org-roam-setup
|
|
||||||
'org-roam-db-autosync-enable "org-roam 2.0")
|
|
||||||
(define-obsolete-function-alias
|
|
||||||
'org-roam-teardown
|
|
||||||
'org-roam-db-autosync-disable "org-roam 2.0")
|
|
||||||
|
|
||||||
(define-obsolete-variable-alias
|
|
||||||
'org-roam-current-node
|
|
||||||
'org-roam-buffer-current-node "org-roam 2.0")
|
|
||||||
(define-obsolete-variable-alias
|
|
||||||
'org-roam-current-directory
|
|
||||||
'org-roam-buffer-current-directory "org-roam 2.0")
|
|
||||||
(define-obsolete-function-alias
|
|
||||||
'org-roam-buffer-render
|
|
||||||
'org-roam-buffer-render-contents "org-roam 2.0")
|
|
||||||
(define-obsolete-function-alias
|
|
||||||
'org-roam-buffer
|
|
||||||
'org-roam-buffer-display-dedicated "org-roam 2.0")
|
|
||||||
(define-obsolete-function-alias
|
|
||||||
'org-roam-visit-thing
|
|
||||||
'org-roam-buffer-visit-thing "org-roam 2.0")
|
|
||||||
|
|
||||||
(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")
|
|
||||||
|
|
||||||
(define-obsolete-function-alias
|
|
||||||
'org-roam-add-property
|
|
||||||
'org-roam-property-add "org-roam 2.1")
|
|
||||||
|
|
||||||
(define-obsolete-function-alias
|
|
||||||
'org-roam-remove-property
|
|
||||||
'org-roam-property-remove "org-roam 2.1")
|
|
||||||
|
|
||||||
(define-obsolete-variable-alias
|
|
||||||
'org-roam-mode-section-functions
|
|
||||||
'org-roam-mode-sections "org-roam 2.2.0")
|
|
||||||
|
|
||||||
;;; Obsolete functions
|
;;; Obsolete functions
|
||||||
(make-obsolete 'org-roam-get-keyword 'org-collect-keywords "org-roam 2.0")
|
|
||||||
|
|
||||||
(provide 'org-roam-compat)
|
(provide 'org-roam-compat)
|
||||||
|
|
||||||
|
133
org-roam-completion.el
Normal file
133
org-roam-completion.el
Normal file
@ -0,0 +1,133 @@
|
|||||||
|
;;; org-roam-completion.el --- Completion features -*- 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-sqlite3 "1.0.2") (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 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:
|
||||||
|
(require 'cl-lib)
|
||||||
|
(require 'org-element)
|
||||||
|
|
||||||
|
(declare-function org-roam--get-titles "org-roam")
|
||||||
|
|
||||||
|
(defcustom org-roam-completion-ignore-case t
|
||||||
|
"Whether to ignore case in Org-roam `completion-at-point' completions."
|
||||||
|
:group 'org-roam
|
||||||
|
:type 'boolean)
|
||||||
|
|
||||||
|
(defcustom org-roam-completion-everywhere nil
|
||||||
|
"When non-nil, provide link completion matching outside of Org links."
|
||||||
|
:group 'org-roam
|
||||||
|
:type 'boolean)
|
||||||
|
|
||||||
|
(defvar org-roam-completion-functions (list #'org-roam-complete-link-at-point
|
||||||
|
#'org-roam-complete-everywhere)
|
||||||
|
"List of functions to be used with `completion-at-point' for Org-roam.")
|
||||||
|
|
||||||
|
(defun org-roam-complete-everywhere ()
|
||||||
|
"Provides completions for links for any word at point.
|
||||||
|
This is a `completion-at-point' function, and is active when
|
||||||
|
`org-roam-completion-everywhere' is non-nil."
|
||||||
|
(let ((end (point))
|
||||||
|
(start (point))
|
||||||
|
(exit-fn (lambda (&rest _) nil))
|
||||||
|
collection)
|
||||||
|
(when (and org-roam-completion-everywhere
|
||||||
|
(thing-at-point 'word)
|
||||||
|
(not (save-match-data (org-in-regexp org-link-any-re))))
|
||||||
|
(let ((bounds (bounds-of-thing-at-point 'word)))
|
||||||
|
(setq start (car bounds)
|
||||||
|
end (cdr bounds)
|
||||||
|
collection #'org-roam--get-titles
|
||||||
|
exit-fn (lambda (str _status)
|
||||||
|
(delete-char (- (length str)))
|
||||||
|
(insert "[[roam:" str "]]")))))
|
||||||
|
(when collection
|
||||||
|
(let ((prefix (buffer-substring-no-properties start end)))
|
||||||
|
(list start end
|
||||||
|
(if (functionp collection)
|
||||||
|
(completion-table-case-fold
|
||||||
|
(completion-table-dynamic
|
||||||
|
(lambda (_)
|
||||||
|
(cl-remove-if (apply-partially #'string= prefix)
|
||||||
|
(funcall collection))))
|
||||||
|
(not org-roam-completion-ignore-case))
|
||||||
|
collection)
|
||||||
|
:exit-function exit-fn)))))
|
||||||
|
|
||||||
|
(defun org-roam-complete-link-at-point ()
|
||||||
|
"Do appropriate completion for the link at point."
|
||||||
|
(let ((end (point))
|
||||||
|
(start (point))
|
||||||
|
collection link-type)
|
||||||
|
(when (org-in-regexp org-link-bracket-re 1)
|
||||||
|
(setq start (match-beginning 1)
|
||||||
|
end (match-end 1))
|
||||||
|
(let ((context (org-element-context)))
|
||||||
|
(pcase (org-element-lineage context '(link) t)
|
||||||
|
(`nil nil)
|
||||||
|
(link
|
||||||
|
(setq link-type (org-element-property :type link))
|
||||||
|
(when (member link-type '("roam" "fuzzy"))
|
||||||
|
(when (string= link-type "roam") (setq start (+ start (length "roam:"))))
|
||||||
|
(setq collection #'org-roam--get-titles))))))
|
||||||
|
(when collection
|
||||||
|
(let ((prefix (buffer-substring-no-properties start end)))
|
||||||
|
(list start end
|
||||||
|
(if (functionp collection)
|
||||||
|
(completion-table-case-fold
|
||||||
|
(completion-table-dynamic
|
||||||
|
(lambda (_)
|
||||||
|
(cl-remove-if (apply-partially #'string= prefix)
|
||||||
|
(funcall collection))))
|
||||||
|
(not org-roam-completion-ignore-case))
|
||||||
|
collection)
|
||||||
|
:exit-function
|
||||||
|
(lambda (str &rest _)
|
||||||
|
(delete-char (- 0 (length str)))
|
||||||
|
(insert (concat (unless (string= link-type "roam") "roam:")
|
||||||
|
str))
|
||||||
|
(forward-char 2)))))))
|
||||||
|
|
||||||
|
(defun org-roam--register-completion-functions ()
|
||||||
|
"."
|
||||||
|
(dolist (fn org-roam-completion-functions)
|
||||||
|
(add-hook 'completion-at-point-functions fn nil t)))
|
||||||
|
|
||||||
|
(add-hook 'org-roam-find-file-hook #'org-roam--register-completion-functions)
|
||||||
|
|
||||||
|
(provide 'org-roam-completion)
|
||||||
|
|
||||||
|
;;; org-roam-completion.el ends here
|
@ -1,14 +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-2025 Jethro Kuan <jethrokuan95@gmail.com>
|
;; Copyright © 2020 Jethro Kuan <jethrokuan95@gmail.com>
|
||||||
;; Copyright © 2020 Leo Vivier <leo.vivier+dev@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>
|
;; 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: 2.3.1
|
;; Version: 2.0.0
|
||||||
;; Package-Requires: ((emacs "26.1") (dash "2.13") (org-roam "2.1"))
|
;; Package-Requires: ((emacs "26.1") (dash "2.13") (f "0.17.2") (org "9.4") (emacsql "3.0.0") (emacsql-sqlite3 "1.0.2") (magit-section "2.90.1"))
|
||||||
|
|
||||||
;; This file is NOT part of GNU Emacs.
|
;; This file is NOT part of GNU Emacs.
|
||||||
|
|
||||||
@ -29,27 +29,29 @@
|
|||||||
|
|
||||||
;;; Commentary:
|
;;; Commentary:
|
||||||
;;
|
;;
|
||||||
;; This extension provides functionality for creating daily-notes, or shortly
|
;; This library provides functionality for creating daily-notes. This is a
|
||||||
;; "dailies". Dailies implemented here as a unique node per unique file, where
|
;; concept borrowed from Roam Research.
|
||||||
;; each file named after certain date and stored in `org-roam-dailies-directory'.
|
|
||||||
;;
|
|
||||||
;; One can use dailies for various purposes, e.g. journaling, fleeting notes,
|
|
||||||
;; scratch notes or whatever else you can think of.
|
|
||||||
;;
|
;;
|
||||||
;;; Code:
|
;;; Code:
|
||||||
(require 'dash)
|
;;; Library Requires
|
||||||
(require 'org-roam)
|
(require 'org-capture)
|
||||||
|
(require 'org-roam-capture)
|
||||||
|
(require 'f)
|
||||||
|
|
||||||
;;; Faces
|
;;;; Declarations
|
||||||
|
(defvar org-roam-directory)
|
||||||
|
(defvar org-roam-file-extensions)
|
||||||
|
(declare-function org-roam--org-file-p "org-roam")
|
||||||
|
|
||||||
|
;;;; Faces
|
||||||
(defface org-roam-dailies-calendar-note
|
(defface org-roam-dailies-calendar-note
|
||||||
'((t :inherit (org-link) :underline nil))
|
'((t :inherit (org-link) :underline nil))
|
||||||
"Face for dates with a daily-note in the calendar."
|
"Face for dates with a daily-note in the calendar."
|
||||||
:group 'org-roam-faces)
|
:group 'org-roam-faces)
|
||||||
|
|
||||||
;;; Options
|
;;;; Customizable variables
|
||||||
(defcustom org-roam-dailies-directory "daily/"
|
(defcustom org-roam-dailies-directory "daily/"
|
||||||
"Path to daily-notes.
|
"Path to daily-notes."
|
||||||
This path is relative to `org-roam-directory'."
|
|
||||||
:group 'org-roam
|
:group 'org-roam
|
||||||
:type 'string)
|
:type 'string)
|
||||||
|
|
||||||
@ -59,13 +61,11 @@ This path is relative to `org-roam-directory'."
|
|||||||
:type 'hook)
|
:type 'hook)
|
||||||
|
|
||||||
(defcustom org-roam-dailies-capture-templates
|
(defcustom org-roam-dailies-capture-templates
|
||||||
`(("d" "default" entry
|
'(("d" "default" entry
|
||||||
"* %?"
|
"* %?"
|
||||||
:target (file+head "%<%Y-%m-%d>.org"
|
:if-new `(file+head ,(concat org-roam-dailies-directory "%<%Y-%m-%d>.org")
|
||||||
"#+title: %<%Y-%m-%d>\n")))
|
"#+title: %<%Y-%m-%d>\n")))
|
||||||
"Capture templates for daily-notes in Org-roam.
|
"Capture templates for daily-notes in Org-roam.
|
||||||
Note that for daily files to show up in the calendar, they have to be of format
|
|
||||||
\"org-time-string.org\".
|
|
||||||
See `org-roam-capture-templates' for the template documentation."
|
See `org-roam-capture-templates' for the template documentation."
|
||||||
:group 'org-roam
|
:group 'org-roam
|
||||||
:type '(repeat
|
:type '(repeat
|
||||||
@ -91,7 +91,7 @@ See `org-roam-capture-templates' for the template documentation."
|
|||||||
(function :tag "Template function")))
|
(function :tag "Template function")))
|
||||||
(plist :inline t
|
(plist :inline t
|
||||||
;; Give the most common options as checkboxes
|
;; Give the most common options as checkboxes
|
||||||
:options (((const :format "%v " :target)
|
:options (((const :format "%v " :if-new)
|
||||||
(choice :tag "Node location"
|
(choice :tag "Node location"
|
||||||
(list :tag "File"
|
(list :tag "File"
|
||||||
(const :format "" file)
|
(const :format "" file)
|
||||||
@ -104,13 +104,13 @@ See `org-roam-capture-templates' for the template documentation."
|
|||||||
(const :format "" file+olp)
|
(const :format "" file+olp)
|
||||||
(string :tag " File")
|
(string :tag " File")
|
||||||
(list :tag "Outline path"
|
(list :tag "Outline path"
|
||||||
(repeat (string :tag "Headline"))))
|
(repeat string :tag "Headline")))
|
||||||
(list :tag "File & Head Content & Outline path"
|
(list :tag "File & Head Content & Outline path"
|
||||||
(const :format "" file+head+olp)
|
(const :format "" file+head+olp)
|
||||||
(string :tag " File")
|
(string :tag " File")
|
||||||
(string :tag " Head Content")
|
(string :tag " Head Content")
|
||||||
(list :tag "Outline path"
|
(list :tag "Outline path"
|
||||||
(repeat (string :tag "Headline"))))))
|
(repeat string :tag "Headline")))))
|
||||||
((const :format "%v " :prepend) (const t))
|
((const :format "%v " :prepend) (const t))
|
||||||
((const :format "%v " :immediate-finish) (const t))
|
((const :format "%v " :immediate-finish) (const t))
|
||||||
((const :format "%v " :jump-to-captured) (const t))
|
((const :format "%v " :jump-to-captured) (const t))
|
||||||
@ -126,109 +126,170 @@ See `org-roam-capture-templates' for the template documentation."
|
|||||||
((const :format "%v " :table-line-pos) (string))
|
((const :format "%v " :table-line-pos) (string))
|
||||||
((const :format "%v " :kill-buffer) (const t))))))))
|
((const :format "%v " :kill-buffer) (const t))))))))
|
||||||
|
|
||||||
;;; Commands
|
;;;; Utilities
|
||||||
;;;; Today
|
(defun org-roam-dailies-directory--get-absolute-path ()
|
||||||
;;;###autoload
|
"Get absolute path to `org-roam-dailies-directory'."
|
||||||
(defun org-roam-dailies-capture-today (&optional goto keys)
|
(expand-file-name org-roam-dailies-directory org-roam-directory))
|
||||||
"Create an entry in the daily-note for today.
|
|
||||||
When GOTO is non-nil, go the note without creating an entry.
|
|
||||||
|
|
||||||
ELisp programs can set KEYS to a string associated with a template.
|
(defun org-roam-dailies-find-directory ()
|
||||||
In this case, interactive selection will be bypassed."
|
"Find and open `org-roam-dailies-directory'."
|
||||||
(interactive "P")
|
|
||||||
(org-roam-dailies--capture (current-time) goto keys))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun org-roam-dailies-goto-today (&optional keys)
|
|
||||||
"Find the daily-note for today, creating it if necessary.
|
|
||||||
|
|
||||||
ELisp programs can set KEYS to a string associated with a template.
|
|
||||||
In this case, interactive selection will be bypassed."
|
|
||||||
(interactive)
|
(interactive)
|
||||||
(org-roam-dailies-capture-today t keys))
|
(find-file (org-roam-dailies-directory--get-absolute-path)))
|
||||||
|
|
||||||
;;;; Tomorrow
|
(defun org-roam-dailies--daily-note-p (&optional file)
|
||||||
;;;###autoload
|
"Return t if FILE is an Org-roam daily-note, nil otherwise.
|
||||||
(defun org-roam-dailies-capture-tomorrow (n &optional goto keys)
|
|
||||||
|
If FILE is not specified, use the current buffer's file-path."
|
||||||
|
(when-let ((path (or file
|
||||||
|
(buffer-base-buffer (buffer-file-name))))
|
||||||
|
(directory (org-roam-dailies-directory--get-absolute-path)))
|
||||||
|
(setq path (expand-file-name path))
|
||||||
|
(save-match-data
|
||||||
|
(and
|
||||||
|
(org-roam--org-file-p path)
|
||||||
|
(f-descendant-of-p path directory)))))
|
||||||
|
|
||||||
|
(defun org-roam-dailies--capture (time &optional goto)
|
||||||
|
"Capture an entry in a daily-note for TIME, creating it if necessary.
|
||||||
|
|
||||||
|
When GOTO is non-nil, go the note without creating an entry."
|
||||||
|
(org-roam-capture- :goto (when goto '(4))
|
||||||
|
:node (org-roam-node-create)
|
||||||
|
:templates org-roam-dailies-capture-templates
|
||||||
|
:props (list :default-time time)))
|
||||||
|
|
||||||
|
;;;; Commands
|
||||||
|
;;; Today
|
||||||
|
(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)
|
||||||
|
(when goto
|
||||||
|
(run-hooks 'org-roam-dailies-find-file-hook)))
|
||||||
|
|
||||||
|
(defun org-roam-dailies-find-today ()
|
||||||
|
"Find the daily-note for today, creating it if necessary."
|
||||||
|
(interactive)
|
||||||
|
(org-roam-dailies-capture-today t))
|
||||||
|
|
||||||
|
;;; Tomorrow
|
||||||
|
(defun org-roam-dailies-capture-tomorrow (n &optional goto)
|
||||||
"Create an entry in the daily-note for tomorrow.
|
"Create an entry in the daily-note for tomorrow.
|
||||||
|
|
||||||
With numeric argument N, use the daily-note N days in the future.
|
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
|
With a `C-u' prefix or when GOTO is non-nil, go the note without
|
||||||
creating an entry.
|
creating an entry."
|
||||||
|
|
||||||
ELisp programs can set KEYS to a string associated with a template.
|
|
||||||
In this case, interactive selection will be bypassed."
|
|
||||||
(interactive "p")
|
(interactive "p")
|
||||||
(org-roam-dailies--capture (time-add (* n 86400) (current-time)) goto keys))
|
(org-roam-dailies--capture (time-add (* n 86400) (current-time)) goto))
|
||||||
|
|
||||||
;;;###autoload
|
(defun org-roam-dailies-find-tomorrow (n)
|
||||||
(defun org-roam-dailies-goto-tomorrow (n &optional keys)
|
|
||||||
"Find the daily-note for tomorrow, creating it if necessary.
|
"Find the daily-note for tomorrow, creating it if necessary.
|
||||||
|
|
||||||
With numeric argument N, use the daily-note N days in the
|
With numeric argument N, use the daily-note N days in the
|
||||||
future.
|
future."
|
||||||
|
|
||||||
ELisp programs can set KEYS to a string associated with a template.
|
|
||||||
In this case, interactive selection will be bypassed."
|
|
||||||
(interactive "p")
|
(interactive "p")
|
||||||
(org-roam-dailies-capture-tomorrow n t keys))
|
(org-roam-dailies-capture-tomorrow n t))
|
||||||
|
|
||||||
;;;; Yesterday
|
;;; Yesterday
|
||||||
;;;###autoload
|
(defun org-roam-dailies-capture-yesterday (n &optional goto)
|
||||||
(defun org-roam-dailies-capture-yesterday (n &optional goto keys)
|
|
||||||
"Create an entry in the daily-note for yesteday.
|
"Create an entry in the daily-note for yesteday.
|
||||||
|
|
||||||
With numeric argument N, use the daily-note N days in the past.
|
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.
|
When GOTO is non-nil, go the note without creating an entry."
|
||||||
|
|
||||||
ELisp programs can set KEYS to a string associated with a template.
|
|
||||||
In this case, interactive selection will be bypassed."
|
|
||||||
(interactive "p")
|
(interactive "p")
|
||||||
(org-roam-dailies-capture-tomorrow (- n) goto keys))
|
(org-roam-dailies-capture-tomorrow (- n) goto))
|
||||||
|
|
||||||
;;;###autoload
|
(defun org-roam-dailies-find-yesterday (n)
|
||||||
(defun org-roam-dailies-goto-yesterday (n &optional keys)
|
|
||||||
"Find the daily-note for yesterday, creating it if necessary.
|
"Find the daily-note for yesterday, creating it if necessary.
|
||||||
|
|
||||||
With numeric argument N, use the daily-note N days in the
|
With numeric argument N, use the daily-note N days in the
|
||||||
future.
|
future."
|
||||||
|
|
||||||
ELisp programs can set KEYS to a string associated with a template.
|
|
||||||
In this case, interactive selection will be bypassed."
|
|
||||||
(interactive "p")
|
(interactive "p")
|
||||||
(org-roam-dailies-capture-tomorrow (- n) t keys))
|
(org-roam-dailies-capture-tomorrow (- n) t))
|
||||||
|
|
||||||
;;;; Date
|
;;; Calendar
|
||||||
;;;###autoload
|
(defvar org-roam-dailies-calendar-hook (list 'org-roam-dailies-calendar-mark-entries)
|
||||||
(defun org-roam-dailies-capture-date (&optional goto prefer-future keys)
|
"Hooks to run when showing the `org-roam-dailies-calendar'.")
|
||||||
|
|
||||||
|
(defun org-roam-dailies-calendar--install-hook ()
|
||||||
|
"Install Org-roam-dailies hooks to calendar."
|
||||||
|
(add-hook 'calendar-today-visible-hook #'org-roam-dailies-calendar--run-hook)
|
||||||
|
(add-hook 'calendar-today-invisible-hook #'org-roam-dailies-calendar--run-hook))
|
||||||
|
|
||||||
|
(defun org-roam-dailies-calendar--run-hook ()
|
||||||
|
"Run Org-roam-dailies hooks to calendar."
|
||||||
|
(run-hooks 'org-roam-dailies-calendar-hook)
|
||||||
|
(remove-hook 'calendar-today-visible-hook #'org-roam-dailies-calendar--run-hook)
|
||||||
|
(remove-hook 'calendar-today-invisible-hook #'org-roam-dailies-calendar--run-hook))
|
||||||
|
|
||||||
|
(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 the 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 (org-roam-dailies-directory--get-absolute-path))
|
||||||
|
(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
|
||||||
|
(defun org-roam-dailies-capture-date (&optional goto prefer-future)
|
||||||
"Create an entry in the daily-note for a date using the calendar.
|
"Create an entry in the daily-note for a date using the calendar.
|
||||||
|
|
||||||
Prefer past dates, unless PREFER-FUTURE is non-nil.
|
Prefer past dates, unless PREFER-FUTURE is non-nil.
|
||||||
|
|
||||||
With a `C-u' prefix or when GOTO is non-nil, go the note without
|
With a `C-u' prefix or when GOTO is non-nil, go the note without
|
||||||
creating an entry.
|
creating an entry."
|
||||||
|
|
||||||
ELisp programs can set KEYS to a string associated with a template.
|
|
||||||
In this case, interactive selection will be bypassed."
|
|
||||||
(interactive "P")
|
(interactive "P")
|
||||||
(let ((time (let ((org-read-date-prefer-future prefer-future))
|
(org-roam-dailies-calendar--install-hook)
|
||||||
(org-read-date nil t nil (if goto
|
(let* ((time-str (let ((org-read-date-prefer-future prefer-future))
|
||||||
"Find daily-note: "
|
(org-read-date nil nil nil (if goto
|
||||||
"Capture to daily-note: ")))))
|
"Find daily-note: "
|
||||||
(org-roam-dailies--capture time goto keys)))
|
"Capture to daily-note: "))))
|
||||||
|
(time (org-read-date nil t time-str)))
|
||||||
|
(org-roam-dailies--capture time goto)
|
||||||
|
(when goto
|
||||||
|
(run-hooks 'org-roam-dailies-find-file-hook))))
|
||||||
|
|
||||||
;;;###autoload
|
(defun org-roam-dailies-find-date (&optional prefer-future)
|
||||||
(defun org-roam-dailies-goto-date (&optional prefer-future keys)
|
|
||||||
"Find the daily-note for a date using the calendar, creating it if necessary.
|
"Find the daily-note for a date using the calendar, creating it if necessary.
|
||||||
Prefer past dates, unless PREFER-FUTURE is non-nil.
|
Prefer past dates, unless PREFER-FUTURE is non-nil."
|
||||||
|
|
||||||
ELisp programs can set KEYS to a string associated with a template.
|
|
||||||
In this case, interactive selection will be bypassed."
|
|
||||||
(interactive)
|
(interactive)
|
||||||
(org-roam-dailies-capture-date t prefer-future keys))
|
(org-roam-dailies-capture-date t prefer-future))
|
||||||
|
|
||||||
;;;; Navigation
|
;;; Navigation
|
||||||
(defun org-roam-dailies-goto-next-note (&optional n)
|
(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 (org-roam-dailies-directory--get-absolute-path))
|
||||||
|
(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-find-next-note (&optional n)
|
||||||
"Find next daily-note.
|
"Find next daily-note.
|
||||||
|
|
||||||
With numeric argument N, find note N days in the future. If N is
|
With numeric argument N, find note N days in the future. If N is
|
||||||
@ -256,108 +317,28 @@ negative, find note N days in the past."
|
|||||||
(find-file note)
|
(find-file note)
|
||||||
(run-hooks 'org-roam-dailies-find-file-hook)))
|
(run-hooks 'org-roam-dailies-find-file-hook)))
|
||||||
|
|
||||||
(defun org-roam-dailies-goto-previous-note (&optional n)
|
(defun org-roam-dailies-find-previous-note (&optional n)
|
||||||
"Find previous daily-note.
|
"Find previous daily-note.
|
||||||
|
|
||||||
With numeric argument N, find note N days in the past. If N is
|
With numeric argument N, find note N days in the past. If N is
|
||||||
negative, find note N days in the future."
|
negative, find note N days in the future."
|
||||||
(interactive "p")
|
(interactive "p")
|
||||||
(let ((n (if n (- n) -1)))
|
(let ((n (if n (- n) -1)))
|
||||||
(org-roam-dailies-goto-next-note n)))
|
(org-roam-dailies-find-next-note n)))
|
||||||
|
|
||||||
(defun org-roam-dailies--list-files (&rest extra-files)
|
;;;; Bindings
|
||||||
"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--daily-note-p (&optional file)
|
|
||||||
"Return t if FILE is an Org-roam daily-note, nil otherwise.
|
|
||||||
If FILE is not specified, use the current buffer's file-path."
|
|
||||||
(when-let ((path (expand-file-name
|
|
||||||
(or file
|
|
||||||
(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)
|
|
||||||
(org-roam-descendant-of-p path directory)))))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun org-roam-dailies-find-directory ()
|
|
||||||
"Find and open `org-roam-dailies-directory'."
|
|
||||||
(interactive)
|
|
||||||
(find-file (expand-file-name org-roam-dailies-directory org-roam-directory)))
|
|
||||||
|
|
||||||
;;; Calendar integration
|
|
||||||
(defun org-roam-dailies-calendar--file-to-date (file)
|
|
||||||
"Convert FILE to date.
|
|
||||||
Return (MONTH DAY YEAR) or nil if not an Org time-string."
|
|
||||||
(ignore-errors
|
|
||||||
(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-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 (remove nil
|
|
||||||
(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)))))
|
|
||||||
|
|
||||||
(add-hook 'calendar-today-visible-hook #'org-roam-dailies-calendar-mark-entries)
|
|
||||||
(add-hook 'calendar-today-invisible-hook #'org-roam-dailies-calendar-mark-entries)
|
|
||||||
|
|
||||||
;;; Capture implementation
|
|
||||||
(add-to-list 'org-roam-capture--template-keywords :override-default-time)
|
|
||||||
|
|
||||||
(defun org-roam-dailies--capture (time &optional goto keys)
|
|
||||||
"Capture an entry in a daily-note for TIME, creating it if necessary.
|
|
||||||
When GOTO is non-nil, go the note without creating an entry.
|
|
||||||
|
|
||||||
ELisp programs can set KEYS to a string associated with a template.
|
|
||||||
In this case, interactive selection will be bypassed."
|
|
||||||
(let ((org-roam-directory (expand-file-name org-roam-dailies-directory org-roam-directory))
|
|
||||||
(org-roam-dailies-directory "./"))
|
|
||||||
(org-roam-capture- :goto (when goto '(4))
|
|
||||||
:keys keys
|
|
||||||
: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)))
|
|
||||||
|
|
||||||
(add-hook 'org-roam-capture-preface-hook #'org-roam-dailies--override-capture-time-h)
|
|
||||||
(defun org-roam-dailies--override-capture-time-h ()
|
|
||||||
"Override the `:default-time' with the time from `:override-default-time'."
|
|
||||||
(prog1 nil
|
|
||||||
(when (org-roam-capture--get :override-default-time)
|
|
||||||
(org-capture-put :default-time (org-roam-capture--get :override-default-time)))))
|
|
||||||
|
|
||||||
;;; Bindings
|
|
||||||
(defvar org-roam-dailies-map (make-sparse-keymap)
|
(defvar org-roam-dailies-map (make-sparse-keymap)
|
||||||
"Keymap for `org-roam-dailies'.")
|
"Keymap for `org-roam-dailies'.")
|
||||||
|
|
||||||
(define-prefix-command 'org-roam-dailies-map)
|
(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 "d") #'org-roam-dailies-find-today)
|
||||||
(define-key org-roam-dailies-map (kbd "y") #'org-roam-dailies-goto-yesterday)
|
(define-key org-roam-dailies-map (kbd "y") #'org-roam-dailies-find-yesterday)
|
||||||
(define-key org-roam-dailies-map (kbd "t") #'org-roam-dailies-goto-tomorrow)
|
(define-key org-roam-dailies-map (kbd "t") #'org-roam-dailies-find-tomorrow)
|
||||||
(define-key org-roam-dailies-map (kbd "n") #'org-roam-dailies-capture-today)
|
(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 "f") #'org-roam-dailies-find-next-note)
|
||||||
(define-key org-roam-dailies-map (kbd "b") #'org-roam-dailies-goto-previous-note)
|
(define-key org-roam-dailies-map (kbd "b") #'org-roam-dailies-find-previous-note)
|
||||||
(define-key org-roam-dailies-map (kbd "c") #'org-roam-dailies-goto-date)
|
(define-key org-roam-dailies-map (kbd "c") #'org-roam-dailies-find-date)
|
||||||
(define-key org-roam-dailies-map (kbd "v") #'org-roam-dailies-capture-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-key org-roam-dailies-map (kbd ".") #'org-roam-dailies-find-directory)
|
||||||
|
|
745
org-roam-db.el
745
org-roam-db.el
@ -1,12 +1,12 @@
|
|||||||
;;; org-roam-db.el --- Org-roam database API -*- coding: utf-8; lexical-binding: t; -*-
|
;;; org-roam-db.el --- Org-roam database API -*- coding: utf-8; lexical-binding: t; -*-
|
||||||
|
|
||||||
;; Copyright © 2020-2025 Jethro Kuan <jethrokuan95@gmail.com>
|
;; Copyright © 2020 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: 2.3.1
|
;; Version: 2.0.0
|
||||||
;; Package-Requires: ((emacs "26.1") (dash "2.13") (org "9.6") (emacsql "4.1.0") (magit-section "3.0.0"))
|
;; Package-Requires: ((emacs "26.1") (dash "2.13") (f "0.17.2") (org "9.4") (emacsql "3.0.0") (emacsql-sqlite3 "1.0.2") (magit-section "2.90.1"))
|
||||||
|
|
||||||
;; This file is NOT part of GNU Emacs.
|
;; This file is NOT part of GNU Emacs.
|
||||||
|
|
||||||
@ -27,17 +27,37 @@
|
|||||||
|
|
||||||
;;; Commentary:
|
;;; Commentary:
|
||||||
;;
|
;;
|
||||||
;; This module provides the underlying database API to Org-roam.
|
;; This library provides the underlying database api to org-roam.
|
||||||
;;
|
;;
|
||||||
;;; Code:
|
;;; Code:
|
||||||
(require 'org-roam)
|
;;;; Library Requires
|
||||||
(require 'url-parse)
|
(eval-when-compile (require 'subr-x))
|
||||||
(require 'ol)
|
(require 'emacsql)
|
||||||
(defvar org-outline-path-cache)
|
(require 'emacsql-sqlite3)
|
||||||
|
(require 'seq)
|
||||||
|
|
||||||
;;; Options
|
(eval-and-compile
|
||||||
(defcustom org-roam-db-location (locate-user-emacs-file "org-roam.db")
|
(require 'org-roam-macs)
|
||||||
"The path to file where the Org-roam database is stored.
|
;; 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-verbose)
|
||||||
|
(defvar org-agenda-files)
|
||||||
|
|
||||||
|
(declare-function org-roam-id-at-point "org-roam")
|
||||||
|
(declare-function org-roam--org-roam-file-p "org-roam")
|
||||||
|
(declare-function org-roam--list-all-files "org-roam")
|
||||||
|
(declare-function org-roam-node-at-point "org-roam")
|
||||||
|
|
||||||
|
;;;; Options
|
||||||
|
(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.
|
||||||
|
If this is non-nil, the Org-roam sqlite database is saved here.
|
||||||
|
|
||||||
It is the user's responsibility to set this correctly, especially
|
It is the user's responsibility to set this correctly, especially
|
||||||
when used with multiple Org-roam instances."
|
when used with multiple Org-roam instances."
|
||||||
@ -46,77 +66,29 @@ 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 `org-roam-db-sync', Emacs can pause multiple times to
|
During large, heavy operations like `org-roam-db-sync',
|
||||||
perform garbage collection because of the large number of
|
many GC operations happen because of the large number of
|
||||||
temporary structures generated (e.g. parsed ASTs).
|
temporary structures generated (e.g. parsed ASTs). Temporarily
|
||||||
|
increasing `gc-cons-threshold' will help reduce the number of GC
|
||||||
|
operations, at the cost of temporary memory usage.
|
||||||
|
|
||||||
`gc-cons-threshold' is temporarily set to
|
This defaults to the original value of `gc-cons-threshold', but
|
||||||
`org-roam-db-gc-threshold' during this operation, and increasing
|
tweaking this number may lead to better overall performance. For
|
||||||
`gc-cons-threshold' will help reduce the number of GC operations,
|
example, to reduce the number of GCs, one may set it to a large
|
||||||
at the cost of memory usage. Tweaking this value may lead to
|
value like `most-positive-fixnum'."
|
||||||
better overall performance.
|
|
||||||
|
|
||||||
For example, to reduce the number of GCs to the minimum, on
|
|
||||||
machines with large memory one may set it to
|
|
||||||
`most-positive-fixnum'."
|
|
||||||
:type 'int
|
:type 'int
|
||||||
:group 'org-roam)
|
:group 'org-roam)
|
||||||
|
|
||||||
(defcustom org-roam-db-node-include-function (lambda () t)
|
(defconst org-roam-db--version 12)
|
||||||
"A custom function to check if the point contains a valid node.
|
|
||||||
This function is called each time a node (both file and headline)
|
|
||||||
is about to be saved into the Org-roam database.
|
|
||||||
|
|
||||||
If the function returns nil, Org-roam will skip the node. This
|
|
||||||
function is useful for excluding certain nodes from the Org-roam
|
|
||||||
database."
|
|
||||||
:type 'function
|
|
||||||
:group 'org-roam)
|
|
||||||
|
|
||||||
(defcustom org-roam-db-update-on-save t
|
|
||||||
"If t, update the Org-roam database upon saving the file.
|
|
||||||
Disable this if your files are large and updating the database is
|
|
||||||
slow."
|
|
||||||
:type 'boolean
|
|
||||||
:group 'org-roam)
|
|
||||||
|
|
||||||
(defcustom org-roam-db-extra-links-elements '(node-property keyword)
|
|
||||||
"The list of Org element types to include for parsing by Org-roam.
|
|
||||||
|
|
||||||
By default, when parsing Org's AST, links within keywords and
|
|
||||||
property drawers are not parsed as links. Sometimes however, it
|
|
||||||
is desirable to parse and cache these links (e.g. hiding links in
|
|
||||||
a property drawer)."
|
|
||||||
:package-version '(org-roam . "2.2.0")
|
|
||||||
:group 'org-roam
|
|
||||||
:type '(set
|
|
||||||
(const :tag "keywords" keyword)
|
|
||||||
(const :tag "property drawers" node-property)))
|
|
||||||
|
|
||||||
(defcustom org-roam-db-extra-links-exclude-keys '((node-property . ("ROAM_REFS"))
|
|
||||||
(keyword . ("transclude")))
|
|
||||||
"Keys to ignore when mapping over links.
|
|
||||||
|
|
||||||
The car of the association list is the Org element type (e.g.
|
|
||||||
keyword). The cdr is a list of case-insensitive strings to
|
|
||||||
exclude from being treated as links.
|
|
||||||
|
|
||||||
For example, we use this to prevent self-referential links in
|
|
||||||
ROAM_REFS."
|
|
||||||
:package-version '(org-roam . "2.2.0")
|
|
||||||
:group 'org-roam
|
|
||||||
:type '(alist))
|
|
||||||
|
|
||||||
;;; Variables
|
|
||||||
(defconst org-roam-db-version 20)
|
|
||||||
|
|
||||||
(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-connection ()
|
(defun org-roam-db--get-connection ()
|
||||||
"Return the database connection, if any."
|
"Return the database connection, if any."
|
||||||
(gethash (expand-file-name (file-name-as-directory 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 ()
|
||||||
@ -127,8 +99,9 @@ Performs a database upgrade when required."
|
|||||||
(emacsql-live-p (org-roam-db--get-connection)))
|
(emacsql-live-p (org-roam-db--get-connection)))
|
||||||
(let ((init-db (not (file-exists-p org-roam-db-location))))
|
(let ((init-db (not (file-exists-p org-roam-db-location))))
|
||||||
(make-directory (file-name-directory org-roam-db-location) t)
|
(make-directory (file-name-directory org-roam-db-location) t)
|
||||||
(let ((conn (emacsql-sqlite-open org-roam-db-location)))
|
(let ((conn (emacsql-sqlite3 org-roam-db-location)))
|
||||||
(puthash (expand-file-name (file-name-as-directory org-roam-directory))
|
(set-process-query-on-exit-flag (emacsql-process conn) nil)
|
||||||
|
(puthash (expand-file-name org-roam-directory)
|
||||||
conn
|
conn
|
||||||
org-roam-db--connection)
|
org-roam-db--connection)
|
||||||
(when init-db
|
(when init-db
|
||||||
@ -136,109 +109,88 @@ Performs a database upgrade when required."
|
|||||||
(let* ((version (caar (emacsql conn "PRAGMA user_version")))
|
(let* ((version (caar (emacsql conn "PRAGMA user_version")))
|
||||||
(version (org-roam-db--upgrade-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. %s"
|
"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."
|
||||||
(apply #'emacsql (org-roam-db) sql args))
|
(if (stringp sql)
|
||||||
|
(emacsql (org-roam-db) (apply #'format sql args))
|
||||||
|
(apply #'emacsql (org-roam-db) sql args)))
|
||||||
|
|
||||||
(defun org-roam-db-query! (handler sql &rest args)
|
;;;; Schemata
|
||||||
"Run SQL query on Org-roam database with ARGS.
|
;; NOTE: Foreign key somehow doesn't work! Adding a file column to every table as a workaround.
|
||||||
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
|
|
||||||
(defconst org-roam-db--table-schemata
|
(defconst org-roam-db--table-schemata
|
||||||
'((files
|
'((files
|
||||||
[(file :unique :primary-key)
|
[(file :unique :primary-key)
|
||||||
title
|
(hash :not-null)])
|
||||||
(hash :not-null)
|
|
||||||
(atime :not-null)
|
|
||||||
(mtime :not-null)])
|
|
||||||
|
|
||||||
(nodes
|
(nodes
|
||||||
([(id :not-null :primary-key)
|
[(id :primary-key :not-null)
|
||||||
(file :not-null)
|
(file :not-null)
|
||||||
(level :not-null)
|
(level :not-null)
|
||||||
(pos :not-null)
|
(pos :not-null)
|
||||||
todo
|
todo
|
||||||
priority
|
priority
|
||||||
(scheduled text)
|
(scheduled text)
|
||||||
(deadline text)
|
(deadline text)
|
||||||
title
|
title]
|
||||||
properties
|
(:foreign-key [file] :references files [file] :on-delete :cascade))
|
||||||
olp]
|
|
||||||
(:foreign-key [file] :references files [file] :on-delete :cascade)))
|
|
||||||
|
|
||||||
(aliases
|
(aliases
|
||||||
([(node-id :not-null)
|
[(file :not-null)
|
||||||
alias]
|
(node-id :not-null)
|
||||||
(:foreign-key [node-id] :references nodes [id] :on-delete :cascade)))
|
alias]
|
||||||
|
(:foreign-key [node-id] :references nodes [id] :on-delete :cascade))
|
||||||
(citations
|
|
||||||
([(node-id :not-null)
|
|
||||||
(cite-key :not-null)
|
|
||||||
(pos :not-null)
|
|
||||||
properties]
|
|
||||||
(:foreign-key [node-id] :references nodes [id] :on-delete :cascade)))
|
|
||||||
|
|
||||||
(refs
|
(refs
|
||||||
([(node-id :not-null)
|
([(file :not-null)
|
||||||
|
(node-id :not-null)
|
||||||
(ref :not-null)
|
(ref :not-null)
|
||||||
(type :not-null)]
|
(type :not-null)]
|
||||||
(:foreign-key [node-id] :references nodes [id] :on-delete :cascade)))
|
(:foreign-key [node-id] :references nodes [id] :on-delete :cascade)))
|
||||||
|
|
||||||
(tags
|
(tags
|
||||||
([(node-id :not-null)
|
[(file :not-null)
|
||||||
tag]
|
(node-id :not-null)
|
||||||
(:foreign-key [node-id] :references nodes [id] :on-delete :cascade)))
|
tag]
|
||||||
|
(:foreign-key [node-id] :references nodes [id] :on-delete :cascade))
|
||||||
|
|
||||||
(links
|
(links
|
||||||
([(pos :not-null)
|
[(file :not-null)
|
||||||
(source :not-null)
|
(pos :not-null)
|
||||||
(dest :not-null)
|
(source :not-null)
|
||||||
(type :not-null)
|
(dest :not-null)
|
||||||
(properties :not-null)]
|
(type :not-null)
|
||||||
(:foreign-key [source] :references nodes [id] :on-delete :cascade)))))
|
(properties :not-null)]
|
||||||
|
(:foreign-key [file] :references files [file] :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
|
||||||
|
(emacsql db "PRAGMA foreign_keys = ON")
|
||||||
(pcase-dolist (`(,table ,schema) org-roam-db--table-schemata)
|
(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))
|
||||||
(pcase-dolist (`(,index-name ,table ,columns) org-roam-db--table-indices)
|
(emacsql db (format "PRAGMA user_version = %s" org-roam-db--version))))
|
||||||
(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--upgrade-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-sync t))))
|
(org-roam-db-sync t))))
|
||||||
version)
|
version)
|
||||||
|
|
||||||
@ -256,8 +208,8 @@ the current `org-roam-directory'."
|
|||||||
(dolist (conn (hash-table-values org-roam-db--connection))
|
(dolist (conn (hash-table-values org-roam-db--connection))
|
||||||
(org-roam-db--close conn)))
|
(org-roam-db--close conn)))
|
||||||
|
|
||||||
;;; Database API
|
;;;; Database API
|
||||||
;;;; Clearing
|
;;;;; Clearing
|
||||||
(defun org-roam-db-clear-all ()
|
(defun org-roam-db-clear-all ()
|
||||||
"Clears all entries in the Org-roam cache."
|
"Clears all entries in the Org-roam cache."
|
||||||
(interactive)
|
(interactive)
|
||||||
@ -270,136 +222,107 @@ the current `org-roam-directory'."
|
|||||||
This is equivalent to removing the node from the graph.
|
This is equivalent to removing the node from the graph.
|
||||||
If FILE is nil, clear the current buffer."
|
If FILE is nil, clear the current buffer."
|
||||||
(setq file (or file (buffer-file-name (buffer-base-buffer))))
|
(setq file (or file (buffer-file-name (buffer-base-buffer))))
|
||||||
(org-roam-db-query [:delete :from files
|
(dolist (table (mapcar #'car org-roam-db--table-schemata))
|
||||||
:where (= file $s1)]
|
(org-roam-db-query `[:delete :from ,table
|
||||||
file))
|
:where (= file $s1)]
|
||||||
|
file)))
|
||||||
|
|
||||||
;;;; Updating tables
|
;;;;; Updating tables
|
||||||
|
(defun org-roam-db-insert-file ()
|
||||||
(defun org-roam-db--file-title ()
|
|
||||||
"In current Org buffer, get the title.
|
|
||||||
If there is no title, return the file name relative to
|
|
||||||
`org-roam-directory'."
|
|
||||||
(org-link-display-format
|
|
||||||
(or (string-join (cdr (assoc "TITLE" (org-collect-keywords '("title")))) " ")
|
|
||||||
(file-name-sans-extension (file-relative-name
|
|
||||||
(buffer-file-name (buffer-base-buffer))
|
|
||||||
org-roam-directory)))))
|
|
||||||
|
|
||||||
(defun org-roam-db-insert-file (&optional hash)
|
|
||||||
"Update the files table for the current buffer.
|
"Update the files table for the current buffer.
|
||||||
If UPDATE-P is non-nil, first remove the file in the database.
|
If UPDATE-P is non-nil, first remove the file in the database."
|
||||||
If HASH is non-nil, use that as the file's hash without recalculating it."
|
|
||||||
(let* ((file (buffer-file-name))
|
(let* ((file (buffer-file-name))
|
||||||
(file-title (org-roam-db--file-title))
|
(hash (org-roam-db--file-hash)))
|
||||||
(attr (file-attributes file))
|
|
||||||
(atime (file-attribute-access-time attr))
|
|
||||||
(mtime (file-attribute-modification-time attr))
|
|
||||||
(hash (or hash (org-roam-db--file-hash file))))
|
|
||||||
(org-roam-db-query
|
(org-roam-db-query
|
||||||
[:insert :into files
|
[:insert :into files
|
||||||
:values $v1]
|
:values $v1]
|
||||||
(list (vector file file-title hash atime mtime)))))
|
(list (vector file hash)))))
|
||||||
|
|
||||||
(defun org-roam-db-get-scheduled-time ()
|
(defun org-roam-db-get-scheduled-time ()
|
||||||
"Return the scheduled time at point in ISO8601 format."
|
"Return the scheduled time at point in ISO8601 format."
|
||||||
(when-let ((time (org-get-scheduled-time (point))))
|
(when-let ((time (org-get-scheduled-time (point))))
|
||||||
(format-time-string "%FT%T" time)))
|
(org-format-time-string "%FT%T%z" time)))
|
||||||
|
|
||||||
(defun org-roam-db-get-deadline-time ()
|
(defun org-roam-db-get-deadline-time ()
|
||||||
"Return the deadline time at point in ISO8601 format."
|
"Return the deadline time at point in ISO8601 format."
|
||||||
(when-let ((time (org-get-deadline-time (point))))
|
(when-let ((time (org-get-deadline-time (point))))
|
||||||
(format-time-string "%FT%T" time)))
|
(org-format-time-string "%FT%T%z" time)))
|
||||||
|
|
||||||
(defun org-roam-db-node-p ()
|
(defun org-roam-db-map-headlines (fns)
|
||||||
"Return t if headline at point is an Org-roam node, else return nil."
|
"Run FNS over all headlines in the current buffer."
|
||||||
(and (org-id-get)
|
(org-with-point-at 1
|
||||||
(not (org-entry-get (point) "ROAM_EXCLUDE"))
|
(org-map-entries
|
||||||
(funcall org-roam-db-node-include-function)))
|
(lambda ()
|
||||||
|
(dolist (fn fns)
|
||||||
(defun org-roam-db-map-nodes (fns)
|
(funcall fn))))))
|
||||||
"Run FNS over all nodes in the current buffer."
|
|
||||||
(org-with-wide-buffer
|
|
||||||
(org-map-region
|
|
||||||
(lambda ()
|
|
||||||
(when (org-roam-db-node-p)
|
|
||||||
(dolist (fn fns)
|
|
||||||
(funcall fn))))
|
|
||||||
(point-min) (point-max))))
|
|
||||||
|
|
||||||
(defun org-roam-db-map-links (fns)
|
(defun org-roam-db-map-links (fns)
|
||||||
"Run FNS over all links in the current buffer."
|
"Run FNS over all links in the current buffer."
|
||||||
(org-with-point-at 1
|
(org-with-point-at 1
|
||||||
(while (re-search-forward org-link-any-re nil :no-error)
|
(org-element-map (org-element-parse-buffer) 'link
|
||||||
;; `re-search-forward' let the cursor one character after the link, we need to go backward one char to
|
(lambda (link)
|
||||||
;; make the point be on the link.
|
(dolist (fn fns)
|
||||||
(backward-char)
|
(funcall fn link))))))
|
||||||
(let* ((begin (match-beginning 0))
|
|
||||||
(element (org-element-context))
|
|
||||||
(type (org-element-type element))
|
|
||||||
link)
|
|
||||||
(cond
|
|
||||||
;; Links correctly recognized by Org Mode
|
|
||||||
((eq type 'link)
|
|
||||||
(setq link element))
|
|
||||||
;; Links in property drawers and lines starting with #+. Recall that, as for Org Mode v9.4.4, the
|
|
||||||
;; org-element-type of links within properties drawers is "node-property" and for lines starting with
|
|
||||||
;; #+ is "keyword".
|
|
||||||
((and (member type org-roam-db-extra-links-elements)
|
|
||||||
(not (member-ignore-case (org-element-property :key element)
|
|
||||||
(cdr (assoc type org-roam-db-extra-links-exclude-keys))))
|
|
||||||
(setq link (save-excursion
|
|
||||||
(goto-char begin)
|
|
||||||
(save-match-data (org-element-link-parser)))))))
|
|
||||||
(when link
|
|
||||||
(dolist (fn fns)
|
|
||||||
(funcall fn link)))))))
|
|
||||||
|
|
||||||
(defun org-roam-db-map-citations (info fns)
|
|
||||||
"Run FNS over all citations in the current buffer.
|
|
||||||
INFO is the org-element parsed buffer."
|
|
||||||
(org-element-map info 'citation-reference
|
|
||||||
(lambda (cite)
|
|
||||||
(dolist (fn fns)
|
|
||||||
(funcall fn cite)))))
|
|
||||||
|
|
||||||
(defun org-roam-db-insert-file-node ()
|
(defun org-roam-db-insert-file-node ()
|
||||||
"Insert the file-level node into the Org-roam cache."
|
"Insert the file-level node into the Org-roam cache."
|
||||||
(org-with-point-at 1
|
(org-with-point-at 1
|
||||||
(when (and (= (org-outline-level) 0)
|
(when (= (org-outline-level) 0)
|
||||||
(org-roam-db-node-p))
|
|
||||||
(when-let ((id (org-id-get)))
|
(when-let ((id (org-id-get)))
|
||||||
(let* ((file (buffer-file-name (buffer-base-buffer)))
|
(let* ((file (buffer-file-name (buffer-base-buffer)))
|
||||||
(title (org-roam-db--file-title))
|
(title (or (cadr (assoc "TITLE" (org-collect-keywords '("title"))
|
||||||
|
#'string-equal))
|
||||||
|
(file-relative-name file org-roam-directory)))
|
||||||
(pos (point))
|
(pos (point))
|
||||||
(todo nil)
|
(todo nil)
|
||||||
(priority nil)
|
(priority nil)
|
||||||
(scheduled nil)
|
(scheduled nil)
|
||||||
(deadline nil)
|
(deadline nil)
|
||||||
(level 0)
|
(level 0)
|
||||||
|
(aliases (org-entry-get (point) "ROAM_ALIASES"))
|
||||||
(tags org-file-tags)
|
(tags org-file-tags)
|
||||||
(properties (org-entry-properties))
|
(refs (org-entry-get (point) "ROAM_REFS")))
|
||||||
(olp nil))
|
(condition-case nil
|
||||||
(org-roam-db-query!
|
(progn
|
||||||
(lambda (err)
|
(org-roam-db-query
|
||||||
(lwarn 'org-roam :warning "%s for %s (%s) in %s"
|
[:insert :into nodes
|
||||||
(error-message-string err)
|
:values $v1]
|
||||||
title id file))
|
(vector id file level pos todo priority
|
||||||
[:insert :into nodes
|
scheduled deadline title))
|
||||||
:values $v1]
|
(when tags
|
||||||
(vector id file level pos todo priority
|
(org-roam-db-query
|
||||||
scheduled deadline title properties olp))
|
[:insert :into tags
|
||||||
(when tags
|
:values $v1]
|
||||||
(org-roam-db-query
|
(mapcar (lambda (tag)
|
||||||
[:insert :into tags
|
(vector file id (substring-no-properties tag)))
|
||||||
:values $v1]
|
tags)))
|
||||||
(mapcar (lambda (tag)
|
(when aliases
|
||||||
(vector id (substring-no-properties tag)))
|
(org-roam-db-query
|
||||||
tags)))
|
[:insert :into aliases
|
||||||
(org-roam-db-insert-aliases)
|
:values $v1]
|
||||||
(org-roam-db-insert-refs))))))
|
(mapcar (lambda (alias)
|
||||||
|
(vector file 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 file 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)))))
|
||||||
|
(t
|
||||||
|
(lwarn '(org-roam) :error "Duplicate ID %s, skipping..." id))))))))
|
||||||
|
|
||||||
(cl-defun org-roam-db-insert-node-data ()
|
(defun org-roam-db-insert-node-data ()
|
||||||
"Insert node data for headline at point into the Org-roam cache."
|
"Insert node data for headline at point into the Org-roam cache."
|
||||||
(when-let ((id (org-id-get)))
|
(when-let ((id (org-id-get)))
|
||||||
(let* ((file (buffer-file-name (buffer-base-buffer)))
|
(let* ((file (buffer-file-name (buffer-base-buffer)))
|
||||||
@ -410,139 +333,72 @@ INFO is the org-element parsed buffer."
|
|||||||
(level (nth 1 heading-components))
|
(level (nth 1 heading-components))
|
||||||
(scheduled (org-roam-db-get-scheduled-time))
|
(scheduled (org-roam-db-get-scheduled-time))
|
||||||
(deadline (org-roam-db-get-deadline-time))
|
(deadline (org-roam-db-get-deadline-time))
|
||||||
(title (or (nth 4 heading-components)
|
(title (nth 4 heading-components)))
|
||||||
(progn (lwarn 'org-roam :warning "Node in %s:%s:%s has no title, skipping..."
|
(condition-case nil
|
||||||
file
|
(org-roam-db-query
|
||||||
(line-number-at-pos)
|
[:insert :into nodes
|
||||||
(1+ (- (point) (line-beginning-position))))
|
:values $v1]
|
||||||
(cl-return-from org-roam-db-insert-node-data))))
|
(vector id file level pos todo priority
|
||||||
(properties (org-entry-properties))
|
scheduled deadline title))
|
||||||
(olp (org-get-outline-path nil 'use-cache))
|
(t
|
||||||
(title (org-link-display-format title)))
|
(lwarn '(org-roam) :error
|
||||||
(org-roam-db-query!
|
"Duplicate ID %s, skipping..." id))))))
|
||||||
(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 ()
|
(defun org-roam-db-insert-aliases ()
|
||||||
"Insert aliases for node at point into Org-roam cache."
|
"Insert aliases for node at point into Org-roam cache."
|
||||||
(when-let* ((node-id (org-id-get))
|
(when-let ((file (buffer-file-name (buffer-base-buffer)))
|
||||||
(aliases (org-entry-get (point) "ROAM_ALIASES"))
|
(node-id (org-id-get))
|
||||||
(aliases (split-string-and-unquote aliases)))
|
(aliases (org-entry-get (point) "ROAM_ALIASES")))
|
||||||
(org-roam-db-query [:insert :into aliases
|
(org-roam-db-query [:insert :into aliases
|
||||||
:values $v1]
|
:values $v1]
|
||||||
(mapcar (lambda (alias)
|
(mapcar (lambda (alias)
|
||||||
(vector node-id alias))
|
(vector file node-id alias))
|
||||||
aliases))))
|
(split-string-and-unquote aliases)))))
|
||||||
|
|
||||||
(defun org-roam-db-insert-tags ()
|
(defun org-roam-db-insert-tags ()
|
||||||
"Insert tags for node at point into Org-roam cache."
|
"Insert tags for node at point into Org-roam cache."
|
||||||
(when-let ((node-id (org-id-get))
|
(when-let ((file (buffer-file-name (buffer-base-buffer)))
|
||||||
|
(node-id (org-id-get))
|
||||||
(tags (org-get-tags)))
|
(tags (org-get-tags)))
|
||||||
(org-roam-db-query [:insert :into tags
|
(org-roam-db-query [:insert :into tags
|
||||||
:values $v1]
|
:values $v1]
|
||||||
(mapcar (lambda (tag)
|
(mapcar (lambda (tag)
|
||||||
(vector node-id (substring-no-properties tag))) tags))))
|
(vector file node-id tag)) tags))))
|
||||||
|
|
||||||
(defun org-roam-db-insert-refs ()
|
(defun org-roam-db-insert-refs ()
|
||||||
"Insert refs for node at point into Org-roam cache."
|
"Insert refs for node at point into Org-roam cache."
|
||||||
(when-let* ((node-id (org-id-get))
|
(when-let* ((file (buffer-file-name (buffer-base-buffer)))
|
||||||
|
(node-id (org-id-get))
|
||||||
(refs (org-entry-get (point) "ROAM_REFS"))
|
(refs (org-entry-get (point) "ROAM_REFS"))
|
||||||
(refs (split-string-and-unquote refs)))
|
(refs (split-string-and-unquote refs)))
|
||||||
(let (rows)
|
(let (rows)
|
||||||
(dolist (ref refs)
|
(dolist (ref refs)
|
||||||
(save-match-data
|
(save-match-data
|
||||||
(cond (;; @citeKey
|
(if (string-match org-link-plain-re ref)
|
||||||
(string-prefix-p "@" ref)
|
(progn
|
||||||
(push (vector node-id (substring ref 1) "cite") rows))
|
(push (vector file node-id (match-string 2 ref) (match-string 1 ref)) rows))
|
||||||
(;; [cite:@citeKey]
|
(lwarn '(org-roam) :warning
|
||||||
(string-prefix-p "[cite:" ref)
|
"%s:%s\tInvalid ref %s, skipping..." (buffer-file-name) (point) ref))))
|
||||||
(condition-case nil
|
(org-roam-db-query [:insert :into refs
|
||||||
(let ((cite-obj (org-cite-parse-objects ref)))
|
:values $v1]
|
||||||
(org-element-map cite-obj 'citation-reference
|
rows))))
|
||||||
(lambda (cite)
|
|
||||||
(let ((key (org-element-property :key cite)))
|
|
||||||
(push (vector node-id key "cite") rows)))))
|
|
||||||
(error
|
|
||||||
(lwarn '(org-roam) :warning
|
|
||||||
"%s:%s\tInvalid cite %s, skipping..." (buffer-file-name) (point) ref))))
|
|
||||||
(;; https://google.com, cite:citeKey
|
|
||||||
;; Note: we use string-match here because it matches any link: e.g. [[cite:abc][abc]]
|
|
||||||
;; But this form of matching is loose, and can accept invalid links e.g. [[cite:abc]
|
|
||||||
(string-match org-link-any-re (org-link-encode ref '(#x20)))
|
|
||||||
(setq ref (org-link-encode ref '(#x20)))
|
|
||||||
(let ((ref-url (url-generic-parse-url (or (match-string 2 ref) (match-string 0 ref))))
|
|
||||||
(link-type ()) ;; clear url-type for backward compatible.
|
|
||||||
(path ()))
|
|
||||||
(setq link-type (url-type ref-url))
|
|
||||||
(setf (url-type ref-url) nil)
|
|
||||||
(setq path (org-link-decode (url-recreate-url ref-url)))
|
|
||||||
(if (and (boundp 'org-ref-cite-types)
|
|
||||||
(or (assoc link-type org-ref-cite-types)
|
|
||||||
(member link-type org-ref-cite-types)))
|
|
||||||
(dolist (key (org-roam-org-ref-path-to-keys path))
|
|
||||||
(push (vector node-id key link-type) rows))
|
|
||||||
(push (vector node-id path link-type) rows))))
|
|
||||||
(t
|
|
||||||
(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-insert-link (link)
|
(defun org-roam-db-insert-link (link)
|
||||||
"Insert link data for LINK at current point into the Org-roam cache."
|
"Insert link data for LINK at current point into the Org-roam cache."
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(goto-char (org-element-property :begin link))
|
(goto-char (org-element-property :begin link))
|
||||||
(let* ((type (org-element-property :type link))
|
(let ((file (buffer-file-name (buffer-base-buffer)))
|
||||||
(path (org-element-property :path link))
|
(type (org-element-property :type link))
|
||||||
(option (and (string-match "::\\(.*\\)\\'" path)
|
(dest (org-element-property :path link))
|
||||||
(match-string 1 path)))
|
(properties (list :outline (org-get-outline-path)))
|
||||||
(path (if (not option) path
|
(source (org-roam-id-at-point)))
|
||||||
(substring path 0 (match-beginning 0))))
|
(when source
|
||||||
(source (org-roam-id-at-point))
|
|
||||||
(properties (list :outline (ignore-errors
|
|
||||||
;; This can error if link is not under any headline
|
|
||||||
(org-get-outline-path 'with-self 'use-cache))))
|
|
||||||
(properties (if option (plist-put properties :search-option option)
|
|
||||||
properties)))
|
|
||||||
;; For Org-ref links, we need to split the path into the cite keys
|
|
||||||
(when (and source path)
|
|
||||||
(if (and (boundp 'org-ref-cite-types)
|
|
||||||
(or (assoc type org-ref-cite-types)
|
|
||||||
(member type org-ref-cite-types)))
|
|
||||||
(org-roam-db-query
|
|
||||||
[:insert :into citations
|
|
||||||
:values $v1]
|
|
||||||
(mapcar (lambda (k) (vector source k (point) properties))
|
|
||||||
(org-roam-org-ref-path-to-keys path)))
|
|
||||||
(org-roam-db-query
|
|
||||||
[:insert :into links
|
|
||||||
:values $v1]
|
|
||||||
(vector (point) source path type properties)))))))
|
|
||||||
|
|
||||||
(defun org-roam-db-insert-citation (citation)
|
|
||||||
"Insert data for CITATION at current point into the Org-roam cache."
|
|
||||||
(save-excursion
|
|
||||||
(goto-char (org-element-property :begin citation))
|
|
||||||
(let ((key (org-element-property :key citation))
|
|
||||||
(source (org-roam-id-at-point))
|
|
||||||
(properties (list :outline (ignore-errors
|
|
||||||
;; This can error if link is not under any headline
|
|
||||||
(org-get-outline-path 'with-self 'use-cache)))))
|
|
||||||
(when (and source key)
|
|
||||||
(org-roam-db-query
|
(org-roam-db-query
|
||||||
[:insert :into citations
|
[:insert :into links
|
||||||
:values $v1]
|
:values $v1]
|
||||||
(vector source key (point) properties))))))
|
(vector file (point) source dest type properties))))))
|
||||||
|
|
||||||
;;;; Fetching
|
;;;;; Fetching
|
||||||
(defun org-roam-db--get-current-files ()
|
(defun org-roam-db--get-current-files ()
|
||||||
"Return a hash-table of file to the hash of its file contents."
|
"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]))
|
(let ((current-files (org-roam-db-query [:select [file hash] :from files]))
|
||||||
@ -551,69 +407,27 @@ INFO is the org-element parsed buffer."
|
|||||||
(puthash (car row) (cadr row) ht))
|
(puthash (car row) (cadr row) ht))
|
||||||
ht))
|
ht))
|
||||||
|
|
||||||
(defun org-roam-db--file-hash (file-path)
|
(defun org-roam-db--file-hash (&optional file-path)
|
||||||
"Compute the hash of FILE-PATH."
|
"Compute the hash of FILE-PATH, a file or current buffer."
|
||||||
(with-temp-buffer
|
(if file-path
|
||||||
(set-buffer-multibyte nil)
|
(with-temp-buffer
|
||||||
(insert-file-contents-literally file-path)
|
(set-buffer-multibyte nil)
|
||||||
(secure-hash 'sha1 (current-buffer))))
|
(insert-file-contents-literally file-path)
|
||||||
|
(secure-hash 'sha1 (current-buffer)))
|
||||||
|
(org-with-wide-buffer
|
||||||
|
(secure-hash 'sha1 (current-buffer)))))
|
||||||
|
|
||||||
;;;; Synchronization
|
;;;;; Updating
|
||||||
(defun org-roam-db-update-file (&optional file-path no-require)
|
|
||||||
"Update Org-roam cache for FILE-PATH.
|
|
||||||
|
|
||||||
If the file does not exist anymore, remove it from the cache.
|
|
||||||
|
|
||||||
If the file exists, update the cache with information.
|
|
||||||
|
|
||||||
If NO-REQUIRE, don't require optional libraries. Set NO-REQUIRE
|
|
||||||
when the libraries are already required at some toplevel, e.g.
|
|
||||||
in `org-roam-db-sync'."
|
|
||||||
(setq file-path (or file-path (buffer-file-name (buffer-base-buffer))))
|
|
||||||
(let ((content-hash (org-roam-db--file-hash file-path))
|
|
||||||
(db-hash (caar (org-roam-db-query [:select hash :from files
|
|
||||||
:where (= file $s1)] file-path)))
|
|
||||||
info)
|
|
||||||
(unless (string= content-hash db-hash)
|
|
||||||
(unless no-require
|
|
||||||
(org-roam-require '(org-ref oc)))
|
|
||||||
(org-roam-with-file file-path nil
|
|
||||||
(emacsql-with-transaction (org-roam-db)
|
|
||||||
(org-with-wide-buffer
|
|
||||||
(org-set-regexps-and-options 'tags-only)
|
|
||||||
;; Org doesn't use this anymore, so we probably should stop too.
|
|
||||||
;; (org-refresh-category-properties)
|
|
||||||
(org-roam-db-clear-file)
|
|
||||||
(org-roam-db-insert-file content-hash)
|
|
||||||
(org-roam-db-insert-file-node)
|
|
||||||
(setq org-outline-path-cache nil)
|
|
||||||
(org-roam-db-map-nodes
|
|
||||||
(list #'org-roam-db-insert-node-data
|
|
||||||
#'org-roam-db-insert-aliases
|
|
||||||
#'org-roam-db-insert-tags
|
|
||||||
#'org-roam-db-insert-refs))
|
|
||||||
(setq org-outline-path-cache nil)
|
|
||||||
(setq info (org-element-parse-buffer))
|
|
||||||
(org-roam-db-map-links
|
|
||||||
(list #'org-roam-db-insert-link))
|
|
||||||
(when (fboundp 'org-cite-insert)
|
|
||||||
(require 'oc) ;ensure feature is loaded
|
|
||||||
(org-roam-db-map-citations
|
|
||||||
info
|
|
||||||
(list #'org-roam-db-insert-citation)))))))))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun org-roam-db-sync (&optional force)
|
(defun org-roam-db-sync (&optional force)
|
||||||
"Synchronize the cache state with the current Org files on-disk.
|
"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")
|
||||||
(org-roam-db--close) ;; Force a reconnect
|
|
||||||
(when force (delete-file org-roam-db-location))
|
(when force (delete-file org-roam-db-location))
|
||||||
|
(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
|
||||||
(org-roam-require '(org-ref oc))
|
|
||||||
(let* ((gc-cons-threshold org-roam-db-gc-threshold)
|
(let* ((gc-cons-threshold org-roam-db-gc-threshold)
|
||||||
(org-agenda-files nil)
|
(org-agenda-files nil)
|
||||||
(org-roam-files (org-roam-list-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))
|
||||||
(modified-files nil))
|
(modified-files nil))
|
||||||
(dolist (file org-roam-files)
|
(dolist (file org-roam-files)
|
||||||
@ -622,116 +436,49 @@ If FORCE, force a rebuild of the cache from scratch."
|
|||||||
contents-hash)
|
contents-hash)
|
||||||
(push file modified-files)))
|
(push file modified-files)))
|
||||||
(remhash file current-files))
|
(remhash file current-files))
|
||||||
(emacsql-with-transaction (org-roam-db)
|
(if (fboundp 'dolist-with-progress-reporter)
|
||||||
(org-roam-dolist-with-progress (file (hash-table-keys current-files))
|
(dolist-with-progress-reporter (file (hash-table-keys current-files))
|
||||||
"Clearing removed files..."
|
"Clearing removed files..."
|
||||||
(org-roam-db-clear-file file))
|
(org-roam-db-clear-file file))
|
||||||
(org-roam-dolist-with-progress (file modified-files)
|
(dolist (file (hash-table-keys current-files))
|
||||||
"Processing modified files..."
|
(org-roam-db-clear-file file)))
|
||||||
(condition-case err
|
(if (fboundp 'dolist-with-progress-reporter)
|
||||||
(org-roam-db-update-file file 'no-require)
|
(dolist-with-progress-reporter (file modified-files)
|
||||||
(error
|
"Processing modified files..."
|
||||||
(org-roam-db-clear-file file)
|
(org-roam-db-update-file file))
|
||||||
(lwarn 'org-roam :error "Failed to process %s with error %s, skipping..."
|
(dolist (file modified-files)
|
||||||
file (error-message-string err))))))))
|
(org-roam-db-update-file file)))))
|
||||||
|
|
||||||
;;;###autoload
|
(defun org-roam-db-update-file (&optional file-path)
|
||||||
(define-minor-mode org-roam-db-autosync-mode
|
"Update Org-roam cache for FILE-PATH.
|
||||||
"Global minor mode to keep your Org-roam session automatically synchronized.
|
If the file does not exist anymore, remove it from the cache.
|
||||||
Through the session this will continue to setup your
|
If the file exists, update the cache with information."
|
||||||
buffers (that are Org-roam file visiting), keep track of the
|
(setq file-path (or file-path (buffer-file-name (buffer-base-buffer))))
|
||||||
related changes, maintain cache consistency and incrementally
|
(let ((content-hash (org-roam-db--file-hash file-path))
|
||||||
update the currently active database.
|
(db-hash (caar (org-roam-db-query [:select hash :from files
|
||||||
|
:where (= file $s1)] file-path))))
|
||||||
|
(unless (string= content-hash db-hash)
|
||||||
|
(org-roam-with-file file-path nil
|
||||||
|
(save-excursion
|
||||||
|
(org-set-regexps-and-options 'tags-only)
|
||||||
|
(org-roam-db-clear-file)
|
||||||
|
(org-roam-db-insert-file)
|
||||||
|
(org-roam-db-insert-file-node)
|
||||||
|
(org-roam-db-map-headlines
|
||||||
|
(list #'org-roam-db-insert-node-data
|
||||||
|
#'org-roam-db-insert-aliases
|
||||||
|
#'org-roam-db-insert-tags
|
||||||
|
#'org-roam-db-insert-refs))
|
||||||
|
(org-roam-db-map-links
|
||||||
|
(list #'org-roam-db-insert-link)))))))
|
||||||
|
|
||||||
If you need to manually trigger resync of the currently active
|
(defun org-roam-db--update-on-save-h ()
|
||||||
database, see `org-roam-db-sync' command."
|
"."
|
||||||
:group 'org-roam
|
(add-hook 'after-save-hook #'org-roam-db-update-file nil t))
|
||||||
:global t
|
|
||||||
:init-value nil
|
|
||||||
(let ((enabled org-roam-db-autosync-mode))
|
|
||||||
(cond
|
|
||||||
(enabled
|
|
||||||
(add-hook 'find-file-hook #'org-roam-db-autosync--setup-file-h)
|
|
||||||
(add-hook 'kill-emacs-hook #'org-roam-db--close-all)
|
|
||||||
(advice-add #'rename-file :after #'org-roam-db-autosync--rename-file-a)
|
|
||||||
(advice-add #'delete-file :before #'org-roam-db-autosync--delete-file-a)
|
|
||||||
(advice-add #'vc-delete-file :around #'org-roam-db-autosync--vc-delete-file-a)
|
|
||||||
(org-roam-db-sync))
|
|
||||||
(t
|
|
||||||
(remove-hook 'find-file-hook #'org-roam-db-autosync--setup-file-h)
|
|
||||||
(remove-hook 'kill-emacs-hook #'org-roam-db--close-all)
|
|
||||||
(advice-remove #'rename-file #'org-roam-db-autosync--rename-file-a)
|
|
||||||
(advice-remove #'delete-file #'org-roam-db-autosync--delete-file-a)
|
|
||||||
(advice-remove #'vc-delete-file #'org-roam-db-autosync--vc-delete-file-a)
|
|
||||||
(org-roam-db--close-all)
|
|
||||||
;; Disable local hooks for all org-roam buffers
|
|
||||||
(dolist (buf (org-roam-buffer-list))
|
|
||||||
(with-current-buffer buf
|
|
||||||
(remove-hook 'after-save-hook #'org-roam-db-autosync--try-update-on-save-h t)))))))
|
|
||||||
|
|
||||||
;;;###autoload
|
(add-to-list 'org-roam-find-file-hook #'org-roam-db--update-on-save-h)
|
||||||
(defun org-roam-db-autosync-enable ()
|
|
||||||
"Activate `org-roam-db-autosync-mode'."
|
|
||||||
(org-roam-db-autosync-mode +1))
|
|
||||||
|
|
||||||
(defun org-roam-db-autosync-disable ()
|
;; Diagnostic Interactives
|
||||||
"Deactivate `org-roam-db-autosync-mode'."
|
|
||||||
(org-roam-db-autosync-mode -1))
|
|
||||||
|
|
||||||
(defun org-roam-db-autosync-toggle ()
|
|
||||||
"Toggle `org-roam-db-autosync-mode' enabled/disabled."
|
|
||||||
(org-roam-db-autosync-mode 'toggle))
|
|
||||||
|
|
||||||
(defun org-roam-db-autosync--delete-file-a (file &optional _trash)
|
|
||||||
"Maintain cache consistency when file deletes.
|
|
||||||
FILE is removed from the database."
|
|
||||||
(when (and (not (auto-save-file-name-p file))
|
|
||||||
(not (backup-file-name-p file))
|
|
||||||
(org-roam-file-p file))
|
|
||||||
(org-roam-db-clear-file (expand-file-name file))))
|
|
||||||
|
|
||||||
(defun org-roam-db-autosync--vc-delete-file-a (fun file)
|
|
||||||
"Maintain cache consistency on file deletion by FUN.
|
|
||||||
FILE is removed from the database."
|
|
||||||
(let ((org-roam-file-p (and (not (auto-save-file-name-p file))
|
|
||||||
(not (backup-file-name-p file))
|
|
||||||
(org-roam-file-p file))))
|
|
||||||
(apply fun `(,file))
|
|
||||||
(when (and org-roam-file-p
|
|
||||||
(not (file-exists-p file)))
|
|
||||||
(org-roam-db-clear-file (expand-file-name file)))))
|
|
||||||
|
|
||||||
(defun org-roam-db-autosync--rename-file-a (old-file new-file-or-dir &rest _args)
|
|
||||||
"Maintain cache consistency of file rename.
|
|
||||||
OLD-FILE is cleared from the database, and NEW-FILE-OR-DIR is added."
|
|
||||||
(let ((new-file (if (directory-name-p new-file-or-dir)
|
|
||||||
(expand-file-name (file-name-nondirectory old-file) new-file-or-dir)
|
|
||||||
new-file-or-dir)))
|
|
||||||
(setq new-file (expand-file-name new-file))
|
|
||||||
(setq old-file (expand-file-name old-file))
|
|
||||||
(when (and (not (auto-save-file-name-p old-file))
|
|
||||||
(not (auto-save-file-name-p new-file))
|
|
||||||
(not (backup-file-name-p old-file))
|
|
||||||
(not (backup-file-name-p new-file))
|
|
||||||
(org-roam-file-p old-file))
|
|
||||||
(org-roam-db-clear-file old-file))
|
|
||||||
(when (org-roam-file-p new-file)
|
|
||||||
(org-roam-db-update-file new-file))))
|
|
||||||
|
|
||||||
(defun org-roam-db-autosync--setup-file-h ()
|
|
||||||
"Setup the current buffer if it visits an Org-roam file."
|
|
||||||
(when (org-roam-file-p) (run-hooks 'org-roam-find-file-hook)))
|
|
||||||
|
|
||||||
(add-hook 'org-roam-find-file-hook #'org-roam-db-autosync--setup-update-on-save-h)
|
|
||||||
(defun org-roam-db-autosync--setup-update-on-save-h ()
|
|
||||||
"Setup the current buffer to update the DB after saving the current file."
|
|
||||||
(add-hook 'after-save-hook #'org-roam-db-autosync--try-update-on-save-h nil t))
|
|
||||||
|
|
||||||
(defun org-roam-db-autosync--try-update-on-save-h ()
|
|
||||||
"If appropriate, update the database for the current file after saving buffer."
|
|
||||||
(when org-roam-db-update-on-save (org-roam-db-update-file)))
|
|
||||||
|
|
||||||
;;; Diagnostics
|
|
||||||
(defun org-roam-db-diagnose-node ()
|
(defun org-roam-db-diagnose-node ()
|
||||||
"Print information about node at point."
|
"Print information about node at point."
|
||||||
(interactive)
|
(interactive)
|
||||||
|
221
org-roam-doctor.el
Normal file
221
org-roam-doctor.el
Normal file
@ -0,0 +1,221 @@
|
|||||||
|
;;; 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: 2.0.0
|
||||||
|
;; Package-Requires: ((emacs "26.1") (dash "2.13") (f "0.17.2") (org "9.4") (emacsql "3.0.0") (emacsql-sqlite3 "1.0.2") (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 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 'dash)
|
||||||
|
(eval-when-compile
|
||||||
|
(require 'org-roam-macs))
|
||||||
|
(require 'org-roam)
|
||||||
|
|
||||||
|
(defvar org-roam-mode-map)
|
||||||
|
|
||||||
|
(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")
|
||||||
|
|
||||||
|
(defvar org-roam-verbose)
|
||||||
|
|
||||||
|
(defcustom org-roam-doctor-inhibit-startup t
|
||||||
|
"Inhibit `org-mode' startup when processing files with `org-doctor'.
|
||||||
|
When non-nil, images and LaTeX preview will not be generated,
|
||||||
|
tables will not be aligned, and headlines will not respect
|
||||||
|
startup visability. This significantly improves performance when
|
||||||
|
processing multiple files"
|
||||||
|
:type 'boolean
|
||||||
|
:group 'org-roam)
|
||||||
|
|
||||||
|
(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))))))
|
||||||
|
|
||||||
|
(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 "id" (org-element-property :type l))
|
||||||
|
(let ((id (org-element-property :path l)))
|
||||||
|
(unless (org-id-find id)
|
||||||
|
(push `(,(org-element-property :begin l)
|
||||||
|
,(format "Broken id link \"%s\"" id))
|
||||||
|
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-node-insert))
|
||||||
|
(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")
|
||||||
|
(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))
|
||||||
|
(org-inhibit-startup org-roam-doctor-inhibit-startup))
|
||||||
|
(org-id-update-id-locations)
|
||||||
|
(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,94 +0,0 @@
|
|||||||
;;; org-roam-id.el --- ID-related utilities for Org-roam -*- lexical-binding: t; -*-
|
|
||||||
|
|
||||||
;; Copyright © 2020-2025 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.3.1
|
|
||||||
;; Package-Requires: ((emacs "26.1") (dash "2.13") (org "9.6") (magit-section "3.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 module provides ID-related facilities using the Org-roam database.
|
|
||||||
;;
|
|
||||||
;;; Code:
|
|
||||||
(require 'org-id)
|
|
||||||
|
|
||||||
(defun org-roam-id-at-point ()
|
|
||||||
"Return the ID at point, if any.
|
|
||||||
Recursively traverses up the headline tree to find the
|
|
||||||
first encapsulating ID."
|
|
||||||
(org-with-wide-buffer
|
|
||||||
(org-back-to-heading-or-point-min t)
|
|
||||||
(while (and (not (org-roam-db-node-p))
|
|
||||||
(not (bobp)))
|
|
||||||
(org-roam-up-heading-or-point-min))
|
|
||||||
(when (org-roam-db-node-p)
|
|
||||||
(org-id-get))))
|
|
||||||
|
|
||||||
(defun org-roam-id-find (id &optional markerp)
|
|
||||||
"Return the location of the entry with the id ID using the Org-roam db.
|
|
||||||
The return value is a cons cell (file-name . position), or nil
|
|
||||||
if there is no entry with that ID.
|
|
||||||
With optional argument MARKERP, return the position as a new marker."
|
|
||||||
(cond
|
|
||||||
((symbolp id) (setq id (symbol-name id)))
|
|
||||||
((numberp id) (setq id (number-to-string id))))
|
|
||||||
(let ((node (org-roam-populate (org-roam-node-create :id id))))
|
|
||||||
(when-let ((file (org-roam-node-file node)))
|
|
||||||
(if markerp
|
|
||||||
(let ((buffer (or (find-buffer-visiting file)
|
|
||||||
(find-file-noselect file))))
|
|
||||||
(with-current-buffer buffer
|
|
||||||
(move-marker (make-marker) (org-roam-node-point node) buffer)))
|
|
||||||
(cons (org-roam-node-file node)
|
|
||||||
(org-roam-node-point node))))))
|
|
||||||
|
|
||||||
(defalias 'org-roam-id-open 'org-id-open
|
|
||||||
"Obsolete alias - use `org-id-open' directly.")
|
|
||||||
|
|
||||||
(advice-add 'org-id-find :before-until #'org-roam-id-find)
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun org-roam-update-org-id-locations (&rest directories)
|
|
||||||
"Scan Org-roam files to update `org-id' related state.
|
|
||||||
This is like `org-id-update-id-locations', but will automatically
|
|
||||||
use the currently bound `org-directory' and `org-roam-directory'
|
|
||||||
along with DIRECTORIES (if any), where the lookup for files in
|
|
||||||
these directories will be always recursive.
|
|
||||||
|
|
||||||
Note: Org-roam doesn't have hard dependency on
|
|
||||||
`org-id-locations-file' to lookup IDs for nodes that are stored
|
|
||||||
in the database, but it still tries to properly integrates with
|
|
||||||
`org-id'. This allows the user to cross-reference IDs outside of
|
|
||||||
the current `org-roam-directory', and also link with \"id:\"
|
|
||||||
links to headings/files within the current `org-roam-directory'
|
|
||||||
that are excluded from identification in Org-roam as
|
|
||||||
`org-roam-node's, e.g. with \"ROAM_EXCLUDE\" property."
|
|
||||||
(interactive)
|
|
||||||
(cl-loop for dir in (cons org-roam-directory directories)
|
|
||||||
for org-roam-directory = dir
|
|
||||||
nconc (org-roam-list-files) into files
|
|
||||||
finally (org-id-update-id-locations files org-roam-verbose)))
|
|
||||||
|
|
||||||
(provide 'org-roam-id)
|
|
||||||
|
|
||||||
;;; org-roam-id.el ends here
|
|
@ -1,53 +0,0 @@
|
|||||||
;;; org-roam-log.el --- Integrations with Org-log -*- coding: utf-8; lexical-binding: t; -*-
|
|
||||||
|
|
||||||
;; Copyright © 2022-2025 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.3.1
|
|
||||||
;; Package-Requires: ((emacs "26.1") (dash "2.13") (org "9.6") (emacsql "4.1.0") (magit-section "3.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 module provides integrations with Org-log.
|
|
||||||
;;
|
|
||||||
;;; Code:
|
|
||||||
(require 'org-roam)
|
|
||||||
|
|
||||||
(defcustom org-roam-log-setup-hook nil
|
|
||||||
"Hook run when a log for an Org-roam file is setup."
|
|
||||||
:group 'org-roam
|
|
||||||
:type 'hook)
|
|
||||||
|
|
||||||
(defun org-roam-log-p ()
|
|
||||||
"Return t if the log buffer is for an Org-roam file, nil otherwise."
|
|
||||||
(and org-log-note-marker
|
|
||||||
(org-roam-file-p (buffer-file-name (marker-buffer org-log-note-marker)))))
|
|
||||||
|
|
||||||
(defun org-roam-log--setup ()
|
|
||||||
"Run hooks in `org-roam-log-setup-hook'."
|
|
||||||
(run-hooks 'org-roam-log-setup-hook))
|
|
||||||
|
|
||||||
(add-hook 'org-roam-log-setup-hook #'org-roam--register-completion-functions-h)
|
|
||||||
(add-hook 'org-log-buffer-setup-hook #'org-roam-log--setup)
|
|
||||||
|
|
||||||
(provide 'org-roam-log)
|
|
||||||
;;; org-roam-log.el ends here
|
|
86
org-roam-macs.el
Normal file
86
org-roam-macs.el
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
;;; org-roam-macs.el --- Macros/utility functions -*- 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-sqlite3 "1.0.2") (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 macros used throughout org-roam.
|
||||||
|
;;
|
||||||
|
;;; Code:
|
||||||
|
(defmacro org-roam-plist-map! (fn plist)
|
||||||
|
"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)))))))
|
||||||
|
|
||||||
|
(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
|
||||||
|
(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 (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)
|
||||||
|
"Execute BODY within a temp buffer.
|
||||||
|
Like `with-temp-buffer', but propagates `org-roam-directory'.
|
||||||
|
If FILE, set `default-directory' to FILE's directory and insert its contents."
|
||||||
|
(declare (indent 1) (debug t))
|
||||||
|
(let ((current-org-roam-directory (make-symbol "current-org-roam-directory")))
|
||||||
|
`(let ((,current-org-roam-directory org-roam-directory))
|
||||||
|
(with-temp-buffer
|
||||||
|
(let ((org-roam-directory ,current-org-roam-directory))
|
||||||
|
(delay-mode-hooks (org-mode))
|
||||||
|
(when ,file
|
||||||
|
(insert-file-contents ,file)
|
||||||
|
(setq-local default-directory (file-name-directory ,file)))
|
||||||
|
,@body)))))
|
||||||
|
|
||||||
|
(provide 'org-roam-macs)
|
||||||
|
|
||||||
|
;;; org-roam-macs.el ends here
|
@ -1,168 +0,0 @@
|
|||||||
;;; org-roam-migrate.el --- Migration utilities from v1 to v2 -*- coding: utf-8; lexical-binding: t; -*-
|
|
||||||
|
|
||||||
;; Copyright © 2020-2025 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.3.1
|
|
||||||
;; Package-Requires: ((emacs "26.1") (dash "2.13") (org "9.6") (emacsql "4.1.0") (magit-section "3.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 is a special library provided for the v1 users of this package. It's
|
|
||||||
;; purpose is to ease the transition from v1 to v2, by providing migration
|
|
||||||
;; utilities to convert from v1 notes to v2 nodes.
|
|
||||||
;;
|
|
||||||
;;; Code:
|
|
||||||
(require 'org-roam)
|
|
||||||
|
|
||||||
;;; Migration wizard (v1 -> v2)
|
|
||||||
;;;###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))
|
|
||||||
|
|
||||||
;; Upgrade database to v2
|
|
||||||
(org-roam-db-sync 'force)
|
|
||||||
|
|
||||||
;; Convert v1 to v2
|
|
||||||
(dolist (f (org-roam-list-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-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"))))))
|
|
||||||
(dolist (alias aliases)
|
|
||||||
(org-roam-alias-add alias)))
|
|
||||||
(let ((case-fold-search t))
|
|
||||||
(org-with-point-at 1
|
|
||||||
(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 (cl-mapcan (lambda (value)
|
|
||||||
(cl-mapcan
|
|
||||||
(lambda (k) (org-split-string k ":"))
|
|
||||||
(split-string value)))
|
|
||||||
(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" (org-make-tag-string 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) nil t)))))))
|
|
||||||
|
|
||||||
(provide 'org-roam-migrate)
|
|
||||||
;;; org-roam-migrate.el ends here
|
|
664
org-roam-mode.el
664
org-roam-mode.el
@ -1,12 +1,11 @@
|
|||||||
;;; org-roam-mode.el --- Major mode for special Org-roam buffers -*- lexical-binding: t -*-
|
;;; org-roam-mode.el --- create and refresh Org-roam buffers -*- lexical-binding: t -*-
|
||||||
|
;; Copyright © 2020 Jethro Kuan <jethrokuan95@gmail.com>
|
||||||
;; Copyright © 2020-2025 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: 2.3.1
|
;; Version: 2.0.0
|
||||||
;; Package-Requires: ((emacs "26.1") (dash "2.13") (org "9.6") (emacsql "4.1.0") (magit-section "3.0.0"))
|
;; Package-Requires: ((emacs "26.1") (dash "2.13") (f "0.17.2") (org "9.4") (emacsql "3.0.0") (emacsql-sqlite3 "1.0.2") (magit-section "2.90.1"))
|
||||||
|
|
||||||
;; This file is NOT part of GNU Emacs.
|
;; This file is NOT part of GNU Emacs.
|
||||||
|
|
||||||
@ -27,64 +26,19 @@
|
|||||||
|
|
||||||
;;; Commentary:
|
;;; Commentary:
|
||||||
;;
|
;;
|
||||||
;; This module implements `org-roam-mode', which is a major mode that used by
|
;; This library implements the abstract major-mode `org-roam-mode', from which
|
||||||
;; special Org-roam buffers to display various content in a section-like manner
|
;; almost all other Org-roam major-modes derive.
|
||||||
;; about the nodes and relevant to them information (e.g. backlinks) with which
|
|
||||||
;; the user can interact with.
|
|
||||||
;;
|
;;
|
||||||
;;; Code:
|
;;; Code:
|
||||||
(require 'org-roam)
|
(require 'magit-section)
|
||||||
|
|
||||||
;;;; Declarations
|
(require 'org-roam-utils)
|
||||||
(defvar org-ref-buffer-hacked)
|
|
||||||
|
|
||||||
;;; Options
|
(defvar org-roam-directory)
|
||||||
(defcustom org-roam-mode-sections (list #'org-roam-backlinks-section
|
(defvar org-roam-find-file-hook)
|
||||||
#'org-roam-reflinks-section)
|
|
||||||
"A list of sections for the `org-roam-mode' based buffers.
|
|
||||||
Each section is a function that is passed the `org-roam-node'
|
|
||||||
for which the section will be constructed as the first
|
|
||||||
argument. Normally this node is `org-roam-buffer-current-node'.
|
|
||||||
The function may also accept other optional arguments. Each item
|
|
||||||
in the list is either:
|
|
||||||
|
|
||||||
1. A function, which is called only with the `org-roam-node' as the argument
|
(declare-function org-roam--org-file-p "org-roam")
|
||||||
2. A list, containing the function and the optional arguments.
|
(declare-function org-roam-node-at-point "org-roam")
|
||||||
|
|
||||||
For example, one can add
|
|
||||||
|
|
||||||
(org-roam-backlinks-section :unique t)
|
|
||||||
|
|
||||||
to the list to pass :unique t to the section-rendering function."
|
|
||||||
:group 'org-roam
|
|
||||||
:type `(repeat (choice (symbol :tag "Function")
|
|
||||||
(list :tag "Function with arguments"
|
|
||||||
(symbol :tag "Function")
|
|
||||||
(repeat :tag "Arguments" :inline t (sexp :tag "Arg"))))))
|
|
||||||
|
|
||||||
(defcustom org-roam-buffer-postrender-functions (list)
|
|
||||||
"Functions to run after the Org-roam buffer is rendered.
|
|
||||||
Each function accepts no arguments, and is run with the Org-roam
|
|
||||||
buffer as the current buffer."
|
|
||||||
:group 'org-roam
|
|
||||||
:type 'hook)
|
|
||||||
|
|
||||||
(defcustom org-roam-preview-function #'org-roam-preview-default-function
|
|
||||||
"The preview function to use to populate the Org-roam buffer.
|
|
||||||
|
|
||||||
The function takes no arguments, but the point is temporarily set
|
|
||||||
to the exact location of the backlink."
|
|
||||||
:group 'org-roam
|
|
||||||
:type 'function)
|
|
||||||
|
|
||||||
(defcustom org-roam-preview-postprocess-functions (list #'org-roam-strip-comments)
|
|
||||||
"A list of functions to postprocess the preview content.
|
|
||||||
|
|
||||||
Each function takes a single argument, the string for the preview
|
|
||||||
content, and returns the post-processed string. The functions are
|
|
||||||
applied in order of appearance in the list."
|
|
||||||
:group 'org-roam
|
|
||||||
:type 'hook)
|
|
||||||
|
|
||||||
;;; Faces
|
;;; Faces
|
||||||
(defface org-roam-header-line
|
(defface org-roam-header-line
|
||||||
@ -166,160 +120,84 @@ and `:slant'."
|
|||||||
"Face for the dimmer part of the widgets."
|
"Face for the dimmer part of the widgets."
|
||||||
:group 'org-roam-faces)
|
:group 'org-roam-faces)
|
||||||
|
|
||||||
;;; Major mode
|
;;; Variables
|
||||||
|
(defvar org-roam-current-node nil
|
||||||
|
"The current node at point.")
|
||||||
|
|
||||||
|
(defcustom org-roam-mode-sections (list #'org-roam-backlinks-section
|
||||||
|
#'org-roam-reflinks-section)
|
||||||
|
"List of functions that insert sections for Org-roam."
|
||||||
|
:group 'org-roam
|
||||||
|
:type '(repeat function))
|
||||||
|
|
||||||
|
;;; The mode
|
||||||
(defvar org-roam-mode-map
|
(defvar org-roam-mode-map
|
||||||
(let ((map (make-sparse-keymap)))
|
(let ((map (make-sparse-keymap)))
|
||||||
(set-keymap-parent map magit-section-mode-map)
|
(set-keymap-parent map magit-section-mode-map)
|
||||||
(define-key map [C-return] 'org-roam-buffer-visit-thing)
|
(define-key map [C-return] 'org-roam-visit-thing)
|
||||||
(define-key map (kbd "C-m") 'org-roam-buffer-visit-thing)
|
(define-key map (kbd "C-m") 'org-roam-visit-thing)
|
||||||
(define-key map [remap revert-buffer] 'org-roam-buffer-refresh)
|
(define-key map [remap revert-buffer] 'org-roam-buffer-render)
|
||||||
map)
|
map)
|
||||||
"Parent keymap for all keymaps of modes derived from `org-roam-mode'.")
|
"Parent keymap for all keymaps of modes derived from `org-roam-mode'.")
|
||||||
|
|
||||||
(define-derived-mode org-roam-mode magit-section-mode "Org-roam"
|
(define-derived-mode org-roam-mode magit-section-mode "Org-roam"
|
||||||
"Major mode for displaying relevant information about Org-roam nodes.
|
"Major mode for Org-roam's buffer."
|
||||||
This mode is used by special Org-roam buffers, such as persistent
|
|
||||||
`org-roam-buffer' and dedicated Org-roam buffers
|
|
||||||
\(`org-roam-buffer-display-dedicated'), which render the
|
|
||||||
information in a section-like manner (see
|
|
||||||
`org-roam-mode-sections'), with which the user can
|
|
||||||
interact with."
|
|
||||||
:group 'org-roam
|
:group 'org-roam
|
||||||
(face-remap-add-relative 'header-line 'org-roam-header-line))
|
(face-remap-add-relative 'header-line 'org-roam-header-line))
|
||||||
|
|
||||||
;;; Buffers
|
;;; Key functions
|
||||||
(defvar org-roam-buffer-current-node nil
|
(defun org-roam-visit-thing ()
|
||||||
"The node for which an `org-roam-mode' based buffer displays its contents.
|
|
||||||
This set both, locally and globally. Normally the local value is
|
|
||||||
only set in the `org-roam-mode' based buffers, while the global
|
|
||||||
value shows the current node in the persistent `org-roam-buffer'.")
|
|
||||||
|
|
||||||
(put 'org-roam-buffer-current-node 'permanent-local t)
|
|
||||||
|
|
||||||
(defvar org-roam-buffer-current-directory nil
|
|
||||||
"The `org-roam-directory' value of `org-roam-buffer-current-node'.
|
|
||||||
Set both, locally and globally in the same way as
|
|
||||||
`org-roam-buffer-current-node'.")
|
|
||||||
|
|
||||||
(put 'org-roam-buffer-current-directory 'permanent-local t)
|
|
||||||
|
|
||||||
;;;; Library
|
|
||||||
(defun org-roam-buffer-visit-thing ()
|
|
||||||
"This is a placeholder command.
|
"This is a placeholder command.
|
||||||
Where applicable, section-specific keymaps bind another command
|
Where applicable, section-specific keymaps bind another command
|
||||||
which visits the thing at point."
|
which visits the thing at point."
|
||||||
(interactive)
|
(interactive)
|
||||||
(user-error "There is no thing at point that could be visited"))
|
(user-error "There is no thing at point that could be visited"))
|
||||||
|
|
||||||
(defun org-roam-buffer-file-at-point (&optional assert)
|
(defun org-roam-buffer-render ()
|
||||||
"Return the file at point in the current `org-roam-mode' based buffer.
|
"Render the current node 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))
|
|
||||||
(t (cl-assert (derived-mode-p 'org-roam-mode))))))
|
|
||||||
file
|
|
||||||
(when assert
|
|
||||||
(user-error "No file at point"))))
|
|
||||||
|
|
||||||
(defun org-roam-buffer-refresh ()
|
|
||||||
"Refresh the contents of the currently selected Org-roam buffer."
|
|
||||||
(interactive)
|
(interactive)
|
||||||
(cl-assert (derived-mode-p 'org-roam-mode))
|
(when (derived-mode-p 'org-roam-mode)
|
||||||
(save-excursion (org-roam-buffer-render-contents)))
|
(let ((inhibit-read-only t))
|
||||||
|
(erase-buffer)
|
||||||
|
(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-sections)
|
||||||
|
(funcall fn org-roam-current-node))))))
|
||||||
|
|
||||||
(defun org-roam-buffer-render-contents ()
|
(defun org-roam-buffer ()
|
||||||
"Recompute and render the contents of an Org-roam buffer.
|
"Launch an Org-roam buffer for the current node at point."
|
||||||
Assumes that the current buffer is an `org-roam-mode' based
|
(interactive)
|
||||||
buffer."
|
(if-let ((node (org-roam-node-at-point)))
|
||||||
(let ((inhibit-read-only t))
|
(progn
|
||||||
(erase-buffer)
|
(let ((buffer (get-buffer-create
|
||||||
(org-roam-mode)
|
(concat "org-roam: "
|
||||||
(setq-local default-directory org-roam-buffer-current-directory)
|
(file-relative-name (buffer-file-name) org-roam-directory)))))
|
||||||
(setq-local org-roam-directory org-roam-buffer-current-directory)
|
(with-current-buffer buffer
|
||||||
(org-roam-buffer-set-header-line-format
|
(org-roam-mode)
|
||||||
(org-roam-node-title org-roam-buffer-current-node))
|
(setq-local org-roam-current-node node)
|
||||||
(magit-insert-section (org-roam)
|
(org-roam-buffer-render))
|
||||||
(magit-insert-heading)
|
(switch-to-buffer-other-window buffer)))
|
||||||
(dolist (section org-roam-mode-sections)
|
(user-error "No node at point")))
|
||||||
(pcase section
|
|
||||||
((pred functionp)
|
|
||||||
(funcall section org-roam-buffer-current-node))
|
|
||||||
(`(,fn . ,args)
|
|
||||||
(apply fn (cons org-roam-buffer-current-node args)))
|
|
||||||
(_
|
|
||||||
(user-error "Invalid `org-roam-mode-sections' specification")))))
|
|
||||||
(run-hooks 'org-roam-buffer-postrender-functions)
|
|
||||||
(goto-char 0)))
|
|
||||||
|
|
||||||
(defun org-roam-buffer-set-header-line-format (string)
|
;;; Persistent buffer
|
||||||
"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)))
|
|
||||||
|
|
||||||
;;;; Dedicated buffer
|
|
||||||
;;;###autoload
|
|
||||||
(defun org-roam-buffer-display-dedicated (node)
|
|
||||||
"Launch NODE dedicated Org-roam buffer.
|
|
||||||
Unlike the persistent `org-roam-buffer', the contents of this
|
|
||||||
buffer won't be automatically changed and will be held in place.
|
|
||||||
|
|
||||||
In interactive calls prompt to select NODE, unless called with
|
|
||||||
`universal-argument', in which case NODE will be set to
|
|
||||||
`org-roam-node-at-point'."
|
|
||||||
(interactive
|
|
||||||
(list (if current-prefix-arg
|
|
||||||
(org-roam-node-at-point 'assert)
|
|
||||||
(org-roam-node-read nil nil nil 'require-match))))
|
|
||||||
(let ((buffer (get-buffer-create (org-roam-buffer--dedicated-name node))))
|
|
||||||
(with-current-buffer buffer
|
|
||||||
(setq-local org-roam-buffer-current-node node)
|
|
||||||
(setq-local org-roam-buffer-current-directory org-roam-directory)
|
|
||||||
(org-roam-buffer-render-contents))
|
|
||||||
(display-buffer buffer)))
|
|
||||||
|
|
||||||
(defun org-roam-buffer--dedicated-name (node)
|
|
||||||
"Construct buffer name for NODE dedicated Org-roam buffer."
|
|
||||||
(let ((title (org-roam-node-title node))
|
|
||||||
(filename (file-relative-name (org-roam-node-file node) org-roam-directory)))
|
|
||||||
(format "*org-roam: %s<%s>*" title filename)))
|
|
||||||
|
|
||||||
(defun org-roam-buffer-dedicated-p (&optional buffer)
|
|
||||||
"Return t if an Org-roam BUFFER is a node dedicated one.
|
|
||||||
See `org-roam-buffer-display-dedicated' for more details.
|
|
||||||
If BUFFER is nil, default it to `current-buffer'."
|
|
||||||
(or buffer (setq buffer (current-buffer)))
|
|
||||||
(string-match-p (concat "^" (regexp-quote "*org-roam: "))
|
|
||||||
(buffer-name buffer)))
|
|
||||||
|
|
||||||
;;;; Persistent buffer
|
|
||||||
(defvar org-roam-buffer "*org-roam*"
|
(defvar org-roam-buffer "*org-roam*"
|
||||||
"The persistent Org-roam buffer name. Must be surround with \"*\".
|
"The persistent Org-roam buffer name.")
|
||||||
The content inside of this buffer will be automatically updated
|
|
||||||
to the nearest node at point that comes from the current buffer.
|
|
||||||
To toggle its display use `org-roam-buffer-toggle' command.")
|
|
||||||
|
|
||||||
(defun org-roam-buffer-toggle ()
|
(defun org-roam-buffer--post-command-h ()
|
||||||
"Toggle display of the persistent `org-roam-buffer'."
|
"Reconstructs the Org-roam buffer.
|
||||||
(interactive)
|
This needs to be quick or infrequent, because this is run at
|
||||||
(pcase (org-roam-buffer--visibility)
|
`post-command-hook'. If REDISPLAY, force an update of
|
||||||
('visible
|
the Org-roam buffer."
|
||||||
(progn
|
(when (get-buffer-window org-roam-buffer)
|
||||||
(quit-window nil (get-buffer-window org-roam-buffer))
|
(when-let ((node (org-roam-node-at-point)))
|
||||||
(remove-hook 'post-command-hook #'org-roam-buffer--redisplay-h)))
|
(unless (equal node org-roam-current-node)
|
||||||
((or 'exists 'none)
|
(setq org-roam-current-node node)
|
||||||
(progn
|
(org-roam-buffer-persistent-redisplay)))))
|
||||||
(display-buffer (get-buffer-create org-roam-buffer))
|
|
||||||
(org-roam-buffer-persistent-redisplay)))))
|
|
||||||
|
|
||||||
(define-inline org-roam-buffer--visibility ()
|
(define-inline org-roam-buffer--visibility ()
|
||||||
"Return the current visibility state of the persistent `org-roam-buffer'.
|
"Return whether the current visibility state of the org-roam buffer.
|
||||||
Valid states are `visible', `exists' and `none'."
|
Valid states are 'visible, 'exists and 'none."
|
||||||
(declare (side-effect-free t))
|
(declare (side-effect-free t))
|
||||||
(inline-quote
|
(inline-quote
|
||||||
(cond
|
(cond
|
||||||
@ -327,147 +205,41 @@ Valid states are `visible', `exists' and `none'."
|
|||||||
((get-buffer org-roam-buffer) 'exists)
|
((get-buffer org-roam-buffer) 'exists)
|
||||||
(t 'none))))
|
(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
|
||||||
|
(display-buffer (get-buffer-create org-roam-buffer))
|
||||||
|
(setq org-roam-current-node (org-roam-node-at-point))
|
||||||
|
(org-roam-buffer-persistent-redisplay)))))
|
||||||
|
|
||||||
(defun org-roam-buffer-persistent-redisplay ()
|
(defun org-roam-buffer-persistent-redisplay ()
|
||||||
"Recompute contents of the persistent `org-roam-buffer'.
|
"Recompute contents of the persistent Org-roam buffer.
|
||||||
Has no effect when there's no `org-roam-node-at-point'."
|
Has no effect when `org-roam-current-node' is nil."
|
||||||
(when-let ((node (org-roam-node-at-point)))
|
(when org-roam-current-node
|
||||||
(unless (equal node org-roam-buffer-current-node)
|
(with-current-buffer (get-buffer-create org-roam-buffer)
|
||||||
(setq org-roam-buffer-current-node node
|
(let ((inhibit-read-only t))
|
||||||
org-roam-buffer-current-directory org-roam-directory)
|
(erase-buffer)
|
||||||
(with-current-buffer (get-buffer-create org-roam-buffer)
|
(org-roam-mode)
|
||||||
(org-roam-buffer-render-contents)
|
(org-roam-set-header-line-format (org-roam-node-title org-roam-current-node))
|
||||||
(add-hook 'kill-buffer-hook #'org-roam-buffer--persistent-cleanup-h nil t)))))
|
(magit-insert-section (org-roam)
|
||||||
|
(magit-insert-heading)
|
||||||
|
(dolist (fn org-roam-mode-sections)
|
||||||
|
(funcall fn org-roam-current-node)))))))
|
||||||
|
|
||||||
(defun org-roam-buffer--persistent-cleanup-h ()
|
(defun org-roam-buffer--redisplay ()
|
||||||
"Clean-up global state that's dedicated for the persistent `org-roam-buffer'."
|
"."
|
||||||
(setq-default org-roam-buffer-current-node nil
|
(add-hook 'post-command-hook #'org-roam-buffer--post-command-h nil t))
|
||||||
org-roam-buffer-current-directory nil))
|
|
||||||
|
|
||||||
(add-hook 'org-roam-find-file-hook #'org-roam-buffer--setup-redisplay-h)
|
(add-hook 'org-roam-find-file-hook #'org-roam-buffer--redisplay)
|
||||||
(defun org-roam-buffer--setup-redisplay-h ()
|
|
||||||
"Setup automatic redisplay of the persistent `org-roam-buffer'."
|
|
||||||
(add-hook 'post-command-hook #'org-roam-buffer--redisplay-h nil t))
|
|
||||||
|
|
||||||
(defun org-roam-buffer--redisplay-h ()
|
|
||||||
"Reconstruct the persistent `org-roam-buffer'.
|
|
||||||
This needs to be quick or infrequent, because this designed to
|
|
||||||
run at `post-command-hook'."
|
|
||||||
(and (get-buffer-window org-roam-buffer)
|
|
||||||
(org-roam-buffer-persistent-redisplay)))
|
|
||||||
|
|
||||||
;;; Sections
|
;;; Sections
|
||||||
;;;; Node
|
|
||||||
(defvar org-roam-node-map
|
|
||||||
(let ((map (make-sparse-keymap)))
|
|
||||||
(set-keymap-parent map org-roam-mode-map)
|
|
||||||
(define-key map [remap org-roam-buffer-visit-thing] 'org-roam-node-visit)
|
|
||||||
map)
|
|
||||||
"Keymap for `org-roam-node-section's.")
|
|
||||||
|
|
||||||
(defclass org-roam-node-section (magit-section)
|
|
||||||
((keymap :initform 'org-roam-node-map)
|
|
||||||
(node :initform nil))
|
|
||||||
"A `magit-section' used by `org-roam-mode' to outline NODE in its own heading.")
|
|
||||||
|
|
||||||
(cl-defun org-roam-node-insert-section (&key source-node point properties)
|
|
||||||
"Insert section for a link from SOURCE-NODE to some other node.
|
|
||||||
The other node is normally `org-roam-buffer-current-node'.
|
|
||||||
|
|
||||||
SOURCE-NODE is an `org-roam-node' that links or references with
|
|
||||||
the other node.
|
|
||||||
|
|
||||||
POINT is a character position where the link is located in
|
|
||||||
SOURCE-NODE's file.
|
|
||||||
|
|
||||||
PROPERTIES (a plist) contains additional information about the
|
|
||||||
link.
|
|
||||||
|
|
||||||
Despite the name, this function actually inserts 2 sections at
|
|
||||||
the same time:
|
|
||||||
|
|
||||||
1. `org-roam-node-section' for a heading that describes
|
|
||||||
SOURCE-NODE. Acts as a parent section of the following one.
|
|
||||||
|
|
||||||
2. `org-roam-preview-section' for a preview content that comes
|
|
||||||
from SOURCE-NODE's file for the link (that references the
|
|
||||||
other node) at POINT. Acts a child section of the previous
|
|
||||||
one."
|
|
||||||
(magit-insert-section section (org-roam-node-section)
|
|
||||||
(let ((outline (if-let ((outline (plist-get properties :outline)))
|
|
||||||
(mapconcat #'org-link-display-format outline " > ")
|
|
||||||
"Top")))
|
|
||||||
(insert (concat (propertize (org-roam-node-title source-node)
|
|
||||||
'font-lock-face 'org-roam-title)
|
|
||||||
(format " (%s)"
|
|
||||||
(propertize outline 'font-lock-face 'org-roam-olp)))))
|
|
||||||
(magit-insert-heading)
|
|
||||||
(oset section node source-node)
|
|
||||||
(magit-insert-section section (org-roam-preview-section)
|
|
||||||
(insert (org-roam-fontify-like-in-org-mode
|
|
||||||
(org-roam-preview-get-contents (org-roam-node-file source-node) point))
|
|
||||||
"\n")
|
|
||||||
(oset section file (org-roam-node-file source-node))
|
|
||||||
(oset section point point)
|
|
||||||
(insert ?\n))))
|
|
||||||
|
|
||||||
;;;; Preview
|
|
||||||
(defvar org-roam-preview-map
|
|
||||||
(let ((map (make-sparse-keymap)))
|
|
||||||
(set-keymap-parent map org-roam-mode-map)
|
|
||||||
(define-key map [remap org-roam-buffer-visit-thing] 'org-roam-preview-visit)
|
|
||||||
map)
|
|
||||||
"Keymap for `org-roam-preview-section's.")
|
|
||||||
|
|
||||||
(defclass org-roam-preview-section (magit-section)
|
|
||||||
((keymap :initform 'org-roam-preview-map)
|
|
||||||
(file :initform nil)
|
|
||||||
(point :initform nil))
|
|
||||||
"A `magit-section' used by `org-roam-mode' to contain preview content.
|
|
||||||
The preview content comes from FILE, and the link as at POINT.")
|
|
||||||
|
|
||||||
(defun org-roam-preview-visit (file point &optional other-window)
|
|
||||||
"Visit FILE at POINT and return the visited buffer.
|
|
||||||
With OTHER-WINDOW non-nil do so in another window.
|
|
||||||
In interactive calls OTHER-WINDOW is set with
|
|
||||||
`universal-argument'."
|
|
||||||
(interactive (list (org-roam-buffer-file-at-point 'assert)
|
|
||||||
(oref (magit-current-section) point)
|
|
||||||
current-prefix-arg))
|
|
||||||
(let ((buf (find-file-noselect file))
|
|
||||||
(display-buffer-fn (if other-window
|
|
||||||
#'switch-to-buffer-other-window
|
|
||||||
#'pop-to-buffer-same-window)))
|
|
||||||
(funcall display-buffer-fn buf)
|
|
||||||
(with-current-buffer buf
|
|
||||||
(widen)
|
|
||||||
(goto-char point))
|
|
||||||
(when (org-invisible-p) (org-fold-show-context))
|
|
||||||
buf))
|
|
||||||
|
|
||||||
(defun org-roam-preview-default-function ()
|
|
||||||
"Return the preview content at point.
|
|
||||||
|
|
||||||
This function returns the all contents under the current
|
|
||||||
headline, up to the next headline."
|
|
||||||
(let ((beg (save-excursion
|
|
||||||
(org-roam-end-of-meta-data t)
|
|
||||||
(point)))
|
|
||||||
(end (save-excursion
|
|
||||||
(org-next-visible-heading 1)
|
|
||||||
(point))))
|
|
||||||
(string-trim (buffer-substring-no-properties beg end))))
|
|
||||||
|
|
||||||
(defun org-roam-preview-get-contents (file pt)
|
|
||||||
"Get preview content for FILE at PT."
|
|
||||||
(save-excursion
|
|
||||||
(org-roam-with-temp-buffer file
|
|
||||||
(org-with-wide-buffer
|
|
||||||
(goto-char pt)
|
|
||||||
(let ((s (funcall org-roam-preview-function)))
|
|
||||||
(dolist (fn org-roam-preview-postprocess-functions)
|
|
||||||
(setq s (funcall fn s)))
|
|
||||||
s)))))
|
|
||||||
|
|
||||||
;;;; Backlinks
|
;;;; Backlinks
|
||||||
(cl-defstruct (org-roam-backlink (:constructor org-roam-backlink-create)
|
(cl-defstruct (org-roam-backlink (:constructor org-roam-backlink-create)
|
||||||
(:copier nil))
|
(:copier nil))
|
||||||
@ -482,23 +254,14 @@ headline, up to the next headline."
|
|||||||
(org-roam-populate (org-roam-backlink-target-node backlink)))
|
(org-roam-populate (org-roam-backlink-target-node backlink)))
|
||||||
backlink)
|
backlink)
|
||||||
|
|
||||||
(cl-defun org-roam-backlinks-get (node &key unique)
|
(defun org-roam-backlinks-get (node)
|
||||||
"Return the backlinks for NODE.
|
"Return the backlinks for NODE."
|
||||||
|
(let ((backlinks (org-roam-db-query
|
||||||
When UNIQUE is nil, show all positions where references are found.
|
[:select [source dest pos properties]
|
||||||
When UNIQUE is t, limit to unique sources."
|
:from links
|
||||||
(let* ((sql (if unique
|
:where (= dest $s1)
|
||||||
[:select :distinct [source dest pos properties]
|
:and (= type "id")]
|
||||||
:from links
|
(org-roam-node-id node))))
|
||||||
:where (= dest $s1)
|
|
||||||
:and (= type "id")
|
|
||||||
:group :by source
|
|
||||||
:having (funcall min pos)]
|
|
||||||
[:select [source dest pos properties]
|
|
||||||
:from links
|
|
||||||
:where (= dest $s1)
|
|
||||||
:and (= type "id")]))
|
|
||||||
(backlinks (org-roam-db-query sql (org-roam-node-id node))))
|
|
||||||
(cl-loop for backlink in backlinks
|
(cl-loop for backlink in backlinks
|
||||||
collect (pcase-let ((`(,source-id ,dest-id ,pos ,properties) backlink))
|
collect (pcase-let ((`(,source-id ,dest-id ,pos ,properties) backlink))
|
||||||
(org-roam-populate
|
(org-roam-populate
|
||||||
@ -514,28 +277,16 @@ Sorts by title."
|
|||||||
(string< (org-roam-node-title (org-roam-backlink-source-node a))
|
(string< (org-roam-node-title (org-roam-backlink-source-node a))
|
||||||
(org-roam-node-title (org-roam-backlink-source-node b))))
|
(org-roam-node-title (org-roam-backlink-source-node b))))
|
||||||
|
|
||||||
(cl-defun org-roam-backlinks-section (node &key (unique nil) (show-backlink-p nil)
|
(defun org-roam-backlinks-section (node)
|
||||||
(section-heading "Backlinks:"))
|
"The backlinks section for NODE."
|
||||||
"The backlinks section for NODE.
|
(when-let ((backlinks (seq-sort #'org-roam-backlinks-sort (org-roam-backlinks-get node))))
|
||||||
|
|
||||||
When UNIQUE is nil, show all positions where references are found.
|
|
||||||
When UNIQUE is t, limit to unique sources.
|
|
||||||
|
|
||||||
When SHOW-BACKLINK-P is not null, only show backlinks for which
|
|
||||||
this predicate is not nil.
|
|
||||||
|
|
||||||
SECTION-HEADING is the string used as a heading for the backlink section."
|
|
||||||
(when-let ((backlinks (seq-sort #'org-roam-backlinks-sort (org-roam-backlinks-get node :unique unique))))
|
|
||||||
(magit-insert-section (org-roam-backlinks)
|
(magit-insert-section (org-roam-backlinks)
|
||||||
(magit-insert-heading section-heading)
|
(magit-insert-heading "Backlinks:")
|
||||||
(dolist (backlink backlinks)
|
(dolist (backlink backlinks)
|
||||||
(when (or (null show-backlink-p)
|
(org-roam-node-insert-section
|
||||||
(and (not (null show-backlink-p))
|
:source-node (org-roam-backlink-source-node backlink)
|
||||||
(funcall show-backlink-p backlink)))
|
:point (org-roam-backlink-point backlink)
|
||||||
(org-roam-node-insert-section
|
:properties (org-roam-backlink-properties backlink)))
|
||||||
:source-node (org-roam-backlink-source-node backlink)
|
|
||||||
:point (org-roam-backlink-point backlink)
|
|
||||||
:properties (org-roam-backlink-properties backlink))))
|
|
||||||
(insert ?\n))))
|
(insert ?\n))))
|
||||||
|
|
||||||
;;;; Reflinks
|
;;;; Reflinks
|
||||||
@ -552,27 +303,22 @@ SECTION-HEADING is the string used as a heading for the backlink section."
|
|||||||
|
|
||||||
(defun org-roam-reflinks-get (node)
|
(defun org-roam-reflinks-get (node)
|
||||||
"Return the reflinks for NODE."
|
"Return the reflinks for NODE."
|
||||||
(let ((refs (org-roam-db-query [:select :distinct [refs:ref links:source links:pos links:properties]
|
(let ((refs (org-roam-db-query [:select [ref] :from refs
|
||||||
:from refs
|
:where (= node-id $s1)]
|
||||||
:left-join links
|
|
||||||
:where (= refs:node-id $s1)
|
|
||||||
:and (= links:dest refs:ref)
|
|
||||||
:union
|
|
||||||
:select :distinct [refs:ref citations:node-id
|
|
||||||
citations:pos citations:properties]
|
|
||||||
:from refs
|
|
||||||
:left-join citations
|
|
||||||
:where (= refs:node-id $s1)
|
|
||||||
:and (= citations:cite-key refs:ref)]
|
|
||||||
(org-roam-node-id node)))
|
(org-roam-node-id node)))
|
||||||
links)
|
links)
|
||||||
(pcase-dolist (`(,ref ,source-id ,pos ,properties) refs)
|
(pcase-dolist (`(,ref) refs)
|
||||||
(push (org-roam-populate
|
(pcase-dolist (`(,source-id ,pos ,properties) (org-roam-db-query
|
||||||
(org-roam-reflink-create
|
[:select [source pos properties]
|
||||||
:source-node (org-roam-node-create :id source-id)
|
:from links
|
||||||
:ref ref
|
:where (= dest $s1)]
|
||||||
:point pos
|
ref))
|
||||||
:properties properties)) links))
|
(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))
|
links))
|
||||||
|
|
||||||
(defun org-roam-reflinks-sort (a b)
|
(defun org-roam-reflinks-sort (a b)
|
||||||
@ -583,46 +329,52 @@ Sorts by title."
|
|||||||
|
|
||||||
(defun org-roam-reflinks-section (node)
|
(defun org-roam-reflinks-section (node)
|
||||||
"The reflinks section for NODE."
|
"The reflinks section for NODE."
|
||||||
(when-let ((refs (org-roam-node-refs node))
|
(when (org-roam-node-refs node)
|
||||||
(reflinks (seq-sort #'org-roam-reflinks-sort (org-roam-reflinks-get node))))
|
(let* ((reflinks (seq-sort #'org-roam-reflinks-sort (org-roam-reflinks-get node))))
|
||||||
(magit-insert-section (org-roam-reflinks)
|
(magit-insert-section (org-roam-reflinks)
|
||||||
(magit-insert-heading "Reflinks:")
|
(magit-insert-heading "Reflinks:")
|
||||||
(dolist (reflink reflinks)
|
(dolist (reflink reflinks)
|
||||||
(org-roam-node-insert-section
|
(org-roam-node-insert-section
|
||||||
:source-node (org-roam-reflink-source-node reflink)
|
:source-node (org-roam-reflink-source-node reflink)
|
||||||
:point (org-roam-reflink-point reflink)
|
:point (org-roam-reflink-point reflink)
|
||||||
:properties (org-roam-reflink-properties reflink)))
|
:properties (org-roam-reflink-properties reflink)))
|
||||||
(insert ?\n))))
|
(insert ?\n)))))
|
||||||
|
|
||||||
;;;; Grep
|
;;;; Unlinked references
|
||||||
(defvar org-roam-grep-map
|
(defvar org-roam-grep-map
|
||||||
(let ((map (make-sparse-keymap)))
|
(let ((map (make-sparse-keymap)))
|
||||||
(set-keymap-parent map org-roam-mode-map)
|
(set-keymap-parent map org-roam-mode-map)
|
||||||
(define-key map [remap org-roam-buffer-visit-thing] 'org-roam-grep-visit)
|
(define-key map [remap org-roam-visit-thing] 'org-roam-file-visit)
|
||||||
map)
|
map)
|
||||||
"Keymap for Org-roam grep result sections.")
|
"Keymap for Org-roam grep result sections.")
|
||||||
|
|
||||||
(defclass org-roam-grep-section (magit-section)
|
(defclass org-roam-grep-section (magit-section)
|
||||||
((keymap :initform 'org-roam-grep-map)
|
((keymap :initform org-roam-grep-map)
|
||||||
(file :initform nil)
|
(file :initform nil)
|
||||||
(row :initform nil)
|
(row :initform nil)
|
||||||
(col :initform nil))
|
(col :initform nil)))
|
||||||
"A `magit-section' used by `org-roam-mode' to contain grep output.")
|
|
||||||
|
|
||||||
(defun org-roam-grep-visit (file &optional other-window row col)
|
(defun org-roam-file-at-point (&optional assert)
|
||||||
"Visit FILE at row ROW (if any) and column COL (if any). Return the buffer.
|
"Return the file at point.
|
||||||
With OTHER-WINDOW non-nil (in interactive calls set with
|
If ASSERT, throw an error."
|
||||||
`universal-argument') display the buffer in another window
|
(if-let ((file (magit-section-case
|
||||||
instead."
|
(org-roam-node-section (org-roam-node-file (oref it node)))
|
||||||
(interactive (list (org-roam-buffer-file-at-point t)
|
(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
|
current-prefix-arg
|
||||||
(oref (magit-current-section) row)
|
(oref (magit-current-section) row)
|
||||||
(oref (magit-current-section) col)))
|
(oref (magit-current-section) col)))
|
||||||
(let ((buf (find-file-noselect file))
|
(let ((buf (find-file-noselect file)))
|
||||||
(display-buffer-fn (if other-window
|
|
||||||
#'switch-to-buffer-other-window
|
|
||||||
#'pop-to-buffer-same-window)))
|
|
||||||
(funcall display-buffer-fn buf)
|
|
||||||
(with-current-buffer buf
|
(with-current-buffer buf
|
||||||
(widen)
|
(widen)
|
||||||
(goto-char (point-min))
|
(goto-char (point-min))
|
||||||
@ -630,10 +382,10 @@ instead."
|
|||||||
(forward-line (1- row)))
|
(forward-line (1- row)))
|
||||||
(when col
|
(when col
|
||||||
(forward-char (1- col))))
|
(forward-char (1- col))))
|
||||||
(when (org-invisible-p) (org-fold-show-context))
|
(funcall (if other-window
|
||||||
buf))
|
#'switch-to-buffer-other-window
|
||||||
|
#'pop-to-buffer-same-window) buf)))
|
||||||
|
|
||||||
;;;; Unlinked references
|
|
||||||
(defvar org-roam-unlinked-references-result-re
|
(defvar org-roam-unlinked-references-result-re
|
||||||
(rx (group (one-or-more anything))
|
(rx (group (one-or-more anything))
|
||||||
":"
|
":"
|
||||||
@ -648,7 +400,7 @@ instead."
|
|||||||
"Return the preview line from FILE.
|
"Return the preview line from FILE.
|
||||||
This is the ROW within FILE."
|
This is the ROW within FILE."
|
||||||
(with-temp-buffer
|
(with-temp-buffer
|
||||||
(insert-file-contents file)
|
(insert-file-contents-literally file)
|
||||||
(forward-line (1- row))
|
(forward-line (1- row))
|
||||||
(buffer-substring-no-properties
|
(buffer-substring-no-properties
|
||||||
(save-excursion
|
(save-excursion
|
||||||
@ -658,69 +410,49 @@ This is the ROW within FILE."
|
|||||||
(end-of-line)
|
(end-of-line)
|
||||||
(point)))))
|
(point)))))
|
||||||
|
|
||||||
(defun org-roam-unlinked-references--rg-command (titles temp-file)
|
|
||||||
"Return the ripgrep command searching for TITLES using TEMP-FILE for pattern.
|
|
||||||
This avoids shell escaping issues by writing the pattern to a file instead
|
|
||||||
of passing it directly through the shell command line."
|
|
||||||
;; Write pattern to temp file to avoid shell escaping issues with quotes,
|
|
||||||
;; spaces, and other special characters in titles
|
|
||||||
(with-temp-file temp-file
|
|
||||||
(insert "\\[([^[]]++|(?R))*\\]"
|
|
||||||
(mapconcat (lambda (title)
|
|
||||||
;; Use regexp-quote instead of shell-quote-argument
|
|
||||||
;; since we're writing a regex pattern, not a shell argument
|
|
||||||
(format "|(\\b%s\\b)" (regexp-quote title)))
|
|
||||||
titles "")))
|
|
||||||
|
|
||||||
(concat "rg --follow --only-matching --vimgrep --pcre2 --ignore-case "
|
|
||||||
(mapconcat (lambda (glob) (concat "--glob " glob))
|
|
||||||
(org-roam--list-files-search-globs org-roam-file-extensions)
|
|
||||||
" ")
|
|
||||||
" --file " (shell-quote-argument temp-file) " "
|
|
||||||
(shell-quote-argument (expand-file-name org-roam-directory))))
|
|
||||||
|
|
||||||
(defun org-roam-unlinked-references-section (node)
|
(defun org-roam-unlinked-references-section (node)
|
||||||
"The unlinked references section for NODE.
|
"The unlinked references section for NODE.
|
||||||
References from FILE are excluded."
|
References from FILE are excluded."
|
||||||
(when (and (executable-find "rg")
|
(when (and (executable-find "rg")
|
||||||
(org-roam-node-title node)
|
|
||||||
(not (string-match "PCRE2 is not available"
|
(not (string-match "PCRE2 is not available"
|
||||||
(shell-command-to-string "rg --pcre2-version"))))
|
(shell-command-to-string "rg --pcre2-version"))))
|
||||||
(let* ((titles (cons (org-roam-node-title node)
|
(let* ((titles (cons (org-roam-node-title node)
|
||||||
(org-roam-node-aliases node)))
|
(org-roam-node-aliases node)))
|
||||||
;; Create temp file for the regex pattern
|
(rg-command (concat "rg -o --vimgrep -P -i "
|
||||||
(temp-file (make-temp-file "org-roam-rg-pattern-"))
|
(string-join (mapcar (lambda (glob) (concat "-g " glob))
|
||||||
(rg-command (org-roam-unlinked-references--rg-command titles temp-file)))
|
(org-roam--list-files-search-globs
|
||||||
;; Use unwind-protect to ensure temp file cleanup even if errors occur
|
org-roam-file-extensions)) " ")
|
||||||
(unwind-protect
|
(format " '\\[([^[]]++|(?R))*\\]%s' "
|
||||||
(let* ((results (split-string (shell-command-to-string rg-command) "\n"))
|
(mapconcat (lambda (title)
|
||||||
f row col match)
|
(format "|(\\b%s\\b)" (shell-quote-argument title)))
|
||||||
(magit-insert-section (unlinked-references)
|
titles ""))
|
||||||
(magit-insert-heading "Unlinked References:")
|
org-roam-directory))
|
||||||
(dolist (line results)
|
(results (split-string (shell-command-to-string rg-command) "\n"))
|
||||||
(save-match-data
|
f row col match)
|
||||||
(when (string-match org-roam-unlinked-references-result-re line)
|
(magit-insert-section (unlinked-references)
|
||||||
(setq f (match-string 1 line)
|
(magit-insert-heading "Unlinked References:")
|
||||||
row (string-to-number (match-string 2 line))
|
(dolist (line results)
|
||||||
col (string-to-number (match-string 3 line))
|
(save-match-data
|
||||||
match (match-string 4 line))
|
(when (string-match org-roam-unlinked-references-result-re line)
|
||||||
(when (and match
|
(setq f (match-string 1 line)
|
||||||
(not (file-equal-p (org-roam-node-file node) f))
|
row (string-to-number (match-string 2 line))
|
||||||
(member (downcase match) (mapcar #'downcase titles)))
|
col (string-to-number (match-string 3 line))
|
||||||
(magit-insert-section section (org-roam-grep-section)
|
match (match-string 4 line))
|
||||||
(oset section file f)
|
(when (and match
|
||||||
(oset section row row)
|
(not (f-equal-p (org-roam-node-file node) f))
|
||||||
(oset section col col)
|
(member (downcase match) (mapcar #'downcase titles)))
|
||||||
(insert (propertize (format "%s:%s:%s"
|
(magit-insert-section section (org-roam-grep-section)
|
||||||
(truncate-string-to-width (file-name-base f) 15 nil nil t)
|
(oset section file f)
|
||||||
row col) 'font-lock-face 'org-roam-dim)
|
(oset section row row)
|
||||||
" "
|
(oset section col col)
|
||||||
(org-roam-fontify-like-in-org-mode
|
(insert (propertize (format "%s:%s:%s"
|
||||||
(org-roam-unlinked-references-preview-line f row))
|
(truncate-string-to-width (file-name-base f) 15 nil nil "...")
|
||||||
"\n"))))))
|
row col) 'font-lock-face 'org-roam-dim)
|
||||||
(insert ?\n)))
|
" "
|
||||||
;; Clean up temp file - this runs even if an error occurs above
|
(org-roam-fontify-like-in-org-mode
|
||||||
(delete-file temp-file)))))
|
(org-roam-unlinked-references-preview-line f row))
|
||||||
|
"\n"))))))
|
||||||
|
(insert ?\n)))))
|
||||||
|
|
||||||
(provide 'org-roam-mode)
|
(provide 'org-roam-mode)
|
||||||
;;; org-roam-mode.el ends here
|
;;; org-roam-mode.el ends here
|
||||||
|
1196
org-roam-node.el
1196
org-roam-node.el
File diff suppressed because it is too large
Load Diff
107
org-roam-protocol.el
Normal file
107
org-roam-protocol.el
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
;;; org-roam-protocol.el --- Protocol handler for roam:// links -*- 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-sqlite3 "1.0.2") (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:
|
||||||
|
;;
|
||||||
|
;; We extend org-protocol, adding custom Org-roam handlers. The setup
|
||||||
|
;; instructions for `org-protocol' can be found in org-protocol.el.
|
||||||
|
;;
|
||||||
|
;; We define 2 protocols:
|
||||||
|
;;
|
||||||
|
;; 1. "roam-file": This protocol simply opens the file given by the FILE key
|
||||||
|
;; 2. "roam-ref": This protocol creates or opens a note with the given REF
|
||||||
|
;;
|
||||||
|
;;; Code:
|
||||||
|
(require 'org-protocol)
|
||||||
|
(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
|
||||||
|
(defun org-roam-protocol-open-ref (info)
|
||||||
|
"Process an org-protocol://roam-ref?ref= style url with INFO.
|
||||||
|
|
||||||
|
It opens or creates a note with the given ref.
|
||||||
|
|
||||||
|
javascript:location.href = \\='org-protocol://roam-ref?template=r&ref=\\='+ \\
|
||||||
|
encodeURIComponent(location.href) + \\='&title=\\=' + \\
|
||||||
|
encodeURIComponent(document.title) + \\='&body=\\=' + \\
|
||||||
|
encodeURIComponent(window.getSelection())"
|
||||||
|
(unless (plist-get info :ref)
|
||||||
|
(user-error "No ref key provided"))
|
||||||
|
(org-roam-plist-map! (lambda (k v)
|
||||||
|
(org-link-decode
|
||||||
|
(if (equal k :ref)
|
||||||
|
(org-protocol-sanitize-uri v)
|
||||||
|
v))) info)
|
||||||
|
(when org-roam-protocol-store-links
|
||||||
|
(push (list (plist-get info :ref)
|
||||||
|
(plist-get info :title)) org-stored-links))
|
||||||
|
(org-link-store-props :type (and (string-match org-link-plain-re
|
||||||
|
(plist-get info :ref))
|
||||||
|
(match-string 1 (plist-get info :ref)))
|
||||||
|
:link (plist-get info :ref)
|
||||||
|
:annotation (org-link-make-string (plist-get info :ref)
|
||||||
|
(or (plist-get info :title)
|
||||||
|
(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)
|
||||||
|
|
||||||
|
(defun org-roam-protocol-open-file (info)
|
||||||
|
"This handler simply opens the file with emacsclient.
|
||||||
|
|
||||||
|
INFO is an alist containing additional information passed by the protocol URL.
|
||||||
|
It should contain the FILE key, pointing to the path of the file to open.
|
||||||
|
|
||||||
|
Example protocol string:
|
||||||
|
|
||||||
|
org-protocol://roam-file?file=/path/to/file.org"
|
||||||
|
(when-let ((file (plist-get info :file)))
|
||||||
|
(raise-frame)
|
||||||
|
(find-file file))
|
||||||
|
nil)
|
||||||
|
|
||||||
|
(push '("org-roam-ref" :protocol "roam-ref" :function org-roam-protocol-open-ref)
|
||||||
|
org-protocol-protocol-alist)
|
||||||
|
(push '("org-roam-file" :protocol "roam-file" :function org-roam-protocol-open-file)
|
||||||
|
org-protocol-protocol-alist)
|
||||||
|
|
||||||
|
(provide 'org-roam-protocol)
|
||||||
|
|
||||||
|
;;; org-roam-protocol.el ends here
|
77
org-roam-refile.el
Normal file
77
org-roam-refile.el
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
;;; org-roam-refile.el --- Refile Org-roam Notes -*- 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-sqlite3 "1.0.2") (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:
|
||||||
|
;;
|
||||||
|
;; Org-roam refile allows you to refile notes to your nodes.
|
||||||
|
;;
|
||||||
|
;;; Code:
|
||||||
|
(defvar org-auto-align-tags)
|
||||||
|
(defvar org-loop-over-headlines-in-active-region)
|
||||||
|
|
||||||
|
(defun org-roam-refile ()
|
||||||
|
"Refile to node."
|
||||||
|
(interactive)
|
||||||
|
(let* ((regionp (org-region-active-p))
|
||||||
|
(region-start (and regionp (region-beginning)))
|
||||||
|
(region-end (and regionp (region-end)))
|
||||||
|
(node (org-roam-node-read nil nil 'require-match))
|
||||||
|
(file (org-roam-node-file node))
|
||||||
|
(nbuf (or (find-buffer-visiting file)
|
||||||
|
(find-file-noselect file)))
|
||||||
|
level reversed)
|
||||||
|
(if regionp
|
||||||
|
(progn
|
||||||
|
(org-kill-new (buffer-substring region-start region-end))
|
||||||
|
(org-save-markers-in-region region-start region-end))
|
||||||
|
(org-copy-subtree 1 nil t))
|
||||||
|
(with-current-buffer nbuf
|
||||||
|
(org-with-wide-buffer
|
||||||
|
(goto-char (org-roam-node-point node))
|
||||||
|
(setq level (org-get-valid-level (funcall outline-level) 1)
|
||||||
|
reversed (org-notes-order-reversed-p))
|
||||||
|
(goto-char
|
||||||
|
(if reversed
|
||||||
|
(or (outline-next-heading) (point-max))
|
||||||
|
(or (save-excursion (org-get-next-sibling))
|
||||||
|
(org-end-of-subtree t t)
|
||||||
|
(point-max))))
|
||||||
|
(unless (bolp) (newline))
|
||||||
|
(org-paste-subtree level nil nil t)
|
||||||
|
(and org-auto-align-tags
|
||||||
|
(let ((org-loop-over-headlines-in-active-region nil))
|
||||||
|
(org-align-tags)))
|
||||||
|
(when (fboundp 'deactivate-mark) (deactivate-mark))))
|
||||||
|
(if regionp
|
||||||
|
(delete-region (point) (+ (point) (- region-end region-start)))
|
||||||
|
(org-preserve-local-variables
|
||||||
|
(delete-region
|
||||||
|
(and (org-back-to-heading t) (point))
|
||||||
|
(min (1+ (buffer-size)) (org-end-of-subtree t t) (point)))))))
|
||||||
|
|
||||||
|
(provide 'org-roam-refile)
|
||||||
|
;;; org-roam-refile.el ends here
|
@ -1,12 +1,12 @@
|
|||||||
;;; org-roam-utils.el --- Utilities for Org-roam -*- lexical-binding: t; -*-
|
;;; org-roam-utils.el --- Utilities for Org-roam -*- coding: utf-8; lexical-binding: t; -*-
|
||||||
|
|
||||||
;; Copyright © 2020-2025 Jethro Kuan <jethrokuan95@gmail.com>
|
;; Copyright © 2020 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: 2.3.1
|
;; Version: 2.0.0
|
||||||
;; Package-Requires: ((emacs "26.1") (dash "2.13") (org "9.6"))
|
;; Package-Requires: ((emacs "26.1") (dash "2.13") (f "0.17.2") (org "9.4") (emacsql "3.0.0") (emacsql-sqlite3 "1.0.2") (magit-section "2.90.1"))
|
||||||
|
|
||||||
;; This file is NOT part of GNU Emacs.
|
;; This file is NOT part of GNU Emacs.
|
||||||
|
|
||||||
@ -27,184 +27,47 @@
|
|||||||
|
|
||||||
;;; Commentary:
|
;;; Commentary:
|
||||||
;;
|
;;
|
||||||
;; This library provides definitions for utilities that used throughout the
|
;; This library implements utility functions used throughout
|
||||||
;; whole package.
|
;; Org-roam.
|
||||||
|
;;
|
||||||
;;
|
;;
|
||||||
;;; Code:
|
;;; Code:
|
||||||
|
;;;; Library Requires
|
||||||
|
(require 'dash)
|
||||||
|
(require 's)
|
||||||
|
|
||||||
(require 'org-roam)
|
(defvar org-roam-verbose)
|
||||||
|
|
||||||
(defun org-roam-require (libs)
|
;; This is necessary to ensure all dependents on this module see
|
||||||
"Require LIBS."
|
;; `org-mode-hook' and `org-inhibit-startup' as dynamic variables,
|
||||||
(dolist (lib libs)
|
;; regardless of whether Org is loaded before their compilation.
|
||||||
(require lib nil 'noerror)))
|
(require 'org)
|
||||||
|
|
||||||
;;; String utilities
|
;;;; Utility Functions
|
||||||
;; TODO Refactor this.
|
(defun org-roam--list-interleave (lst separator)
|
||||||
(defun org-roam-replace-string (old new s)
|
"Interleaves elements in LST with SEPARATOR."
|
||||||
"Replace OLD with NEW in S."
|
(when lst
|
||||||
(declare (pure t) (side-effect-free t))
|
(let ((new-lst (list (pop lst))))
|
||||||
(replace-regexp-in-string (regexp-quote old) new s t t))
|
(dolist (it lst)
|
||||||
|
(nconc new-lst (list separator it)))
|
||||||
|
new-lst)))
|
||||||
|
|
||||||
(defun org-roam-quote-string (s)
|
(defun org-roam-up-heading-or-point-min ()
|
||||||
"Quotes string S."
|
"Fixed version of Org's `org-up-heading-or-point-min'."
|
||||||
(->> s
|
(ignore-errors (org-back-to-heading t))
|
||||||
(org-roam-replace-string "\\" "\\\\")
|
(let ((p (point)))
|
||||||
(org-roam-replace-string "\"" "\\\"")))
|
(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-word-wrap (len s)
|
(defun org-roam-message (format-string &rest args)
|
||||||
"If S is longer than LEN, wrap the words with newlines."
|
"Pass FORMAT-STRING and ARGS to `message' when `org-roam-verbose' is t."
|
||||||
(declare (side-effect-free t))
|
(when org-roam-verbose
|
||||||
(save-match-data
|
(apply #'message `(,(concat "(org-roam) " format-string) ,@args))))
|
||||||
(with-temp-buffer
|
|
||||||
(insert s)
|
|
||||||
(let ((fill-column len))
|
|
||||||
(fill-region (point-min) (point-max)))
|
|
||||||
(buffer-substring (point-min) (point-max)))))
|
|
||||||
|
|
||||||
(defun org-roam-string-equal (s1 s2)
|
|
||||||
"Return t if S1 and S2 are equal.
|
|
||||||
Like `string-equal', but case-insensitive."
|
|
||||||
(and (= (length s1) (length s2))
|
|
||||||
(or (string-equal s1 s2)
|
|
||||||
(string-equal (downcase s1) (downcase s2)))))
|
|
||||||
|
|
||||||
(defun org-roam-whitespace-content (s)
|
|
||||||
"Return the whitespace content at the end of S."
|
|
||||||
(with-temp-buffer
|
|
||||||
(insert s)
|
|
||||||
(skip-chars-backward " \t\n")
|
|
||||||
(buffer-substring-no-properties
|
|
||||||
(point) (point-max))))
|
|
||||||
|
|
||||||
(defun org-roam-strip-comments (s)
|
|
||||||
"Strip Org comments from string S."
|
|
||||||
(with-temp-buffer
|
|
||||||
(insert s)
|
|
||||||
(goto-char (point-min))
|
|
||||||
(while (not (eobp))
|
|
||||||
(if (org-at-comment-p)
|
|
||||||
(delete-region (line-beginning-position)
|
|
||||||
(progn (forward-line) (point)))
|
|
||||||
(forward-line)))
|
|
||||||
(buffer-string)))
|
|
||||||
|
|
||||||
;;; List utilities
|
|
||||||
(defun org-roam-plist-map! (fn plist)
|
|
||||||
"Map FN over PLIST, modifying it in-place and returning it.
|
|
||||||
FN must take two arguments: the key and the value."
|
|
||||||
(let ((plist-index plist))
|
|
||||||
(while plist-index
|
|
||||||
(let ((key (pop plist-index)))
|
|
||||||
(setf (car plist-index) (funcall fn key (car plist-index))
|
|
||||||
plist-index (cdr plist-index)))))
|
|
||||||
plist)
|
|
||||||
|
|
||||||
(defmacro org-roam-dolist-with-progress (spec msg &rest body)
|
|
||||||
"Loop over a list and report progress in the echo area.
|
|
||||||
Like `dolist-with-progress-reporter', but falls back to `dolist'
|
|
||||||
if the function does not yet exist.
|
|
||||||
|
|
||||||
Evaluate BODY with VAR bound to each car from LIST, in turn.
|
|
||||||
Then evaluate RESULT to get return value, default nil.
|
|
||||||
|
|
||||||
MSG is a progress reporter object or a string. In the latter
|
|
||||||
case, use this string to create a progress reporter.
|
|
||||||
|
|
||||||
SPEC is a list, as per `dolist'."
|
|
||||||
(declare (indent 2))
|
|
||||||
(if (fboundp 'dolist-with-progress-reporter)
|
|
||||||
`(dolist-with-progress-reporter ,spec ,msg ,@body)
|
|
||||||
`(dolist ,spec ,@body)))
|
|
||||||
|
|
||||||
;;; File utilities
|
|
||||||
(defun org-roam-descendant-of-p (a b)
|
|
||||||
"Return t if A is descendant of B."
|
|
||||||
(unless (and a b (equal (file-truename a) (file-truename b)))
|
|
||||||
(string-prefix-p (replace-regexp-in-string "^\\([A-Za-z]\\):" 'downcase (expand-file-name b) t t)
|
|
||||||
(replace-regexp-in-string "^\\([A-Za-z]\\):" 'downcase (expand-file-name a) t t))))
|
|
||||||
|
|
||||||
(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)
|
|
||||||
(find-file-hook 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 (derived-mode-p 'org-mode)
|
|
||||||
(delay-mode-hooks
|
|
||||||
(let ((org-inhibit-startup t)
|
|
||||||
(org-agenda-files nil))
|
|
||||||
(org-mode)
|
|
||||||
(hack-local-variables))))
|
|
||||||
(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))
|
|
||||||
|
|
||||||
;;; Buffer utilities
|
|
||||||
(defmacro org-roam-with-temp-buffer (file &rest body)
|
|
||||||
"Execute BODY within a temp buffer.
|
|
||||||
Like `with-temp-buffer', but propagates `org-roam-directory'.
|
|
||||||
If FILE, set `default-directory' to FILE's directory and insert its contents."
|
|
||||||
(declare (indent 1) (debug t))
|
|
||||||
(let ((current-org-roam-directory (make-symbol "current-org-roam-directory")))
|
|
||||||
`(let ((,current-org-roam-directory org-roam-directory))
|
|
||||||
(with-temp-buffer
|
|
||||||
(let ((org-roam-directory ,current-org-roam-directory)
|
|
||||||
(org-inhibit-startup t))
|
|
||||||
(delay-mode-hooks (org-mode))
|
|
||||||
(when ,file
|
|
||||||
(insert-file-contents ,file)
|
|
||||||
(setq-local default-directory (file-name-directory ,file)))
|
|
||||||
,@body)))))
|
|
||||||
|
|
||||||
;;; Formatting
|
|
||||||
(defun org-roam-format-template (template replacer)
|
|
||||||
"Format TEMPLATE with the function REPLACER.
|
|
||||||
The templates are of form ${foo} for variable foo, and
|
|
||||||
${foo=default} for variable foo with default value \"default\".
|
|
||||||
REPLACER takes an argument of the format variable and the default
|
|
||||||
value (possibly nil). 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))
|
|
||||||
default-val)
|
|
||||||
(when (string-match "\\(.+\\)=\\(.+\\)" var)
|
|
||||||
(setq default-val (match-string 2 var)
|
|
||||||
var (match-string 1 var)))
|
|
||||||
(unwind-protect
|
|
||||||
(let ((v (progn
|
|
||||||
(set-match-data saved-match-data)
|
|
||||||
(funcall replacer var default-val))))
|
|
||||||
(if v
|
|
||||||
(format (apply #'propertize "%s" (text-properties-at 0 var)) v)
|
|
||||||
(signal 'org-roam-format-resolve md)))
|
|
||||||
(set-match-data replacer-match-data))))
|
|
||||||
(if (functionp template)
|
|
||||||
(funcall template)
|
|
||||||
template)
|
|
||||||
;; Need literal to make sure it works
|
|
||||||
t t)
|
|
||||||
(set-match-data saved-match-data))))
|
|
||||||
|
|
||||||
;;; Fontification
|
|
||||||
(defvar org-ref-buffer-hacked)
|
(defvar org-ref-buffer-hacked)
|
||||||
|
|
||||||
(defun org-roam-fontify-like-in-org-mode (s)
|
(defun org-roam-fontify-like-in-org-mode (s)
|
||||||
@ -230,211 +93,102 @@ Like `org-fontify-like-in-org-mode', but supports `org-ref'."
|
|||||||
(insert s)
|
(insert s)
|
||||||
(let ((org-ref-buffer-hacked t))
|
(let ((org-ref-buffer-hacked t))
|
||||||
(org-mode)
|
(org-mode)
|
||||||
(setq-local org-fold-core-style 'overlays)
|
(org-font-lock-ensure)
|
||||||
(font-lock-ensure)
|
|
||||||
(buffer-string))))
|
(buffer-string))))
|
||||||
|
|
||||||
;;; Org-mode utilities
|
(defun org-roam-set-header-line-format (string)
|
||||||
;;;; Motions
|
"Set the header-line using STRING.
|
||||||
(defun org-roam-up-heading-or-point-min ()
|
If the `face' property of any part of STRING is already set, then
|
||||||
"Fixed version of Org's `org-up-heading-or-point-min'."
|
that takes precedence. Also pad the left side of STRING so that
|
||||||
(ignore-errors (org-back-to-heading t))
|
it aligns with the text area."
|
||||||
(let ((p (point)))
|
(setq-local header-line-format
|
||||||
(if (< 1 (funcall outline-level))
|
(concat (propertize " " 'display '(space :align-to 0))
|
||||||
(progn
|
string)))
|
||||||
(org-up-heading-safe)
|
|
||||||
(when (= (point) p)
|
|
||||||
(goto-char (point-min))))
|
|
||||||
(unless (bobp) (goto-char (point-min))))))
|
|
||||||
|
|
||||||
;;;; Keywords
|
;;; Shielding regions
|
||||||
(defun org-roam-get-keyword (name &optional file bound)
|
(defface org-roam-shielded
|
||||||
"Return keyword property NAME from an org FILE.
|
'((t :inherit (warning)))
|
||||||
FILE defaults to current file.
|
"Face for regions that are shielded (marked as read-only).
|
||||||
Only scans up to BOUND bytes of the document."
|
This face is used on the region target by org-roam-insertion
|
||||||
(unless bound
|
during an `org-roam-capture'."
|
||||||
(setq bound 1024))
|
:group 'org-roam-faces)
|
||||||
(if file
|
|
||||||
(with-temp-buffer
|
|
||||||
(insert-file-contents file nil 0 bound)
|
|
||||||
(org-roam--get-keyword name))
|
|
||||||
(org-roam--get-keyword name bound)))
|
|
||||||
|
|
||||||
(defun org-roam--get-keyword (name &optional bound)
|
(defun org-roam-shield-region (beg end)
|
||||||
"Return keyword property NAME in current buffer.
|
"Shield region against modifications.
|
||||||
If BOUND, scan up to BOUND bytes of the buffer."
|
BEG and END are markers for the beginning and end regions.
|
||||||
(save-excursion
|
REGION must be a cons-cell containing the marker to the region
|
||||||
(let ((re (format "^#\\+%s:[ \t]*\\([^\n]+\\)" (upcase name))))
|
beginning and maximum values."
|
||||||
(goto-char (point-min))
|
(add-text-properties beg end
|
||||||
(when (re-search-forward re bound t)
|
'(font-lock-face org-roam-shielded
|
||||||
(buffer-substring-no-properties (match-beginning 1) (match-end 1))))))
|
read-only t)
|
||||||
|
(marker-buffer beg)))
|
||||||
|
|
||||||
(defun org-roam-end-of-meta-data (&optional full)
|
(defun org-roam-unshield-region (beg end)
|
||||||
"Like `org-end-of-meta-data', but supports file-level metadata.
|
"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))))
|
||||||
|
|
||||||
When FULL is non-nil but not t, skip planning information,
|
;;; Formatting
|
||||||
properties, clocking lines and logbook drawers.
|
(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))))
|
||||||
|
|
||||||
When optional argument FULL is t, skip everything above, and also
|
(defun org-roam--process-display-format (format)
|
||||||
skip keywords."
|
"Pre-calculate minimal widths needed by the FORMAT string."
|
||||||
(org-back-to-heading-or-point-min t)
|
(let* ((fields-width 0)
|
||||||
(when (org-at-heading-p) (forward-line))
|
(string-width
|
||||||
;; Skip planning information.
|
(string-width
|
||||||
(when (looking-at-p org-planning-line-re) (forward-line))
|
(org-roam-format
|
||||||
;; Skip property drawer.
|
format
|
||||||
(when (looking-at org-property-drawer-re)
|
(lambda (field)
|
||||||
(goto-char (match-end 0))
|
(setq fields-width
|
||||||
(forward-line))
|
(+ fields-width
|
||||||
;; When FULL is not nil, skip more.
|
(string-to-number
|
||||||
(when (and full (not (org-at-heading-p)))
|
(or (cadr (split-string field ":"))
|
||||||
(catch 'exit
|
"")))))))))
|
||||||
(let ((end (save-excursion (outline-next-heading) (point)))
|
(cons format (+ fields-width string-width))))
|
||||||
(re (concat "[ \t]*$" "\\|" org-clock-line-re)))
|
|
||||||
(while (not (eobp))
|
|
||||||
(cond ;; Skip clock lines.
|
|
||||||
((looking-at-p re) (forward-line))
|
|
||||||
;; Skip logbook drawer.
|
|
||||||
((looking-at-p org-logbook-drawer-re)
|
|
||||||
(if (re-search-forward "^[ \t]*:END:[ \t]*$" end t)
|
|
||||||
(forward-line)
|
|
||||||
(throw 'exit t)))
|
|
||||||
((looking-at-p org-drawer-regexp)
|
|
||||||
(if (re-search-forward "^[ \t]*:END:[ \t]*$" end t)
|
|
||||||
(forward-line)
|
|
||||||
(throw 'exit t)))
|
|
||||||
;; When FULL is t, skip keywords too.
|
|
||||||
((and (eq full t)
|
|
||||||
(looking-at-p org-keyword-regexp))
|
|
||||||
(forward-line))
|
|
||||||
(t (throw 'exit t))))))))
|
|
||||||
|
|
||||||
(defun org-roam-set-keyword (key value)
|
|
||||||
"Set keyword KEY to VALUE.
|
|
||||||
If the property is already set, it's value is replaced."
|
|
||||||
(org-with-point-at 1
|
|
||||||
(let ((case-fold-search t))
|
|
||||||
(if (re-search-forward (concat "^#\\+" key ":\\(.*\\)") (point-max) t)
|
|
||||||
(if (string-blank-p value)
|
|
||||||
(kill-whole-line)
|
|
||||||
(replace-match (concat " " value) 'fixedcase nil nil 1))
|
|
||||||
(org-roam-end-of-meta-data 'drawers)
|
|
||||||
(if (save-excursion (end-of-line) (eobp))
|
|
||||||
(progn
|
|
||||||
(end-of-line)
|
|
||||||
(insert "\n"))
|
|
||||||
(forward-line)
|
|
||||||
(beginning-of-line))
|
|
||||||
(insert "#+" key ": " value "\n")))))
|
|
||||||
|
|
||||||
(defun org-roam-erase-keyword (keyword)
|
|
||||||
"Erase the line where the KEYWORD is, 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)))))
|
|
||||||
|
|
||||||
;;;; Properties
|
|
||||||
(defun org-roam-add-property (val prop)
|
|
||||||
"Add VAL value to PROP property for the node at point.
|
|
||||||
Both, VAL and PROP are strings."
|
|
||||||
(org-roam-property-add prop val))
|
|
||||||
|
|
||||||
(defun org-roam-remove-property (prop &optional val)
|
|
||||||
"Remove VAL value from PROP property for the node at point.
|
|
||||||
Both VAL and PROP are strings.
|
|
||||||
|
|
||||||
If VAL is not specified, user is prompted to select a value."
|
|
||||||
(org-roam-property-remove prop val))
|
|
||||||
|
|
||||||
(defun org-roam-property-add (prop val)
|
|
||||||
"Add VAL value to PROP property for the node at point.
|
|
||||||
Both, VAL and PROP are strings."
|
|
||||||
(let* ((p (org-entry-get (point) prop))
|
|
||||||
(lst (when p (split-string-and-unquote p)))
|
|
||||||
(lst (if (memq val lst) lst (cons val lst)))
|
|
||||||
(lst (seq-uniq lst)))
|
|
||||||
(org-set-property prop (combine-and-quote-strings lst))
|
|
||||||
val))
|
|
||||||
|
|
||||||
(defun org-roam-property-remove (prop &optional val)
|
|
||||||
"Remove VAL value from PROP property for the node at point.
|
|
||||||
Both VAL and PROP are strings.
|
|
||||||
|
|
||||||
If VAL is not specified, user is prompted to select a value."
|
|
||||||
(let* ((p (org-entry-get (point) prop))
|
|
||||||
(lst (when p (split-string-and-unquote p)))
|
|
||||||
(prop-to-remove (or val (completing-read "Remove: " lst)))
|
|
||||||
(lst (delete prop-to-remove lst)))
|
|
||||||
(if lst
|
|
||||||
(org-set-property prop (combine-and-quote-strings lst))
|
|
||||||
(org-delete-property prop))
|
|
||||||
prop-to-remove))
|
|
||||||
|
|
||||||
;;; Refs
|
|
||||||
(defun org-roam-org-ref-path-to-keys (path)
|
|
||||||
"Return a list of keys given an org-ref cite: PATH.
|
|
||||||
Accounts for both v2 and v3."
|
|
||||||
(cond ((fboundp 'org-ref-parse-cite-path)
|
|
||||||
(mapcar (lambda (cite) (plist-get cite :key))
|
|
||||||
(plist-get (org-ref-parse-cite-path path) :references)))
|
|
||||||
((fboundp 'org-ref-split-and-strip-string)
|
|
||||||
(org-ref-split-and-strip-string path))))
|
|
||||||
|
|
||||||
;;; Logs
|
|
||||||
(defvar org-roam-verbose)
|
|
||||||
(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))))
|
|
||||||
|
|
||||||
;;; Diagnostics
|
;;; Diagnostics
|
||||||
;; TODO Update this to also get commit hash
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun org-roam-version (&optional message)
|
(defun org-roam-version (&optional message)
|
||||||
"Return `org-roam' version.
|
"Return `org-roam' version.
|
||||||
Interactively, or when MESSAGE is non-nil, show in the echo area."
|
Interactively, or when MESSAGE is non-nil, show in the echo area."
|
||||||
(interactive)
|
(interactive)
|
||||||
(let* ((toplib (or load-file-name buffer-file-name))
|
(let* ((version
|
||||||
gitdir topdir version)
|
(with-temp-buffer
|
||||||
(unless (and toplib (equal (file-name-nondirectory toplib) "org-roam-utils.el"))
|
(insert-file-contents-literally (locate-library "org-roam.el"))
|
||||||
(setq toplib (locate-library "org-roam-utils.el")))
|
(goto-char (point-min))
|
||||||
(setq toplib (and toplib (org-roam--straight-chase-links toplib)))
|
(save-match-data
|
||||||
(when toplib
|
(if (re-search-forward "\\(?:;; Version: \\([^z-a]*?$\\)\\)" nil nil)
|
||||||
(setq topdir (file-name-directory toplib)
|
(substring-no-properties (match-string 1))
|
||||||
gitdir (expand-file-name ".git" topdir)))
|
"N/A")))))
|
||||||
(when (file-exists-p gitdir)
|
|
||||||
(setq version
|
|
||||||
(let ((default-directory topdir))
|
|
||||||
(shell-command-to-string "git describe --tags --dirty --always"))))
|
|
||||||
(unless version
|
|
||||||
(setq 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))
|
(if (or message (called-interactively-p 'interactive))
|
||||||
(message "%s" version)
|
(message "%s" version)
|
||||||
version)))
|
version)))
|
||||||
|
|
||||||
(defun org-roam--straight-chase-links (filename)
|
|
||||||
"Chase links in FILENAME until a name that is not a link.
|
|
||||||
|
|
||||||
This is the same as `file-chase-links', except that it also
|
|
||||||
handles fake symlinks that are created by the package manager
|
|
||||||
straight.el on Windows.
|
|
||||||
|
|
||||||
See <https://github.com/raxod502/straight.el/issues/520>."
|
|
||||||
(when (and (bound-and-true-p straight-symlink-emulation-mode)
|
|
||||||
(fboundp 'straight-chase-emulated-symlink))
|
|
||||||
(when-let ((target (straight-chase-emulated-symlink filename)))
|
|
||||||
(unless (eq target 'broken)
|
|
||||||
(setq filename target))))
|
|
||||||
(file-chase-links filename))
|
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun org-roam-diagnostics ()
|
(defun org-roam-diagnostics ()
|
||||||
"Collect and print info for `org-roam' issues."
|
"Collect and print info for `org-roam' issues."
|
||||||
@ -449,11 +203,7 @@ See <https://github.com/raxod502/straight.el/issues/520>."
|
|||||||
'("Doom" "Spacemacs" "N/A" "I don't know"))
|
'("Doom" "Spacemacs" "N/A" "I don't know"))
|
||||||
(quit "N/A"))))
|
(quit "N/A"))))
|
||||||
(insert (format "- Org: %s\n" (org-version nil 'full)))
|
(insert (format "- Org: %s\n" (org-version nil 'full)))
|
||||||
(insert (format "- Org-roam: %s" (org-roam-version)))
|
(insert (format "- Org-roam: %s" (org-roam-version)))))
|
||||||
(insert (format "- sqlite-connector: %s"
|
|
||||||
(if-let ((conn (org-roam-db--get-connection)))
|
|
||||||
(eieio-object-class conn)
|
|
||||||
"not connected")))))
|
|
||||||
|
|
||||||
(provide 'org-roam-utils)
|
(provide 'org-roam-utils)
|
||||||
;;; org-roam-utils.el ends here
|
;;; org-roam-utils.el ends here
|
||||||
|
1036
org-roam.el
1036
org-roam.el
File diff suppressed because it is too large
Load Diff
@ -1,8 +0,0 @@
|
|||||||
:PROPERTIES:
|
|
||||||
:ID: 97bf31cf-dfee-45d8-87a5-2ae0dabc4734
|
|
||||||
:END:
|
|
||||||
#+title: Demoteable
|
|
||||||
|
|
||||||
* Demoteable h1
|
|
||||||
|
|
||||||
** Demoteable child
|
|
@ -1,19 +0,0 @@
|
|||||||
:PROPERTIES:
|
|
||||||
:ID: 998b2341-b7fe-434d-848c-5282c0727870
|
|
||||||
:END:
|
|
||||||
#+title: Family
|
|
||||||
|
|
||||||
* Grand-Parent
|
|
||||||
:PROPERTIES:
|
|
||||||
:ID: 77a90980-1994-464e-901f-7e3d3df07fd3
|
|
||||||
:END:
|
|
||||||
|
|
||||||
** Parent
|
|
||||||
:PROPERTIES:
|
|
||||||
:ID: 0fa5bb3e-3d8c-4966-8bc9-78d32e505d69
|
|
||||||
:END:
|
|
||||||
|
|
||||||
*** Child
|
|
||||||
:PROPERTIES:
|
|
||||||
:ID: 5fb4fdc5-b6d2-4f75-8d54-e60053e467ec
|
|
||||||
:END:
|
|
@ -1,3 +0,0 @@
|
|||||||
* Promoteable h1
|
|
||||||
|
|
||||||
** Promoteable child
|
|
@ -1,7 +0,0 @@
|
|||||||
:PROPERTIES:
|
|
||||||
:ROAM_REFS: "http://site.net/docs/01. introduction - hello world.html"
|
|
||||||
:ID: 5b9a7400-f59c-4ef9-acbb-045b69af98f1
|
|
||||||
:END:
|
|
||||||
#+title: ref with space
|
|
||||||
* Note
|
|
||||||
hello
|
|
@ -1,7 +0,0 @@
|
|||||||
:PROPERTIES:
|
|
||||||
:ID: 53fadc75-f48e-461e-be06-44a1e88b2abe
|
|
||||||
:ROAM_EXCLUDE: t
|
|
||||||
:END:
|
|
||||||
#+TITLE: Excluded by Org-roam
|
|
||||||
|
|
||||||
This node is excluded by declaring ~ROAM_EXCLUDE: t~.
|
|
@ -1,5 +0,0 @@
|
|||||||
:PROPERTIES:
|
|
||||||
:ID: 57ff3ce7-5bda-4825-8fca-c09f523e87ba
|
|
||||||
:ROAM_ALIASES: Batman
|
|
||||||
:END:
|
|
||||||
#+title: Bruce Wayne
|
|
@ -1,16 +0,0 @@
|
|||||||
:PROPERTIES:
|
|
||||||
:ID: 9a20ca6c-5555-41c9-a039-ac38bf59c7a9
|
|
||||||
:END:
|
|
||||||
#+title: With Times
|
|
||||||
|
|
||||||
* Scheduled heading
|
|
||||||
SCHEDULED: <2024-07-16 Tue>
|
|
||||||
:PROPERTIES:
|
|
||||||
:ID: a523c198-4cb4-44d2-909c-a0e3258089cd
|
|
||||||
:END:
|
|
||||||
|
|
||||||
* Deadline heading
|
|
||||||
DEADLINE: <2024-07-17 Tue>
|
|
||||||
:PROPERTIES:
|
|
||||||
:ID: 3ab84701-d1c1-463f-b5c6-715e6ff5a0bf
|
|
||||||
:END:
|
|
@ -1,63 +0,0 @@
|
|||||||
;;; test-org-roam-capture.el --- 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)
|
|
||||||
|
|
||||||
(describe "org-roam-capture--fill-template"
|
|
||||||
(it "fills template without newline"
|
|
||||||
(expect
|
|
||||||
(org-roam-capture--fill-template "foo")
|
|
||||||
:to-equal "foo"))
|
|
||||||
|
|
||||||
(it "fills template ensuring newline"
|
|
||||||
(expect
|
|
||||||
(org-roam-capture--fill-template "foo" 'ensure-newline)
|
|
||||||
:to-equal "foo\n"))
|
|
||||||
|
|
||||||
(it "fills template with newline"
|
|
||||||
(expect
|
|
||||||
(org-roam-capture--fill-template "foo\n")
|
|
||||||
:to-equal "foo\n"))
|
|
||||||
|
|
||||||
(it "fills template with two newlines"
|
|
||||||
(expect
|
|
||||||
(org-roam-capture--fill-template "foo\n\n")
|
|
||||||
:to-equal "foo\n\n")
|
|
||||||
(expect
|
|
||||||
(org-roam-capture--fill-template "foo\n\t\n")
|
|
||||||
:to-equal "foo\n\t\n"))
|
|
||||||
|
|
||||||
(it "fills template without deleting newlines in its body"
|
|
||||||
(expect
|
|
||||||
(org-roam-capture--fill-template "foo\n\n\nbar\n\n")
|
|
||||||
:to-equal "foo\n\n\nbar\n\n"))
|
|
||||||
|
|
||||||
(it "expands templates when it's a function"
|
|
||||||
(expect
|
|
||||||
(org-roam-capture--fill-template (lambda () "foo"))
|
|
||||||
:to-equal "foo")))
|
|
||||||
|
|
||||||
(provide 'test-org-roam-capture)
|
|
||||||
|
|
||||||
;;; test-org-roam-capture.el ends here
|
|
@ -1,120 +0,0 @@
|
|||||||
;;; test-org-roam-db.el --- 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)
|
|
||||||
|
|
||||||
(defvar root-directory default-directory)
|
|
||||||
|
|
||||||
(describe "org-roam-db-get-scheduled-time"
|
|
||||||
(before-all
|
|
||||||
(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-file-extensions '("org")
|
|
||||||
org-roam-file-exclude-regexp nil)
|
|
||||||
(org-roam-db-sync))
|
|
||||||
|
|
||||||
(after-all
|
|
||||||
(org-roam-db--close)
|
|
||||||
(delete-file org-roam-db-location)
|
|
||||||
(cd root-directory))
|
|
||||||
|
|
||||||
(it "should get scheduled time for current heading node"
|
|
||||||
(org-roam-id-open "a523c198-4cb4-44d2-909c-a0e3258089cd" nil)
|
|
||||||
(expect (org-roam-db-get-scheduled-time) :to-equal "2024-07-16T00:00:00")))
|
|
||||||
|
|
||||||
(describe "org-roam-db-get-deadline-time"
|
|
||||||
(before-all
|
|
||||||
(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-file-extensions '("org")
|
|
||||||
org-roam-file-exclude-regexp nil)
|
|
||||||
(org-roam-db-sync))
|
|
||||||
|
|
||||||
(after-all
|
|
||||||
(org-roam-db--close)
|
|
||||||
(delete-file org-roam-db-location)
|
|
||||||
(cd root-directory))
|
|
||||||
|
|
||||||
(it "should get deadline time for current heading node"
|
|
||||||
(org-roam-id-open "3ab84701-d1c1-463f-b5c6-715e6ff5a0bf" nil)
|
|
||||||
(expect (org-roam-db-get-deadline-time) :to-equal "2024-07-17T00:00:00")))
|
|
||||||
|
|
||||||
(describe "org-roam-db--file-hash"
|
|
||||||
(it "computes the SHA1 of file"
|
|
||||||
(expect (org-roam-db--file-hash "tests/roam-files/family.org")
|
|
||||||
:to-equal
|
|
||||||
"c4ebf8918c1533df72e4d182cbf1bbd90f776b3b")))
|
|
||||||
|
|
||||||
(describe "org-roam-db-sync"
|
|
||||||
(before-all
|
|
||||||
(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-file-extensions '("org")
|
|
||||||
org-roam-file-exclude-regexp nil)
|
|
||||||
(org-roam-db-sync))
|
|
||||||
|
|
||||||
(after-all
|
|
||||||
(org-roam-db--close)
|
|
||||||
(delete-file org-roam-db-location))
|
|
||||||
|
|
||||||
(it "has the correct number of files"
|
|
||||||
(expect (caar (org-roam-db-query [:select (funcall count) :from files]))
|
|
||||||
:to-equal
|
|
||||||
9))
|
|
||||||
|
|
||||||
(it "has the correct number of nodes"
|
|
||||||
(expect (caar (org-roam-db-query [:select (funcall count) :from nodes]))
|
|
||||||
:to-equal
|
|
||||||
12))
|
|
||||||
|
|
||||||
(it "has the correct number of links"
|
|
||||||
(expect (caar (org-roam-db-query [:select (funcall count) :from links]))
|
|
||||||
:to-equal
|
|
||||||
1))
|
|
||||||
|
|
||||||
(it "respects ROAM_EXCLUDE"
|
|
||||||
;; The excluded node has ID "53fadc75-f48e-461e-be06-44a1e88b2abe"
|
|
||||||
(expect (mapcar #'car (org-roam-db-query [:select id :from nodes]))
|
|
||||||
:to-have-same-items-as
|
|
||||||
'("884b2341-b7fe-434d-848c-5282c0727861"
|
|
||||||
"440795d0-70c1-4165-993d-aebd5eef7a24"
|
|
||||||
"5b9a7400-f59c-4ef9-acbb-045b69af98f1"
|
|
||||||
"0fa5bb3e-3d8c-4966-8bc9-78d32e505d69"
|
|
||||||
"5fb4fdc5-b6d2-4f75-8d54-e60053e467ec"
|
|
||||||
"77a90980-1994-464e-901f-7e3d3df07fd3"
|
|
||||||
"57ff3ce7-5bda-4825-8fca-c09f523e87ba"
|
|
||||||
"998b2341-b7fe-434d-848c-5282c0727870"
|
|
||||||
"a523c198-4cb4-44d2-909c-a0e3258089cd"
|
|
||||||
"3ab84701-d1c1-463f-b5c6-715e6ff5a0bf"
|
|
||||||
"9a20ca6c-5555-41c9-a039-ac38bf59c7a9"
|
|
||||||
"97bf31cf-dfee-45d8-87a5-2ae0dabc4734")))
|
|
||||||
|
|
||||||
(it "reads ref in quotes correctly"
|
|
||||||
(expect (mapcar #'car (org-roam-db-query [:select [ref] :from refs]))
|
|
||||||
:to-have-same-items-as
|
|
||||||
'("//site.net/docs/01. introduction - hello world.html"))))
|
|
||||||
|
|
||||||
(provide 'test-org-roam-db)
|
|
||||||
|
|
||||||
;;; test-org-roam-db.el ends here
|
|
@ -1,79 +0,0 @@
|
|||||||
;;; test-org-roam-id.el --- 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)
|
|
||||||
|
|
||||||
(defvar root-directory default-directory)
|
|
||||||
|
|
||||||
(describe "org-roam-id-at-point"
|
|
||||||
(before-all
|
|
||||||
(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-file-extensions '("org")
|
|
||||||
org-roam-file-exclude-regexp nil)
|
|
||||||
(org-roam-db-sync))
|
|
||||||
|
|
||||||
(after-all
|
|
||||||
(org-roam-db--close)
|
|
||||||
(delete-file org-roam-db-location)
|
|
||||||
(cd root-directory))
|
|
||||||
|
|
||||||
(it "returns the correct node ids"
|
|
||||||
(find-file "tests/roam-files/family.org" nil)
|
|
||||||
(expect (org-roam-id-at-point) :to-equal "998b2341-b7fe-434d-848c-5282c0727870")
|
|
||||||
|
|
||||||
(search-forward "Grand")
|
|
||||||
(expect (org-roam-id-at-point) :to-equal "77a90980-1994-464e-901f-7e3d3df07fd3")
|
|
||||||
|
|
||||||
(search-forward "Child")
|
|
||||||
(expect (org-roam-id-at-point) :to-equal "5fb4fdc5-b6d2-4f75-8d54-e60053e467ec")))
|
|
||||||
|
|
||||||
(describe "org-roam-id-find"
|
|
||||||
(before-all
|
|
||||||
(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-file-extensions '("org")
|
|
||||||
org-roam-file-exclude-regexp nil)
|
|
||||||
(org-roam-db-sync))
|
|
||||||
|
|
||||||
(after-all
|
|
||||||
(org-roam-db--close)
|
|
||||||
(delete-file org-roam-db-location))
|
|
||||||
|
|
||||||
(it "finds nothing for non-existing node"
|
|
||||||
(expect (org-roam-id-find "non-existing") :to-equal nil))
|
|
||||||
|
|
||||||
(it "finds the correct file node"
|
|
||||||
(let ((location (org-roam-id-find "884b2341-b7fe-434d-848c-5282c0727861")))
|
|
||||||
(expect (car location) :to-match ".*/tests/roam-files/foo.org")
|
|
||||||
(expect (cdr location) :to-equal 1)))
|
|
||||||
|
|
||||||
(it "finds the correct heading node"
|
|
||||||
(let ((location (org-roam-id-find "0fa5bb3e-3d8c-4966-8bc9-78d32e505d69")))
|
|
||||||
(expect (car location) :to-match ".*/tests/roam-files/family.org")
|
|
||||||
(expect (cdr location) :to-equal 156))))
|
|
||||||
|
|
||||||
(provide 'test-org-roam-id)
|
|
||||||
|
|
||||||
;;; test-org-roam-id.el ends here
|
|
@ -1,56 +0,0 @@
|
|||||||
;;; test-org-roam-link-replace.el --- Tests for Org-roam link replacement -*- lexical-binding: t; -*-
|
|
||||||
|
|
||||||
;; Copyright (C) 2025
|
|
||||||
|
|
||||||
;; 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:
|
|
||||||
;; Tests for commits fc86387 and 89dfaef - link replacement optimization
|
|
||||||
;;; Code:
|
|
||||||
|
|
||||||
(require 'buttercup)
|
|
||||||
(require 'org-roam)
|
|
||||||
(require 'org-roam-node)
|
|
||||||
|
|
||||||
(describe "org-roam-link-replace-all optimization"
|
|
||||||
(before-all
|
|
||||||
(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-db-sync))
|
|
||||||
|
|
||||||
(after-all
|
|
||||||
(org-roam-db--close)
|
|
||||||
(delete-file org-roam-db-location))
|
|
||||||
|
|
||||||
(it "only processes roam: links, not other bracket links"
|
|
||||||
(with-temp-buffer
|
|
||||||
(org-mode)
|
|
||||||
(insert "[[file:test.org][File]]\n[[roam:Foo]]\n[[https://example.com][Web]]")
|
|
||||||
(let ((replace-count 0)
|
|
||||||
(original-fn (symbol-function 'org-roam-link-replace-at-point)))
|
|
||||||
;; Wrap the original function to count calls
|
|
||||||
(cl-letf (((symbol-function 'org-roam-link-replace-at-point)
|
|
||||||
(lambda ()
|
|
||||||
(cl-incf replace-count)
|
|
||||||
(funcall original-fn))))
|
|
||||||
(org-roam-link-replace-all)
|
|
||||||
;; Should only be called once, for the roam: link
|
|
||||||
(expect replace-count :to-equal 1)
|
|
||||||
(expect (buffer-string) :to-match "\\[\\[id:.*\\]\\[Foo\\]\\]"))))))
|
|
||||||
|
|
||||||
(provide 'test-org-roam-link-replace)
|
|
||||||
|
|
||||||
;;; test-org-roam-link-replace.el ends here
|
|
@ -1,39 +0,0 @@
|
|||||||
;;; test-org-roam-mode.el --- 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)
|
|
||||||
|
|
||||||
(describe "org-roam-unlinked-references--rg-command"
|
|
||||||
(before-each
|
|
||||||
;; the space in the directory is on purpose
|
|
||||||
(setq org-roam-directory "/tmp/org roam"))
|
|
||||||
|
|
||||||
(it "returns the correct rg command for unlinked references"
|
|
||||||
(expect (org-roam-unlinked-references--rg-command '("foo" "bar") "/tmp/regex")
|
|
||||||
:to-equal
|
|
||||||
"rg --follow --only-matching --vimgrep --pcre2 --ignore-case --glob \"*.org\" --glob \"*.org.gpg\" --glob \"*.org.age\" --file /tmp/regex /tmp/org\\ roam")))
|
|
||||||
|
|
||||||
(provide 'test-org-roam-mode)
|
|
||||||
|
|
||||||
;;; test-org-roam-mode.el ends here
|
|
@ -1,166 +0,0 @@
|
|||||||
;;; test-org-roam-node.el --- 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)
|
|
||||||
|
|
||||||
(defvar root-directory default-directory)
|
|
||||||
|
|
||||||
(describe "org-roam-node-from-id"
|
|
||||||
(before-all
|
|
||||||
(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-file-extensions '("org")
|
|
||||||
org-roam-file-exclude-regexp nil)
|
|
||||||
(org-roam-db-sync))
|
|
||||||
|
|
||||||
(after-all
|
|
||||||
(org-roam-db--close)
|
|
||||||
(delete-file org-roam-db-location))
|
|
||||||
|
|
||||||
(it "returns nil for unknown id"
|
|
||||||
(expect (org-roam-node-from-id "non-existing") :to-equal nil))
|
|
||||||
|
|
||||||
(it "returns correct node from id"
|
|
||||||
(let ((node (org-roam-node-from-id "884b2341-b7fe-434d-848c-5282c0727861")))
|
|
||||||
(expect (org-roam-node-title node) :to-equal "Foo"))))
|
|
||||||
|
|
||||||
(describe "org-roam-node-from-title-or-alias"
|
|
||||||
(before-all
|
|
||||||
(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-file-extensions '("org")
|
|
||||||
org-roam-file-exclude-regexp nil)
|
|
||||||
(org-roam-db-sync))
|
|
||||||
|
|
||||||
(after-all
|
|
||||||
(org-roam-db--close)
|
|
||||||
(delete-file org-roam-db-location))
|
|
||||||
|
|
||||||
(it "returns nil for unknown title"
|
|
||||||
(expect (org-roam-node-from-title-or-alias "non-existing") :to-equal nil))
|
|
||||||
|
|
||||||
(it "returns correct node from title"
|
|
||||||
(let ((node (org-roam-node-from-title-or-alias "Foo")))
|
|
||||||
(expect (org-roam-node-title node) :to-equal "Foo")))
|
|
||||||
|
|
||||||
(it "returns correct node from alias"
|
|
||||||
(let ((node (org-roam-node-from-title-or-alias "Batman")))
|
|
||||||
(expect (org-roam-node-title node) :to-equal "Bruce Wayne")))
|
|
||||||
|
|
||||||
(it "returns correct node from alias with nocase"
|
|
||||||
(let ((node (org-roam-node-from-title-or-alias "batman" t)))
|
|
||||||
(expect (org-roam-node-title node) :to-equal "Bruce Wayne"))))
|
|
||||||
|
|
||||||
(describe "org-roam-demote-entire-buffer"
|
|
||||||
(it "demotes an entire org buffer"
|
|
||||||
;; Use a temporary copy to avoid interfering with other tests
|
|
||||||
(let ((temp-file (make-temp-file "test-demoteable-" nil ".org")))
|
|
||||||
(copy-file "tests/roam-files/demoteable.org" temp-file t)
|
|
||||||
(find-file temp-file)
|
|
||||||
(org-roam-demote-entire-buffer)
|
|
||||||
(expect (buffer-substring-no-properties (point) (point-max))
|
|
||||||
:to-equal "* Demoteable\n:PROPERTIES:\n:ID: 97bf31cf-dfee-45d8-87a5-2ae0dabc4734\n:END:\n\n** Demoteable h1\n\n*** Demoteable child\n")
|
|
||||||
(kill-buffer)
|
|
||||||
(delete-file temp-file))))
|
|
||||||
|
|
||||||
(describe "org-roam--h1-count"
|
|
||||||
(after-each
|
|
||||||
(cd root-directory))
|
|
||||||
|
|
||||||
(it "returns the correct number of level-1 headings"
|
|
||||||
(find-file "tests/roam-files/foo.org" nil)
|
|
||||||
(expect (org-roam--h1-count) :to-equal 0)
|
|
||||||
|
|
||||||
(cd root-directory)
|
|
||||||
|
|
||||||
(find-file "tests/roam-files/family.org" nil)
|
|
||||||
(expect (org-roam--h1-count) :to-equal 1)))
|
|
||||||
|
|
||||||
(describe "org-roam--buffer-promoteable-p"
|
|
||||||
(after-each
|
|
||||||
(cd root-directory))
|
|
||||||
|
|
||||||
(it "should check if buffer is promoteable"
|
|
||||||
(find-file "tests/roam-files/foo.org" nil)
|
|
||||||
(expect (org-roam--buffer-promoteable-p) :to-equal nil)
|
|
||||||
|
|
||||||
(cd root-directory)
|
|
||||||
|
|
||||||
(find-file "tests/roam-files/family.org" nil)
|
|
||||||
(expect (org-roam--buffer-promoteable-p) :to-equal nil)
|
|
||||||
|
|
||||||
(cd root-directory)
|
|
||||||
|
|
||||||
(find-file "tests/roam-files/promoteable.org" nil)
|
|
||||||
(expect (org-roam--buffer-promoteable-p) :to-equal t)))
|
|
||||||
|
|
||||||
(describe "org-roam--get-titles"
|
|
||||||
(before-all
|
|
||||||
(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-file-extensions '("org")
|
|
||||||
org-roam-file-exclude-regexp nil)
|
|
||||||
(org-roam-db-sync))
|
|
||||||
|
|
||||||
(after-all
|
|
||||||
(org-roam-db--close)
|
|
||||||
(delete-file org-roam-db-location))
|
|
||||||
|
|
||||||
(it "returns the list of titles and aliases"
|
|
||||||
(expect (org-roam--get-titles)
|
|
||||||
:to-have-same-items-as
|
|
||||||
`("Bar" "Batman" "Bruce Wayne" "Child" "Deadline heading" "Demoteable" "Family"
|
|
||||||
"Foo" "Grand-Parent" "Parent" "ref with space" "Scheduled heading" "With Times"))))
|
|
||||||
|
|
||||||
|
|
||||||
(describe "org-roam-alias"
|
|
||||||
(before-all
|
|
||||||
(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-file-extensions '("org")
|
|
||||||
org-roam-file-exclude-regexp nil)
|
|
||||||
(org-roam-db-sync))
|
|
||||||
|
|
||||||
(after-all
|
|
||||||
(org-roam-db--close)
|
|
||||||
(delete-file org-roam-db-location)
|
|
||||||
(cd root-directory))
|
|
||||||
|
|
||||||
(it "adds an alias to a node"
|
|
||||||
(cd root-directory)
|
|
||||||
(find-file "tests/roam-files/foo.org" nil)
|
|
||||||
(org-roam-alias-add "qux")
|
|
||||||
(expect (buffer-substring-no-properties (point) (point-max))
|
|
||||||
:to-equal ":PROPERTIES:\n:ID: 884b2341-b7fe-434d-848c-5282c0727861\n:ROAM_ALIASES: qux\n:END:\n#+title: Foo\n"))
|
|
||||||
|
|
||||||
(it "removes an alias from a node"
|
|
||||||
(cd root-directory)
|
|
||||||
(find-file "tests/roam-files/with-alias.org" nil)
|
|
||||||
(org-roam-alias-remove "Batman")
|
|
||||||
(expect (buffer-substring-no-properties (point) (point-max))
|
|
||||||
:to-equal ":PROPERTIES:\n:ID: 57ff3ce7-5bda-4825-8fca-c09f523e87ba\n:END:\n#+title: Bruce Wayne\n")))
|
|
||||||
|
|
||||||
(provide 'test-org-roam-node)
|
|
||||||
|
|
||||||
;;; test-org-roam-node.el ends here
|
|
@ -1,64 +0,0 @@
|
|||||||
;;; test-org-roam-utils.el --- 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)
|
|
||||||
|
|
||||||
(describe "org-roam-whitespace-content"
|
|
||||||
(it "extracts whitespace correctly"
|
|
||||||
(expect
|
|
||||||
(org-roam-whitespace-content "foo")
|
|
||||||
:to-equal "")
|
|
||||||
(expect
|
|
||||||
(org-roam-whitespace-content "foo\n")
|
|
||||||
:to-equal "\n")
|
|
||||||
(expect
|
|
||||||
(org-roam-whitespace-content "foo\n\t\n")
|
|
||||||
:to-equal "\n\t\n")))
|
|
||||||
|
|
||||||
(describe "org-roam-db--file-title"
|
|
||||||
(it "supports normal titles"
|
|
||||||
(expect
|
|
||||||
(with-temp-buffer
|
|
||||||
(insert "#+title:normal title")
|
|
||||||
(org-roam-db--file-title))
|
|
||||||
:to-equal "normal title"))
|
|
||||||
(it "supports multi-line titles"
|
|
||||||
(expect
|
|
||||||
(with-temp-buffer
|
|
||||||
(insert "#+title: title:\n#+title: separated by newline")
|
|
||||||
(org-roam-db--file-title))
|
|
||||||
:to-equal "title: separated by newline"))
|
|
||||||
(it "supports file-name based titles"
|
|
||||||
(progn
|
|
||||||
(setq org-roam-directory temporary-file-directory
|
|
||||||
org-roam-db-location (expand-file-name "org-roam.db" temporary-file-directory)
|
|
||||||
org-roam-file-extensions '("org"))
|
|
||||||
(with-temp-buffer
|
|
||||||
(write-file (expand-file-name "test file.org" org-roam-directory))
|
|
||||||
(org-roam-db--file-title)))
|
|
||||||
:to-equal "test file"))
|
|
||||||
|
|
||||||
(provide 'test-org-roam-utils)
|
|
||||||
|
|
||||||
;;; test-org-roam-utils.el ends here
|
|
@ -24,58 +24,30 @@
|
|||||||
(require 'buttercup)
|
(require 'buttercup)
|
||||||
(require 'org-roam)
|
(require 'org-roam)
|
||||||
|
|
||||||
(defvar root-directory default-directory)
|
(describe "org-roam-db-sync"
|
||||||
|
(before-all
|
||||||
(describe "org-roam-file-p"
|
|
||||||
(it "checks if given file respects criteria"
|
|
||||||
(setq org-roam-directory "/non-existent")
|
|
||||||
(expect (org-roam-file-p "tests/roam-files/family.org") :to-equal nil)
|
|
||||||
|
|
||||||
(setq org-roam-directory (expand-file-name "tests/roam-files"))
|
|
||||||
(expect (org-roam-file-p "tests/roam-files/family.org") :to-equal t)
|
|
||||||
(expect (org-roam-file-p "tests/roam-files/markdown.md") :to-equal nil)
|
|
||||||
|
|
||||||
(setq org-roam-file-exclude-regexp (regexp-quote "family.org"))
|
|
||||||
(expect (org-roam-file-p "tests/roam-files/family.org") :to-equal nil)))
|
|
||||||
|
|
||||||
(describe "org-roam-buffer-p"
|
|
||||||
(it "checks if current buffer respects criteria"
|
|
||||||
(setq org-roam-directory (expand-file-name "tests/roam-files")
|
(setq org-roam-directory (expand-file-name "tests/roam-files")
|
||||||
org-roam-file-exclude-regexp nil)
|
org-roam-db-location (expand-file-name "org-roam.db" temporary-file-directory))
|
||||||
(find-file "tests/roam-files/family.org" nil)
|
(org-roam-setup))
|
||||||
(expect (org-roam-buffer-p) :to-equal t)
|
|
||||||
(cd root-directory)))
|
|
||||||
|
|
||||||
(describe "org-roam-list-files"
|
|
||||||
(before-each
|
|
||||||
(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-file-extensions '("org")
|
|
||||||
org-roam-file-exclude-regexp nil))
|
|
||||||
|
|
||||||
(after-all
|
(after-all
|
||||||
(org-roam-db--close)
|
(org-roam-teardown)
|
||||||
(delete-file org-roam-db-location))
|
(delete-file org-roam-db-location))
|
||||||
|
|
||||||
(it "gets files correctly"
|
(it "has the correct number of files"
|
||||||
(expect (length (org-roam-list-files)) :to-equal 9))
|
(expect (caar (org-roam-db-query [:select (funcall count) :from files]))
|
||||||
|
:to-equal
|
||||||
|
2))
|
||||||
|
|
||||||
(it "respects org-roam-file-extensions"
|
(it "has the correct number of nodes"
|
||||||
(setq org-roam-file-extensions '("md"))
|
(expect (caar (org-roam-db-query [:select (funcall count) :from nodes]))
|
||||||
(expect (length (org-roam-list-files)) :to-equal 1)
|
:to-equal
|
||||||
(setq org-roam-file-extensions '("org" "md"))
|
2))
|
||||||
(expect (length (org-roam-list-files)) :to-equal 10))
|
|
||||||
|
|
||||||
(it "respects org-roam-file-exclude-regexp"
|
(it "has the correct number of links"
|
||||||
(setq org-roam-file-exclude-regexp (regexp-quote "foo.org"))
|
(expect (caar (org-roam-db-query [:select (funcall count) :from links]))
|
||||||
(expect (length (org-roam-list-files)) :to-equal 8)))
|
:to-equal
|
||||||
|
1)))
|
||||||
(describe "org-roam--list-files-search-globs"
|
|
||||||
|
|
||||||
(it "returns the correct list of globs"
|
|
||||||
(expect (org-roam--list-files-search-globs org-roam-file-extensions)
|
|
||||||
:to-have-same-items-as
|
|
||||||
'("\"*.org\"" "\"*.org.gpg\"" "\"*.org.age\""))))
|
|
||||||
|
|
||||||
(provide 'test-org-roam)
|
(provide 'test-org-roam)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user