Commit aa462a56b8

aa462a56b8bab666ca3c042e5298bae7b1a7c247

parent: 942b1aeb78

Verified · cmc

cmc <hello@cleberg.net> · 2026-11-19 21:12 UTC

Denote block insert commands; sync string catalog

- Insert Denote Links, Missing Links, Backlinks, Files, Files as Headings
  and Sequence Block, as denote-org-dblock-insert-* ask and write them.
- l10n: scripts/sync-strings.sh run, kept in the catalog's JSON format.

Layout: unified · split

Sources/OrgCore/Commands/Command.swift +1 −1
@@ -346,7 +346,7 @@ public enum Commands {
346346 ShiftTimestamp(up: true), ShiftTimestamp(up: false), ShiftTimestampDay(later: true), ShiftTimestampDay(later: false),
347347 OpenLinkAtPoint(), CreateID(), ToggleComment(), ToggleHeading(), ToggleItem(), MarkSubtree(),
348348 CopySubtree(cut: false), CopySubtree(cut: true), CloneSubtree(), SortEntries(), InsertStructureTemplate(), EditSpecial(), TableEditField(), TangleCommand(.all), TangleCommand(.block), TangleCommand(.target),
349 UpdateDynamicBlock(), ClockReportTable(), SetEffort(), CtrlCCtrlC(), EvaluateTimeRange(), FootnoteAction(), FootnoteAction(special: true), TableEvalFormula(named: false), TableEvalFormula(named: true), SortTableLines(), TransposeTable(), GotoHeading(), SparseTreeCommand(), SetPriority(), SetPriority(value: "A"), SetPriority(value: "B"), SetPriority(value: "C"), SetPriority(value: " "), ReadAndSetProperty(), DeleteProperty(), DeleteProperty(globally: true), PropertyAction(), NextAllowedValue(previous: false), NextAllowedValue(previous: true), InsertColumnView(), ShowColumnView(), ShowColumnView(global: true), ToggleArchiveTag(), ArchiveToSibling(), ToggleOrderedProperty(),
349 UpdateDynamicBlock(), ClockReportTable(), InsertDenoteBlock(.links), InsertDenoteBlock(.missingLinks), InsertDenoteBlock(.backlinks), InsertDenoteBlock(.files), InsertDenoteBlock(.filesAsHeadings), InsertDenoteBlock(.sequence), SetEffort(), CtrlCCtrlC(), EvaluateTimeRange(), FootnoteAction(), FootnoteAction(special: true), TableEvalFormula(named: false), TableEvalFormula(named: true), SortTableLines(), TransposeTable(), GotoHeading(), SparseTreeCommand(), SetPriority(), SetPriority(value: "A"), SetPriority(value: "B"), SetPriority(value: "C"), SetPriority(value: " "), ReadAndSetProperty(), DeleteProperty(), DeleteProperty(globally: true), PropertyAction(), NextAllowedValue(previous: false), NextAllowedValue(previous: true), InsertColumnView(), ShowColumnView(), ShowColumnView(global: true), ToggleArchiveTag(), ArchiveToSibling(), ToggleOrderedProperty(),
350350 InsertDrawer(), DragElement(forward: true), DragElement(forward: false), CycleBullet(previous: false), CycleBullet(previous: true),
351351 Emphasize(), Emphasize(marker: "*"), Emphasize(marker: "/"), Emphasize(marker: "_"), Emphasize(marker: "="), Emphasize(marker: "~"), Emphasize(marker: "+"),
352352 ]
Sources/OrgCore/Commands/DenoteBlocks.swift +69
@@ -225,3 +225,72 @@ extension EmacsBuffer {
225225 return out
226226 }
227227}
228
229/// `denote-org-dblock-insert-links` and the others: denote-org's questions, then the block
230/// with its parameters, as `org-create-dblock` writes them, updated.
231public struct InsertDenoteBlock: OrgCommand {
232 public enum Kind: String, CaseIterable, Sendable {
233 case links, missingLinks = "missing-links", backlinks, files, filesAsHeadings = "files-as-headings", sequence
234 }
235
236 public let kind: Kind
237 public init(_ kind: Kind) { self.kind = kind }
238 public var id: String { "org.denote.dblock-insert-\(kind.rawValue)" }
239 public var title: String {
240 switch kind {
241 case .links: "Insert Denote Links Block"
242 case .missingLinks: "Insert Denote Missing Links Block"
243 case .backlinks: "Insert Denote Backlinks Block"
244 case .files: "Insert Denote Files Block"
245 case .filesAsHeadings: "Insert Denote Files as Headings Block"
246 case .sequence: "Insert Denote Sequence Block"
247 }
248 }
249 public func applies(in context: EditContext) -> Bool { true }
250
251 static let sortComponents = ["title", "keywords", "signature", "identifier", "random", "last-modified"]
252
253 /// `prin1-to-string` of a string.
254 static func quoted(_ s: String) -> String {
255 "\"" + s.replacingOccurrences(of: "\\", with: "\\\\").replacingOccurrences(of: "\"", with: "\\\"") + "\""
256 }
257
258 public func run(in context: EditContext) -> CommandStep {
259 let answers = context.answers
260 let params: String
261 switch kind {
262 case .links, .missingLinks:
263 guard let regexp = answers["regexp"] else { return .prompt(Self.regexpPrompt) }
264 params = ":regexp \(Self.quoted(regexp)) :not-regexp nil :excluded-dirs-regexp nil :sort-by-component nil :reverse-sort nil :id-only nil :include-date nil"
265 case .backlinks:
266 params = ":excluded-dirs-regexp nil :sort-by-component nil :reverse-sort nil :id-only nil :this-heading-only nil :include-date nil"
267 case .files, .filesAsHeadings:
268 guard let regexp = answers["regexp"] else { return .prompt(Self.regexpPrompt) }
269 guard let sort = answers["sort"] else {
270 return .prompt(Prompt(key: "sort", message: "Sort by file name component: ", choices: Self.sortComponents))
271 }
272 let rest = kind == .files ? ":no-front-matter nil :file-separator nil :add-links nil" : ":add-links nil :exclude-tags nil"
273 params = ":regexp \(Self.quoted(regexp)) :not-regexp nil :excluded-dirs-regexp nil :sort-by-component \(sort.isEmpty ? "nil" : sort) :reverse-sort nil " + rest
274 case .sequence:
275 let files = DenoteSequence.files(DenoteBlocks.files(in: context.options.denoteDirectories ?? []).map(\.path))
276 let labels = files.map { ($0.path as NSString).lastPathComponent }
277 guard let file = answers["sequence"] else {
278 guard !files.isEmpty else { return .failed("There are no sequence notes in the denote-directory") }
279 return .prompt(Prompt(key: "sequence", message: "List descendants of: ", choices: labels))
280 }
281 guard let depthText = answers["depth"] else {
282 return .prompt(Prompt(key: "depth", message: "Maximum relative depth from root node (default 2): ", requireMatch: false))
283 }
284 guard let index = labels.firstIndex(of: file) else { return .failed("No sequence note \(file)") }
285 guard let depth = depthText.isEmpty ? 2 : Int(depthText.trimmingCharacters(in: .whitespaces)) else { return .failed("Please enter a number.") }
286 params = ":sequence \(Self.quoted(files[index].sequence)) :depth \(depth)"
287 }
288 return commitBuffer(context) { buffer in
289 let begin = buffer.createDynamicBlock("denote-\(kind.rawValue) " + params)
290 try buffer.updateDynamicBlock(at: begin)
291 buffer.point = begin
292 }
293 }
294
295 static let regexpPrompt = Prompt(key: "regexp", message: "Match files with the given REGEXP: ", requireMatch: false)
296}
Tests/OrgAppTests/DenoteOracleTests.swift +36
@@ -189,6 +189,42 @@ struct DenoteOracleTests {
189189 }
190190 #expect(ours == theirs, "\(block)\nours:\n\(ours)\ntheirs:\n\(theirs)")
191191 }
192 // The insert commands, at the end of a line of text and on an empty line.
193 let inserts: [(lisp: String, kind: InsertDenoteBlock.Kind, answers: [String: String])] = [
194 ("(denote-org-dblock-insert-links \"_emacs\")", .links, ["regexp": "_emacs"]),
195 ("(denote-org-dblock-insert-missing-links \".\")", .missingLinks, ["regexp": "."]),
196 ("(denote-org-dblock-insert-backlinks)", .backlinks, [:]),
197 ("(denote-org-dblock-insert-files \"beta\" 'title)", .files, ["regexp": "beta", "sort": "title"]),
198 ("(denote-org-dblock-insert-files-as-headings \"_work\" nil)", .filesAsHeadings, ["regexp": "_work", "sort": ""]),
199 ("(denote-org-dblock-insert-sequence \(dir.appendingPathComponent("20261004T090000==1--root__seq.org").path.debugDescription) 2)", .sequence,
200 ["sequence": "20261004T090000==1--root__seq.org", "depth": "2"]),
201 ]
202 for (lisp, kind, answers) in inserts {
203 for text in [head + "Last line", head] {
204 try text.write(to: current, atomically: true, encoding: .utf8)
205 let theirs = try DailiesTests.emacs("""
206 (progn (setq load-path (append (list \(paths)) load-path) coding-system-for-read 'utf-8 coding-system-for-write 'utf-8)
207 (require 'org) (require 'denote) (require 'denote-sequence nil t) (require 'denote-org)
208 (setq denote-directory \((dir.path + "/").debugDescription))
209 (find-file \(current.path.debugDescription))
210 (goto-char (point-max))
211 \(lisp)
212 (princ (buffer-string)))
213 """)
214 var options = EditingOptions.org
215 options.filePath = current.path
216 options.denoteDirectories = [dir.path]
217 let end = (text as NSString).length
218 let context = EditContext(revision: 0, text: text, tree: OrgParser.parse(text), selection: [end..<end], answers: answers, options: options)
219 var ours = text
220 if case .commit(let result) = InsertDenoteBlock(kind).run(in: context) {
221 for edit in result.edits.sorted(by: { $0.range.lowerBound > $1.range.lowerBound }) { ours = edit.apply(to: ours) }
222 } else {
223 ours = "failed"
224 }
225 #expect(ours == theirs, "\(lisp)\nours:\n\(ours)\ntheirs:\n\(theirs)")
226 }
227 }
192228 }
193229
194230 /// denote-sequence's new parents, children and siblings, relatives and conversions, for
docs/manual/guide/03-keys.org +6
@@ -1089,6 +1089,12 @@ See [[file:09-links.org][Links]].
10891089| Convert Note Sequence Scheme (=app.node.sequence-convert=) | — | — | — | =denote-sequence-convert=. |
10901090| Insert Sequence Link… (=app.node.sequence-link=) | — | — | — | =denote-sequence-link=. |
10911091| Sequence Hierarchy… (=app.node.sequence-hierarchy=) | — | — | — | =denote-sequence-view-hierarchy=. |
1092| Insert Denote Links Block (=org.denote.dblock-insert-links=) | — | — | — | =denote-org-dblock-insert-links=. |
1093| Insert Denote Missing Links Block (=org.denote.dblock-insert-missing-links=) | — | — | — | =denote-org-dblock-insert-missing-links=. |
1094| Insert Denote Backlinks Block (=org.denote.dblock-insert-backlinks=) | — | — | — | =denote-org-dblock-insert-backlinks=. |
1095| Insert Denote Files Block (=org.denote.dblock-insert-files=) | — | — | — | =denote-org-dblock-insert-files=. |
1096| Insert Denote Files as Headings Block (=org.denote.dblock-insert-files-as-headings=) | — | — | — | =denote-org-dblock-insert-files-as-headings=. |
1097| Insert Denote Sequence Block (=org.denote.dblock-insert-sequence=) | — | — | — | =denote-org-dblock-insert-sequence=. |
10921098
10931099** Unbound commands
10941100
docs/manual/guide/09-links.org +6
@@ -442,6 +442,12 @@ Dynamic Block, over the files in =denote-directory=:
442442| =denote-files-as-headings= | The same, each note's title a heading and its headings one level down |
443443| =denote-sequence= | A note's descendants, =:depth= levels deep, indented; with =:sequence ""= every note with a sequence |
444444
445Insert Denote Links Block, Insert Denote Missing Links Block, Insert Denote Backlinks Block,
446Insert Denote Files Block, Insert Denote Files as Headings Block and Insert Denote Sequence
447Block (=denote-org-dblock-insert-links= and the others) ask what denote-org asks (the
448regexp; for files, the sort component; for a sequence, the note and the depth, 2 by
449default), then insert the block with all its parameters and fill it.
450
445451They take denote-org's parameters: =:not-regexp=, =:sort-by-component= (=title=,
446452=keywords=, =signature=, =identifier=, =last-modified=, =random=), =:reverse-sort=,
447453=:id-only=, =:include-date=, =:block-name=, and for =denote-files= =:no-front-matter=,
l10n/Localizable.xcstrings +36 −7
@@ -52,6 +52,8 @@
5252 },
5353 "shouldTranslate": false
5454 },
55 "%@ (orgstar+)": {},
56 "%@ a month, billed yearly": {},
5557 "%@ ago": {
5658 "localizations": {
5759 "de": {
@@ -120,6 +122,8 @@
120122 }
121123 }
122124 },
125 "%@ needs orgstar+": {},
126 "%@ needs orgstar+.": {},
123127 "%@ state": {
124128 "localizations": {
125129 "de": {
@@ -1381,6 +1385,7 @@
13811385 }
13821386 }
13831387 },
1388 "Activate": {},
13841389 "Add": {
13851390 "localizations": {
13861391 "de": {
@@ -2330,6 +2335,7 @@
23302335 }
23312336 },
23322337 "Allow Notifications": {
2338 "extractionState": "stale",
23332339 "localizations": {
23342340 "de": {
23352341 "stringUnit": {
@@ -3218,6 +3224,7 @@
32183224 }
32193225 }
32203226 },
3227 "Billed monthly": {},
32213228 "Blocked entries": {
32223229 "localizations": {
32233230 "de": {
@@ -3422,6 +3429,7 @@
34223429 }
34233430 }
34243431 },
3432 "Buy orgstar+…": {},
34253433 "By Category of Selected Line": {
34263434 "localizations": {
34273435 "de": {
@@ -4510,6 +4518,7 @@
45104518 }
45114519 }
45124520 },
4521 "Choose a plan": {},
45134522 "Choose your init.el, or the folder holding it (~/.emacs.d, ~/.config/doom).": {
45144523 "localizations": {
45154524 "de": {
@@ -6148,6 +6157,7 @@
61486157 }
61496158 }
61506159 },
6160 "Current plan": {},
61516161 "Cycle TODO State": {
61526162 "localizations": {
61536163 "de": {
@@ -7758,6 +7768,7 @@
77587768 }
77597769 }
77607770 },
7771 "Editing, the agenda, capture, clocking, tables and search stay free.": {},
77617772 "Editor": {
77627773 "localizations": {
77637774 "de": {
@@ -8611,6 +8622,7 @@
86118622 }
86128623 }
86138624 },
8625 "Export, encryption, widgets, the Watch app and more": {},
86148626 "File": {
86158627 "localizations": {
86168628 "de": {
@@ -10210,6 +10222,8 @@
1021010222 }
1021110223 }
1021210224 },
10225 "Included in orgstar+": {},
10226 "Included, because you downloaded orgstar before orgstar+ existed. Thank you.": {},
1021310227 "Incomplete reminders with a due date from the checked lists show in the agenda, read-only; overdue ones under today.": {
1021410228 "localizations": {
1021510229 "de": {
@@ -10687,6 +10701,7 @@
1068710701 }
1068810702 },
1068910703 "License": {
10704 "extractionState": "stale",
1069010705 "localizations": {
1069110706 "de": {
1069210707 "stringUnit": {
@@ -10720,6 +10735,7 @@
1072010735 }
1072110736 }
1072210737 },
10738 "License key": {},
1072310739 "Light": {
1072410740 "localizations": {
1072510741 "de": {
@@ -11406,6 +11422,7 @@
1140611422 }
1140711423 }
1140811424 },
11425 "Manage Subscription": {},
1140911426 "Manual": {
1141011427 "localizations": {
1141111428 "de": {
@@ -11950,6 +11967,7 @@
1195011967 }
1195111968 }
1195211969 },
11970 "Needs orgstar+": {},
1195311971 "Neither": {
1195411972 "localizations": {
1195511973 "de": {
@@ -13759,6 +13777,7 @@
1375913777 }
1376013778 }
1376113779 },
13780 "ORGSTAR1-…": {},
1376213781 "Once a day, from the app's own feed. orgstar ▸ Check for Updates… checks now.": {
1376313782 "localizations": {
1376413783 "de": {
@@ -13793,6 +13812,7 @@
1379313812 }
1379413813 }
1379513814 },
13815 "One payment, no subscription": {},
1379613816 "One space after the title": {
1379713817 "localizations": {
1379813818 "de": {
@@ -15023,6 +15043,7 @@
1502315043 }
1502415044 }
1502515045 },
15046 "Power features and Apple integrations, on top of everything that stays free.": {},
1502615047 "Previous Buffer": {
1502715048 "localizations": {
1502815049 "de": {
@@ -16213,6 +16234,7 @@
1621316234 }
1621416235 }
1621516236 },
16237 "Remove License from This Mac": {},
1621616238 "Remove Tag…": {
1621716239 "localizations": {
1621816240 "de": {
@@ -16655,6 +16677,7 @@
1665516677 }
1665616678 }
1665716679 },
16680 "Restore Purchases": {},
1665816681 "Revert to File on Disk": {
1665916682 "localizations": {
1666016683 "de": {
@@ -16893,6 +16916,7 @@
1689316916 }
1689416917 }
1689516918 },
16919 "Save %lld%%": {},
1689616920 "Save All": {
1689716921 "localizations": {
1689816922 "de": {
@@ -18832,6 +18856,7 @@
1883218856 }
1883318857 },
1883418858 "Source Code": {
18859 "extractionState": "stale",
1883518860 "localizations": {
1883618861 "de": {
1883718862 "stringUnit": {
@@ -19347,6 +19372,7 @@
1934719372 }
1934819373 }
1934919374 },
19375 "Subscriptions renew automatically until cancelled in your Apple Account settings, at least 24 hours before the period ends.": {},
1935019376 "Subtree": {
1935119377 "localizations": {
1935219378 "de": {
@@ -20201,6 +20227,7 @@
2020120227 }
2020220228 }
2020320229 },
20230 "Terms of Use": {},
2020420231 "Text": {
2020520232 "localizations": {
2020620233 "de": {
@@ -20269,6 +20296,7 @@
2026920296 }
2027020297 }
2027120298 },
20299 "The Watch app needs orgstar+. Get it in orgstar on your iPhone, in Settings.": {},
2027220300 "The agenda": {
2027320301 "localizations": {
2027420302 "de": {
@@ -21360,6 +21388,7 @@
2136021388 }
2136121389 }
2136221390 },
21391 "Unlocked. Thanks for supporting orgstar.": {},
2136321392 "Unmark": {
2136421393 "localizations": {
2136521394 "de": {
@@ -22074,6 +22103,7 @@
2207422103 }
2207522104 }
2207622105 },
22106 "Widgets need orgstar+.": {},
2207722107 "Word Count": {
2207822108 "localizations": {
2207922109 "de": {
@@ -22245,6 +22275,7 @@
2224522275 }
2224622276 }
2224722277 },
22278 "You own orgstar+. Thank you for supporting orgstar.": {},
2224822279 "Your capture templates, from the app, the share sheet, widgets and the watch.": {
2224922280 "localizations": {
2225022281 "de": {
@@ -22313,6 +22344,7 @@
2231322344 }
2231422345 }
2231522346 },
22347 "Your key is in the email from the purchase. It is checked on this Mac; nothing is sent.": {},
2231622348 "Your org files on iPhone, in the folders where they already are.": {
2231722349 "localizations": {
2231822350 "de": {
@@ -22347,6 +22379,7 @@
2234722379 }
2234822380 }
2234922381 },
22382 "Your orgstar+ subscription is active. Thank you for supporting orgstar.": {},
2235022383 "Your own bindings go in %@, on top of the preset.": {
2235122384 "localizations": {
2235222385 "de": {
@@ -22386,7 +22419,6 @@
2238622419 },
2238722420 "agenda.later": {
2238822421 "comment": "Shows the next days in the agenda",
22389 "extractionState": "extracted_with_value",
2239022422 "localizations": {
2239122423 "de": {
2239222424 "stringUnit": {
@@ -22428,7 +22460,6 @@
2242822460 },
2242922461 "agenda.mark-done": {
2243022462 "comment": "Swipe action that marks the entry done",
22431 "extractionState": "extracted_with_value",
2243222463 "localizations": {
2243322464 "de": {
2243422465 "stringUnit": {
@@ -22541,7 +22572,6 @@
2254122572 },
2254222573 "none.date": {
2254322574 "comment": "No scheduled or deadline date",
22544 "extractionState": "extracted_with_value",
2254522575 "localizations": {
2254622576 "de": {
2254722577 "stringUnit": {
@@ -22583,7 +22613,6 @@
2258322613 },
2258422614 "none.folder": {
2258522615 "comment": "No configuration folder chosen",
22586 "extractionState": "extracted_with_value",
2258722616 "localizations": {
2258822617 "de": {
2258922618 "stringUnit": {
@@ -22625,7 +22654,6 @@
2262522654 },
2262622655 "none.priority": {
2262722656 "comment": "No priority",
22628 "extractionState": "extracted_with_value",
2262922657 "localizations": {
2263022658 "de": {
2263122659 "stringUnit": {
@@ -22667,7 +22695,6 @@
2266722695 },
2266822696 "none.state": {
2266922697 "comment": "No TODO state",
22670 "extractionState": "extracted_with_value",
2267122698 "localizations": {
2267222699 "de": {
2267322700 "stringUnit": {
@@ -22709,7 +22736,6 @@
2270922736 },
2271022737 "none.tags": {
2271122738 "comment": "No tags",
22712 "extractionState": "extracted_with_value",
2271322739 "localizations": {
2271422740 "de": {
2271522741 "stringUnit": {
@@ -23058,6 +23084,8 @@
2305823084 }
2305923085 }
2306023086 },
23087 "orgstar+": {},
23088 "orgstar+ is a one-time purchase of $39.99 for this Mac. Editing, the agenda, capture, clocking and search stay free.": {},
2306123089 "to": {
2306223090 "localizations": {
2306323091 "de": {
@@ -23099,6 +23127,7 @@
2309923127 "shouldTranslate": false
2310023128 },
2310123129 "© 2026 Christian Cleberg. Free software under the 0BSD license.": {
23130 "extractionState": "stale",
2310223131 "localizations": {
2310323132 "de": {
2310423133 "stringUnit": {