Sources/OrgCore/Commands/OrgOnlyCommands.swift
35 lines · 2356 bytes
1/// Commands that read or write org syntax in the open file, refused in Markdown and other
2/// text files so none of them writes org into one.
3public enum OrgOnlyCommands {
4 /// Visibility commands, which fold Markdown headings as they fold org ones.
5 public static func folds(_ id: String) -> Bool {
6 id == "org.cycle" || id == "org.cycle-global" || id.hasPrefix("org.fold.")
7 }
8
9 /// Whether `id` is refused in a file that isn't org; `markdown` lets the fold commands run,
10 /// and a `path` with a Denote file type lets Denote's link and rename commands run.
11 public static func refuses(_ id: String, markdown: Bool, path: String? = nil) -> Bool {
12 if markdown, folds(id) { return false }
13 if denoteCommands.contains(id), let path, Denote.FileType(path: path) != nil { return false }
14 if id.hasPrefix("org.") || id.hasPrefix("app.attach.") { return true }
15 if id.hasPrefix("app.export.") { return !id.hasPrefix("app.export.icalendar-") }
16 return appCommands.contains(id)
17 }
18
19 /// Commands that follow, insert or rename as Denote does in its Markdown and text notes:
20 /// Open Link on a `denote:` link, Insert Node Link, Rename Note and Rename Note from Front
21 /// Matter.
22 static let denoteCommands: Set<String> = ["org.link.open", "app.node.insert", "app.node.rename", "app.node.rename-from-front-matter"]
23
24 /// App commands that act on the open file's entries, tables, links or Denote front matter.
25 static let appCommands: Set<String> = [
26 "app.refile", "app.refile.copy", "app.archive", "app.clock.in", "app.clock.default", "app.copy-rich-text",
27 "app.export-dialog", "app.export-subtree-dialog", "app.export-subtree", "app.export-body-only", "app.share-subtree",
28 "app.table-import", "app.table-export", "app.table-export.tsv", "app.plot",
29 "app.crypt.encrypt-entry", "app.crypt.encrypt-entries", "app.crypt.open-entry", "app.crypt.decrypt-entry",
30 "app.node.insert", "app.node.rename", "app.node.rename-from-front-matter",
31 "app.node.sequence-convert", "app.node.sequence-link", "app.node.sequence-rename-as-parent", "app.node.sequence-reparent",
32 "app.node.sequence-reparent-recursive", "app.node.sequence-new-child-of-current", "app.node.sequence-new-sibling-of-current",
33 "app.publish.current-file",
34 ]
35}