Skip to content

Commit 938f9af

Browse files
authored
refactor: captures (#613)
* refactor: captures * refactor: make headline detached from template * feat: subtemplates * refactor: move `empty_lines` to `properties` * feat: remove buffer empty lines * fix: properly place capture without headline * tests: add tests for org captures * fix: template validation * chore: remove old tests
1 parent 346b6aa commit 938f9af

File tree

7 files changed

+581
-108
lines changed

7 files changed

+581
-108
lines changed

DOCS.md

+52-16
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,16 @@ Variables:
412412
* `%^{PROMPT|DEFAULT|COMPLETION...}`: Prompt for input, if completion is provided an :h inputlist will be used
413413
* `%(EXP)`: Runs the given lua code and inserts the result. NOTE: this will internally pass the content to the lua `load()` function. So the body inside `%()` should be the body of a function that returns a string.
414414

415+
Templates have the following fields:
416+
* `description` (`string`) — description of the template that is displayed in the template selection menu
417+
* `template` (`string|string[]`) — body of the template that will be used when creating capture
418+
* `target` (`string?`) — name of the file to which the capture content will be added. If the target is not specified, the content will be added to the [`org_default_notes_file`](#orgdefaultnotesfile) file
419+
* `headline` (`string?`) — title of the headline after which the capture content will be added. If no headline is specified, the content will be appended to the end of the file
420+
* `properties` (`table?`):
421+
* `empty_lines` (`table|number?`) — if the value is a number, then empty lines are added before and after the content. If the value is a table, then the following fields are expected:
422+
* `before` (`integer?`) — add empty lines to the beginning of the content
423+
* `after` (`integer?`) — add empty lines to the end of the content
424+
415425
Example:<br />
416426
```lua
417427
{ T = {
@@ -423,20 +433,24 @@ Example:<br />
423433

424434
Journal example:<br />
425435
```lua
426-
{ j = {
427-
description = 'Journal',
428-
template = '\n*** %<%Y-%m-%d> %<%A>\n**** %U\n\n%?',
429-
target = '~/sync/org/journal.org'
430-
} }
436+
{
437+
j = {
438+
description = 'Journal',
439+
template = '\n*** %<%Y-%m-%d> %<%A>\n**** %U\n\n%?',
440+
target = '~/sync/org/journal.org'
441+
},
442+
}
431443
```
432444

433445
Journal example with dynamic target, i.e. a separate file per month:<br />
434446
```lua
435-
{ J = {
436-
description = 'Journal',
437-
template = '\n*** %<%Y-%m-%d> %<%A>\n**** %U\n\n%?',
438-
target = '~/sync/org/journal/%<%Y-%m>.org'
439-
} }
447+
{
448+
J = {
449+
description = 'Journal',
450+
template = '\n*** %<%Y-%m-%d> %<%A>\n**** %U\n\n%?',
451+
target = '~/sync/org/journal/%<%Y-%m>.org'
452+
},
453+
}
440454
```
441455

442456
Nested key example:<br />
@@ -456,16 +470,38 @@ Nested key example:<br />
456470
headline = 'one-time'
457471
}
458472
}
473+
-- or
474+
{
475+
e = {
476+
description = 'Event',
477+
subtemplates = {
478+
r = {
479+
description = 'recurring',
480+
template = '** %?\n %T',
481+
target = '~/org/calendar.org',
482+
headline = 'recurring'
483+
},
484+
o = {
485+
description = 'one-time',
486+
template = '** %?\n %T',
487+
target = '~/org/calendar.org',
488+
headline = 'one-time'
489+
},
490+
},
491+
},
492+
}
459493
```
460494

461495
Lua expression example:<br />
462496
```lua
463-
{ j = {
464-
description = 'Journal',
465-
template = '* %(return vim.fn.getreg "w")',
466-
-- get the content of register "w"
467-
target = '~/sync/org/journal.org'
468-
} }
497+
{
498+
j = {
499+
description = 'Journal',
500+
template = '* %(return vim.fn.getreg "w")',
501+
-- get the content of register "w"
502+
target = '~/sync/org/journal.org'
503+
},
504+
}
469505
```
470506

471507
#### **org_agenda_min_height**

0 commit comments

Comments
 (0)