Skip to content

Commit 9bf000c

Browse files
committed
Added documentation for wildcards and indentation rules
1 parent 90136ee commit 9bf000c

File tree

3 files changed

+127
-0
lines changed

3 files changed

+127
-0
lines changed

docs/manual.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ For clarity: the three available prefixes `/!` and `/!!` and `/!!!` allow for fu
108108
109109
Currently, the below simple wildcard syntax is supported for sorting group:
110110
111+
For practical notes and examples (including common `...` gotchas and indentation), see [wildcards.md](./wildcards.md).
112+
111113
### A single digit (exactly one)
112114
113115
An expression like `\d` or `\[0-9]` matches a single digit (exactly one)

docs/syntax-reference.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ The intention is to make it understandable to non-technical persons.
3232
- the YAML key `sorting-spec:` has to be used
3333
- because indentation matters, the recommended multiline YAML syntax is `sorting-spec: |`
3434
- refer to YAML syntax reference for details on how the pipe `|` character works (e.g. https://en.wikipedia.org/wiki/YAML#Basic_components)
35+
- for practical notes and examples about `...` and indentation, see [wildcards.md](./wildcards.md)
3536
- the `sorting specification` comprises one or more [sections](#Section)
3637
- each `section` has to reside in a single location (a single entry in frontmatter YAML of a note)
3738
- multiple `sections` can exist under a single `sorting-spec: |` YAML entry, one after another

docs/wildcards.md

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# Wildcards and Pattern Matching
2+
3+
This plugin stores its configuration in YAML frontmatter. The value of
4+
`sorting-spec: |` is a multi-line string containing the plugin's sorting
5+
specification "language" (the plugin docs call it an informal language / syntax).
6+
7+
In this document we may refer to it as a DSL (Domain-Specific Language): a small
8+
purpose-built language parsed by the plugin.
9+
10+
In examples below, snippets may show only the sorting-spec lines (the content
11+
that goes under `sorting-spec: |`) for brevity.
12+
13+
Some parts of the syntax look regex-like (for example `\d\d\d\d`), but matching
14+
is not "full regex everywhere". In particular, the `...` token is a plugin
15+
wildcard and should not be treated as the regex `.*`.
16+
17+
## The `...` wildcard
18+
19+
`...` is used for prefix/suffix matching and for patterns where you want to
20+
match an arbitrary run of characters.
21+
22+
Examples:
23+
24+
- `Focus...` matches names starting with `Focus`.
25+
- `...ive` matches names ending with `ive`.
26+
- `A...s` matches names starting with `A` and ending with `s`.
27+
28+
Practical rules:
29+
30+
- Any characters you place next to `...` (including spaces) are literal and must
31+
exist in the name.
32+
- If you want to match an exact name shape that ends where your pattern ends,
33+
omit `...`.
34+
35+
### Example: year folders
36+
37+
Given folders:
38+
39+
- `Reviewed in 2023`
40+
- `Reviewed in 2024`
41+
- `Reviewed in 2025`
42+
- `Reviewed in 2026`
43+
44+
To match them exactly as a group, prefer:
45+
46+
```yaml
47+
/folders Reviewed in 20\d\d
48+
> a-z
49+
```
50+
51+
If you write:
52+
53+
```yaml
54+
/folders Reviewed in 20\d\d ...
55+
> a-z
56+
```
57+
58+
note the space before `...`. That space is a literal character, so this pattern
59+
only matches names that contain a space after the year (for example `Reviewed in
60+
2026 Q1`), and it will _not_ match exact names like `Reviewed in 2026`.
61+
62+
If you want to allow an optional suffix that starts with a space, but also match
63+
the exact name, define two groups (exact first), or use an exact match without
64+
`...`.
65+
66+
## Digits and ISO dates
67+
68+
Common digit patterns:
69+
70+
- `\d` matches one digit.
71+
- `\d\d\d\d` is often used for years.
72+
73+
ISO date prefixes (`YYYY-MM-DD`) sort correctly as plain text, so reverse
74+
alphabetical (`> a-z`) gives newest-first:
75+
76+
```yaml
77+
/:files \d\d\d\d-\d\d-\d\d ...
78+
> a-z
79+
```
80+
81+
## Indentation matters
82+
83+
In the plugin docs, the lines like `< a-z`, `> a-z`, `< modified` are referred to
84+
as sorting instructions / sorting methods (not a YAML concept). In this file we
85+
use the term "sorting instruction".
86+
87+
A sorting instruction must be indented under the group it applies to.
88+
89+
More precisely: inside the `sorting-spec: |` text, the sorting instruction line
90+
must start at a greater indentation level than the group line immediately above
91+
it (at least one extra space).
92+
93+
```yaml
94+
/folders Reviewed in 20\d\d
95+
> a-z
96+
```
97+
98+
In contrast, this is *not* grouped correctly (same indentation as the group
99+
line):
100+
101+
```yaml
102+
/folders Reviewed in 20\d\d
103+
> a-z
104+
```
105+
106+
If the sorting instruction is not indented more than the group line, the plugin
107+
will not associate it with that group.
108+
109+
## Complete example (folders first, then files)
110+
111+
Full YAML frontmatter form:
112+
113+
```yaml
114+
---
115+
sorting-spec: |
116+
target-folder: 03 Literature review
117+
/folders Reviewed in 20\d\d
118+
> a-z
119+
/folders
120+
< a-z
121+
/:files
122+
< a-z
123+
---
124+
```

0 commit comments

Comments
 (0)