mirror of
https://github.com/org-roam/org-roam
synced 2025-08-03 12:27:23 -05:00
Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
c23bca69f8 |
2
.gitignore
vendored
2
.gitignore
vendored
@ -12,4 +12,4 @@
|
|||||||
/doc/mimetype
|
/doc/mimetype
|
||||||
/doc/stats/
|
/doc/stats/
|
||||||
/config.mk
|
/config.mk
|
||||||
/doc/manual.html
|
/doc/manual/
|
||||||
|
8
.readthedocs.yml
Normal file
8
.readthedocs.yml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
version: 2
|
||||||
|
mkdocs:
|
||||||
|
configuration: mkdocs.yml
|
||||||
|
formats: all
|
||||||
|
python:
|
||||||
|
version: 3.7
|
||||||
|
install:
|
||||||
|
- requirements: doc/requirements.txt
|
60
CHANGELOG.md
60
CHANGELOG.md
@ -1,71 +1,16 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
## 1.2.3 (13-11-2020)
|
## 1.2.2 (TBD)
|
||||||
|
|
||||||
Primarily a stabilization and bug-fix release.
|
|
||||||
|
|
||||||
Org-roam-dailies has also been revamped to include new features, see [this video](https://www.youtube.com/watch?v=1q9x2aZCJJ4) for a quick overview.
|
|
||||||
|
|
||||||
### Added
|
|
||||||
- [#978](https://github.com/org-roam/org-roam/pull/978) Revamp org-roam-dailies
|
|
||||||
- [#1183](https://github.com/org-roam/org-roam/pull/1183) Interactive functions for managing aliases and tags in Org-roam file, namely `org-roam-alias-add`, `org-roam-alias-delete`, `org-roam-tag-add`, and `org-roam-tag-delete`.
|
|
||||||
- [#1215](https://github.com/org-roam/org-roam/pull/1215) Multiple `ROAM_KEY` keywords can now be specified in one file. This allows bibliographical entries to share the same note file.
|
|
||||||
- [#1238](https://github.com/org-roam/org-roam/pull/1238) Add `org-roam-prefer-id-links` variable to select linking method
|
|
||||||
- [#1239](https://github.com/org-roam/org-roam/pull/1239) Allow `org-roam-protocol` to capture the webpage's selection, and add a toggle for storing the links to the pages
|
|
||||||
- [#1264](https://github.com/org-roam/org-roam/pull/1264) add `org-roam-db-update-method` to control when the cache is rebuilt.
|
|
||||||
|
|
||||||
### Changed
|
|
||||||
- [#1264](https://github.com/org-roam/org-roam/pull/1264) renamed `org-roam-update-db-idle-seconds` to `org-roam-db-idle-idle-seconds`
|
|
||||||
|
|
||||||
### Fixed
|
|
||||||
- [#1074](https://github.com/org-roam/org-roam/issues/1074) fix `org-roam--extract-links` to handle content boundaries.
|
|
||||||
- [#1193](https://github.com/org-roam/org-roam/issues/1193) fix `org-roam-db-build-cache` by not killing temporary buffer in `org-roam--extract-links`.
|
|
||||||
- [#1195](https://github.com/org-roam/org-roam/issues/1195) fix ID face showing as invalid if within Org ID files, but not Org-roam's.
|
|
||||||
- [#1199](https://github.com/org-roam/org-roam/issues/1199) make Org-roam link insertions respect `org-roam-link-title-format` everywhere.
|
|
||||||
- [#1201](https://github.com/org-roam/org-roam/issues/1201) fix `org-roam-db-build-cache` failing in scenarios involving duplicate IDs and deleted files.
|
|
||||||
- [#1226](https://github.com/org-roam/org-roam/issues/1226) only update relative path of file links
|
|
||||||
- [#1232](https://github.com/org-roam/org-roam/issues/1232) fix incorrect title extractions from narrowed buffers
|
|
||||||
- [#1233](https://github.com/org-roam/org-roam/issues/1233) fixes bug where descriptive file links become plain links during update for relative paths
|
|
||||||
- [#1252](https://github.com/org-roam/org-roam/issues/1252) respect original link type during automatic replacement
|
|
||||||
|
|
||||||
## 1.2.2 (06-10-2020)
|
|
||||||
|
|
||||||
In this release we support fuzzy links of the form `[[roam:Title]]`, `[[roam:*Headline]]` and `[[roam:Title*Headline]]`. Completion for these fuzzy links is supported via `completion-at-point`.
|
|
||||||
|
|
||||||
Org-roam now does not resolve symlinks. This significantly speeds up cache builds, but may result in some workflows breaking. In particular, Org-roam now cannot figure out if two distinct file paths in the Org-roam directory are the same file, and both files will be processed as if they were different files. This error seems to be unavoidable now that symlinks are not resolved, but this workflow is rare and should not affect most users.
|
|
||||||
|
|
||||||
This change requires you to set `org-roam-directory` to the resolved path of a folder. That is:
|
|
||||||
|
|
||||||
```elisp
|
|
||||||
(setq org-roam-directory (file-truename "/path/to/directory/"))
|
|
||||||
```
|
|
||||||
|
|
||||||
### Breaking Changes
|
### Breaking Changes
|
||||||
|
|
||||||
- [#1164](https://github.com/org-roam/org-roam/pull/1164) Org-roam now stores the database in the user's Emacs directory by default
|
|
||||||
- [#910](https://github.com/org-roam/org-roam/pull/910) Deprecate `company-org-roam`, using `completion-at-point` instead. To use this with company, add the `company-capf` backend instead.
|
|
||||||
- [#1109](https://github.com/org-roam/org-roam/pull/1109) Org-roam now does not resolve symlinks.
|
|
||||||
|
|
||||||
### Features
|
### Features
|
||||||
|
|
||||||
- [#1163](https://github.com/org-roam/org-roam/pull/1163) Support file-level IDs introduced in Org 9.4
|
|
||||||
- [#1093](https://github.com/org-roam/org-roam/pull/1093) Add `vanilla` org-roam-tag-source to extract buffer Org tags
|
|
||||||
- [#1079](https://github.com/org-roam/org-roam/pull/1079) Add `org-roam-tag-face` to customize appearance of tags in interactive commands
|
|
||||||
- [#1073](https://github.com/org-roam/org-roam/pull/1073) Rename file on title change, when `org-roam-rename-file-on-title-change` is non-nil.
|
|
||||||
- [#1071](https://github.com/org-roam/org-roam/pull/1071) Update link descriptions on title changes, and clean-up rename file advice
|
|
||||||
- [#1061](https://github.com/org-roam/org-roam/pull/1061) Speed up the extraction of file properties, headlines, and titles
|
|
||||||
- [#1046](https://github.com/org-roam/org-roam/pull/1046) New user option to exclude files from Org-roam
|
|
||||||
- [#1032](https://github.com/org-roam/org-roam/pull/1032) File changes are now propagated to the database on idle timer. This prevents large wait times during file saves.
|
|
||||||
- [#974](https://github.com/org-roam/org-roam/pull/974) Protect region targeted by `org-roam-insert`
|
- [#974](https://github.com/org-roam/org-roam/pull/974) Protect region targeted by `org-roam-insert`
|
||||||
- [#994](https://github.com/org-roam/org-roam/pull/994) Simplify org-roam-store-link
|
- [#994](https://github.com/org-roam/org-roam/pull/994) Simplify org-roam-store-link
|
||||||
- [#1062](https://github.com/org-roam/org-roam/pull/1062) Variable `org-roam-completions-everywhere` allows for completions everywhere from word at point
|
|
||||||
- [#910](https://github.com/org-roam/org-roam/pull/910), [#1105](https://github.com/org-roam/org-roam/pull/1105) Support fuzzy links of the form [[roam:Title]], [[roam:*Headline]] and [[roam:Title*Headline]]
|
|
||||||
|
|
||||||
### Bugfixes
|
### Bugfixes
|
||||||
|
|
||||||
- [#1057](https://github.com/org-roam/org-roam/pull/1057) Improve performance of database builds by preventing generation of LaTeX and image previews.
|
|
||||||
- [#1103](https://github.com/org-roam/org-roam/pull/1103) Fix long build-times for Windows on files with URL links
|
|
||||||
|
|
||||||
## 1.2.1 (27-07-2020)
|
## 1.2.1 (27-07-2020)
|
||||||
|
|
||||||
This release consisted of a big deal of refactoring and bug fixes. Notably, we fixed several catastrophic failures on db builds with bad setups (#854), and modularized tag and title extractions.
|
This release consisted of a big deal of refactoring and bug fixes. Notably, we fixed several catastrophic failures on db builds with bad setups (#854), and modularized tag and title extractions.
|
||||||
@ -76,11 +21,9 @@ We also added some new features that had been a long time coming:
|
|||||||
2. We now support nested captures, which is crucial for `org-roam-protocol` (#966)
|
2. We now support nested captures, which is crucial for `org-roam-protocol` (#966)
|
||||||
|
|
||||||
### Breaking Changes
|
### Breaking Changes
|
||||||
|
|
||||||
- [#908](https://github.com/org-roam/org-roam/pull/908) Normalized titles in database. May break external packages that rely on unnormalized titles.
|
- [#908](https://github.com/org-roam/org-roam/pull/908) Normalized titles in database. May break external packages that rely on unnormalized titles.
|
||||||
|
|
||||||
### Features
|
### Features
|
||||||
|
|
||||||
- [#814](https://github.com/org-roam/org-roam/pull/814) Implement `org-roam-insert-immediate`
|
- [#814](https://github.com/org-roam/org-roam/pull/814) Implement `org-roam-insert-immediate`
|
||||||
- [#833](https://github.com/org-roam/org-roam/pull/833) Add customization of file titles with `org-roam-title-to-slug-function`.
|
- [#833](https://github.com/org-roam/org-roam/pull/833) Add customization of file titles with `org-roam-title-to-slug-function`.
|
||||||
- [#839](https://github.com/org-roam/org-roam/pull/839) Return selected file from `org-roam-insert`
|
- [#839](https://github.com/org-roam/org-roam/pull/839) Return selected file from `org-roam-insert`
|
||||||
@ -122,7 +65,6 @@ We also add `org-roam-unlinked-references`, which naively finds text that could
|
|||||||
- [#679](https://github.com/org-roam/org-roam/pull/679), [#683](https://github.com/org-roam/org-roam/pull/683) Building of the graph now happens in a separate process
|
- [#679](https://github.com/org-roam/org-roam/pull/679), [#683](https://github.com/org-roam/org-roam/pull/683) Building of the graph now happens in a separate process
|
||||||
|
|
||||||
### Bugfixes
|
### Bugfixes
|
||||||
|
|
||||||
- [#714](https://github.com/org-roam/org-roam/pull/714) No longer print citelinks in backlinks buffer if there is no `ROAM_KEY` property or `org-ref` is not installed
|
- [#714](https://github.com/org-roam/org-roam/pull/714) No longer print citelinks in backlinks buffer if there is no `ROAM_KEY` property or `org-ref` is not installed
|
||||||
- [#759](https://github.com/org-roam/org-roam/pull/759), [#760](https://github.com/org-roam/org-roam/pull/760) Tags are only added to the tags table if there are actually tags present
|
- [#759](https://github.com/org-roam/org-roam/pull/759), [#760](https://github.com/org-roam/org-roam/pull/760) Tags are only added to the tags table if there are actually tags present
|
||||||
- [#700](https://github.com/org-roam/org-roam/pull/700), [#733](https://github.com/org-roam/org-roam/pull/733) Allow symlinks within the `org-roam` directory
|
- [#700](https://github.com/org-roam/org-roam/pull/700), [#733](https://github.com/org-roam/org-roam/pull/733) Allow symlinks within the `org-roam` directory
|
||||||
|
@ -63,7 +63,7 @@ Here's a sample configuration with using `use-package`:
|
|||||||
:bind (:map org-roam-mode-map
|
:bind (:map org-roam-mode-map
|
||||||
(("C-c n l" . org-roam)
|
(("C-c n l" . org-roam)
|
||||||
("C-c n f" . org-roam-find-file)
|
("C-c n f" . org-roam-find-file)
|
||||||
("C-c n g" . org-roam-graph))
|
("C-c n g" . org-roam-graph-show))
|
||||||
:map org-mode-map
|
:map org-mode-map
|
||||||
(("C-c n i" . org-roam-insert))
|
(("C-c n i" . org-roam-insert))
|
||||||
(("C-c n I" . org-roam-insert-immediate))))
|
(("C-c n I" . org-roam-insert-immediate))))
|
||||||
@ -121,7 +121,7 @@ General Public License, Version 3
|
|||||||
[roamresearch]: https://www.roamresearch.com/
|
[roamresearch]: https://www.roamresearch.com/
|
||||||
[org]: https://orgmode.org/
|
[org]: https://orgmode.org/
|
||||||
[badge-license]: https://img.shields.io/badge/license-GPL_3-green.svg
|
[badge-license]: https://img.shields.io/badge/license-GPL_3-green.svg
|
||||||
[docs]: https://www.orgroam.com/manual.html
|
[docs]: https://www.orgroam.com/manual/
|
||||||
[discourse]: https://org-roam.discourse.group/
|
[discourse]: https://org-roam.discourse.group/
|
||||||
[slack]: https://join.slack.com/t/orgroam/shared_invite/zt-deoqamys-043YQ~s5Tay3iJ5QRI~Lxg
|
[slack]: https://join.slack.com/t/orgroam/shared_invite/zt-deoqamys-043YQ~s5Tay3iJ5QRI~Lxg
|
||||||
[issues]: https://github.com/org-roam/org-roam/issues
|
[issues]: https://github.com/org-roam/org-roam/issues
|
||||||
|
@ -34,4 +34,4 @@ Contributors
|
|||||||
- Rafael Accácio Nogueira <raccacio@poli.ufrj.br>
|
- Rafael Accácio Nogueira <raccacio@poli.ufrj.br>
|
||||||
- Roland Coeurjoly <rolandcoeurjoly@gmail.com>
|
- Roland Coeurjoly <rolandcoeurjoly@gmail.com>
|
||||||
- Sayan <dit7ya@users.noreply.github.com>
|
- Sayan <dit7ya@users.noreply.github.com>
|
||||||
- Tim Quelch <tim@tquelch.com>
|
- Tim Quelch <tim@quelch.name>
|
||||||
|
@ -28,8 +28,11 @@ dir: org-roam.info
|
|||||||
@$(MAKEINFO) --html --no-split $(MANUAL_HTML_ARGS) $<
|
@$(MAKEINFO) --html --no-split $(MANUAL_HTML_ARGS) $<
|
||||||
|
|
||||||
html-dir:
|
html-dir:
|
||||||
@$(MAKEINFO) --html --no-split $(MANUAL_HTML_ARGS) org-roam.texi
|
@printf "Generating org-roam/*.html\n"
|
||||||
mv org-roam.html manual.html
|
@$(MAKEINFO) --html $(MANUAL_HTML_ARGS) org-roam.texi
|
||||||
|
mv org-roam manual
|
||||||
|
cp -r assets manual
|
||||||
|
cp -r images manual
|
||||||
|
|
||||||
%.pdf: %.texi
|
%.pdf: %.texi
|
||||||
@printf "Generating $@\n"
|
@printf "Generating $@\n"
|
||||||
|
@ -1,59 +1,442 @@
|
|||||||
|
/* Import Inter font */
|
||||||
|
/* More info at https://github.com/xz/fonts */
|
||||||
|
@import url("https://fonts.xz.style/serve/inter.css");
|
||||||
|
|
||||||
:root {
|
:root {
|
||||||
--border: #526980;
|
--nc-font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
|
||||||
--code: #007;
|
Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif,
|
||||||
|
"Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
|
||||||
|
--nc-font-mono: "Courier New", Courier, "Ubuntu Mono", "Liberation Mono",
|
||||||
|
monospace;
|
||||||
|
--nc-tx-1: #000000;
|
||||||
|
--nc-tx-2: #1a1a1a;
|
||||||
|
--nc-bg-1: #ffffff;
|
||||||
|
--nc-bg-2: #f6f8fa;
|
||||||
|
--nc-bg-3: #e5e7eb;
|
||||||
|
--nc-lk-1: #0070f3;
|
||||||
|
--nc-lk-2: #0366d6;
|
||||||
|
--nc-lk-tx: #ffffff;
|
||||||
|
--nc-ac-1: #79ffe1;
|
||||||
|
--nc-ac-tx: #0c4047;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (prefers-color-scheme: dark) {
|
||||||
|
:root {
|
||||||
|
--nc-tx-1: #ffffff;
|
||||||
|
--nc-tx-2: #eeeeee;
|
||||||
|
--nc-bg-1: #000000;
|
||||||
|
--nc-bg-2: #111111;
|
||||||
|
--nc-bg-3: #222222;
|
||||||
|
--nc-lk-1: #3291ff;
|
||||||
|
--nc-lk-2: #0070f3;
|
||||||
|
--nc-lk-tx: #ffffff;
|
||||||
|
--nc-ac-1: #7928ca;
|
||||||
|
--nc-ac-tx: #ffffff;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
* {
|
||||||
|
/* Reset margins and padding */
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
address,
|
||||||
|
area,
|
||||||
|
article,
|
||||||
|
aside,
|
||||||
|
audio,
|
||||||
|
blockquote,
|
||||||
|
datalist,
|
||||||
|
details,
|
||||||
|
dl,
|
||||||
|
fieldset,
|
||||||
|
figure,
|
||||||
|
form,
|
||||||
|
input,
|
||||||
|
iframe,
|
||||||
|
img,
|
||||||
|
meter,
|
||||||
|
nav,
|
||||||
|
ol,
|
||||||
|
optgroup,
|
||||||
|
option,
|
||||||
|
output,
|
||||||
|
p,
|
||||||
|
pre,
|
||||||
|
progress,
|
||||||
|
ruby,
|
||||||
|
section,
|
||||||
|
table,
|
||||||
|
textarea,
|
||||||
|
ul,
|
||||||
|
video {
|
||||||
|
/* Margins for most elements */
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
html,
|
||||||
|
input,
|
||||||
|
select,
|
||||||
|
button {
|
||||||
|
/* Set body font family and some finicky elements */
|
||||||
|
font-family: var(--nc-font-sans);
|
||||||
}
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
margin: 5ex 10ex;
|
/* Center body in page */
|
||||||
max-width: 80ex;
|
margin: 0 auto;
|
||||||
|
max-width: 750px;
|
||||||
|
padding: 2rem;
|
||||||
|
border-radius: 6px;
|
||||||
|
overflow-x: hidden;
|
||||||
|
background: var(--nc-bg-1);
|
||||||
|
|
||||||
|
/* Main body text */
|
||||||
|
color: var(--nc-tx-2);
|
||||||
|
font-size: 1.03rem;
|
||||||
line-height: 1.5;
|
line-height: 1.5;
|
||||||
font-family: sans-serif;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
h1, h2, h3 {
|
::selection {
|
||||||
font-weight: normal;
|
/* Set background color for selected text */
|
||||||
|
background: var(--nc-ac-1);
|
||||||
|
color: var(--nc-ac-tx);
|
||||||
}
|
}
|
||||||
|
|
||||||
pre, code {
|
p {
|
||||||
font-family: x, monospace;
|
margin-bottom: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1,
|
||||||
|
h2,
|
||||||
|
h3,
|
||||||
|
h4,
|
||||||
|
h5,
|
||||||
|
h6 {
|
||||||
|
line-height: 1;
|
||||||
|
color: var(--nc-tx-1);
|
||||||
|
padding-top: 0.875rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1,
|
||||||
|
h2,
|
||||||
|
h3 {
|
||||||
|
color: var(--nc-tx-1);
|
||||||
|
padding-bottom: 2px;
|
||||||
|
margin-bottom: 8px;
|
||||||
|
border-bottom: 1px solid var(--nc-bg-2);
|
||||||
|
}
|
||||||
|
|
||||||
|
h4,
|
||||||
|
h5,
|
||||||
|
h6 {
|
||||||
|
margin-bottom: 0.3rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
font-size: 2.25rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
h2 {
|
||||||
|
font-size: 1.85rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
h3 {
|
||||||
|
font-size: 1.55rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
h4 {
|
||||||
|
font-size: 1.25rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
h5 {
|
||||||
|
font-size: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
h6 {
|
||||||
|
font-size: 0.875rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
color: var(--nc-lk-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
a:hover {
|
||||||
|
color: var(--nc-lk-2);
|
||||||
|
}
|
||||||
|
|
||||||
|
abbr:hover {
|
||||||
|
/* Set the '?' cursor while hovering an abbreviation */
|
||||||
|
cursor: help;
|
||||||
|
}
|
||||||
|
|
||||||
|
blockquote {
|
||||||
|
padding: 1.5rem;
|
||||||
|
background: var(--nc-bg-2);
|
||||||
|
border-left: 5px solid var(--nc-bg-3);
|
||||||
|
}
|
||||||
|
|
||||||
|
abbr {
|
||||||
|
cursor: help;
|
||||||
|
}
|
||||||
|
|
||||||
|
blockquote *:last-child {
|
||||||
|
padding-bottom: 0;
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
header {
|
||||||
|
background: var(--nc-bg-2);
|
||||||
|
border-bottom: 1px solid var(--nc-bg-3);
|
||||||
|
padding: 2rem 1.5rem;
|
||||||
|
|
||||||
|
/* This sets the right and left margins to cancel out the body's margins. It's width is still the same, but the background stretches across the page's width. */
|
||||||
|
|
||||||
|
margin: -2rem calc(0px - (50vw - 50%)) 2rem;
|
||||||
|
|
||||||
|
/* Shorthand for:
|
||||||
|
|
||||||
|
margin-top: -2rem;
|
||||||
|
margin-bottom: 2rem;
|
||||||
|
|
||||||
|
margin-left: calc(0px - (50vw - 50%));
|
||||||
|
margin-right: calc(0px - (50vw - 50%)); */
|
||||||
|
|
||||||
|
padding-left: calc(50vw - 50%);
|
||||||
|
padding-right: calc(50vw - 50%);
|
||||||
|
}
|
||||||
|
|
||||||
|
header h1,
|
||||||
|
header h2,
|
||||||
|
header h3 {
|
||||||
|
padding-bottom: 0;
|
||||||
|
border-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
header > *:first-child {
|
||||||
|
margin-top: 0;
|
||||||
|
padding-top: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
header > *:last-child {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button,
|
||||||
|
button,
|
||||||
|
input[type="submit"],
|
||||||
|
input[type="reset"],
|
||||||
|
input[type="button"] {
|
||||||
|
font-size: 1rem;
|
||||||
|
display: inline-block;
|
||||||
|
padding: 6px 12px;
|
||||||
|
text-align: center;
|
||||||
|
text-decoration: none;
|
||||||
|
white-space: nowrap;
|
||||||
|
background: var(--nc-lk-1);
|
||||||
|
color: var(--nc-lk-tx);
|
||||||
|
border: 0;
|
||||||
|
border-radius: 4px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
cursor: pointer;
|
||||||
|
color: var(--nc-lk-tx);
|
||||||
|
}
|
||||||
|
|
||||||
|
.button[disabled],
|
||||||
|
button[disabled],
|
||||||
|
input[type="submit"][disabled],
|
||||||
|
input[type="reset"][disabled],
|
||||||
|
input[type="button"][disabled] {
|
||||||
|
cursor: default;
|
||||||
|
opacity: 0.5;
|
||||||
|
|
||||||
|
/* Set the [X] cursor while hovering a disabled link */
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button:focus,
|
||||||
|
.button:hover,
|
||||||
|
button:focus,
|
||||||
|
button:hover,
|
||||||
|
input[type="submit"]:focus,
|
||||||
|
input[type="submit"]:hover,
|
||||||
|
input[type="reset"]:focus,
|
||||||
|
input[type="reset"]:hover,
|
||||||
|
input[type="button"]:focus,
|
||||||
|
input[type="button"]:hover {
|
||||||
|
background: var(--nc-lk-2);
|
||||||
|
}
|
||||||
|
|
||||||
|
code,
|
||||||
|
pre,
|
||||||
|
kbd,
|
||||||
|
samp {
|
||||||
|
/* Set the font family for monospaced elements */
|
||||||
|
font-family: var(--nc-font-mono);
|
||||||
|
}
|
||||||
|
|
||||||
|
code,
|
||||||
|
samp,
|
||||||
|
kbd,
|
||||||
|
pre {
|
||||||
|
/* The main preformatted style. This is changed slightly across different cases. */
|
||||||
|
background: var(--nc-bg-2);
|
||||||
|
border: 1px solid var(--nc-bg-3);
|
||||||
|
border-radius: 4px;
|
||||||
|
padding: 3px 6px;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
kbd {
|
||||||
|
/* Makes the kbd element look like a keyboard key */
|
||||||
|
border-bottom: 3px solid var(--nc-bg-3);
|
||||||
}
|
}
|
||||||
|
|
||||||
pre {
|
pre {
|
||||||
padding: 1ex;
|
padding: 1rem 1.4rem;
|
||||||
background: #eee;
|
max-width: 100%;
|
||||||
border: solid 1px #ddd;
|
|
||||||
min-width: 0;
|
|
||||||
font-size: 80%;
|
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
code {
|
pre code {
|
||||||
color: var(--code);
|
/* When <code> is in a <pre>, reset it's formatting to blend in */
|
||||||
|
background: inherit;
|
||||||
|
font-size: inherit;
|
||||||
|
color: inherit;
|
||||||
|
border: 0;
|
||||||
|
padding: 0;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
code pre {
|
||||||
|
/* When <pre> is in a <code>, reset it's formatting to blend in */
|
||||||
|
display: inline;
|
||||||
|
background: inherit;
|
||||||
|
font-size: inherit;
|
||||||
|
color: inherit;
|
||||||
|
border: 0;
|
||||||
|
padding: 0;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
details {
|
||||||
|
/* Make the <details> look more "clickable" */
|
||||||
|
padding: 0.6rem 1rem;
|
||||||
|
background: var(--nc-bg-2);
|
||||||
|
border: 1px solid var(--nc-bg-3);
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
summary {
|
||||||
|
/* Makes the <summary> look more like a "clickable" link with the pointer cursor */
|
||||||
|
cursor: pointer;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
details[open] {
|
||||||
|
/* Adjust the <details> padding while open */
|
||||||
|
padding-bottom: 0.75rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
details[open] summary {
|
||||||
|
/* Adjust the <details> padding while open */
|
||||||
|
margin-bottom: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
details[open] > *:last-child {
|
||||||
|
/* Resets the bottom margin of the last element in the <details> while <details> is opened. This prevents double margins/paddings. */
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
dt {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
dd::before {
|
||||||
|
/* Add an arrow to data table definitions */
|
||||||
|
content: "→ ";
|
||||||
|
}
|
||||||
|
|
||||||
|
hr {
|
||||||
|
/* Reset the border of the <hr> separator, then set a better line */
|
||||||
|
border: 0;
|
||||||
|
border-bottom: 1px solid var(--nc-bg-3);
|
||||||
|
margin: 1rem auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
fieldset {
|
||||||
|
margin-top: 1rem;
|
||||||
|
padding: 2rem;
|
||||||
|
border: 1px solid var(--nc-bg-3);
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
legend {
|
||||||
|
padding: auto 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
textarea {
|
||||||
|
/* Don't let the <textarea> extend off the screen naturally or when dragged by the user */
|
||||||
|
max-width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
ol,
|
||||||
|
ul {
|
||||||
|
/* Replace the browser default padding */
|
||||||
|
padding-left: 2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
li {
|
||||||
|
margin-top: 0.4rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
ul ul,
|
||||||
|
ol ul,
|
||||||
|
ul ol,
|
||||||
|
ol ol {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
mark {
|
||||||
|
padding: 3px 6px;
|
||||||
|
background: var(--nc-ac-1);
|
||||||
|
color: var(--nc-ac-tx);
|
||||||
|
}
|
||||||
|
|
||||||
|
textarea,
|
||||||
|
select,
|
||||||
|
input {
|
||||||
|
padding: 6px 12px;
|
||||||
|
margin-bottom: 0.5rem;
|
||||||
|
background: var(--nc-bg-2);
|
||||||
|
color: var(--nc-tx-2);
|
||||||
|
|
||||||
|
/* Set a border of the same color as the main background. It isn't visible on idle, but prevents the cell from growing in size when a darker border is set on focus. */
|
||||||
|
border: 1px solid var(--nc-bg-2);
|
||||||
|
border-radius: 4px;
|
||||||
|
box-shadow: none;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
textarea:focus,
|
||||||
|
select:focus,
|
||||||
|
input[type]:focus {
|
||||||
|
border: 1px solid var(--nc-bg-3);
|
||||||
|
|
||||||
|
/* Reset any browser default outlines */
|
||||||
|
outline: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
img {
|
img {
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
table {
|
/* Customizations */
|
||||||
border-collapse: collapse;
|
.menu-comment {
|
||||||
width: 100%;
|
font-weight: bold;
|
||||||
}
|
border: 0;
|
||||||
|
margin: 0;
|
||||||
thead {
|
padding: 0;
|
||||||
border-bottom: 1px solid var(--border);
|
font-size: 1.2rem;
|
||||||
}
|
|
||||||
|
|
||||||
tfoot {
|
|
||||||
border-top: 1px solid var(--border);
|
|
||||||
}
|
|
||||||
|
|
||||||
blockquote {
|
|
||||||
margin-left: 1rem;
|
|
||||||
font-style: italic;
|
|
||||||
font-family: serif;
|
|
||||||
border-left: 3px solid;
|
|
||||||
border-left-color: currentcolor;
|
|
||||||
border-color: var(--text-color);
|
|
||||||
padding-left: 1em;
|
|
||||||
}
|
}
|
||||||
|
@ -93,7 +93,7 @@
|
|||||||
You can find us on Discourse and Slack.
|
You can find us on Discourse and Slack.
|
||||||
|
|
||||||
<ul>
|
<ul>
|
||||||
<li>Read our documentation within Emacs, or on the <a href="https://www.orgroam.com/manual.html">Online Manual</a></li>
|
<li>Read our documentation within Emacs, or on the <a href="https://www.orgroam.com/manual/">Online Manual</a></li>
|
||||||
<li>Participate in our forum discussions on <a href="https://org-roam.discourse.group">Discourse</a></li>
|
<li>Participate in our forum discussions on <a href="https://org-roam.discourse.group">Discourse</a></li>
|
||||||
<li>Chat with us on <a href="https://join.slack.com/t/orgroam/shared_invite/zt-deoqamys-043YQ~s5Tay3iJ5QRI~Lxg">Slack</a></li>
|
<li>Chat with us on <a href="https://join.slack.com/t/orgroam/shared_invite/zt-deoqamys-043YQ~s5Tay3iJ5QRI~Lxg">Slack</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
@ -120,6 +120,13 @@
|
|||||||
>org-roam-server</a
|
>org-roam-server</a
|
||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<a
|
||||||
|
class="content footer-links"
|
||||||
|
href="https://github.com/org-roam/company-org-roam"
|
||||||
|
>company-org-roam</a
|
||||||
|
>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col">
|
<div class="col">
|
||||||
|
704
doc/org-roam.org
704
doc/org-roam.org
File diff suppressed because it is too large
Load Diff
1025
doc/org-roam.texi
1025
doc/org-roam.texi
File diff suppressed because it is too large
Load Diff
13
makem.sh
13
makem.sh
@ -591,12 +591,6 @@ function debug {
|
|||||||
}
|
}
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function error_nonblocking {
|
|
||||||
echo_color red "ERROR ($(ts)): $@" >&2
|
|
||||||
((errors_nonblocking++))
|
|
||||||
}
|
|
||||||
|
|
||||||
function error {
|
function error {
|
||||||
echo_color red "ERROR ($(ts)): $@" >&2
|
echo_color red "ERROR ($(ts)): $@" >&2
|
||||||
((errors++))
|
((errors++))
|
||||||
@ -769,7 +763,7 @@ function lint-package {
|
|||||||
--funcall package-lint-batch-and-exit \
|
--funcall package-lint-batch-and-exit \
|
||||||
"${files_project_feature[@]}" \
|
"${files_project_feature[@]}" \
|
||||||
&& success "Linting package finished without errors." \
|
&& success "Linting package finished without errors." \
|
||||||
|| error_nonblocking "Linting package failed."
|
|| error "Linting package failed."
|
||||||
}
|
}
|
||||||
|
|
||||||
function lint-regexps {
|
function lint-regexps {
|
||||||
@ -838,7 +832,6 @@ test_files_regexp='^((tests?|t)/)|-test.el$|^test-'
|
|||||||
|
|
||||||
emacs_command=("emacs")
|
emacs_command=("emacs")
|
||||||
errors=0
|
errors=0
|
||||||
errors_nonblocking=0
|
|
||||||
verbose=0
|
verbose=0
|
||||||
compile=true
|
compile=true
|
||||||
arg_batch="--batch"
|
arg_batch="--batch"
|
||||||
@ -1079,9 +1072,9 @@ done
|
|||||||
|
|
||||||
if [[ $errors -gt 0 ]]
|
if [[ $errors -gt 0 ]]
|
||||||
then
|
then
|
||||||
log_color red "Finished with $errors errors and $errors_nonblocking non-blocking errors."
|
log_color red "Finished with $errors errors."
|
||||||
else
|
else
|
||||||
success "Finished with $errors errors and $errors_nonblocking non-blocking errors."
|
success "Finished without errors."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
exit $errors
|
exit $errors
|
||||||
|
@ -5,8 +5,8 @@
|
|||||||
;; Author: Jethro Kuan <jethrokuan95@gmail.com>
|
;; Author: Jethro Kuan <jethrokuan95@gmail.com>
|
||||||
;; URL: https://github.com/org-roam/org-roam
|
;; URL: https://github.com/org-roam/org-roam
|
||||||
;; Keywords: org-mode, roam, convenience
|
;; Keywords: org-mode, roam, convenience
|
||||||
;; Version: 1.2.3
|
;; Version: 1.2.1
|
||||||
;; Package-Requires: ((emacs "26.1") (dash "2.13") (f "0.17.2") (s "1.12.0") (org "9.3") (emacsql "3.0.0") (emacsql-sqlite3 "1.0.2"))
|
;; Package-Requires: ((emacs "26.1") (dash "2.13") (f "0.17.2") (s "1.12.0") (org "9.3") (emacsql "3.0.0") (emacsql-sqlite3 "1.0.0"))
|
||||||
|
|
||||||
;; This file is NOT part of GNU Emacs.
|
;; This file is NOT part of GNU Emacs.
|
||||||
|
|
||||||
@ -34,8 +34,6 @@
|
|||||||
(require 'cl-lib)
|
(require 'cl-lib)
|
||||||
(require 'dash)
|
(require 'dash)
|
||||||
(require 's)
|
(require 's)
|
||||||
(require 'f)
|
|
||||||
(require 'ol)
|
|
||||||
|
|
||||||
(defvar org-roam-directory)
|
(defvar org-roam-directory)
|
||||||
(defvar org-link-frame-setup)
|
(defvar org-link-frame-setup)
|
||||||
@ -44,18 +42,14 @@
|
|||||||
(defvar org-roam-last-window)
|
(defvar org-roam-last-window)
|
||||||
(defvar org-ref-cite-types) ;; in org-ref-core.el
|
(defvar org-ref-cite-types) ;; in org-ref-core.el
|
||||||
(defvar org-roam-mode)
|
(defvar org-roam-mode)
|
||||||
(defvar org-roam--org-link-bracket-typed-re)
|
|
||||||
|
|
||||||
(declare-function org-roam-db--ensure-built "org-roam-db")
|
(declare-function org-roam-db--ensure-built "org-roam-db")
|
||||||
(declare-function org-roam--extract-refs "org-roam")
|
(declare-function org-roam--extract-ref "org-roam")
|
||||||
(declare-function org-roam--extract-titles "org-roam")
|
|
||||||
(declare-function org-roam--get-title-or-slug "org-roam")
|
(declare-function org-roam--get-title-or-slug "org-roam")
|
||||||
(declare-function org-roam--get-backlinks "org-roam")
|
(declare-function org-roam--get-backlinks "org-roam")
|
||||||
(declare-function org-roam-backlinks-mode "org-roam")
|
(declare-function org-roam-backlinks-mode "org-roam")
|
||||||
(declare-function org-roam-mode "org-roam")
|
(declare-function org-roam-mode "org-roam")
|
||||||
(declare-function org-roam--find-file "org-roam")
|
(declare-function org-roam--find-file "org-roam")
|
||||||
(declare-function org-roam-format-link "org-roam")
|
|
||||||
(declare-function org-roam-link-get-path "org-roam-link")
|
|
||||||
|
|
||||||
(defcustom org-roam-buffer-position 'right
|
(defcustom org-roam-buffer-position 'right
|
||||||
"Position of `org-roam' buffer.
|
"Position of `org-roam' buffer.
|
||||||
@ -106,13 +100,11 @@ For example: (setq org-roam-buffer-window-parameters '((no-other-window . t)))"
|
|||||||
|
|
||||||
(defun org-roam-buffer--find-file (file)
|
(defun org-roam-buffer--find-file (file)
|
||||||
"Open FILE in the window `org-roam' was called from."
|
"Open FILE in the window `org-roam' was called from."
|
||||||
(setq file (expand-file-name file))
|
(if (and org-roam-last-window (window-valid-p org-roam-last-window))
|
||||||
(let ((last-window org-roam-last-window))
|
(progn (with-selected-window org-roam-last-window
|
||||||
(if (window-valid-p last-window)
|
|
||||||
(progn (with-selected-window last-window
|
|
||||||
(org-roam--find-file file))
|
(org-roam--find-file file))
|
||||||
(select-window last-window))
|
(select-window org-roam-last-window))
|
||||||
(org-roam--find-file file))))
|
(org-roam--find-file file)))
|
||||||
|
|
||||||
(defun org-roam-buffer--insert-title ()
|
(defun org-roam-buffer--insert-title ()
|
||||||
"Insert the org-roam-buffer title."
|
"Insert the org-roam-buffer title."
|
||||||
@ -131,29 +123,12 @@ For example: (setq org-roam-buffer-window-parameters '((no-other-window . t)))"
|
|||||||
,wrong-type))))))
|
,wrong-type))))))
|
||||||
(concat string (when (> l 1) "s"))))
|
(concat string (when (> l 1) "s"))))
|
||||||
|
|
||||||
(defun org-roam-buffer-expand-links (content orig-path)
|
|
||||||
"Crawl CONTENT for relative links and corrects them to be correctly displayed.
|
|
||||||
ORIG-PATH is the path where the CONTENT originated."
|
|
||||||
(with-temp-buffer
|
|
||||||
(insert content)
|
|
||||||
(goto-char (point-min))
|
|
||||||
(let (link link-type)
|
|
||||||
(while (re-search-forward org-roam--org-link-bracket-typed-re (point-max) t)
|
|
||||||
(setq link-type (match-string 1)
|
|
||||||
link (match-string 2))
|
|
||||||
(when (and (string-equal link-type "file")
|
|
||||||
(f-relative-p link))
|
|
||||||
(replace-match (org-roam-link-get-path (expand-file-name link (file-name-directory orig-path)))
|
|
||||||
nil t nil 2))))
|
|
||||||
(buffer-string)))
|
|
||||||
|
|
||||||
(defun org-roam-buffer--insert-ref-links ()
|
(defun org-roam-buffer--insert-ref-links ()
|
||||||
"Insert ref backlinks for the current buffer."
|
"Insert ref backlinks for the current buffer."
|
||||||
(when-let* ((refs (with-temp-buffer
|
(when-let ((ref (cdr (with-temp-buffer
|
||||||
(insert-buffer-substring org-roam-buffer--current)
|
(insert-buffer-substring org-roam-buffer--current)
|
||||||
(org-roam--extract-refs)))
|
(org-roam--extract-ref)))))
|
||||||
(paths (mapcar #'cdr refs)))
|
(if-let* ((key-backlinks (org-roam--get-backlinks ref))
|
||||||
(if-let* ((key-backlinks (mapcan #'org-roam--get-backlinks paths))
|
|
||||||
(grouped-backlinks (--group-by (nth 0 it) key-backlinks)))
|
(grouped-backlinks (--group-by (nth 0 it) key-backlinks)))
|
||||||
(progn
|
(progn
|
||||||
(insert (let ((l (length key-backlinks)))
|
(insert (let ((l (length key-backlinks)))
|
||||||
@ -162,58 +137,48 @@ ORIG-PATH is the path where the CONTENT originated."
|
|||||||
(dolist (group grouped-backlinks)
|
(dolist (group grouped-backlinks)
|
||||||
(let ((file-from (car group))
|
(let ((file-from (car group))
|
||||||
(bls (cdr group)))
|
(bls (cdr group)))
|
||||||
(insert (format "** %s\n"
|
(insert (format "** [[file:%s][%s]]\n"
|
||||||
(org-roam-format-link file-from
|
file-from
|
||||||
(org-roam--get-title-or-slug file-from)
|
(org-roam--get-title-or-slug file-from)))
|
||||||
"file")))
|
|
||||||
(dolist (backlink bls)
|
(dolist (backlink bls)
|
||||||
(pcase-let ((`(,file-from _ ,props) backlink))
|
(pcase-let ((`(,file-from _ ,props) backlink))
|
||||||
(insert (if-let ((content (plist-get props :content)))
|
(insert (propertize (plist-get props :content)
|
||||||
(propertize (org-roam-buffer-expand-links content file-from)
|
|
||||||
'help-echo "mouse-1: visit backlinked note"
|
'help-echo "mouse-1: visit backlinked note"
|
||||||
'file-from file-from
|
'file-from file-from
|
||||||
'file-from-point (plist-get props :point))
|
'file-from-point (plist-get props :point)))
|
||||||
"")
|
(insert "\n\n"))))))
|
||||||
"\n\n"))))))
|
|
||||||
(insert "\n\n* No ref backlinks!"))))
|
(insert "\n\n* No ref backlinks!"))))
|
||||||
|
|
||||||
(defun org-roam-buffer--insert-backlinks ()
|
(defun org-roam-buffer--insert-backlinks ()
|
||||||
"Insert the org-roam-buffer backlinks string for the current buffer."
|
"Insert the org-roam-buffer backlinks string for the current buffer."
|
||||||
(let (props file-from)
|
|
||||||
(if-let* ((file-path (buffer-file-name org-roam-buffer--current))
|
(if-let* ((file-path (buffer-file-name org-roam-buffer--current))
|
||||||
(titles (with-current-buffer org-roam-buffer--current
|
(backlinks (org-roam--get-backlinks file-path))
|
||||||
(org-roam--extract-titles)))
|
|
||||||
(backlinks (org-roam--get-backlinks (push file-path titles)))
|
|
||||||
(grouped-backlinks (--group-by (nth 0 it) backlinks)))
|
(grouped-backlinks (--group-by (nth 0 it) backlinks)))
|
||||||
(progn
|
(progn
|
||||||
(insert (let ((l (length backlinks)))
|
(insert (let ((l (length backlinks)))
|
||||||
(format "\n\n* %d %s\n"
|
(format "\n\n* %d %s\n"
|
||||||
l (org-roam-buffer--pluralize "Backlink" l))))
|
l (org-roam-buffer--pluralize "Backlink" l))))
|
||||||
(dolist (group grouped-backlinks)
|
(dolist (group grouped-backlinks)
|
||||||
(setq file-from (car group))
|
(let ((file-from (car group))
|
||||||
(setq props (mapcar (lambda (row) (nth 2 row)) (cdr group)))
|
(bls (cdr group)))
|
||||||
(setq props (seq-sort-by (lambda (p) (plist-get p :point)) #'< props))
|
(insert (format "** [[file:%s][%s]]\n"
|
||||||
(insert (format "** %s\n"
|
file-from
|
||||||
(org-roam-format-link file-from
|
(org-roam--get-title-or-slug file-from)))
|
||||||
(org-roam--get-title-or-slug file-from)
|
(dolist (backlink bls)
|
||||||
"file")))
|
(pcase-let ((`(,file-from _ ,props) backlink))
|
||||||
(dolist (prop props)
|
|
||||||
(insert "*** "
|
(insert "*** "
|
||||||
(if-let ((outline (plist-get prop :outline)))
|
(if-let ((outline (plist-get props :outline)))
|
||||||
(-> outline
|
(string-join outline " > ")
|
||||||
(string-join " > ")
|
|
||||||
(org-roam-buffer-expand-links file-from))
|
|
||||||
"Top")
|
"Top")
|
||||||
"\n"
|
"\n"
|
||||||
(if-let ((content (plist-get prop :content)))
|
|
||||||
(propertize
|
(propertize
|
||||||
(s-trim (s-replace "\n" " " (org-roam-buffer-expand-links content file-from)))
|
(s-trim (s-replace "\n" " "
|
||||||
|
(plist-get props :content)))
|
||||||
'help-echo "mouse-1: visit backlinked note"
|
'help-echo "mouse-1: visit backlinked note"
|
||||||
'file-from file-from
|
'file-from file-from
|
||||||
'file-from-point (plist-get prop :point))
|
'file-from-point (plist-get props :point))
|
||||||
"")
|
"\n\n"))))))
|
||||||
"\n\n"))))
|
(insert "\n\n* No backlinks!")))
|
||||||
(insert "\n\n* No backlinks!"))))
|
|
||||||
|
|
||||||
(defun org-roam-buffer-update ()
|
(defun org-roam-buffer-update ()
|
||||||
"Update the `org-roam-buffer'."
|
"Update the `org-roam-buffer'."
|
||||||
@ -251,7 +216,7 @@ This needs to be quick or infrequent, because this is run at
|
|||||||
(when (and (or redisplay
|
(when (and (or redisplay
|
||||||
(not (eq org-roam-buffer--current buffer)))
|
(not (eq org-roam-buffer--current buffer)))
|
||||||
(eq 'visible (org-roam-buffer--visibility))
|
(eq 'visible (org-roam-buffer--visibility))
|
||||||
(buffer-file-name buffer))
|
(buffer-local-value 'buffer-file-truename buffer))
|
||||||
(setq org-roam-buffer--current buffer)
|
(setq org-roam-buffer--current buffer)
|
||||||
(org-roam-buffer-update))))
|
(org-roam-buffer-update))))
|
||||||
|
|
||||||
|
@ -5,8 +5,8 @@
|
|||||||
;; Author: Jethro Kuan <jethrokuan95@gmail.com>
|
;; Author: Jethro Kuan <jethrokuan95@gmail.com>
|
||||||
;; URL: https://github.com/org-roam/org-roam
|
;; URL: https://github.com/org-roam/org-roam
|
||||||
;; Keywords: org-mode, roam, convenience
|
;; Keywords: org-mode, roam, convenience
|
||||||
;; Version: 1.2.3
|
;; Version: 1.2.1
|
||||||
;; Package-Requires: ((emacs "26.1") (dash "2.13") (f "0.17.2") (s "1.12.0") (org "9.3") (emacsql "3.0.0") (emacsql-sqlite3 "1.0.2"))
|
;; Package-Requires: ((emacs "26.1") (dash "2.13") (f "0.17.2") (s "1.12.0") (org "9.3") (emacsql "3.0.0") (emacsql-sqlite3 "1.0.0"))
|
||||||
|
|
||||||
;; This file is NOT part of GNU Emacs.
|
;; This file is NOT part of GNU Emacs.
|
||||||
|
|
||||||
@ -41,15 +41,20 @@
|
|||||||
(defvar org-roam-directory)
|
(defvar org-roam-directory)
|
||||||
(defvar org-roam-mode)
|
(defvar org-roam-mode)
|
||||||
(defvar org-roam-title-to-slug-function)
|
(defvar org-roam-title-to-slug-function)
|
||||||
|
|
||||||
(declare-function org-roam--get-title-path-completions "org-roam")
|
(declare-function org-roam--get-title-path-completions "org-roam")
|
||||||
(declare-function org-roam--get-ref-path-completions "org-roam")
|
(declare-function org-roam--get-ref-path-completions "org-roam")
|
||||||
(declare-function org-roam--file-path-from-id "org-roam")
|
(declare-function org-roam--file-path-from-id "org-roam")
|
||||||
(declare-function org-roam--find-file "org-roam")
|
(declare-function org-roam--find-file "org-roam")
|
||||||
(declare-function org-roam-format-link "org-roam")
|
(declare-function org-roam--format-link "org-roam")
|
||||||
(declare-function org-roam-mode "org-roam")
|
(declare-function org-roam-mode "org-roam")
|
||||||
(declare-function org-roam-completion--completing-read "org-roam-completion")
|
(declare-function org-roam-completion--completing-read "org-roam-completion")
|
||||||
|
|
||||||
|
(defvar org-roam-capture--file-name-default "%<%Y%m%d%H%M%S>"
|
||||||
|
"The default file name format for Org-roam templates.")
|
||||||
|
|
||||||
|
(defvar org-roam-capture--header-default "#+title: ${title}\n"
|
||||||
|
"The default capture header for Org-roam templates.")
|
||||||
|
|
||||||
(defvar org-roam-capture--file-path nil
|
(defvar org-roam-capture--file-path nil
|
||||||
"The file path for the Org-roam capture.
|
"The file path for the Org-roam capture.
|
||||||
This variable is set during the Org-roam capture process.")
|
This variable is set during the Org-roam capture process.")
|
||||||
@ -75,11 +80,11 @@ note with the given `ref'.")
|
|||||||
(defvar org-roam-capture-additional-template-props nil
|
(defvar org-roam-capture-additional-template-props nil
|
||||||
"Additional props to be added to the Org-roam template.")
|
"Additional props to be added to the Org-roam template.")
|
||||||
|
|
||||||
(defconst org-roam-capture--template-keywords '(:file-name :head :olp)
|
(defconst org-roam-capture--template-keywords '(:file-name :head)
|
||||||
"Keywords used in `org-roam-capture-templates' specific to Org-roam.")
|
"Keywords used in `org-roam-capture-templates' specific to Org-roam.")
|
||||||
|
|
||||||
(defcustom org-roam-capture-templates
|
(defcustom org-roam-capture-templates
|
||||||
`(("d" "default" plain (function org-roam-capture--get-point)
|
'(("d" "default" plain (function org-roam-capture--get-point)
|
||||||
"%?"
|
"%?"
|
||||||
:file-name "%<%Y%m%d%H%M%S>-${slug}"
|
:file-name "%<%Y%m%d%H%M%S>-${slug}"
|
||||||
:head "#+title: ${title}\n"
|
:head "#+title: ${title}\n"
|
||||||
@ -219,10 +224,10 @@ Template string :\n%v")
|
|||||||
((const :format "%v " :kill-buffer) (const t))))))
|
((const :format "%v " :kill-buffer) (const t))))))
|
||||||
|
|
||||||
(defcustom org-roam-capture-ref-templates
|
(defcustom org-roam-capture-ref-templates
|
||||||
'(("r" "ref" plain #'org-roam-capture--get-point
|
'(("r" "ref" plain (function org-roam-capture--get-point)
|
||||||
"%?"
|
"%?"
|
||||||
:file-name "${slug}"
|
:file-name "${slug}"
|
||||||
:head "#+title: ${title}\n#+roam_key: ${ref}"
|
:head "#+title: ${title}\n#+roam_key: ${ref}\n"
|
||||||
:unnarrowed t))
|
:unnarrowed t))
|
||||||
"The Org-roam templates used during a capture from the roam-ref protocol.
|
"The Org-roam templates used during a capture from the roam-ref protocol.
|
||||||
Details on how to specify for the template is given in `org-roam-capture-templates'."
|
Details on how to specify for the template is given in `org-roam-capture-templates'."
|
||||||
@ -335,12 +340,11 @@ the capture)."
|
|||||||
(when region
|
(when region
|
||||||
(delete-region (car region) (cdr region)))
|
(delete-region (car region) (cdr region)))
|
||||||
(let ((path (org-roam-capture--get :file-path))
|
(let ((path (org-roam-capture--get :file-path))
|
||||||
(type (org-roam-capture--get :link-type))
|
|
||||||
(desc (org-roam-capture--get :link-description)))
|
(desc (org-roam-capture--get :link-description)))
|
||||||
(if (eq (point) (marker-position mkr))
|
(if (eq (point) (marker-position mkr))
|
||||||
(insert (org-roam-format-link path desc type))
|
(insert (org-roam--format-link path desc))
|
||||||
(org-with-point-at mkr
|
(org-with-point-at mkr
|
||||||
(insert (org-roam-format-link path desc type))))))))))
|
(insert (org-roam--format-link path desc))))))))))
|
||||||
(when region
|
(when region
|
||||||
(set-marker beg nil)
|
(set-marker beg nil)
|
||||||
(set-marker end nil))
|
(set-marker end nil))
|
||||||
@ -410,36 +414,27 @@ aborted, we do the following:
|
|||||||
the file if the original value of :no-save is not t and
|
the file if the original value of :no-save is not t and
|
||||||
`org-note-abort' is not t."
|
`org-note-abort' is not t."
|
||||||
(let* ((name-templ (or (org-roam-capture--get :file-name)
|
(let* ((name-templ (or (org-roam-capture--get :file-name)
|
||||||
(user-error "Template needs to specify `:file-name'")))
|
org-roam-capture--file-name-default))
|
||||||
(new-id (s-trim (org-roam-capture--fill-template
|
(new-id (s-trim (org-roam-capture--fill-template
|
||||||
name-templ)))
|
name-templ)))
|
||||||
(file-path (org-roam--file-path-from-id new-id))
|
(file-path (org-roam--file-path-from-id new-id))
|
||||||
(roam-head (or (org-roam-capture--get :head)
|
(roam-head (or (org-roam-capture--get :head)
|
||||||
""))
|
org-roam-capture--header-default))
|
||||||
(org-template (org-capture-get :template))
|
(org-template (org-capture-get :template))
|
||||||
(roam-template (concat roam-head org-template)))
|
(roam-template (concat roam-head org-template)))
|
||||||
(unless (or (file-exists-p file-path)
|
(unless (file-exists-p file-path)
|
||||||
(cl-some (lambda (buffer)
|
|
||||||
(string= (buffer-file-name buffer)
|
|
||||||
file-path))
|
|
||||||
(buffer-list)))
|
|
||||||
(make-directory (file-name-directory file-path) t)
|
(make-directory (file-name-directory file-path) t)
|
||||||
(org-roam-capture--put :orig-no-save (org-capture-get :no-save)
|
(org-roam-capture--put :orig-no-save (org-capture-get :no-save)
|
||||||
:new-file t)
|
:new-file t)
|
||||||
(pcase org-roam-capture--context
|
(org-capture-put :template
|
||||||
('dailies
|
;; Fixes org-capture-place-plain-text throwing 'invalid search bound'
|
||||||
;; Populate the header of the daily file before capture to prevent it
|
;; when both :unnarowed t and "%?" is missing from the template string;
|
||||||
;; from appearing in the buffer-restriction
|
;; may become unnecessary when the upstream bug is fixed
|
||||||
(save-window-excursion
|
(if (s-contains-p "%?" roam-template)
|
||||||
(find-file file-path)
|
roam-template
|
||||||
(insert (substring (org-capture-fill-template (concat roam-head "*"))
|
(concat roam-template "%?"))
|
||||||
0 -2))
|
:type 'plain
|
||||||
(set-buffer-modified-p nil))
|
:no-save t))
|
||||||
(org-capture-put :template org-template))
|
|
||||||
(_
|
|
||||||
(org-capture-put :template roam-template
|
|
||||||
:type 'plain)))
|
|
||||||
(org-capture-put :no-save t))
|
|
||||||
file-path))
|
file-path))
|
||||||
|
|
||||||
(defun org-roam-capture--get-point ()
|
(defun org-roam-capture--get-point ()
|
||||||
@ -458,7 +453,7 @@ If there is no file with that ref, a file with that ref is created.
|
|||||||
|
|
||||||
This function is used solely in Org-roam's capture templates: see
|
This function is used solely in Org-roam's capture templates: see
|
||||||
`org-roam-capture-templates'."
|
`org-roam-capture-templates'."
|
||||||
(let* ((file-path (pcase org-roam-capture--context
|
(let ((file-path (pcase org-roam-capture--context
|
||||||
('capture
|
('capture
|
||||||
(or (cdr (assoc 'file org-roam-capture--info))
|
(or (cdr (assoc 'file org-roam-capture--info))
|
||||||
(org-roam-capture--new-file)))
|
(org-roam-capture--new-file)))
|
||||||
@ -476,35 +471,14 @@ This function is used solely in Org-roam's capture templates: see
|
|||||||
(_ (error "Invalid org-roam-capture-context")))))
|
(_ (error "Invalid org-roam-capture-context")))))
|
||||||
(org-capture-put :template
|
(org-capture-put :template
|
||||||
(org-roam-capture--fill-template (org-capture-get :template)))
|
(org-roam-capture--fill-template (org-capture-get :template)))
|
||||||
(org-roam-capture--put :file-path file-path
|
(org-roam-capture--put :file-path file-path)
|
||||||
:finalize (or (org-capture-get :finalize)
|
|
||||||
(org-roam-capture--get :finalize)))
|
|
||||||
(while org-roam-capture-additional-template-props
|
(while org-roam-capture-additional-template-props
|
||||||
(let ((prop (pop org-roam-capture-additional-template-props))
|
(let ((prop (pop org-roam-capture-additional-template-props))
|
||||||
(val (pop org-roam-capture-additional-template-props)))
|
(val (pop org-roam-capture-additional-template-props)))
|
||||||
(org-roam-capture--put prop val)))
|
(org-roam-capture--put prop val)))
|
||||||
(set-buffer (org-capture-target-buffer file-path))
|
(set-buffer (org-capture-target-buffer file-path))
|
||||||
(widen)
|
(widen)
|
||||||
(if-let* ((olp (when (eq org-roam-capture--context 'dailies)
|
(goto-char (point-max))))
|
||||||
(--> (org-roam-capture--get :olp)
|
|
||||||
(pcase it
|
|
||||||
((pred stringp)
|
|
||||||
(list it))
|
|
||||||
((pred listp)
|
|
||||||
it)
|
|
||||||
(wrong-type
|
|
||||||
(signal 'wrong-type-argument
|
|
||||||
`((stringp listp)
|
|
||||||
,wrong-type))))))))
|
|
||||||
(condition-case err
|
|
||||||
(when-let ((marker (org-find-olp `(,file-path ,@olp))))
|
|
||||||
(goto-char marker)
|
|
||||||
(set-marker marker nil))
|
|
||||||
(error
|
|
||||||
(when (org-roam-capture--get :new-file)
|
|
||||||
(kill-buffer))
|
|
||||||
(signal (car err) (cdr err))))
|
|
||||||
(goto-char (point-min)))))
|
|
||||||
|
|
||||||
(defun org-roam-capture--convert-template (template)
|
(defun org-roam-capture--convert-template (template)
|
||||||
"Convert TEMPLATE from Org-roam syntax to `org-capture-templates' syntax."
|
"Convert TEMPLATE from Org-roam syntax to `org-capture-templates' syntax."
|
||||||
@ -519,9 +493,6 @@ This function is used solely in Org-roam's capture templates: see
|
|||||||
(let* ((key (pop rest))
|
(let* ((key (pop rest))
|
||||||
(val (pop rest))
|
(val (pop rest))
|
||||||
(custom (member key org-roam-capture--template-keywords)))
|
(custom (member key org-roam-capture--template-keywords)))
|
||||||
(when (and custom
|
|
||||||
(not val))
|
|
||||||
(user-error "Invalid capture template format: %s\nkey %s cannot be nil" template key))
|
|
||||||
(push val (if custom org-roam-plist options))
|
(push val (if custom org-roam-plist options))
|
||||||
(push key (if custom org-roam-plist options))))
|
(push key (if custom org-roam-plist options))))
|
||||||
(append converted options `(:org-roam ,org-roam-plist))))
|
(append converted options `(:org-roam ,org-roam-plist))))
|
||||||
@ -545,8 +516,7 @@ GOTO and KEYS argument have the same functionality as
|
|||||||
`org-capture'."
|
`org-capture'."
|
||||||
(let* ((org-capture-templates (mapcar #'org-roam-capture--convert-template org-roam-capture-templates))
|
(let* ((org-capture-templates (mapcar #'org-roam-capture--convert-template org-roam-capture-templates))
|
||||||
(one-template-p (= (length org-capture-templates) 1))
|
(one-template-p (= (length org-capture-templates) 1))
|
||||||
org-capture-templates-contexts
|
org-capture-templates-contexts)
|
||||||
(org-capture-link-is-already-stored t))
|
|
||||||
(when one-template-p
|
(when one-template-p
|
||||||
(setq keys (caar org-capture-templates)))
|
(setq keys (caar org-capture-templates)))
|
||||||
(if (or one-template-p
|
(if (or one-template-p
|
||||||
@ -555,11 +525,10 @@ GOTO and KEYS argument have the same functionality as
|
|||||||
(funcall-interactively org-roam-capture-function))))
|
(funcall-interactively org-roam-capture-function))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun org-roam-capture (&optional goto keys)
|
(defun org-roam-capture ()
|
||||||
"Launches an `org-capture' process for a new or existing note.
|
"Launches an `org-capture' process for a new or existing note.
|
||||||
This uses the templates defined at `org-roam-capture-templates'.
|
This uses the templates defined at `org-roam-capture-templates'."
|
||||||
Arguments GOTO and KEYS see `org-capture'."
|
(interactive)
|
||||||
(interactive "P")
|
|
||||||
(unless org-roam-mode (org-roam-mode))
|
(unless org-roam-mode (org-roam-mode))
|
||||||
(let* ((completions (org-roam--get-title-path-completions))
|
(let* ((completions (org-roam--get-title-path-completions))
|
||||||
(title-with-keys (org-roam-completion--completing-read "File: "
|
(title-with-keys (org-roam-completion--completing-read "File: "
|
||||||
@ -572,7 +541,7 @@ Arguments GOTO and KEYS see `org-capture'."
|
|||||||
(cons 'file file-path)))
|
(cons 'file file-path)))
|
||||||
(org-roam-capture--context 'capture))
|
(org-roam-capture--context 'capture))
|
||||||
(condition-case err
|
(condition-case err
|
||||||
(org-roam-capture--capture goto keys)
|
(org-roam-capture--capture)
|
||||||
(error (user-error "%s. Please adjust `org-roam-capture-templates'"
|
(error (user-error "%s. Please adjust `org-roam-capture-templates'"
|
||||||
(error-message-string err)))))))
|
(error-message-string err)))))))
|
||||||
|
|
||||||
|
@ -5,8 +5,8 @@
|
|||||||
;; Author: Jethro Kuan <jethrokuan95@gmail.com>
|
;; Author: Jethro Kuan <jethrokuan95@gmail.com>
|
||||||
;; URL: https://github.com/org-roam/org-roam
|
;; URL: https://github.com/org-roam/org-roam
|
||||||
;; Keywords: org-mode, roam, convenience
|
;; Keywords: org-mode, roam, convenience
|
||||||
;; Version: 1.2.3
|
;; Version: 1.2.1
|
||||||
;; Package-Requires: ((emacs "26.1") (dash "2.13") (f "0.17.2") (s "1.12.0") (org "9.3") (emacsql "3.0.0") (emacsql-sqlite3 "1.0.2"))
|
;; Package-Requires: ((emacs "26.1") (dash "2.13") (f "0.17.2") (s "1.12.0") (org "9.3") (emacsql "3.0.0") (emacsql-sqlite3 "1.0.0"))
|
||||||
|
|
||||||
;; This file is NOT part of GNU Emacs.
|
;; This file is NOT part of GNU Emacs.
|
||||||
|
|
||||||
@ -41,6 +41,8 @@
|
|||||||
"org-roam 1.0.0")
|
"org-roam 1.0.0")
|
||||||
(define-obsolete-function-alias 'org-roam-sql 'org-roam-db-query
|
(define-obsolete-function-alias 'org-roam-sql 'org-roam-db-query
|
||||||
"org-roam 1.0.0")
|
"org-roam 1.0.0")
|
||||||
|
(define-obsolete-function-alias 'org-roam--get-db 'org-roam-db--get
|
||||||
|
"org-roam 1.0.0")
|
||||||
(define-obsolete-function-alias 'org-roam--db-clear 'org-roam-db--clear
|
(define-obsolete-function-alias 'org-roam--db-clear 'org-roam-db--clear
|
||||||
"org-roam 1.0.0")
|
"org-roam 1.0.0")
|
||||||
(define-obsolete-function-alias 'org-roam-show-graph 'org-roam-graph-show
|
(define-obsolete-function-alias 'org-roam-show-graph 'org-roam-graph-show
|
||||||
@ -79,14 +81,9 @@
|
|||||||
"org-roam 1.1.0")
|
"org-roam 1.1.0")
|
||||||
(define-obsolete-function-alias 'org-roam-db--clear 'org-roam-db-clear
|
(define-obsolete-function-alias 'org-roam-db--clear 'org-roam-db-clear
|
||||||
"org-roam 1.2.0")
|
"org-roam 1.2.0")
|
||||||
(define-obsolete-function-alias 'org-roam-dailies-today 'org-roam-dailies-find-today
|
|
||||||
"org-roam 1.2.2")
|
(when (version< (org-version) "9.3")
|
||||||
(define-obsolete-function-alias 'org-roam-dailies-yesterday 'org-roam-dailies-find-yesterday
|
(defalias 'org-link-make-string 'org-make-link-string))
|
||||||
"org-roam 1.2.2")
|
|
||||||
(define-obsolete-function-alias 'org-roam-dailies-tomorrow 'org-roam-dailies-find-tomorrow
|
|
||||||
"org-roam 1.2.2")
|
|
||||||
(define-obsolete-function-alias 'org-roam-dailies-date 'org-roam-dailies-find-date
|
|
||||||
"org-roam 1.2.2")
|
|
||||||
|
|
||||||
;;;; Variables
|
;;;; Variables
|
||||||
(define-obsolete-variable-alias 'org-roam-graphviz-extra-options
|
(define-obsolete-variable-alias 'org-roam-graphviz-extra-options
|
||||||
@ -103,9 +100,6 @@
|
|||||||
'org-roam-dailies-capture-templates "org-roam 1.0.0")
|
'org-roam-dailies-capture-templates "org-roam 1.0.0")
|
||||||
(define-obsolete-variable-alias 'org-roam-date-filename-format
|
(define-obsolete-variable-alias 'org-roam-date-filename-format
|
||||||
'org-roam-dailies-capture-templates "org-roam 1.0.0")
|
'org-roam-dailies-capture-templates "org-roam 1.0.0")
|
||||||
(define-obsolete-variable-alias 'org-roam-update-db-idle-seconds
|
|
||||||
'org-roam-db-update-idle-seconds "org-roam 1.2.2")
|
|
||||||
|
|
||||||
(make-obsolete-variable 'org-roam-buffer-no-delete-other-windows
|
(make-obsolete-variable 'org-roam-buffer-no-delete-other-windows
|
||||||
'org-roam-buffer-window-parameters "org-roam 1.1.1")
|
'org-roam-buffer-window-parameters "org-roam 1.1.1")
|
||||||
|
|
||||||
|
@ -5,8 +5,8 @@
|
|||||||
;; Author: Jethro Kuan <jethrokuan95@gmail.com>
|
;; Author: Jethro Kuan <jethrokuan95@gmail.com>
|
||||||
;; URL: https://github.com/org-roam/org-roam
|
;; URL: https://github.com/org-roam/org-roam
|
||||||
;; Keywords: org-mode, roam, convenience
|
;; Keywords: org-mode, roam, convenience
|
||||||
;; Version: 1.2.3
|
;; Version: 1.2.1
|
||||||
;; Package-Requires: ((emacs "26.1") (dash "2.13") (f "0.17.2") (s "1.12.0") (org "9.3") (emacsql "3.0.0") (emacsql-sqlite3 "1.0.2"))
|
;; Package-Requires: ((emacs "26.1") (dash "2.13") (f "0.17.2") (s "1.12.0") (org "9.3") (emacsql "3.0.0") (emacsql-sqlite3 "1.0.0"))
|
||||||
|
|
||||||
;; This file is NOT part of GNU Emacs.
|
;; This file is NOT part of GNU Emacs.
|
||||||
|
|
||||||
@ -47,11 +47,6 @@
|
|||||||
(function :tag "Custom function"))
|
(function :tag "Custom function"))
|
||||||
:group 'org-roam)
|
:group '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)
|
|
||||||
|
|
||||||
(defun org-roam-completion--helm-candidate-transformer (candidates _source)
|
(defun org-roam-completion--helm-candidate-transformer (candidates _source)
|
||||||
"Transforms CANDIDATES for Helm-based completing read.
|
"Transforms CANDIDATES for Helm-based completing read.
|
||||||
SOURCE is not used."
|
SOURCE is not used."
|
||||||
@ -79,7 +74,6 @@ Return user choice."
|
|||||||
(if (fboundp 'ivy-read)
|
(if (fboundp 'ivy-read)
|
||||||
(ivy-read prompt choices
|
(ivy-read prompt choices
|
||||||
:initial-input initial-input
|
:initial-input initial-input
|
||||||
:preselect initial-input
|
|
||||||
:require-match require-match
|
:require-match require-match
|
||||||
:action (prog1 action
|
:action (prog1 action
|
||||||
(setq action nil))
|
(setq action nil))
|
||||||
|
@ -1,14 +1,12 @@
|
|||||||
;;; org-roam-dailies.el --- Daily-notes for Org-roam -*- coding: utf-8; lexical-binding: t; -*-
|
;;; org-roam-dailies.el --- Daily notes for Org-roam -*- coding: utf-8; lexical-binding: t; -*-
|
||||||
;;;
|
;;;
|
||||||
;; Copyright © 2020 Jethro Kuan <jethrokuan95@gmail.com>
|
;; Copyright © 2020 Jethro Kuan <jethrokuan95@gmail.com>
|
||||||
;; Copyright © 2020 Leo Vivier <leo.vivier+dev@gmail.com>
|
|
||||||
|
|
||||||
;; Author: Jethro Kuan <jethrokuan95@gmail.com>
|
;; Author: Jethro Kuan <jethrokuan95@gmail.com>
|
||||||
;; Leo Vivier <leo.vivier+dev@gmail.com>
|
|
||||||
;; URL: https://github.com/org-roam/org-roam
|
;; URL: https://github.com/org-roam/org-roam
|
||||||
;; Keywords: org-mode, roam, convenience
|
;; Keywords: org-mode, roam, convenience
|
||||||
;; Version: 1.2.3
|
;; Version: 1.2.1
|
||||||
;; Package-Requires: ((emacs "26.1") (dash "2.13") (f "0.17.2") (s "1.12.0") (org "9.3") (emacsql "3.0.0") (emacsql-sqlite3 "1.0.2"))
|
;; Package-Requires: ((emacs "26.1") (dash "2.13") (f "0.17.2") (s "1.12.0") (org "9.3") (emacsql "3.0.0") (emacsql-sqlite3 "1.0.0"))
|
||||||
|
|
||||||
;; This file is NOT part of GNU Emacs.
|
;; This file is NOT part of GNU Emacs.
|
||||||
|
|
||||||
@ -29,7 +27,7 @@
|
|||||||
|
|
||||||
;;; Commentary:
|
;;; Commentary:
|
||||||
;;
|
;;
|
||||||
;; This library provides functionality for creating daily-notes. This is a
|
;; This library provides functionality for creating daily notes. This is a
|
||||||
;; concept borrowed from Roam Research.
|
;; concept borrowed from Roam Research.
|
||||||
;;
|
;;
|
||||||
;;; Code:
|
;;; Code:
|
||||||
@ -37,52 +35,31 @@
|
|||||||
(require 'org-capture)
|
(require 'org-capture)
|
||||||
(require 'org-roam-capture)
|
(require 'org-roam-capture)
|
||||||
(require 'org-roam-macs)
|
(require 'org-roam-macs)
|
||||||
(require 'f)
|
|
||||||
|
|
||||||
;;;; Declarations
|
|
||||||
(defvar org-roam-mode)
|
|
||||||
(defvar org-roam-directory)
|
|
||||||
(declare-function org-roam--org-file-p "org-roam")
|
|
||||||
(declare-function org-roam--file-path-from-id "org-roam")
|
|
||||||
(declare-function org-roam--find-file "org-roam")
|
|
||||||
(declare-function org-roam-mode "org-roam")
|
|
||||||
|
|
||||||
;;;; Customizable variables
|
|
||||||
(defcustom org-roam-dailies-directory "daily/"
|
|
||||||
"Path to daily-notes."
|
|
||||||
:group 'org-roam
|
|
||||||
:type 'string)
|
|
||||||
|
|
||||||
(defcustom org-roam-dailies-find-file-hook nil
|
|
||||||
"Hook that is run right after navigating to a daily-note."
|
|
||||||
:group 'org-roam
|
|
||||||
:type 'hook)
|
|
||||||
|
|
||||||
(defcustom org-roam-dailies-capture-templates
|
(defcustom org-roam-dailies-capture-templates
|
||||||
'(("d" "default" entry (function org-roam-capture--get-point)
|
'(("d" "daily" plain (function org-roam-capture--get-point)
|
||||||
"* %?"
|
""
|
||||||
:file-name "daily/%<%Y-%m-%d>"
|
:immediate-finish t
|
||||||
:head "#+title: %<%Y-%m-%d>\n"))
|
:file-name "%<%Y-%m-%d>"
|
||||||
"Capture templates for daily-notes in Org-roam."
|
:head "#+title: %<%Y-%m-%d>"))
|
||||||
|
"Capture templates for daily notes in Org-roam."
|
||||||
:group 'org-roam
|
:group 'org-roam
|
||||||
;; Adapted from `org-capture-templates'
|
;; Adapted from `org-capture-templates'
|
||||||
:type
|
:type
|
||||||
'(repeat
|
'(repeat
|
||||||
(choice :value ("d" "default" plain (function org-roam-capture--get-point)
|
(choice :value ("d" "daily" plain (function org-roam-capture--get-point)
|
||||||
"%?"
|
""
|
||||||
:file-name "daily/%<%Y-%m-%d>"
|
:immediate-finish t
|
||||||
:head "#+title: %<%Y-%m-%d>\n"
|
:file-name "%<%Y-%m-%d>"
|
||||||
:unnarrowed t)
|
:head "#+title: %<%Y-%m-%d>")
|
||||||
(list :tag "Multikey description"
|
(list :tag "Multikey description"
|
||||||
(string :tag "Keys ")
|
(string :tag "Keys ")
|
||||||
(string :tag "Description"))
|
(string :tag "Description"))
|
||||||
(list :tag "Template entry"
|
(list :tag "Template entry"
|
||||||
(string :tag "Keys ")
|
(string :tag "Keys ")
|
||||||
(string :tag "Description ")
|
(string :tag "Description ")
|
||||||
(choice :tag "Type "
|
(const :format "" plain)
|
||||||
(const :tag "Plain" plain)
|
(const :format "" (function org-roam-capture--get-point))
|
||||||
(const :tag "Entry (for creating headlines)" entry))
|
|
||||||
(const :format "" #'org-roam-capture--get-point)
|
|
||||||
(choice :tag "Template "
|
(choice :tag "Template "
|
||||||
(string :tag "String"
|
(string :tag "String"
|
||||||
:format "String:\n \
|
:format "String:\n \
|
||||||
@ -93,20 +70,16 @@ Template string :\n%v")
|
|||||||
(list :tag "Function"
|
(list :tag "Function"
|
||||||
(const :format "" function)
|
(const :format "" function)
|
||||||
(function :tag "Template function ")))
|
(function :tag "Template function ")))
|
||||||
|
(const :format "" :immediate-finish) (const :format "" t)
|
||||||
(const :format "File name format :" :file-name)
|
(const :format "File name format :" :file-name)
|
||||||
(string :format " %v" :value "daily/%<%Y-%m-%d>")
|
|
||||||
(const :format "Header format :" :head)
|
|
||||||
(string :format " %v" :value "#+title: ${title}\n")
|
(string :format " %v" :value "#+title: ${title}\n")
|
||||||
|
(const :format "Header format :" :head)
|
||||||
|
(string :format "\n%v" :value "%<%Y%m%d%H%M%S>-${slug}")
|
||||||
(plist :inline t
|
(plist :inline t
|
||||||
:tag "Options"
|
:tag "Options"
|
||||||
;; Give the most common options as checkboxes
|
;; Give the most common options as checkboxes
|
||||||
:options
|
:options
|
||||||
(((const :tag "Outline path" :olp)
|
(((const :format "%v " :prepend) (const t))
|
||||||
(repeat :tag "Headings"
|
|
||||||
(string :tag "Heading")))
|
|
||||||
((const :format "%v " :unnarrowed) (const t))
|
|
||||||
((const :format "%v " :prepend) (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))
|
||||||
((const :format "%v " :empty-lines) (const 1))
|
((const :format "%v " :empty-lines) (const 1))
|
||||||
((const :format "%v " :empty-lines-before) (const 1))
|
((const :format "%v " :empty-lines-before) (const 1))
|
||||||
@ -117,250 +90,48 @@ Template string :\n%v")
|
|||||||
((const :format "%v " :time-prompt) (const t))
|
((const :format "%v " :time-prompt) (const t))
|
||||||
((const :format "%v " :tree-type) (const week))
|
((const :format "%v " :tree-type) (const week))
|
||||||
((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))
|
||||||
|
((const :format "%v " :unnarrowed) (const t))))))))
|
||||||
|
|
||||||
;;;; Utilities
|
;; Declarations
|
||||||
(defun org-roam-dailies-directory--get-absolute-path ()
|
(defvar org-roam-mode)
|
||||||
"Get absolute path to `org-roam-dailies-directory'."
|
(declare-function org-roam--file-path-from-id "org-roam")
|
||||||
(-> (concat
|
(declare-function org-roam-mode "org-roam")
|
||||||
(file-name-as-directory org-roam-directory)
|
|
||||||
org-roam-dailies-directory)
|
|
||||||
(file-truename)))
|
|
||||||
|
|
||||||
(defun org-roam-dailies-find-directory ()
|
(defun org-roam-dailies--file-for-time (time)
|
||||||
"Find and open `org-roam-dailies-directory'."
|
"Create and find file for TIME."
|
||||||
(interactive)
|
(let ((org-roam-capture-templates org-roam-dailies-capture-templates)
|
||||||
(org-roam--find-file (org-roam-dailies-directory--get-absolute-path)))
|
|
||||||
|
|
||||||
(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 (or file
|
|
||||||
(-> (buffer-base-buffer)
|
|
||||||
(buffer-file-name))))
|
|
||||||
(directory (org-roam-dailies-directory--get-absolute-path)))
|
|
||||||
(setq path (file-truename 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."
|
|
||||||
(unless org-roam-mode (org-roam-mode))
|
|
||||||
(let ((org-roam-capture-templates (--> org-roam-dailies-capture-templates
|
|
||||||
(if goto (list (car it)) it)))
|
|
||||||
(org-roam-capture--info (list (cons 'time time)))
|
(org-roam-capture--info (list (cons 'time time)))
|
||||||
(org-roam-capture--context 'dailies))
|
(org-roam-capture--context 'dailies))
|
||||||
(setq org-roam-capture-additional-template-props (list :finalize 'find-file))
|
(setq org-roam-capture-additional-template-props (list :finalize 'find-file))
|
||||||
(org-roam-capture--capture (when goto '(4)))))
|
(org-roam--with-template-error 'org-roam-dailies-capture-templates
|
||||||
|
(org-roam-capture--capture))))
|
||||||
|
|
||||||
;;;; Commands
|
(defun org-roam-dailies-today ()
|
||||||
;;; Today
|
"Create and find the daily note for 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)
|
|
||||||
(message "Showing daily-note for today")))
|
|
||||||
|
|
||||||
(defun org-roam-dailies-find-today ()
|
|
||||||
"Find the daily-note for today, creating it if necessary."
|
|
||||||
(interactive)
|
(interactive)
|
||||||
(org-roam-dailies-capture-today t))
|
(unless org-roam-mode (org-roam-mode))
|
||||||
|
(org-roam-dailies--file-for-time (current-time)))
|
||||||
|
|
||||||
;;; Tomorrow
|
(defun org-roam-dailies-tomorrow (n)
|
||||||
(defun org-roam-dailies-capture-tomorrow (n &optional goto)
|
"Create and find the daily note for tomorrow.
|
||||||
"Create an entry in the daily-note for tomorrow.
|
With numeric argument N, use 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
|
|
||||||
creating an entry."
|
|
||||||
(interactive "p")
|
(interactive "p")
|
||||||
(org-roam-dailies--capture (time-add (* n 86400) (current-time)) goto))
|
(unless org-roam-mode (org-roam-mode))
|
||||||
|
(org-roam-dailies--file-for-time (time-add (* n 86400) (current-time))))
|
||||||
|
|
||||||
(defun org-roam-dailies-find-tomorrow (n)
|
(defun org-roam-dailies-yesterday (n)
|
||||||
"Find the daily-note for tomorrow, creating it if necessary.
|
"Create and find the file for yesterday.
|
||||||
|
With numeric argument N, use N days in the past."
|
||||||
With numeric argument N, use the daily-note N days in the
|
|
||||||
future."
|
|
||||||
(interactive "p")
|
(interactive "p")
|
||||||
(org-roam-dailies-capture-tomorrow n t))
|
(unless org-roam-mode (org-roam-mode))
|
||||||
|
(org-roam-dailies-tomorrow (- n)))
|
||||||
|
|
||||||
;;; Yesterday
|
(defun org-roam-dailies-date ()
|
||||||
(defun org-roam-dailies-capture-yesterday (n &optional goto)
|
"Create the file for any date using the calendar interface."
|
||||||
"Create an entry in the daily-note for yesteday.
|
|
||||||
|
|
||||||
With numeric argument N, use the daily-note N days in the past.
|
|
||||||
|
|
||||||
When GOTO is non-nil, go the note without creating an entry."
|
|
||||||
(interactive "p")
|
|
||||||
(org-roam-dailies-capture-tomorrow (- n) goto))
|
|
||||||
|
|
||||||
(defun org-roam-dailies-find-yesterday (n)
|
|
||||||
"Find the daily-note for yesterday, creating it if necessary.
|
|
||||||
|
|
||||||
With numeric argument N, use the daily-note N days in the
|
|
||||||
future."
|
|
||||||
(interactive "p")
|
|
||||||
(org-roam-dailies-capture-tomorrow (- n) t))
|
|
||||||
|
|
||||||
;;; Calendar
|
|
||||||
(defvar org-roam-dailies-calendar-hook (list 'org-roam-dailies-calendar-mark-entries)
|
|
||||||
"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 _ _ _)
|
|
||||||
(-> file
|
|
||||||
(file-name-nondirectory)
|
|
||||||
(file-name-sans-extension)
|
|
||||||
(org-parse-time-string))
|
|
||||||
(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.
|
|
||||||
|
|
||||||
Prefer past dates, unless PREFER-FUTURE is non-nil.
|
|
||||||
|
|
||||||
With a `C-u' prefix or when GOTO is non-nil, go the note without
|
|
||||||
creating an entry."
|
|
||||||
(interactive "P")
|
|
||||||
(org-roam-dailies-calendar--install-hook)
|
|
||||||
(let* ((time-str (let ((org-read-date-prefer-future prefer-future))
|
|
||||||
(org-read-date nil nil nil (if goto
|
|
||||||
"Find daily-note: "
|
|
||||||
"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)
|
|
||||||
(message "Showing note for %s" time-str))))
|
|
||||||
|
|
||||||
(defun org-roam-dailies-find-date (&optional prefer-future)
|
|
||||||
"Find the daily-note for a date using the calendar, creating it if necessary.
|
|
||||||
|
|
||||||
Prefer past dates, unless PREFER-FUTURE is non-nil."
|
|
||||||
(interactive)
|
(interactive)
|
||||||
(org-roam-dailies-capture-date t prefer-future))
|
(let ((time (org-read-date nil 'to-time nil "Date: ")))
|
||||||
|
(org-roam-dailies--file-for-time time)))
|
||||||
;;; Navigation
|
|
||||||
(defun org-roam-dailies--list-files (&rest extra-files)
|
|
||||||
"List all files in `org-roam-dailies-directory'.
|
|
||||||
|
|
||||||
EXTRA-FILES can be used to append extra files to the list."
|
|
||||||
(let ((dir (org-roam-dailies-directory--get-absolute-path)))
|
|
||||||
(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 ""))
|
|
||||||
extra-files)))
|
|
||||||
|
|
||||||
(defun org-roam-dailies--find-next-note-path (&optional n file)
|
|
||||||
"Find next daily-note from FILE.
|
|
||||||
|
|
||||||
With numeric argument N, find note N days in the future. If N is
|
|
||||||
negative, find note N days in the past.
|
|
||||||
|
|
||||||
If FILE is not provided, use the file visited by the current
|
|
||||||
buffer."
|
|
||||||
(unless (org-roam-dailies--daily-note-p file)
|
|
||||||
(user-error "Not in a daily-note"))
|
|
||||||
(let ((n (or n 1))
|
|
||||||
(file (or file
|
|
||||||
(-> (buffer-base-buffer)
|
|
||||||
(buffer-file-name)))))
|
|
||||||
;; Ensure that the buffer is saved before moving
|
|
||||||
(save-buffer file)
|
|
||||||
(let* ((list (org-roam-dailies--list-files))
|
|
||||||
(position
|
|
||||||
(cl-position-if (lambda (candidate)
|
|
||||||
(string= file candidate))
|
|
||||||
list)))
|
|
||||||
(pcase n
|
|
||||||
((pred (natnump))
|
|
||||||
(if (eq position (- (length list) 1))
|
|
||||||
(user-error "Already at newest note")
|
|
||||||
(message "Showing next daily-note")))
|
|
||||||
((pred (integerp))
|
|
||||||
(if (eq position 0)
|
|
||||||
(user-error "Already at oldest note")
|
|
||||||
(message "Showing previous daily-note"))))
|
|
||||||
(nth (+ position n) list))))
|
|
||||||
|
|
||||||
(defun org-roam-dailies-find-next-note (&optional n)
|
|
||||||
"Find next daily-note.
|
|
||||||
|
|
||||||
With numeric argument N, find note N days in the future. If N is
|
|
||||||
negative, find note N days in the past."
|
|
||||||
(interactive "p")
|
|
||||||
(let* ((n (or n 1))
|
|
||||||
(next (org-roam-dailies--find-next-note-path n)))
|
|
||||||
(find-file next)
|
|
||||||
(run-hooks 'org-roam-dailies-find-file-hook)))
|
|
||||||
|
|
||||||
(defun org-roam-dailies-find-previous-note (&optional n)
|
|
||||||
"Find previous daily-note.
|
|
||||||
|
|
||||||
With numeric argument N, find note N days in the past. If N is
|
|
||||||
negative, find note N days in the future."
|
|
||||||
(interactive "p")
|
|
||||||
(let ((n (if n (- n) -1)))
|
|
||||||
(org-roam-dailies-find-next-note n)))
|
|
||||||
|
|
||||||
;;;; Bindings
|
|
||||||
(defvar org-roam-dailies-map (make-sparse-keymap)
|
|
||||||
"Keymap for `org-roam-dailies'.")
|
|
||||||
|
|
||||||
(define-prefix-command 'org-roam-dailies-map)
|
|
||||||
|
|
||||||
(define-key org-roam-dailies-map (kbd "d") #'org-roam-dailies-find-today)
|
|
||||||
(define-key org-roam-dailies-map (kbd "y") #'org-roam-dailies-find-yesterday)
|
|
||||||
(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 "f") #'org-roam-dailies-find-next-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-find-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)
|
|
||||||
|
|
||||||
(provide 'org-roam-dailies)
|
(provide 'org-roam-dailies)
|
||||||
|
|
||||||
|
484
org-roam-db.el
484
org-roam-db.el
@ -5,8 +5,8 @@
|
|||||||
;; Author: Jethro Kuan <jethrokuan95@gmail.com>
|
;; Author: Jethro Kuan <jethrokuan95@gmail.com>
|
||||||
;; URL: https://github.com/org-roam/org-roam
|
;; URL: https://github.com/org-roam/org-roam
|
||||||
;; Keywords: org-mode, roam, convenience
|
;; Keywords: org-mode, roam, convenience
|
||||||
;; Version: 1.2.3
|
;; Version: 1.2.1
|
||||||
;; Package-Requires: ((emacs "26.1") (dash "2.13") (f "0.17.2") (s "1.12.0") (org "9.3") (emacsql "3.0.0") (emacsql-sqlite3 "1.0.2"))
|
;; Package-Requires: ((emacs "26.1") (dash "2.13") (f "0.17.2") (s "1.12.0") (org "9.3") (emacsql "3.0.0") (emacsql-sqlite3 "1.0.0"))
|
||||||
|
|
||||||
;; This file is NOT part of GNU Emacs.
|
;; This file is NOT part of GNU Emacs.
|
||||||
|
|
||||||
@ -35,24 +35,17 @@
|
|||||||
(require 'emacsql)
|
(require 'emacsql)
|
||||||
(require 'emacsql-sqlite3)
|
(require 'emacsql-sqlite3)
|
||||||
(require 'seq)
|
(require 'seq)
|
||||||
|
|
||||||
(eval-and-compile
|
|
||||||
(require 'org-roam-macs)
|
(require 'org-roam-macs)
|
||||||
;; For `org-with-wide-buffer'
|
|
||||||
(require 'org-macs))
|
|
||||||
|
|
||||||
(defvar org-roam-directory)
|
(defvar org-roam-directory)
|
||||||
(defvar org-roam-enable-headline-linking)
|
|
||||||
(defvar org-roam-verbose)
|
(defvar org-roam-verbose)
|
||||||
(defvar org-roam-file-name)
|
(defvar org-roam-file-name)
|
||||||
|
|
||||||
(defvar org-agenda-files)
|
|
||||||
|
|
||||||
(declare-function org-roam--org-roam-file-p "org-roam")
|
(declare-function org-roam--org-roam-file-p "org-roam")
|
||||||
(declare-function org-roam--extract-titles "org-roam")
|
(declare-function org-roam--extract-titles "org-roam")
|
||||||
(declare-function org-roam--extract-refs "org-roam")
|
(declare-function org-roam--extract-ref "org-roam")
|
||||||
(declare-function org-roam--extract-tags "org-roam")
|
(declare-function org-roam--extract-tags "org-roam")
|
||||||
(declare-function org-roam--extract-ids "org-roam")
|
(declare-function org-roam--extract-headlines "org-roam")
|
||||||
(declare-function org-roam--extract-links "org-roam")
|
(declare-function org-roam--extract-links "org-roam")
|
||||||
(declare-function org-roam--list-all-files "org-roam")
|
(declare-function org-roam--list-all-files "org-roam")
|
||||||
(declare-function org-roam--path-to-slug "org-roam")
|
(declare-function org-roam--path-to-slug "org-roam")
|
||||||
@ -60,7 +53,7 @@
|
|||||||
(declare-function org-roam-buffer--update-maybe "org-roam-buffer")
|
(declare-function org-roam-buffer--update-maybe "org-roam-buffer")
|
||||||
|
|
||||||
;;;; Options
|
;;;; Options
|
||||||
(defcustom org-roam-db-location (expand-file-name "org-roam.db" user-emacs-directory)
|
(defcustom org-roam-db-location nil
|
||||||
"The full path to file where the Org-roam database is stored.
|
"The full path to file where the Org-roam database is stored.
|
||||||
If this is non-nil, the Org-roam sqlite database is saved here.
|
If this is non-nil, the Org-roam sqlite database is saved here.
|
||||||
|
|
||||||
@ -84,38 +77,20 @@ value like `most-positive-fixnum'."
|
|||||||
:type 'int
|
:type 'int
|
||||||
:group 'org-roam)
|
:group 'org-roam)
|
||||||
|
|
||||||
(defconst org-roam-db--version 10)
|
(defconst org-roam-db--version 7)
|
||||||
|
|
||||||
(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.")
|
||||||
|
|
||||||
(defvar org-roam-db-dirty nil
|
|
||||||
"Whether the org-roam database is dirty and requires an update.
|
|
||||||
Contains pairs of `org-roam-directory' and `org-roam-db-location'
|
|
||||||
so that multi-directories are updated.")
|
|
||||||
|
|
||||||
(defcustom org-roam-db-update-method 'idle-timer
|
|
||||||
"Method to update the Org-roam database.
|
|
||||||
|
|
||||||
`immediate'
|
|
||||||
Update the database immediately upon file changes.
|
|
||||||
|
|
||||||
`idle-timer'
|
|
||||||
Updates the database if dirty, if Emacs idles for `org-roam-db-update-idle-seconds'."
|
|
||||||
:type '(set (const :tag "idle-timer" idle-timer)
|
|
||||||
(const :tag "immediate" immediate))
|
|
||||||
:group 'org-roam)
|
|
||||||
|
|
||||||
(defcustom org-roam-db-update-idle-seconds 2
|
|
||||||
"Number of idle seconds before triggering an Org-roam database update."
|
|
||||||
:type 'integer
|
|
||||||
:group 'org-roam)
|
|
||||||
|
|
||||||
;;;; Core Functions
|
;;;; Core Functions
|
||||||
|
(defun org-roam-db--get ()
|
||||||
|
"Return the sqlite db file."
|
||||||
|
(or org-roam-db-location
|
||||||
|
(expand-file-name "org-roam.db" org-roam-directory)))
|
||||||
|
|
||||||
(defun org-roam-db--get-connection ()
|
(defun org-roam-db--get-connection ()
|
||||||
"Return the database connection, if any."
|
"Return the database connection, if any."
|
||||||
(gethash (expand-file-name org-roam-directory)
|
(gethash (file-truename org-roam-directory)
|
||||||
org-roam-db--connection))
|
org-roam-db--connection))
|
||||||
|
|
||||||
(defun org-roam-db ()
|
(defun org-roam-db ()
|
||||||
@ -124,11 +99,12 @@ Initializes and stores the database, and the database connection.
|
|||||||
Performs a database upgrade when required."
|
Performs a database upgrade when required."
|
||||||
(unless (and (org-roam-db--get-connection)
|
(unless (and (org-roam-db--get-connection)
|
||||||
(emacsql-live-p (org-roam-db--get-connection)))
|
(emacsql-live-p (org-roam-db--get-connection)))
|
||||||
(let ((init-db (not (file-exists-p org-roam-db-location))))
|
(let* ((db-file (org-roam-db--get))
|
||||||
(make-directory (file-name-directory org-roam-db-location) t)
|
(init-db (not (file-exists-p db-file))))
|
||||||
(let ((conn (emacsql-sqlite3 org-roam-db-location)))
|
(make-directory (file-name-directory db-file) t)
|
||||||
|
(let ((conn (emacsql-sqlite3 db-file)))
|
||||||
(set-process-query-on-exit-flag (emacsql-process conn) nil)
|
(set-process-query-on-exit-flag (emacsql-process conn) nil)
|
||||||
(puthash (expand-file-name org-roam-directory)
|
(puthash (file-truename org-roam-directory)
|
||||||
conn
|
conn
|
||||||
org-roam-db--connection)
|
org-roam-db--connection)
|
||||||
(when init-db
|
(when init-db
|
||||||
@ -162,14 +138,13 @@ SQL can be either the emacsql vector representation, or a string."
|
|||||||
(hash :not-null)
|
(hash :not-null)
|
||||||
(meta :not-null)])
|
(meta :not-null)])
|
||||||
|
|
||||||
(ids
|
(headlines
|
||||||
[(id :unique :primary-key)
|
[(id :unique :primary-key)
|
||||||
(file :not-null)
|
(file :not-null)])
|
||||||
(level :not-null)])
|
|
||||||
|
|
||||||
(links
|
(links
|
||||||
[(source :not-null)
|
[(from :not-null)
|
||||||
(dest :not-null)
|
(to :not-null)
|
||||||
(type :not-null)
|
(type :not-null)
|
||||||
(properties :not-null)])
|
(properties :not-null)])
|
||||||
|
|
||||||
@ -218,27 +193,11 @@ 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)))
|
||||||
|
|
||||||
;;;; Timer-based updating
|
|
||||||
(defvar org-roam-db-file-update-timer nil
|
|
||||||
"Timer for updating the database when dirty.")
|
|
||||||
|
|
||||||
(defun org-roam-db-mark-dirty ()
|
|
||||||
"Mark the Org-roam database as dirty."
|
|
||||||
(add-to-list 'org-roam-db-dirty (list org-roam-directory org-roam-db-location)
|
|
||||||
nil #'equal))
|
|
||||||
|
|
||||||
(defun org-roam-db-update-cache-on-timer ()
|
|
||||||
"Update the cache if the database is dirty.
|
|
||||||
This function is called on `org-roam-db-file-update-timer'."
|
|
||||||
(pcase-dolist (`(,org-roam-directory ,org-roam-db-location) org-roam-db-dirty)
|
|
||||||
(org-roam-db-build-cache))
|
|
||||||
(setq org-roam-db-dirty nil))
|
|
||||||
|
|
||||||
;;;; Database API
|
;;;; Database API
|
||||||
;;;;; Initialization
|
;;;;; Initialization
|
||||||
(defun org-roam-db--initialized-p ()
|
(defun org-roam-db--initialized-p ()
|
||||||
"Whether the Org-roam cache has been initialized."
|
"Whether the Org-roam cache has been initialized."
|
||||||
(and (file-exists-p org-roam-db-location)
|
(and (file-exists-p (org-roam-db--get))
|
||||||
(> (caar (org-roam-db-query [:select (funcall count) :from titles]))
|
(> (caar (org-roam-db-query [:select (funcall count) :from titles]))
|
||||||
0)))
|
0)))
|
||||||
|
|
||||||
@ -251,68 +210,75 @@ This function is called on `org-roam-db-file-update-timer'."
|
|||||||
(defun org-roam-db-clear ()
|
(defun org-roam-db-clear ()
|
||||||
"Clears all entries in the Org-roam cache."
|
"Clears all entries in the Org-roam cache."
|
||||||
(interactive)
|
(interactive)
|
||||||
(when (file-exists-p org-roam-db-location)
|
(when (file-exists-p (org-roam-db--get))
|
||||||
(dolist (table (mapcar #'car org-roam-db--table-schemata))
|
(dolist (table (mapcar #'car org-roam-db--table-schemata))
|
||||||
(org-roam-db-query `[:delete :from ,table]))))
|
(org-roam-db-query `[:delete :from ,table]))))
|
||||||
|
|
||||||
(defun org-roam-db--clear-file (&optional filepath)
|
(defun org-roam-db--clear-file (&optional filepath)
|
||||||
"Remove any related links to the file at FILEPATH.
|
"Remove any related links to the file at FILEPATH.
|
||||||
This is equivalent to removing the node from the graph."
|
This is equivalent to removing the node from the graph."
|
||||||
(let ((file (expand-file-name (or filepath
|
(let ((file (file-truename (or filepath
|
||||||
(buffer-file-name (buffer-base-buffer))))))
|
(buffer-file-name (buffer-base-buffer))))))
|
||||||
(dolist (table (mapcar #'car org-roam-db--table-schemata))
|
(dolist (table (mapcar #'car org-roam-db--table-schemata))
|
||||||
(org-roam-db-query `[:delete :from ,table
|
(org-roam-db-query `[:delete :from ,table
|
||||||
:where (= ,(if (eq table 'links) 'source 'file) $s1)]
|
:where (= ,(if (eq table 'links) 'from 'file) $s1)]
|
||||||
file))))
|
file))))
|
||||||
|
|
||||||
;;;;; Inserting
|
;;;;; Insertion
|
||||||
(defun org-roam-db--insert-meta (&optional update-p)
|
(defun org-roam-db--insert-meta (file hash meta)
|
||||||
"Update the metadata of the current buffer into the cache.
|
"Insert HASH and META for a FILE into the Org-roam cache."
|
||||||
If UPDATE-P is non-nil, first remove the meta for the file in the database."
|
|
||||||
(let* ((file (or org-roam-file-name (buffer-file-name)))
|
|
||||||
(attr (file-attributes file))
|
|
||||||
(atime (file-attribute-access-time attr))
|
|
||||||
(mtime (file-attribute-modification-time attr))
|
|
||||||
(hash (org-roam-db--file-hash)))
|
|
||||||
(when update-p
|
|
||||||
(org-roam-db-query [:delete :from files
|
|
||||||
:where (= file $s1)]
|
|
||||||
file))
|
|
||||||
(org-roam-db-query
|
(org-roam-db-query
|
||||||
[:insert :into files
|
[:insert :into files
|
||||||
:values $v1]
|
:values $v1]
|
||||||
(list (vector file hash (list :atime atime :mtime mtime))))))
|
(list (vector file hash meta))))
|
||||||
|
|
||||||
(defun org-roam-db--insert-titles (&optional update-p)
|
(defun org-roam-db--insert-links (links)
|
||||||
"Update the titles of the current buffer into the cache.
|
"Insert LINKS into the Org-roam cache."
|
||||||
If UPDATE-P is non-nil, first remove titles for the file in the database.
|
(org-roam-db-query
|
||||||
Returns the number of rows inserted."
|
[:insert :into links
|
||||||
(let* ((file (or org-roam-file-name (buffer-file-name)))
|
:values $v1]
|
||||||
(titles (or (org-roam--extract-titles)
|
links))
|
||||||
(list (org-roam--path-to-slug file))))
|
|
||||||
(rows (mapcar (lambda (title)
|
(defun org-roam-db--insert-titles (file titles)
|
||||||
(vector file title)) titles)))
|
"Insert TITLES for a FILE into the Org-roam cache."
|
||||||
(when update-p
|
|
||||||
(org-roam-db-query [:delete :from titles
|
|
||||||
:where (= file $s1)]
|
|
||||||
file))
|
|
||||||
(org-roam-db-query
|
(org-roam-db-query
|
||||||
[:insert :into titles
|
[:insert :into titles
|
||||||
:values $v1]
|
:values $v1]
|
||||||
rows)
|
(mapcar (lambda (title)
|
||||||
(length rows)))
|
(vector file title)) titles)))
|
||||||
|
|
||||||
(defun org-roam-db--insert-refs (&optional update-p)
|
(defun org-roam-db--insert-headlines (headlines)
|
||||||
"Update the refs of the current buffer into the cache.
|
"Insert HEADLINES into the Org-roam cache.
|
||||||
If UPDATE-P is non-nil, first remove the ref for the file in the database."
|
Returns t if the insertion was successful, nil otherwise.
|
||||||
(let ((file (or org-roam-file-name (buffer-file-name)))
|
Insertions can fail when there is an ID conflict."
|
||||||
(count 0))
|
(condition-case nil
|
||||||
(when update-p
|
(progn
|
||||||
(org-roam-db-query [:delete :from refs
|
(org-roam-db-query
|
||||||
:where (= file $s1)]
|
[:insert :into headlines
|
||||||
file))
|
:values $v1]
|
||||||
(when-let ((refs (org-roam--extract-refs)))
|
headlines)
|
||||||
(dolist (ref refs)
|
t)
|
||||||
|
(error
|
||||||
|
(unless (listp headlines)
|
||||||
|
(setq headlines (list headlines)))
|
||||||
|
(lwarn '(org-roam) :error
|
||||||
|
(format "Duplicate IDs in %s, one of:\n\n%s\n\nskipping..."
|
||||||
|
(aref (car headlines) 1)
|
||||||
|
(string-join (mapcar (lambda (hl)
|
||||||
|
(aref hl 0)) headlines) "\n")))
|
||||||
|
nil)))
|
||||||
|
|
||||||
|
(defun org-roam-db--insert-tags (file tags)
|
||||||
|
"Insert TAGS for a FILE into the Org-roam cache."
|
||||||
|
(org-roam-db-query
|
||||||
|
[:insert :into tags
|
||||||
|
:values $v1]
|
||||||
|
(list (vector file tags))))
|
||||||
|
|
||||||
|
(defun org-roam-db--insert-ref (file ref)
|
||||||
|
"Insert REF for FILE into the Org-roam cache.
|
||||||
|
Returns t if successful, and nil otherwise.
|
||||||
|
Insertions can fail if the key is already in the database."
|
||||||
(let ((key (cdr ref))
|
(let ((key (cdr ref))
|
||||||
(type (car ref)))
|
(type (car ref)))
|
||||||
(condition-case nil
|
(condition-case nil
|
||||||
@ -320,7 +286,7 @@ If UPDATE-P is non-nil, first remove the ref for the file in the database."
|
|||||||
(org-roam-db-query
|
(org-roam-db-query
|
||||||
[:insert :into refs :values $v1]
|
[:insert :into refs :values $v1]
|
||||||
(list (vector key file type)))
|
(list (vector key file type)))
|
||||||
(cl-incf count))
|
t)
|
||||||
(error
|
(error
|
||||||
(lwarn '(org-roam) :error
|
(lwarn '(org-roam) :error
|
||||||
(format "Duplicate ref %s in:\n\nA: %s\nB: %s\n\nskipping..."
|
(format "Duplicate ref %s in:\n\nA: %s\nB: %s\n\nskipping..."
|
||||||
@ -329,70 +295,8 @@ If UPDATE-P is non-nil, first remove the ref for the file in the database."
|
|||||||
(caar (org-roam-db-query
|
(caar (org-roam-db-query
|
||||||
[:select file :from refs
|
[:select file :from refs
|
||||||
:where (= ref $v1)]
|
:where (= ref $v1)]
|
||||||
(vector key))))))))))
|
(vector key)))))
|
||||||
count))
|
nil))))
|
||||||
|
|
||||||
(defun org-roam-db--insert-links (&optional update-p)
|
|
||||||
"Update the file links of the current buffer in the cache.
|
|
||||||
If UPDATE-P is non-nil, first remove the links for the file in the database.
|
|
||||||
Return the number of rows inserted."
|
|
||||||
(let ((file (or org-roam-file-name (buffer-file-name))))
|
|
||||||
(when update-p
|
|
||||||
(org-roam-db-query [:delete :from links
|
|
||||||
:where (= source $s1)]
|
|
||||||
file))
|
|
||||||
(if-let ((links (org-roam--extract-links)))
|
|
||||||
(progn
|
|
||||||
(org-roam-db-query
|
|
||||||
[:insert :into links
|
|
||||||
:values $v1]
|
|
||||||
links)
|
|
||||||
(length links))
|
|
||||||
0)))
|
|
||||||
|
|
||||||
(defun org-roam-db--insert-ids (&optional update-p)
|
|
||||||
"Update the ids of the current buffer into the cache.
|
|
||||||
If UPDATE-P is non-nil, first remove ids for the file in the database.
|
|
||||||
Returns the number of rows inserted."
|
|
||||||
(let ((file (or org-roam-file-name (buffer-file-name))))
|
|
||||||
(when update-p
|
|
||||||
(org-roam-db-query [:delete :from ids
|
|
||||||
:where (= file $s1)]
|
|
||||||
file))
|
|
||||||
(if-let ((ids (org-roam--extract-ids file)))
|
|
||||||
(condition-case nil
|
|
||||||
(progn
|
|
||||||
(org-roam-db-query
|
|
||||||
[:insert :into ids
|
|
||||||
:values $v1]
|
|
||||||
ids)
|
|
||||||
(length ids))
|
|
||||||
(error
|
|
||||||
(lwarn '(org-roam) :error
|
|
||||||
(format "Duplicate IDs in %s, one of:\n\n%s\n\nskipping..."
|
|
||||||
(aref (car ids) 1)
|
|
||||||
(string-join (mapcar (lambda (hl)
|
|
||||||
(aref hl 0)) ids) "\n")))
|
|
||||||
0))
|
|
||||||
0)))
|
|
||||||
|
|
||||||
(defun org-roam-db--insert-tags (&optional update-p)
|
|
||||||
"Insert tags for the current buffer into the Org-roam cache.
|
|
||||||
If UPDATE-P is non-nil, first remove tags for the file in the database.
|
|
||||||
Return the number of rows inserted."
|
|
||||||
(let* ((file (or org-roam-file-name (buffer-file-name)))
|
|
||||||
(tags (org-roam--extract-tags file)))
|
|
||||||
(when update-p
|
|
||||||
(org-roam-db-query [:delete :from tags
|
|
||||||
:where (= file $s1)]
|
|
||||||
file))
|
|
||||||
(if tags
|
|
||||||
(progn (org-roam-db-query
|
|
||||||
[:insert :into tags
|
|
||||||
:values $v1]
|
|
||||||
(list (vector file tags)))
|
|
||||||
1)
|
|
||||||
0)))
|
|
||||||
|
|
||||||
;;;;; Fetching
|
;;;;; Fetching
|
||||||
(defun org-roam-db--get-current-files ()
|
(defun org-roam-db--get-current-files ()
|
||||||
@ -410,29 +314,19 @@ Return the number of rows inserted."
|
|||||||
:limit 1]
|
:limit 1]
|
||||||
file)))
|
file)))
|
||||||
|
|
||||||
(defun org-roam-db--get-tags ()
|
|
||||||
"Return all distinct tags from the cache."
|
|
||||||
(let ((rows (org-roam-db-query [:select :distinct [tags] :from tags]))
|
|
||||||
acc)
|
|
||||||
(dolist (row rows)
|
|
||||||
(dolist (tag (car row))
|
|
||||||
(unless (member tag acc)
|
|
||||||
(push tag acc))))
|
|
||||||
acc))
|
|
||||||
|
|
||||||
(defun org-roam-db--connected-component (file)
|
(defun org-roam-db--connected-component (file)
|
||||||
"Return all files reachable from/connected to FILE, including the file itself.
|
"Return all files reachable from/connected to FILE, including the file itself.
|
||||||
If the file does not have any connections, nil is returned."
|
If the file does not have any connections, nil is returned."
|
||||||
(let* ((query "WITH RECURSIVE
|
(let* ((query "WITH RECURSIVE
|
||||||
links_of(file, link) AS
|
links_of(file, link) AS
|
||||||
(WITH filelinks AS (SELECT * FROM links WHERE NOT \"type\" = '\"cite\"'),
|
(WITH filelinks AS (SELECT * FROM links WHERE \"type\" = '\"file\"'),
|
||||||
citelinks AS (SELECT * FROM links
|
citelinks AS (SELECT * FROM links
|
||||||
JOIN refs ON links.\"dest\" = refs.\"ref\"
|
JOIN refs ON links.\"to\" = refs.\"ref\"
|
||||||
AND links.\"type\" = '\"cite\"')
|
AND links.\"type\" = '\"cite\"')
|
||||||
SELECT \"source\", \"dest\" FROM filelinks UNION
|
SELECT \"from\", \"to\" FROM filelinks UNION
|
||||||
SELECT \"dest\", \"source\" FROM filelinks UNION
|
SELECT \"to\", \"from\" FROM filelinks UNION
|
||||||
SELECT \"file\", \"source\" FROM citelinks UNION
|
SELECT \"file\", \"from\" FROM citelinks UNION
|
||||||
SELECT \"dest\", \"file\" FROM citelinks),
|
SELECT \"from\", \"file\" FROM citelinks),
|
||||||
connected_component(file) AS
|
connected_component(file) AS
|
||||||
(SELECT link FROM links_of WHERE file = $s1
|
(SELECT link FROM links_of WHERE file = $s1
|
||||||
UNION
|
UNION
|
||||||
@ -447,14 +341,14 @@ This includes the file itself. If the file does not have any
|
|||||||
connections, nil is returned."
|
connections, nil is returned."
|
||||||
(let* ((query "WITH RECURSIVE
|
(let* ((query "WITH RECURSIVE
|
||||||
links_of(file, link) AS
|
links_of(file, link) AS
|
||||||
(WITH filelinks AS (SELECT * FROM links WHERE NOT \"type\" = '\"cite\"'),
|
(WITH filelinks AS (SELECT * FROM links WHERE \"type\" = '\"file\"'),
|
||||||
citelinks AS (SELECT * FROM links
|
citelinks AS (SELECT * FROM links
|
||||||
JOIN refs ON links.\"dest\" = refs.\"ref\"
|
JOIN refs ON links.\"to\" = refs.\"ref\"
|
||||||
AND links.\"type\" = '\"cite\"')
|
AND links.\"type\" = '\"cite\"')
|
||||||
SELECT \"source\", \"dest\" FROM filelinks UNION
|
SELECT \"from\", \"to\" FROM filelinks UNION
|
||||||
SELECT \"dest\", \"source\" FROM filelinks UNION
|
SELECT \"to\", \"from\" FROM filelinks UNION
|
||||||
SELECT \"file\", \"source\" FROM citelinks UNION
|
SELECT \"file\", \"from\" FROM citelinks UNION
|
||||||
SELECT \"source\", \"file\" FROM citelinks),
|
SELECT \"from\", \"file\" FROM citelinks),
|
||||||
-- Links are traversed in a breadth-first search. In order to calculate the
|
-- Links are traversed in a breadth-first search. In order to calculate the
|
||||||
-- distance of nodes and to avoid following cyclic links, the visited nodes
|
-- distance of nodes and to avoid following cyclic links, the visited nodes
|
||||||
-- are tracked in 'trace'.
|
-- are tracked in 'trace'.
|
||||||
@ -476,123 +370,183 @@ connections, nil is returned."
|
|||||||
|
|
||||||
(defun org-roam-db--file-hash (&optional file-path)
|
(defun org-roam-db--file-hash (&optional file-path)
|
||||||
"Compute the hash of FILE-PATH, a file or current buffer."
|
"Compute the hash of FILE-PATH, a file or current buffer."
|
||||||
(if file-path
|
(let* ((file-p (and file-path))
|
||||||
|
(file-path (or file-path
|
||||||
|
(buffer-file-name (current-buffer))))
|
||||||
|
(encrypted-p (and file-path
|
||||||
|
(string= (org-roam--file-name-extension file-path)
|
||||||
|
"gpg"))))
|
||||||
|
(cond ((and encrypted-p file-p)
|
||||||
(with-temp-buffer
|
(with-temp-buffer
|
||||||
(set-buffer-multibyte nil)
|
(set-buffer-multibyte nil)
|
||||||
(insert-file-contents-literally file-path)
|
(insert-file-contents-literally file-path)
|
||||||
(secure-hash 'sha1 (current-buffer)))
|
(secure-hash 'sha1 (current-buffer))))
|
||||||
(org-with-wide-buffer
|
(file-p
|
||||||
(secure-hash 'sha1 (current-buffer)))))
|
(with-temp-buffer
|
||||||
|
(insert-file-contents file-path)
|
||||||
|
(secure-hash 'sha1 (current-buffer))))
|
||||||
|
(t
|
||||||
|
(secure-hash 'sha1 (current-buffer))))))
|
||||||
|
|
||||||
;;;;; Updating
|
;;;;; Updating
|
||||||
|
(defun org-roam-db--update-meta ()
|
||||||
|
"Update the metadata of the current buffer into the cache."
|
||||||
|
(let* ((file (file-truename (buffer-file-name)))
|
||||||
|
(attr (file-attributes file))
|
||||||
|
(atime (file-attribute-access-time attr))
|
||||||
|
(mtime (file-attribute-modification-time attr))
|
||||||
|
(hash (org-roam-db--file-hash)))
|
||||||
|
(org-roam-db-query [:delete :from files
|
||||||
|
:where (= file $s1)]
|
||||||
|
file)
|
||||||
|
(org-roam-db--insert-meta file hash (list :atime atime :mtime mtime))))
|
||||||
|
|
||||||
|
(defun org-roam-db--update-titles ()
|
||||||
|
"Update the title of the current buffer into the cache."
|
||||||
|
(let* ((file (file-truename (buffer-file-name)))
|
||||||
|
(titles (or (org-roam--extract-titles)
|
||||||
|
(list (org-roam--path-to-slug file)))))
|
||||||
|
(org-roam-db-query [:delete :from titles
|
||||||
|
:where (= file $s1)]
|
||||||
|
file)
|
||||||
|
(org-roam-db--insert-titles file titles)))
|
||||||
|
|
||||||
|
(defun org-roam-db--update-tags ()
|
||||||
|
"Update the tags of the current buffer into the cache."
|
||||||
|
(let ((file (file-truename (buffer-file-name)))
|
||||||
|
(tags (org-roam--extract-tags)))
|
||||||
|
(org-roam-db-query [:delete :from tags
|
||||||
|
:where (= file $s1)]
|
||||||
|
file)
|
||||||
|
(when tags
|
||||||
|
(org-roam-db--insert-tags file tags))))
|
||||||
|
|
||||||
|
(defun org-roam-db--update-refs ()
|
||||||
|
"Update the ref of the current buffer into the cache."
|
||||||
|
(let ((file (file-truename (buffer-file-name))))
|
||||||
|
(org-roam-db-query [:delete :from refs
|
||||||
|
:where (= file $s1)]
|
||||||
|
file)
|
||||||
|
(when-let ((ref (org-roam--extract-ref)))
|
||||||
|
(org-roam-db--insert-ref file ref))))
|
||||||
|
|
||||||
|
(defun org-roam-db--update-links ()
|
||||||
|
"Update the file links of the current buffer in the cache."
|
||||||
|
(let ((file (file-truename (buffer-file-name))))
|
||||||
|
(org-roam-db-query [:delete :from links
|
||||||
|
:where (= from $s1)]
|
||||||
|
file)
|
||||||
|
(when-let ((links (org-roam--extract-links)))
|
||||||
|
(org-roam-db--insert-links links))))
|
||||||
|
|
||||||
|
(defun org-roam-db--update-headlines ()
|
||||||
|
"Update the file headlines of the current buffer into the cache."
|
||||||
|
(let* ((file (file-truename (buffer-file-name))))
|
||||||
|
(org-roam-db-query [:delete :from headlines
|
||||||
|
:where (= file $s1)]
|
||||||
|
file)
|
||||||
|
(when-let ((headlines (org-roam--extract-headlines)))
|
||||||
|
(org-roam-db--insert-headlines headlines))))
|
||||||
|
|
||||||
(defun org-roam-db--update-file (&optional file-path)
|
(defun org-roam-db--update-file (&optional file-path)
|
||||||
"Update Org-roam cache for FILE-PATH.
|
"Update Org-roam cache for FILE-PATH."
|
||||||
If the file does not exist anymore, remove it from the cache.
|
(when (org-roam--org-roam-file-p file-path)
|
||||||
If the file exists, update the cache with information."
|
(let ((buf (or (and file-path
|
||||||
(setq file-path (or file-path
|
(find-file-noselect file-path t))
|
||||||
(buffer-file-name (buffer-base-buffer))))
|
(current-buffer))))
|
||||||
(if (not (file-exists-p file-path))
|
|
||||||
(org-roam-db--clear-file file-path)
|
|
||||||
;; save the file before performing a database update
|
|
||||||
(when-let ((buf (find-buffer-visiting file-path)))
|
|
||||||
(with-current-buffer buf
|
(with-current-buffer buf
|
||||||
(save-buffer)))
|
(save-excursion
|
||||||
(org-roam--with-temp-buffer file-path
|
|
||||||
(emacsql-with-transaction (org-roam-db)
|
(emacsql-with-transaction (org-roam-db)
|
||||||
(org-roam-db--insert-meta 'update)
|
(org-roam-db--update-meta)
|
||||||
(org-roam-db--insert-tags 'update)
|
(org-roam-db--update-tags)
|
||||||
(org-roam-db--insert-titles 'update)
|
(org-roam-db--update-titles)
|
||||||
(org-roam-db--insert-refs 'update)
|
(org-roam-db--update-refs)
|
||||||
(when org-roam-enable-headline-linking
|
(org-roam-db--update-headlines)
|
||||||
(org-roam-db--insert-ids 'update))
|
(org-roam-db--update-links))
|
||||||
(org-roam-db--insert-links 'update)))))
|
(org-roam-buffer--update-maybe :redisplay t))))))
|
||||||
|
|
||||||
(defun org-roam-db-build-cache (&optional force)
|
(defun org-roam-db-build-cache (&optional force)
|
||||||
"Build the cache for `org-roam-directory'.
|
"Build the cache for `org-roam-directory'.
|
||||||
If FORCE, force a rebuild of the cache from scratch."
|
If FORCE, force a rebuild of the cache from scratch."
|
||||||
(interactive "P")
|
(interactive "P")
|
||||||
(when force (delete-file org-roam-db-location))
|
(when force (delete-file (org-roam-db--get)))
|
||||||
(org-roam-db--close) ;; Force a reconnect
|
(org-roam-db--close) ;; Force a reconnect
|
||||||
(org-roam-db) ;; To initialize the database, no-op if already initialized
|
(org-roam-db) ;; To initialize the database, no-op if already initialized
|
||||||
(let* ((gc-cons-threshold org-roam-db-gc-threshold)
|
(let* ((gc-cons-threshold org-roam-db-gc-threshold)
|
||||||
(org-agenda-files nil)
|
|
||||||
(org-roam-files (org-roam--list-all-files))
|
(org-roam-files (org-roam--list-all-files))
|
||||||
(current-files (org-roam-db--get-current-files))
|
(current-files (org-roam-db--get-current-files))
|
||||||
(id-count 0)
|
(file-count 0)
|
||||||
|
(headline-count 0)
|
||||||
(link-count 0)
|
(link-count 0)
|
||||||
(tag-count 0)
|
(tag-count 0)
|
||||||
(title-count 0)
|
(title-count 0)
|
||||||
(ref-count 0)
|
(ref-count 0)
|
||||||
(deleted-count 0)
|
(deleted-count 0))
|
||||||
(modified-count 0)
|
(emacsql-with-transaction (org-roam-db)
|
||||||
(modified-files nil))
|
;; Two-step building
|
||||||
|
;; First step: Rebuild files and headlines
|
||||||
(dolist (file org-roam-files)
|
(dolist (file org-roam-files)
|
||||||
(let ((contents-hash (org-roam-db--file-hash file)))
|
|
||||||
(unless (string= (gethash file current-files)
|
|
||||||
contents-hash)
|
|
||||||
(push (cons file contents-hash) modified-files)))
|
|
||||||
(remhash file current-files))
|
|
||||||
(dolist (file (hash-table-keys current-files))
|
|
||||||
;; These files are no longer around, remove from cache...
|
|
||||||
(org-roam-db--clear-file file)
|
|
||||||
(setq deleted-count (1+ deleted-count)))
|
|
||||||
(pcase-dolist (`(,file . _) modified-files)
|
|
||||||
(org-roam-db--clear-file file))
|
|
||||||
;; Process all the files for IDs first
|
|
||||||
;;
|
|
||||||
;; We do this so that link extraction is cheaper: this eliminates the need
|
|
||||||
;; to read the file to check if the ID really exists
|
|
||||||
(pcase-dolist (`(,file . ,contents-hash) modified-files)
|
|
||||||
(let* ((attr (file-attributes file))
|
(let* ((attr (file-attributes file))
|
||||||
(atime (file-attribute-access-time attr))
|
(atime (file-attribute-access-time attr))
|
||||||
(mtime (file-attribute-modification-time attr)))
|
(mtime (file-attribute-modification-time attr)))
|
||||||
|
(let ((contents-hash (org-roam-db--file-hash file)))
|
||||||
|
(unless (string= (gethash file current-files)
|
||||||
|
contents-hash)
|
||||||
(condition-case nil
|
(condition-case nil
|
||||||
(org-roam--with-temp-buffer file
|
(org-roam--with-temp-buffer file
|
||||||
|
(org-roam-db--clear-file file)
|
||||||
(org-roam-db-query
|
(org-roam-db-query
|
||||||
[:insert :into files
|
[:insert :into files
|
||||||
:values $v1]
|
:values $v1]
|
||||||
(vector file contents-hash (list :atime atime :mtime mtime)))
|
(vector file contents-hash (list :atime atime :mtime mtime)))
|
||||||
(when org-roam-enable-headline-linking
|
(setq file-count (1+ file-count))
|
||||||
(setq id-count (+ id-count (org-roam-db--insert-ids)))))
|
(when-let ((headlines (org-roam--extract-headlines file)))
|
||||||
|
(when (org-roam-db--insert-headlines headlines)
|
||||||
|
(setq headline-count (1+ headline-count)))))
|
||||||
(file-error
|
(file-error
|
||||||
(setq org-roam-files (remove file org-roam-files))
|
(setq org-roam-files (remove file org-roam-files))
|
||||||
(org-roam-db--clear-file file)
|
(org-roam-db--clear-file file)
|
||||||
(lwarn '(org-roam) :warning
|
(lwarn '(org-roam) :warning
|
||||||
"Skipping unreadable file while building cache: %s" file)))))
|
"Skipping unreadable file while building cache: %s" file)))))))
|
||||||
(pcase-dolist (`(,file . _) modified-files)
|
;; Second step: Rebuild the rest
|
||||||
(org-roam-message "Processed %s/%s modified files..." modified-count (length modified-files))
|
(dolist (file org-roam-files)
|
||||||
(condition-case nil
|
(let ((contents-hash (org-roam-db--file-hash file)))
|
||||||
|
(unless (string= (gethash file current-files)
|
||||||
|
contents-hash)
|
||||||
(org-roam--with-temp-buffer file
|
(org-roam--with-temp-buffer file
|
||||||
(setq modified-count (1+ modified-count))
|
(when-let (links (org-roam--extract-links file))
|
||||||
(setq link-count (+ link-count (org-roam-db--insert-links)))
|
(org-roam-db-query
|
||||||
(setq tag-count (+ tag-count (org-roam-db--insert-tags)))
|
[:insert :into links
|
||||||
(setq title-count (+ title-count (org-roam-db--insert-titles)))
|
:values $v1]
|
||||||
(setq ref-count (+ ref-count (org-roam-db--insert-refs))))
|
links)
|
||||||
(file-error
|
(setq link-count (1+ link-count)))
|
||||||
(setq org-roam-files (remove file org-roam-files))
|
(when-let (tags (org-roam--extract-tags file))
|
||||||
|
(org-roam-db-query
|
||||||
|
[:insert :into tags
|
||||||
|
:values $v1]
|
||||||
|
(vector file tags))
|
||||||
|
(setq tag-count (1+ tag-count)))
|
||||||
|
(let ((titles (or (org-roam--extract-titles)
|
||||||
|
(list (org-roam--path-to-slug file)))))
|
||||||
|
(org-roam-db--insert-titles file titles)
|
||||||
|
(setq title-count (+ title-count (length titles))))
|
||||||
|
(when-let* ((ref (org-roam--extract-ref)))
|
||||||
|
(when (org-roam-db--insert-ref file ref)
|
||||||
|
(setq ref-count (1+ ref-count))))))
|
||||||
|
(remhash file current-files)))
|
||||||
|
(dolist (file (hash-table-keys current-files))
|
||||||
|
;; These files are no longer around, remove from cache...
|
||||||
(org-roam-db--clear-file file)
|
(org-roam-db--clear-file file)
|
||||||
(lwarn '(org-roam) :warning
|
(setq deleted-count (1+ deleted-count))))
|
||||||
"Skipping unreadable file while building cache: %s" file))))
|
(org-roam-message "files: Δ%s, headlines: Δ%s, links: Δ%s, tags: Δ%s, titles: Δ%s, refs: Δ%s, deleted: Δ%s"
|
||||||
(org-roam-message "total: Δ%s, files-modified: Δ%s, ids: Δ%s, links: Δ%s, tags: Δ%s, titles: Δ%s, refs: Δ%s, deleted: Δ%s"
|
file-count
|
||||||
(length org-roam-files)
|
headline-count
|
||||||
modified-count
|
|
||||||
id-count
|
|
||||||
link-count
|
link-count
|
||||||
tag-count
|
tag-count
|
||||||
title-count
|
title-count
|
||||||
ref-count
|
ref-count
|
||||||
deleted-count)))
|
deleted-count)))
|
||||||
|
|
||||||
(defun org-roam-db-update ()
|
|
||||||
"Update the database."
|
|
||||||
(pcase org-roam-db-update-method
|
|
||||||
('immediate
|
|
||||||
(org-roam-db-build-cache))
|
|
||||||
('idle-timer
|
|
||||||
(org-roam-db-mark-dirty))
|
|
||||||
(_
|
|
||||||
(user-error "Invalid `org-roam-db-update-method'"))))
|
|
||||||
|
|
||||||
(provide 'org-roam-db)
|
(provide 'org-roam-db)
|
||||||
|
|
||||||
;;; org-roam-db.el ends here
|
;;; org-roam-db.el ends here
|
||||||
|
@ -5,8 +5,8 @@
|
|||||||
;; Author: Jethro Kuan <jethrokuan95@gmail.com>
|
;; Author: Jethro Kuan <jethrokuan95@gmail.com>
|
||||||
;; URL: https://github.com/org-roam/org-roam
|
;; URL: https://github.com/org-roam/org-roam
|
||||||
;; Keywords: org-mode, roam, convenience
|
;; Keywords: org-mode, roam, convenience
|
||||||
;; Version: 1.2.3
|
;; Version: 1.2.1
|
||||||
;; Package-Requires: ((emacs "26.1") (dash "2.13") (f "0.17.2") (s "1.12.0") (org "9.3") (emacsql "3.0.0") (emacsql-sqlite3 "1.0.2"))
|
;; Package-Requires: ((emacs "26.1") (dash "2.13") (f "0.17.2") (s "1.12.0") (org "9.3") (emacsql "3.0.0") (emacsql-sqlite3 "1.0.0"))
|
||||||
|
|
||||||
;; This file is NOT part of GNU Emacs.
|
;; This file is NOT part of GNU Emacs.
|
||||||
|
|
||||||
|
@ -5,8 +5,8 @@
|
|||||||
;; Author: Jethro Kuan <jethrokuan95@gmail.com>
|
;; Author: Jethro Kuan <jethrokuan95@gmail.com>
|
||||||
;; URL: https://github.com/jethrokuan/org-roam
|
;; URL: https://github.com/jethrokuan/org-roam
|
||||||
;; Keywords: org-mode, roam, convenience
|
;; Keywords: org-mode, roam, convenience
|
||||||
;; Version: 1.2.3
|
;; Version: 1.2.1
|
||||||
;; Package-Requires: ((emacs "26.1") (dash "2.13") (f "0.17.2") (s "1.12.0") (org "9.3") (emacsql "3.0.0") (emacsql-sqlite3 "1.0.2"))
|
;; Package-Requires: ((emacs "26.1") (dash "2.13") (f "0.17.2") (s "1.12.0") (org "9.3") (emacsql "3.0.0") (emacsql-sqlite3 "1.0.0"))
|
||||||
|
|
||||||
;; This file is NOT part of GNU Emacs.
|
;; This file is NOT part of GNU Emacs.
|
||||||
|
|
||||||
@ -59,15 +59,6 @@
|
|||||||
(defvar org-roam-verbose)
|
(defvar org-roam-verbose)
|
||||||
(defvar org-roam-mode)
|
(defvar org-roam-mode)
|
||||||
|
|
||||||
(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))
|
(cl-defstruct (org-roam-doctor-checker (:copier nil))
|
||||||
(name 'missing-checker-name)
|
(name 'missing-checker-name)
|
||||||
(description "")
|
(description "")
|
||||||
@ -303,8 +294,7 @@ If CHECKALL, run the check for all Org-roam files."
|
|||||||
(defun org-roam-doctor-start (files checkers)
|
(defun org-roam-doctor-start (files checkers)
|
||||||
"Lint FILES using CHECKERS."
|
"Lint FILES using CHECKERS."
|
||||||
(save-window-excursion
|
(save-window-excursion
|
||||||
(let ((existing-buffers (org-roam--get-roam-buffers))
|
(let ((existing-buffers (org-roam--get-roam-buffers)))
|
||||||
(org-inhibit-startup org-roam-doctor-inhibit-startup))
|
|
||||||
(dolist (f files)
|
(dolist (f files)
|
||||||
(let ((buf (find-file-noselect f)))
|
(let ((buf (find-file-noselect f)))
|
||||||
(org-roam-doctor--check buf checkers)
|
(org-roam-doctor--check buf checkers)
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
;; Author: Jethro Kuan <jethrokuan95@gmail.com>
|
;; Author: Jethro Kuan <jethrokuan95@gmail.com>
|
||||||
;; URL: https://github.com/org-roam/org-roam
|
;; URL: https://github.com/org-roam/org-roam
|
||||||
;; Keywords: org-mode, roam, convenience
|
;; Keywords: org-mode, roam, convenience
|
||||||
;; Version: 1.2.3
|
;; Version: 1.2.1
|
||||||
;; Package-Requires: ((emacs "26.1"))
|
;; Package-Requires: ((emacs "26.1"))
|
||||||
|
|
||||||
;; This file is NOT part of GNU Emacs.
|
;; This file is NOT part of GNU Emacs.
|
||||||
@ -42,11 +42,6 @@
|
|||||||
"Face for Org-roam links."
|
"Face for Org-roam links."
|
||||||
:group 'org-roam-faces)
|
:group 'org-roam-faces)
|
||||||
|
|
||||||
(defface org-roam-tag
|
|
||||||
'((t :weight bold))
|
|
||||||
"Face for Org-roam tags in minibuffer commands."
|
|
||||||
:group 'org-roam-faces)
|
|
||||||
|
|
||||||
(defface org-roam-link-current
|
(defface org-roam-link-current
|
||||||
'((t :inherit org-link))
|
'((t :inherit org-link))
|
||||||
"Face for Org-roam links pointing to the current buffer."
|
"Face for Org-roam links pointing to the current buffer."
|
||||||
@ -65,11 +60,6 @@ This face is used on the region target by `org-roam-insertion'
|
|||||||
during an `org-roam-capture'."
|
during an `org-roam-capture'."
|
||||||
:group 'org-roam-faces)
|
:group 'org-roam-faces)
|
||||||
|
|
||||||
(defface org-roam-dailies-calendar-note
|
|
||||||
'((t :inherit (org-roam-link) :underline nil))
|
|
||||||
"Face for dates with a daily-note in the calendar"
|
|
||||||
:group 'org-roam-faces)
|
|
||||||
|
|
||||||
;;; _
|
;;; _
|
||||||
|
|
||||||
(provide 'org-roam-faces)
|
(provide 'org-roam-faces)
|
||||||
|
0
org-roam-flow.el
Normal file
0
org-roam-flow.el
Normal file
@ -5,8 +5,8 @@
|
|||||||
;; Author: Jethro Kuan <jethrokuan95@gmail.com>
|
;; Author: Jethro Kuan <jethrokuan95@gmail.com>
|
||||||
;; URL: https://github.com/org-roam/org-roam
|
;; URL: https://github.com/org-roam/org-roam
|
||||||
;; Keywords: org-mode, roam, convenience
|
;; Keywords: org-mode, roam, convenience
|
||||||
;; Version: 1.2.3
|
;; Version: 1.2.1
|
||||||
;; Package-Requires: ((emacs "26.1") (dash "2.13") (f "0.17.2") (s "1.12.0") (org "9.3") (emacsql "3.0.0") (emacsql-sqlite3 "1.0.2"))
|
;; Package-Requires: ((emacs "26.1") (dash "2.13") (f "0.17.2") (s "1.12.0") (org "9.3") (emacsql "3.0.0") (emacsql-sqlite3 "1.0.0"))
|
||||||
|
|
||||||
;; This file is NOT part of GNU Emacs.
|
;; This file is NOT part of GNU Emacs.
|
||||||
|
|
||||||
@ -32,8 +32,7 @@
|
|||||||
;;; Code:
|
;;; Code:
|
||||||
(require 'xml) ;xml-escape-string
|
(require 'xml) ;xml-escape-string
|
||||||
(require 's) ;s-truncate, s-replace
|
(require 's) ;s-truncate, s-replace
|
||||||
(eval-and-compile
|
(require 'org-roam-macs)
|
||||||
(require 'org-roam-macs))
|
|
||||||
(require 'org-roam-db)
|
(require 'org-roam-db)
|
||||||
|
|
||||||
;;;; Declarations
|
;;;; Declarations
|
||||||
@ -170,15 +169,15 @@ into a digraph."
|
|||||||
(let* ((nodes (org-roam-db-query node-query))
|
(let* ((nodes (org-roam-db-query node-query))
|
||||||
(edges-query
|
(edges-query
|
||||||
`[:with selected :as [:select [file] :from ,node-query]
|
`[:with selected :as [:select [file] :from ,node-query]
|
||||||
:select :distinct [dest source] :from links
|
:select :distinct [to from] :from links
|
||||||
:where (and (in dest selected) (in source selected))])
|
:where (and (in to selected) (in from selected))])
|
||||||
(edges-cites-query
|
(edges-cites-query
|
||||||
`[:with selected :as [:select [file] :from ,node-query]
|
`[:with selected :as [:select [file] :from ,node-query]
|
||||||
:select :distinct [file source]
|
:select :distinct [file from]
|
||||||
:from links :inner :join refs :on (and (= links:dest refs:ref)
|
:from links :inner :join refs :on (and (= links:to refs:ref)
|
||||||
(= links:type "cite")
|
(= links:type "cite")
|
||||||
(= refs:type "cite"))
|
(= refs:type "cite"))
|
||||||
:where (and (in file selected) (in source selected))])
|
:where (and (in file selected) (in from selected))])
|
||||||
(edges (org-roam-db-query edges-query))
|
(edges (org-roam-db-query edges-query))
|
||||||
(edges-cites (org-roam-db-query edges-cites-query)))
|
(edges-cites (org-roam-db-query edges-cites-query)))
|
||||||
(insert "digraph \"org-roam\" {\n")
|
(insert "digraph \"org-roam\" {\n")
|
||||||
@ -266,7 +265,7 @@ CALLBACK is passed the graph file as its sole argument."
|
|||||||
"Build a graph of nodes connected to FILE.
|
"Build a graph of nodes connected to FILE.
|
||||||
If MAX-DISTANCE is non-nil, limit nodes to MAX-DISTANCE steps.
|
If MAX-DISTANCE is non-nil, limit nodes to MAX-DISTANCE steps.
|
||||||
CALLBACK is passed to `org-roam-graph--build'."
|
CALLBACK is passed to `org-roam-graph--build'."
|
||||||
(let* ((file (expand-file-name file))
|
(let* ((file (file-truename file))
|
||||||
(files (or (if (and max-distance (>= max-distance 0))
|
(files (or (if (and max-distance (>= max-distance 0))
|
||||||
(org-roam-db--links-with-max-distance file max-distance)
|
(org-roam-db--links-with-max-distance file max-distance)
|
||||||
(org-roam-db--connected-component file))
|
(org-roam-db--connected-component file))
|
||||||
|
314
org-roam-link.el
314
org-roam-link.el
@ -1,314 +0,0 @@
|
|||||||
;;; org-roam-link.el --- Custom links for Org-roam -*- coding: utf-8; lexical-binding: t; -*-
|
|
||||||
|
|
||||||
;; Copyright © 2020 Jethro Kuan <jethrokuan95@gmail.com>
|
|
||||||
;; Alan Carroll
|
|
||||||
|
|
||||||
;; Author: Jethro Kuan <jethrokuan95@gmail.com>
|
|
||||||
;; URL: https://github.com/org-roam/org-roam
|
|
||||||
;; Keywords: org-mode, roam, convenience
|
|
||||||
;; Version: 1.2.3
|
|
||||||
;; Package-Requires: ((emacs "26.1") (dash "2.13") (f "0.17.2") (s "1.12.0") (org "9.3") (emacsql "3.0.0") (emacsql-sqlite3 "1.0.2"))
|
|
||||||
|
|
||||||
;; 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 adds the custom `roam:' link to Org-roam. `roam:' links allow linking to
|
|
||||||
;; Org-roam files via their titles and headlines.
|
|
||||||
;;
|
|
||||||
;;; Code:
|
|
||||||
;;;; Dependencies
|
|
||||||
|
|
||||||
(require 'ol)
|
|
||||||
(require 'org-roam-compat)
|
|
||||||
(require 'org-roam-macs)
|
|
||||||
(require 'org-roam-db)
|
|
||||||
|
|
||||||
(require 'org-element)
|
|
||||||
|
|
||||||
(defvar org-roam-completion-ignore-case)
|
|
||||||
(defvar org-roam-directory)
|
|
||||||
(declare-function org-roam--find-file "org-roam")
|
|
||||||
(declare-function org-roam-find-file "org-roam")
|
|
||||||
(declare-function org-roam-format-link "org-roam")
|
|
||||||
|
|
||||||
(defcustom org-roam-link-auto-replace t
|
|
||||||
"When non-nil, replace Org-roam's roam links with file or id links whenever possible."
|
|
||||||
:group 'org-roam
|
|
||||||
:type 'boolean)
|
|
||||||
|
|
||||||
(defcustom org-roam-link-file-path-type 'relative
|
|
||||||
"How the path name in file links should be stored.
|
|
||||||
Valid values are:
|
|
||||||
|
|
||||||
relative Relative to the current directory, i.e. the directory of the file
|
|
||||||
into which the link is being inserted.
|
|
||||||
absolute Absolute path, if possible with ~ for home directory.
|
|
||||||
noabbrev Absolute path, no abbreviation of home directory."
|
|
||||||
:group 'org-roam
|
|
||||||
:type '(choice
|
|
||||||
(const relative)
|
|
||||||
(const absolute)
|
|
||||||
(const noabbrev))
|
|
||||||
:safe #'symbolp)
|
|
||||||
|
|
||||||
;;; the roam: link
|
|
||||||
(org-link-set-parameters "roam"
|
|
||||||
:follow #'org-roam-link-follow-link)
|
|
||||||
|
|
||||||
(defun org-roam-link-follow-link (path)
|
|
||||||
"Navigates to location specified by PATH."
|
|
||||||
(pcase-let ((`(,link-type ,loc ,desc ,mkr) (org-roam-link--get-location path)))
|
|
||||||
(when (and org-roam-link-auto-replace loc desc)
|
|
||||||
(org-roam-link--replace-link link-type loc desc))
|
|
||||||
(pcase link-type
|
|
||||||
("file"
|
|
||||||
(if loc
|
|
||||||
(org-roam--find-file loc)
|
|
||||||
(org-roam-find-file desc nil nil t)))
|
|
||||||
("id"
|
|
||||||
(org-goto-marker-or-bmk mkr)))))
|
|
||||||
|
|
||||||
;;; Retrieval Functions
|
|
||||||
(defun org-roam-link--get-titles ()
|
|
||||||
"Return all titles within Org-roam."
|
|
||||||
(mapcar #'car (org-roam-db-query [:select [titles:title] :from titles])))
|
|
||||||
|
|
||||||
(defun org-roam-link--get-headlines (&optional file with-marker use-stack)
|
|
||||||
"Return all outline headings for the current buffer.
|
|
||||||
If FILE, return outline headings for passed FILE instead.
|
|
||||||
If WITH-MARKER, return a cons cell of (headline . marker).
|
|
||||||
If USE-STACK, include the parent paths as well."
|
|
||||||
(let* ((buf (or (and file
|
|
||||||
(or (find-buffer-visiting file)
|
|
||||||
(find-file-noselect file)))
|
|
||||||
(current-buffer)))
|
|
||||||
(outline-level-fn outline-level)
|
|
||||||
(path-separator "/")
|
|
||||||
(stack-level 0)
|
|
||||||
stack cands name level marker)
|
|
||||||
(with-current-buffer buf
|
|
||||||
(save-excursion
|
|
||||||
(goto-char (point-min))
|
|
||||||
(while (re-search-forward org-complex-heading-regexp nil t)
|
|
||||||
(save-excursion
|
|
||||||
(setq name (substring-no-properties (or (match-string 4) "")))
|
|
||||||
(setq marker (point-marker))
|
|
||||||
(when use-stack
|
|
||||||
(goto-char (match-beginning 0))
|
|
||||||
(setq level (funcall outline-level-fn))
|
|
||||||
;; Update stack. The empty entry guards against incorrect
|
|
||||||
;; headline hierarchies, e.g. a level 3 headline
|
|
||||||
;; immediately following a level 1 entry.
|
|
||||||
(while (<= level stack-level)
|
|
||||||
(pop stack)
|
|
||||||
(cl-decf stack-level))
|
|
||||||
(while (> level stack-level)
|
|
||||||
(push name stack)
|
|
||||||
(cl-incf stack-level))
|
|
||||||
(setq name (mapconcat #'identity
|
|
||||||
(reverse stack)
|
|
||||||
path-separator)))
|
|
||||||
(push (if with-marker
|
|
||||||
(cons name marker)
|
|
||||||
name) cands)))))
|
|
||||||
(nreverse cands)))
|
|
||||||
|
|
||||||
(defun org-roam-link--get-file-from-title (title &optional no-interactive)
|
|
||||||
"Return the file path corresponding to TITLE.
|
|
||||||
When NO-INTERACTIVE, return nil if there are multiple options."
|
|
||||||
(let ((files (mapcar #'car (org-roam-db-query [:select [titles:file] :from titles
|
|
||||||
:where (= titles:title $v1)]
|
|
||||||
(vector title)))))
|
|
||||||
(pcase files
|
|
||||||
('nil nil)
|
|
||||||
(`(,file) file)
|
|
||||||
(_
|
|
||||||
(unless no-interactive
|
|
||||||
(completing-read "Select file: " files))))))
|
|
||||||
|
|
||||||
(defun org-roam-link--get-id-from-headline (headline &optional file)
|
|
||||||
"Return (marker . id) correspondng to HEADLINE.
|
|
||||||
If FILE, get headline from FILE instead.
|
|
||||||
If there is no corresponding headline, return nil."
|
|
||||||
(save-excursion
|
|
||||||
(with-current-buffer (or (and file
|
|
||||||
(or (find-buffer-visiting file)
|
|
||||||
(find-file-noselect file)))
|
|
||||||
(current-buffer))
|
|
||||||
(let ((headlines (org-roam-link--get-headlines file 'with-markers)))
|
|
||||||
(when-let ((marker (cdr (assoc-string headline headlines))))
|
|
||||||
(goto-char marker)
|
|
||||||
(cons marker
|
|
||||||
(when org-roam-link-auto-replace
|
|
||||||
(org-id-get-create))))))))
|
|
||||||
|
|
||||||
;;; Path-related functions
|
|
||||||
(defun org-roam-link-get-path (path &optional type)
|
|
||||||
"Return the PATH of the link to use.
|
|
||||||
If TYPE is non-nil, create a link of TYPE. Otherwise, respect
|
|
||||||
`org-link-file-path-type'."
|
|
||||||
(pcase (or type org-roam-link-file-path-type)
|
|
||||||
('absolute
|
|
||||||
(abbreviate-file-name (expand-file-name path)))
|
|
||||||
('noabbrev
|
|
||||||
(expand-file-name path))
|
|
||||||
('relative
|
|
||||||
(file-relative-name path))))
|
|
||||||
|
|
||||||
(defun org-roam-link--split-path (path)
|
|
||||||
"Splits PATH into title and headline.
|
|
||||||
Return a list of the form (type title has-headline-p headline star-idx).
|
|
||||||
type is one of `title', `headline', `title+headline'.
|
|
||||||
title is the title component of the path.
|
|
||||||
headline is the headline component of the path.
|
|
||||||
star-idx is the index of the asterisk, if any."
|
|
||||||
(save-match-data
|
|
||||||
(let* ((star-index (string-match-p "\\*" path))
|
|
||||||
(title (substring-no-properties path 0 star-index))
|
|
||||||
(headline (if star-index
|
|
||||||
(substring-no-properties path (+ 1 star-index))
|
|
||||||
""))
|
|
||||||
(type (cond ((not star-index)
|
|
||||||
'title)
|
|
||||||
((= 0 star-index)
|
|
||||||
'headline)
|
|
||||||
(t 'title+headline))))
|
|
||||||
(list type title headline star-index))))
|
|
||||||
|
|
||||||
(defun org-roam-link--get-location (link)
|
|
||||||
"Return the location of Org-roam fuzzy LINK.
|
|
||||||
The location is returned as a list containing (link-type loc desc marker).
|
|
||||||
nil is returned if there is no matching location.
|
|
||||||
|
|
||||||
link-type is either \"file\" or \"id\".
|
|
||||||
loc is the target location: e.g. a file path, or an id.
|
|
||||||
marker is a marker to the headline, if applicable."
|
|
||||||
(let (mkr link-type desc loc)
|
|
||||||
(pcase-let ((`(,type ,title ,headline _) (org-roam-link--split-path link)))
|
|
||||||
(pcase type
|
|
||||||
('title+headline
|
|
||||||
(let ((file (org-roam-link--get-file-from-title title)))
|
|
||||||
(if (not file)
|
|
||||||
(org-roam-message "Cannot find matching file")
|
|
||||||
(setq mkr (org-roam-link--get-id-from-headline headline file))
|
|
||||||
(pcase mkr
|
|
||||||
(`(,marker . ,target-id)
|
|
||||||
(setq mkr marker
|
|
||||||
loc target-id
|
|
||||||
link-type "id"
|
|
||||||
desc headline))
|
|
||||||
(_ (org-roam-message "cannot find matching id"))))))
|
|
||||||
('title
|
|
||||||
(setq loc (org-roam-link--get-file-from-title title)
|
|
||||||
desc title
|
|
||||||
link-type "file"))
|
|
||||||
('headline
|
|
||||||
(setq mkr (org-roam-link--get-id-from-headline headline))
|
|
||||||
(pcase mkr
|
|
||||||
(`(,marker . ,target-id)
|
|
||||||
(setq mkr marker
|
|
||||||
loc target-id
|
|
||||||
desc headline
|
|
||||||
link-type "id"))
|
|
||||||
(_ (org-roam-message "Cannot find matching headline")))))
|
|
||||||
(list link-type loc desc mkr))))
|
|
||||||
|
|
||||||
;;; Conversion Functions
|
|
||||||
(defun org-roam-link--replace-link (link-type loc &optional desc)
|
|
||||||
"Replace link at point with a vanilla Org link.
|
|
||||||
LINK-TYPE is the Org link type, typically \"file\" or \"id\".
|
|
||||||
LOC is path for the Org link.
|
|
||||||
DESC is the link description."
|
|
||||||
(save-excursion
|
|
||||||
(save-match-data
|
|
||||||
(unless (org-in-regexp org-link-bracket-re 1)
|
|
||||||
(user-error "No link at point"))
|
|
||||||
(replace-match "")
|
|
||||||
(insert (org-roam-format-link loc desc link-type)))))
|
|
||||||
|
|
||||||
(defun org-roam-link-replace-all ()
|
|
||||||
"Replace all roam links in the current buffer."
|
|
||||||
(interactive)
|
|
||||||
(save-excursion
|
|
||||||
(goto-char (point-min))
|
|
||||||
(while (re-search-forward org-link-bracket-re nil t)
|
|
||||||
(let ((context (org-element-context)))
|
|
||||||
(pcase (org-element-lineage context '(link) t)
|
|
||||||
(`nil nil)
|
|
||||||
(link
|
|
||||||
(when (string-equal "roam" (org-element-property :type link))
|
|
||||||
(pcase-let ((`(,link-type ,loc ,desc _) (org-roam-link--get-location (org-element-property :path link))))
|
|
||||||
(when (and link-type loc)
|
|
||||||
(org-roam-link--replace-link link-type loc desc))))))))))
|
|
||||||
|
|
||||||
(defun org-roam-link--replace-link-on-save ()
|
|
||||||
"Hook to replace all roam links on save."
|
|
||||||
(when org-roam-link-auto-replace
|
|
||||||
(org-roam-link-replace-all)))
|
|
||||||
|
|
||||||
;;; Completion
|
|
||||||
(defun org-roam-link-complete-at-point ()
|
|
||||||
"Do appropriate completion for the link at point."
|
|
||||||
(let ((end (point))
|
|
||||||
(start (point))
|
|
||||||
collection link-type headline-only-p)
|
|
||||||
(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:"))))
|
|
||||||
(pcase-let ((`(,type ,title _ ,star-idx)
|
|
||||||
(org-roam-link--split-path (org-element-property :path link))))
|
|
||||||
(pcase type
|
|
||||||
('title+headline
|
|
||||||
(when-let ((file (org-roam-link--get-file-from-title title t)))
|
|
||||||
(setq collection (apply-partially #'org-roam-link--get-headlines file))
|
|
||||||
(setq start (+ start star-idx 1))))
|
|
||||||
('title
|
|
||||||
(setq collection #'org-roam-link--get-titles))
|
|
||||||
('headline
|
|
||||||
(setq collection #'org-roam-link--get-headlines)
|
|
||||||
(setq start (+ start star-idx 1))
|
|
||||||
(setq headline-only-p t)))))))))
|
|
||||||
(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)
|
|
||||||
(if headline-only-p 1 0)))
|
|
||||||
(insert (concat (unless (string= link-type "roam") "roam:")
|
|
||||||
(when headline-only-p "*")
|
|
||||||
str))))))))
|
|
||||||
|
|
||||||
(provide 'org-roam-link)
|
|
||||||
;;; org-roam-link.el ends here
|
|
@ -5,8 +5,8 @@
|
|||||||
;; Author: Jethro Kuan <jethrokuan95@gmail.com>
|
;; Author: Jethro Kuan <jethrokuan95@gmail.com>
|
||||||
;; URL: https://github.com/org-roam/org-roam
|
;; URL: https://github.com/org-roam/org-roam
|
||||||
;; Keywords: org-mode, roam, convenience
|
;; Keywords: org-mode, roam, convenience
|
||||||
;; Version: 1.2.3
|
;; Version: 1.2.1
|
||||||
;; Package-Requires: ((emacs "26.1") (dash "2.13") (f "0.17.2") (s "1.12.0") (org "9.3") (emacsql "3.0.0") (emacsql-sqlite3 "1.0.2"))
|
;; Package-Requires: ((emacs "26.1") (dash "2.13") (f "0.17.2") (s "1.12.0") (org "9.3") (emacsql "3.0.0") (emacsql-sqlite3 "1.0.0"))
|
||||||
|
|
||||||
;; This file is NOT part of GNU Emacs.
|
;; This file is NOT part of GNU Emacs.
|
||||||
|
|
||||||
@ -34,24 +34,9 @@
|
|||||||
;;; Code:
|
;;; Code:
|
||||||
;;;; Library Requires
|
;;;; Library Requires
|
||||||
(require 'dash)
|
(require 'dash)
|
||||||
(require 's)
|
|
||||||
|
|
||||||
(defvar org-roam-verbose)
|
(defvar org-roam-verbose)
|
||||||
|
|
||||||
;; This is necessary to ensure all dependents on this module see
|
|
||||||
;; `org-mode-hook' and `org-inhibit-startup' as dynamic variables,
|
|
||||||
;; regardless of whether Org is loaded before their compilation.
|
|
||||||
(require 'org)
|
|
||||||
|
|
||||||
;;;; Utility Functions
|
|
||||||
(defun org-roam--list-interleave (lst separator)
|
|
||||||
"Interleaves elements in LST with SEPARATOR."
|
|
||||||
(when lst
|
|
||||||
(let ((new-lst (list (pop lst))))
|
|
||||||
(dolist (it lst)
|
|
||||||
(nconc new-lst (list separator it)))
|
|
||||||
new-lst)))
|
|
||||||
|
|
||||||
(defmacro org-roam--with-temp-buffer (file &rest body)
|
(defmacro org-roam--with-temp-buffer (file &rest body)
|
||||||
"Execute BODY within a temp buffer.
|
"Execute BODY within a temp buffer.
|
||||||
Like `with-temp-buffer', but propagates `org-roam-directory'.
|
Like `with-temp-buffer', but propagates `org-roam-directory'.
|
||||||
@ -61,14 +46,26 @@ If FILE, set `org-roam-temp-file-name' to file and insert its contents."
|
|||||||
`(let ((,current-org-roam-directory org-roam-directory))
|
`(let ((,current-org-roam-directory org-roam-directory))
|
||||||
(with-temp-buffer
|
(with-temp-buffer
|
||||||
(let ((org-roam-directory ,current-org-roam-directory)
|
(let ((org-roam-directory ,current-org-roam-directory)
|
||||||
(org-mode-hook nil)
|
(org-mode-hook nil))
|
||||||
(org-inhibit-startup t))
|
|
||||||
(org-mode)
|
(org-mode)
|
||||||
(when ,file
|
(when ,file
|
||||||
(insert-file-contents ,file)
|
(insert-file-contents ,file)
|
||||||
(setq-local org-roam-file-name ,file))
|
(setq-local org-roam-file-name ,file))
|
||||||
,@body)))))
|
,@body)))))
|
||||||
|
|
||||||
|
(defmacro org-roam--with-template-error (templates &rest body)
|
||||||
|
"Eval BODY, and point to TEMPLATES on error.
|
||||||
|
Provides more informative error messages so that users know where
|
||||||
|
to look.
|
||||||
|
|
||||||
|
\(fn TEMPLATES BODY...)"
|
||||||
|
(declare (debug (form body)) (indent 1))
|
||||||
|
`(condition-case err
|
||||||
|
,@body
|
||||||
|
(error (user-error "%s. Please adjust `%s'"
|
||||||
|
(error-message-string err)
|
||||||
|
,templates))))
|
||||||
|
|
||||||
(defun org-roam-message (format-string &rest args)
|
(defun org-roam-message (format-string &rest args)
|
||||||
"Pass FORMAT-STRING and ARGS to `message' when `org-roam-verbose' is t."
|
"Pass FORMAT-STRING and ARGS to `message' when `org-roam-verbose' is t."
|
||||||
(when org-roam-verbose
|
(when org-roam-verbose
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
;; Author: Jethro Kuan <jethrokuan95@gmail.com>
|
;; Author: Jethro Kuan <jethrokuan95@gmail.com>
|
||||||
;; URL: https://github.com/org-roam/org-roam
|
;; URL: https://github.com/org-roam/org-roam
|
||||||
;; Keywords: org-mode, roam, convenience
|
;; Keywords: org-mode, roam, convenience
|
||||||
;; Version: 1.2.3
|
;; Version: 1.2.1
|
||||||
;; Package-Requires: ((emacs "26.1") (org "9.3"))
|
;; Package-Requires: ((emacs "26.1") (org "9.3"))
|
||||||
|
|
||||||
;; This file is NOT part of GNU Emacs.
|
;; This file is NOT part of GNU Emacs.
|
||||||
@ -37,12 +37,6 @@
|
|||||||
;;; Code:
|
;;; Code:
|
||||||
(require 'org-protocol)
|
(require 'org-protocol)
|
||||||
(require 'org-roam)
|
(require 'org-roam)
|
||||||
(require 'ol) ;; for org-link-decode
|
|
||||||
|
|
||||||
(defcustom org-roam-protocol-store-links nil
|
|
||||||
"Whether to store links when capturing websites with `org-roam-protocol'."
|
|
||||||
:type 'boolean
|
|
||||||
:group 'org-roam)
|
|
||||||
|
|
||||||
;;;; Functions
|
;;;; Functions
|
||||||
(defun org-roam-protocol-open-ref (info)
|
(defun org-roam-protocol-open-ref (info)
|
||||||
@ -51,7 +45,7 @@
|
|||||||
It opens or creates a note with the given ref.
|
It opens or creates a note with the given ref.
|
||||||
|
|
||||||
javascript:location.href = \\='org-protocol://roam-ref?template=r&ref=\\='+ \\
|
javascript:location.href = \\='org-protocol://roam-ref?template=r&ref=\\='+ \\
|
||||||
encodeURIComponent(location.href) + \\='&title=\\=' + \\
|
encodeURIComponent(location.href) + \\='&title=\\=' \\
|
||||||
encodeURIComponent(document.title) + \\='&body=\\=' + \\
|
encodeURIComponent(document.title) + \\='&body=\\=' + \\
|
||||||
encodeURIComponent(window.getSelection())"
|
encodeURIComponent(window.getSelection())"
|
||||||
(when-let* ((alist (org-roam--plist-to-alist info))
|
(when-let* ((alist (org-roam--plist-to-alist info))
|
||||||
@ -63,26 +57,13 @@ It opens or creates a note with the given ref.
|
|||||||
(error "No ref key provided"))
|
(error "No ref key provided"))
|
||||||
(when-let ((title (cdr (assoc 'title decoded-alist))))
|
(when-let ((title (cdr (assoc 'title decoded-alist))))
|
||||||
(push (cons 'slug (funcall org-roam-title-to-slug-function title)) decoded-alist))
|
(push (cons 'slug (funcall org-roam-title-to-slug-function title)) decoded-alist))
|
||||||
(let-alist decoded-alist
|
|
||||||
(let* ((ref (org-protocol-sanitize-uri .ref))
|
|
||||||
(type (and (string-match "^\\([a-z]+\\):" ref)
|
|
||||||
(match-string 1 ref)))
|
|
||||||
(title (or .title ""))
|
|
||||||
(body (or .body ""))
|
|
||||||
(orglink
|
|
||||||
(org-link-make-string ref (or (org-string-nw-p title) ref))))
|
|
||||||
(when org-roam-protocol-store-links
|
|
||||||
(push (list ref title) org-stored-links))
|
|
||||||
(org-link-store-props :type type
|
|
||||||
:link ref
|
|
||||||
:annotation orglink
|
|
||||||
:initial body)))
|
|
||||||
(let* ((org-roam-capture-templates org-roam-capture-ref-templates)
|
(let* ((org-roam-capture-templates org-roam-capture-ref-templates)
|
||||||
(org-roam-capture--context 'ref)
|
(org-roam-capture--context 'ref)
|
||||||
(org-roam-capture--info decoded-alist)
|
(org-roam-capture--info decoded-alist)
|
||||||
(template (cdr (assoc 'template decoded-alist))))
|
(template (cdr (assoc 'template decoded-alist))))
|
||||||
(raise-frame)
|
(raise-frame)
|
||||||
(org-roam-capture--capture nil template)
|
(org-roam--with-template-error 'org-roam-capture-ref-templates
|
||||||
|
(org-roam-capture--capture nil template))
|
||||||
(org-roam-message "Item captured.")))
|
(org-roam-message "Item captured.")))
|
||||||
nil)
|
nil)
|
||||||
|
|
||||||
|
949
org-roam.el
949
org-roam.el
File diff suppressed because it is too large
Load Diff
@ -1 +0,0 @@
|
|||||||
#+roam_key: cite:mitsuha2007
|
|
@ -1,2 +0,0 @@
|
|||||||
#+roam_key: https://www.orgroam.com/
|
|
||||||
#+roam_key: cite:orgroam2020
|
|
@ -29,7 +29,7 @@
|
|||||||
|
|
||||||
(defun test-org-roam-perf--abs-path (file-path)
|
(defun test-org-roam-perf--abs-path (file-path)
|
||||||
"Get absolute FILE-PATH from `org-roam-directory'."
|
"Get absolute FILE-PATH from `org-roam-directory'."
|
||||||
(expand-file-name file-path org-roam-directory))
|
(file-truename (expand-file-name file-path org-roam-directory)))
|
||||||
|
|
||||||
(defun test-org-roam-perf--init ()
|
(defun test-org-roam-perf--init ()
|
||||||
"."
|
"."
|
||||||
@ -45,7 +45,7 @@
|
|||||||
(pcase (benchmark-run 1 (org-roam-db-build-cache t))
|
(pcase (benchmark-run 1 (org-roam-db-build-cache t))
|
||||||
(`(,time ,gcs ,time-in-gc)
|
(`(,time ,gcs ,time-in-gc)
|
||||||
(message "Elapsed time: %fs (%fs in %d GCs)" time time-in-gc gcs)
|
(message "Elapsed time: %fs (%fs in %d GCs)" time time-in-gc gcs)
|
||||||
(expect time :to-be-less-than 110))))
|
(expect time :to-be-less-than 100))))
|
||||||
(it "builds quickly without change"
|
(it "builds quickly without change"
|
||||||
(pcase (benchmark-run 1 (org-roam-db-build-cache))
|
(pcase (benchmark-run 1 (org-roam-db-build-cache))
|
||||||
(`(,time ,gcs ,time-in-gc)
|
(`(,time ,gcs ,time-in-gc)
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
|
|
||||||
(defun test-org-roam--abs-path (file-path)
|
(defun test-org-roam--abs-path (file-path)
|
||||||
"Get absolute FILE-PATH from `org-roam-directory'."
|
"Get absolute FILE-PATH from `org-roam-directory'."
|
||||||
(expand-file-name file-path org-roam-directory))
|
(file-truename (expand-file-name file-path org-roam-directory)))
|
||||||
|
|
||||||
(defun test-org-roam--find-file (path)
|
(defun test-org-roam--find-file (path)
|
||||||
"PATH."
|
"PATH."
|
||||||
@ -35,7 +35,7 @@
|
|||||||
(make-directory (file-name-directory path) t)
|
(make-directory (file-name-directory path) t)
|
||||||
(find-file path)))
|
(find-file path)))
|
||||||
|
|
||||||
(defvar test-org-roam-directory (expand-file-name "tests/roam-files")
|
(defvar test-org-roam-directory (file-truename (concat default-directory "tests/roam-files"))
|
||||||
"Directory containing org-roam test org files.")
|
"Directory containing org-roam test org files.")
|
||||||
|
|
||||||
(defun test-org-roam--init ()
|
(defun test-org-roam--init ()
|
||||||
@ -49,7 +49,7 @@
|
|||||||
|
|
||||||
(defun test-org-roam--teardown ()
|
(defun test-org-roam--teardown ()
|
||||||
(org-roam-mode -1)
|
(org-roam-mode -1)
|
||||||
(delete-file org-roam-db-location)
|
(delete-file (org-roam-db--get))
|
||||||
(org-roam-db--close))
|
(org-roam-db--close))
|
||||||
|
|
||||||
(describe "org-roam--str-to-list"
|
(describe "org-roam--str-to-list"
|
||||||
@ -71,40 +71,6 @@
|
|||||||
(expect (org-roam--str-to-list "\"hello")
|
(expect (org-roam--str-to-list "\"hello")
|
||||||
:to-throw)))
|
:to-throw)))
|
||||||
|
|
||||||
(describe "Ref extraction"
|
|
||||||
(before-all
|
|
||||||
(test-org-roam--init))
|
|
||||||
|
|
||||||
(after-all
|
|
||||||
(test-org-roam--teardown))
|
|
||||||
|
|
||||||
(cl-flet
|
|
||||||
((test (fn file)
|
|
||||||
(let* ((fname (test-org-roam--abs-path file))
|
|
||||||
(buf (find-file-noselect fname)))
|
|
||||||
(with-current-buffer buf
|
|
||||||
;; Unlike tag extraction, it doesn't make sense to
|
|
||||||
;; pass a filename.
|
|
||||||
(funcall fn)))))
|
|
||||||
;; Enable "cite:" link parsing
|
|
||||||
(org-link-set-parameters "cite")
|
|
||||||
(it "extracts web keys"
|
|
||||||
(expect (test #'org-roam--extract-ref
|
|
||||||
"web_ref.org")
|
|
||||||
:to-equal
|
|
||||||
'("website" . "//google.com/")))
|
|
||||||
(it "extracts cite keys"
|
|
||||||
(expect (test #'org-roam--extract-ref
|
|
||||||
"cite_ref.org")
|
|
||||||
:to-equal
|
|
||||||
'("cite" . "mitsuha2007")))
|
|
||||||
(it "extracts all keys"
|
|
||||||
(expect (test #'org-roam--extract-refs
|
|
||||||
"multiple-refs.org")
|
|
||||||
:to-have-same-items-as
|
|
||||||
'(("cite" . "orgroam2020")
|
|
||||||
("website" . "//www.orgroam.com/"))))))
|
|
||||||
|
|
||||||
(describe "Title extraction"
|
(describe "Title extraction"
|
||||||
:var (org-roam-title-sources)
|
:var (org-roam-title-sources)
|
||||||
(before-all
|
(before-all
|
||||||
@ -273,7 +239,7 @@
|
|||||||
:to-equal
|
:to-equal
|
||||||
'("t1" "t2 with space" "t3" "tags"))))))
|
'("t1" "t2 with space" "t3" "tags"))))))
|
||||||
|
|
||||||
(describe "ID extraction"
|
(describe "Headline extraction"
|
||||||
(before-all
|
(before-all
|
||||||
(test-org-roam--init))
|
(test-org-roam--init))
|
||||||
|
|
||||||
@ -286,34 +252,12 @@
|
|||||||
(buf (find-file-noselect fname)))
|
(buf (find-file-noselect fname)))
|
||||||
(with-current-buffer buf
|
(with-current-buffer buf
|
||||||
(funcall fn fname)))))
|
(funcall fn fname)))))
|
||||||
(it "extracts ids"
|
(it "extracts headlines"
|
||||||
(expect (test #'org-roam--extract-ids
|
(expect (test #'org-roam--extract-headlines
|
||||||
"headlines/headline.org")
|
"headlines/headline.org")
|
||||||
:to-have-same-items-as
|
|
||||||
`(["e84d0630-efad-4017-9059-5ef917908823" ,(test-org-roam--abs-path "headlines/headline.org") 1]
|
|
||||||
["801b58eb-97e2-435f-a33e-ff59a2f0c213" ,(test-org-roam--abs-path "headlines/headline.org") 1])))))
|
|
||||||
|
|
||||||
(describe "Test roam links"
|
|
||||||
(it ""
|
|
||||||
(expect (org-roam-link--split-path "")
|
|
||||||
:to-equal
|
:to-equal
|
||||||
'(title "" "" nil)))
|
`(["e84d0630-efad-4017-9059-5ef917908823" ,(test-org-roam--abs-path "headlines/headline.org")]
|
||||||
(it "title"
|
["801b58eb-97e2-435f-a33e-ff59a2f0c213" ,(test-org-roam--abs-path "headlines/headline.org")])))))
|
||||||
(expect (org-roam-link--split-path "title")
|
|
||||||
:to-equal
|
|
||||||
'(title "title" "" nil)))
|
|
||||||
(it "title*"
|
|
||||||
(expect (org-roam-link--split-path "title*")
|
|
||||||
:to-equal
|
|
||||||
'(title+headline "title" "" 5)))
|
|
||||||
(it "title*headline"
|
|
||||||
(expect (org-roam-link--split-path "title*headline")
|
|
||||||
:to-equal
|
|
||||||
'(title+headline "title" "headline" 5)))
|
|
||||||
(it "*headline"
|
|
||||||
(expect (org-roam-link--split-path "*headline")
|
|
||||||
:to-equal
|
|
||||||
'(headline "" "headline" 0))))
|
|
||||||
|
|
||||||
;;; Tests
|
;;; Tests
|
||||||
(xdescribe "org-roam-db-build-cache"
|
(xdescribe "org-roam-db-build-cache"
|
||||||
@ -334,21 +278,21 @@
|
|||||||
|
|
||||||
;; Links
|
;; Links
|
||||||
(expect (caar (org-roam-db-query [:select (funcall count) :from links
|
(expect (caar (org-roam-db-query [:select (funcall count) :from links
|
||||||
:where (= source $s1)]
|
:where (= from $s1)]
|
||||||
(test-org-roam--abs-path "foo.org"))) :to-be 1)
|
(test-org-roam--abs-path "foo.org"))) :to-be 1)
|
||||||
(expect (caar (org-roam-db-query [:select (funcall count) :from links
|
(expect (caar (org-roam-db-query [:select (funcall count) :from links
|
||||||
:where (= source $s1)]
|
:where (= from $s1)]
|
||||||
(test-org-roam--abs-path "nested/bar.org"))) :to-be 2)
|
(test-org-roam--abs-path "nested/bar.org"))) :to-be 2)
|
||||||
|
|
||||||
;; Links -- File-to
|
;; Links -- File-to
|
||||||
(expect (caar (org-roam-db-query [:select (funcall count) :from links
|
(expect (caar (org-roam-db-query [:select (funcall count) :from links
|
||||||
:where (= dest $s1)]
|
:where (= to $s1)]
|
||||||
(test-org-roam--abs-path "nested/foo.org"))) :to-be 1)
|
(test-org-roam--abs-path "nested/foo.org"))) :to-be 1)
|
||||||
(expect (caar (org-roam-db-query [:select (funcall count) :from links
|
(expect (caar (org-roam-db-query [:select (funcall count) :from links
|
||||||
:where (= dest $s1)]
|
:where (= to $s1)]
|
||||||
(test-org-roam--abs-path "nested/bar.org"))) :to-be 1)
|
(test-org-roam--abs-path "nested/bar.org"))) :to-be 1)
|
||||||
(expect (caar (org-roam-db-query [:select (funcall count) :from links
|
(expect (caar (org-roam-db-query [:select (funcall count) :from links
|
||||||
:where (= dest $s1)]
|
:where (= to $s1)]
|
||||||
(test-org-roam--abs-path "unlinked.org"))) :to-be 0)
|
(test-org-roam--abs-path "unlinked.org"))) :to-be 0)
|
||||||
;; TODO Test titles
|
;; TODO Test titles
|
||||||
(expect (org-roam-db-query [:select * :from titles])
|
(expect (org-roam-db-query [:select * :from titles])
|
||||||
|
Reference in New Issue
Block a user