Commit 0adc91d2a0
Verified · cmc
Changed files (38)
- Sources/OrgApp/CitationActions.swift added +156
- Sources/OrgApp/CommandTitles.swift +1
- Sources/OrgApp/CompletionSources.swift +4
- Sources/OrgApp/EmacsImport.swift +5
- Sources/OrgApp/LinkFollow.swift +8 −2
- Sources/OrgApp/OrgPreferences.swift +5
- Sources/OrgApp/UserConfig.swift +2
- Sources/OrgCore/Commands/CitationCommands.swift added +160
- Sources/OrgCore/Commands/Dwim.swift +4 −2
- Sources/OrgCore/Completion/IndexCompletion.swift +17 −1
- Sources/OrgCore/Completion/OrgCompletion.swift +23 −2
- Sources/OrgCore/Export/Citations.swift +8 −11
- Sources/OrgCore/Export/HTMLExport.swift +1 −1
- Sources/OrgCore/Export/MarkdownExport.swift +1 −1
- Sources/OrgCore/Export/ODTExport.swift +1 −1
- Sources/OrgCore/Keymap/PresetDoom.swift +4
- Sources/OrgCore/Keymap/PresetEmacs.swift +3
- Sources/OrgCore/Links/Bibliography.swift added +217
- Sources/OrgCore/Links/Links.swift +15 −1
- Sources/OrgCore/Parser/Settings.swift +3
- Sources/OrgEditorAppKit/EditorCommands.swift +1
- Sources/OrgEditorAppKit/OrgEditor.swift +1
- Sources/Orgstar/ContentView.swift +23 −1
- Sources/Orgstar/LinkOpener.swift +7 −2
- Sources/Orgstar/OrgstarApp.swift +1 −1
- Sources/OrgstarMobile/EditorScreen.swift +15
- Sources/OrgstarMobile/MobileEditor.swift +2 −2
- Sources/OrgstarMobile/ReaderScreen.swift +2
- Tests/OrgAppTests/AppTests.swift +2
- Tests/OrgAppTests/CitationActionsTests.swift added +143
- Tests/OrgAppTests/EmacsImportTests.swift +11
- Tests/OrgCoreTests/CitationInsertTests.swift added +288
- docs/manual/guide/03-keys.org +3 −1
- docs/manual/guide/09-links.org +78 −3
- docs/manual/guide/12-export.org +1 −1
- docs/manual/guide/13-configuration.org +3
- docs/manual/guide/14-ios.org +3
- l10n/Localizable.xcstrings +420
Sources/OrgApp/CitationActions.swift added +156 · view
| @@ -0,0 +1,156 @@ | ||
| 1 | import OrgCore | |
| 2 | import SwiftUI | |
| 3 | ||
| 4 | /// A followed citation's bibliography entry and what it offers to open. | |
| 5 | public struct CitationEntry: Identifiable, Sendable { | |
| 6 | public var id: String { key } | |
| 7 | public var key: String | |
| 8 | public var summary: String | |
| 9 | /// The entry's files, its DOI and URL, then the entry in its bibliography file. | |
| 10 | public var links: [(label: String, link: OrgLink)] | |
| 11 | ||
| 12 | public init(_ entry: BibEntry, text: String? = nil) { | |
| 13 | key = entry.key | |
| 14 | summary = entry.summary | |
| 15 | var links: [(String, OrgLink)] = entry.files.map { file in | |
| 16 | (String(localized: "Open \((file as NSString).lastPathComponent)", comment: "Opens a citation's file"), OrgLink(type: "file", path: file, raw: "file:" + file)) | |
| 17 | } | |
| 18 | if let doi = entry.doi { links.append((String(localized: "Open DOI", comment: "Opens a citation's DOI"), OrgLink(type: "doi", path: doi, raw: "doi:" + doi))) } | |
| 19 | if let url = entry.url, url.contains(":") { links.append((String(localized: "Open URL", comment: "Opens a citation's URL"), Links.parse(plain: url))) } | |
| 20 | let line = text.flatMap { Bibliography.line(of: entry.key, in: $0, json: (entry.file as NSString).pathExtension.lowercased() == "json") } | |
| 21 | links.append((String(localized: "Show in Bibliography", comment: "Opens the bibliography file at a citation's entry"), | |
| 22 | OrgLink(type: "file", path: entry.file, searchOption: line.map(String.init), raw: "file:" + entry.file))) | |
| 23 | self.links = links | |
| 24 | } | |
| 25 | } | |
| 26 | ||
| 27 | /// Insert Citation… and following citations, as `org-cite-insert` and `org-cite-follow` with | |
| 28 | /// the basic processor, with the platform's questions. Bibliography files are read off the | |
| 29 | /// main thread. | |
| 30 | @MainActor | |
| 31 | public struct CitationActions { | |
| 32 | public var session: DocumentSession | |
| 33 | /// The editor's text and caret. | |
| 34 | public var context: () -> EditContext? | |
| 35 | /// Runs a command in the editor. | |
| 36 | public var perform: (any OrgCommand) -> Void | |
| 37 | public var show: (String) -> Void | |
| 38 | public var ask: (Prompt, @escaping (String?) -> Void) -> Void | |
| 39 | /// Shows a followed citation's entry. | |
| 40 | public var present: (CitationEntry) -> Void | |
| 41 | /// In the Mac sandbox, asks for access to bibliography files outside the sidebar's | |
| 42 | /// folders. False when one is still out of reach. | |
| 43 | public var reach: ([String]) -> Bool = { _ in true } | |
| 44 | public var cache = BibliographyCache.shared | |
| 45 | ||
| 46 | public init( | |
| 47 | session: DocumentSession, context: @escaping () -> EditContext?, perform: @escaping (any OrgCommand) -> Void, show: @escaping (String) -> Void, | |
| 48 | ask: @escaping (Prompt, @escaping (String?) -> Void) -> Void, present: @escaping (CitationEntry) -> Void | |
| 49 | ) { | |
| 50 | self.session = session | |
| 51 | self.context = context | |
| 52 | self.perform = perform | |
| 53 | self.show = show | |
| 54 | self.ask = ask | |
| 55 | self.present = present | |
| 56 | } | |
| 57 | ||
| 58 | /// `org-cite-basic`'s styles, as `org-cite-basic--complete-style` offers them. | |
| 59 | nonisolated static let styles = ["author", "noauthor", "nocite", "note", "numeric", "text", "nil"] | |
| 60 | ||
| 61 | /// The bibliography files of `text`, a file at `path`: its `#+bibliography:` files, then | |
| 62 | /// `org-cite-global-bibliography`'s. | |
| 63 | nonisolated static func files(_ text: String, path: String?) -> [String] { | |
| 64 | Bibliography.files(in: text, directory: path.map { ($0 as NSString).deletingLastPathComponent }, global: OrgPreferences.citeGlobalBibliography()) | |
| 65 | } | |
| 66 | ||
| 67 | /// Insert Citation…: on a citation's style a new style; otherwise a key from the | |
| 68 | /// bibliography, and for a new citation a style; for a new reference a prefix and suffix. | |
| 69 | public func insert() { | |
| 70 | guard let context = context() else { return show(String(localized: "No file is open")) } | |
| 71 | let place = Citations.place(at: context.caret, tree: context.tree) | |
| 72 | let stylePrompt = Prompt(key: "style", message: String(localized: "Style (empty for default): ", comment: "Insert Citation… asks for a citation style"), | |
| 73 | choices: Self.styles, requireMatch: false) | |
| 74 | if place == .style { | |
| 75 | return ask(stylePrompt) { style in | |
| 76 | guard let style else { return } | |
| 77 | perform(InsertCitation(key: nil, style: style)) | |
| 78 | } | |
| 79 | } | |
| 80 | let files = Self.files(context.text, path: session.path) | |
| 81 | guard !files.isEmpty else { return show(String(localized: "No bibliography set", comment: "Insert Citation… in a file without #+bibliography")) } | |
| 82 | guard reach(files) else { return } | |
| 83 | let cache = cache | |
| 84 | Task { | |
| 85 | let entries = await cache.load(files) | |
| 86 | guard !entries.isEmpty else { return show(String(localized: "No bibliography set", comment: "Insert Citation… in a file without #+bibliography")) } | |
| 87 | let labels = entries.map(\.label) | |
| 88 | ask(Prompt(key: "key", message: String(localized: "Key: ", comment: "Insert Citation… asks for a bibliography entry"), choices: labels)) { answer in | |
| 89 | guard let answer, let index = labels.firstIndex(of: answer) else { return } | |
| 90 | let key = entries[index].key | |
| 91 | guard place != .key else { return perform(InsertCitation(key: key)) } | |
| 92 | affixes { prefix, suffix in | |
| 93 | guard place == .new else { return perform(InsertCitation(key: key, prefix: prefix, suffix: suffix)) } | |
| 94 | ask(stylePrompt) { style in | |
| 95 | guard let style else { return } | |
| 96 | perform(InsertCitation(key: key, style: style, prefix: prefix, suffix: suffix)) | |
| 97 | } | |
| 98 | } | |
| 99 | } | |
| 100 | } | |
| 101 | } | |
| 102 | ||
| 103 | /// Asks for the new reference's prefix and suffix, either of which may be empty. | |
| 104 | private func affixes(_ then: @escaping (String, String) -> Void) { | |
| 105 | ask(Prompt(key: "prefix", message: String(localized: "Prefix (empty for none): ", comment: "Insert Citation… asks for text before the key"), requireMatch: false)) { prefix in | |
| 106 | guard let prefix else { return } | |
| 107 | ask(Prompt(key: "suffix", message: String(localized: "Suffix (empty for none): ", comment: "Insert Citation… asks for text after the key"), requireMatch: false)) { suffix in | |
| 108 | guard let suffix else { return } | |
| 109 | then(prefix, suffix) | |
| 110 | } | |
| 111 | } | |
| 112 | } | |
| 113 | ||
| 114 | /// Following a citation: its entry, from the file's bibliographies, with its file, DOI, | |
| 115 | /// URL and place in the bibliography file. Of several keys, one is asked for first, as | |
| 116 | /// `org-cite-basic-goto` does. | |
| 117 | public func follow(_ keys: [String]) { | |
| 118 | guard keys.count == 1 else { | |
| 119 | return ask(Prompt(key: "key", message: String(localized: "Select citation key: ", comment: "Following a citation with several keys"), choices: keys)) { key in | |
| 120 | guard let key else { return } | |
| 121 | follow([key]) | |
| 122 | } | |
| 123 | } | |
| 124 | let key = keys[0] | |
| 125 | guard let document = session.document else { return show(String(localized: "No file is open")) } | |
| 126 | let files = Self.files(document.text, path: session.path) | |
| 127 | guard reach(files) else { return } | |
| 128 | let cache = cache | |
| 129 | Task { | |
| 130 | let found = await Self.find(key, in: files, cache: cache) | |
| 131 | guard let found else { return show(String(localized: "Cannot find citation key: \(key)", comment: "Following a citation whose key no bibliography has")) } | |
| 132 | present(found) | |
| 133 | } | |
| 134 | } | |
| 135 | ||
| 136 | @concurrent | |
| 137 | nonisolated static func find(_ key: String, in files: [String], cache: BibliographyCache) async -> CitationEntry? { | |
| 138 | guard let entry = cache.entries(files).first(where: { $0.key == key }) else { return nil } | |
| 139 | return CitationEntry(entry, text: (try? String(contentsOfFile: entry.file, encoding: .utf8))) | |
| 140 | } | |
| 141 | } | |
| 142 | ||
| 143 | extension View { | |
| 144 | /// Shows a followed citation's entry with a button for each thing it offers to open. | |
| 145 | public func citationAlert(_ entry: Binding<CitationEntry?>, open: @escaping (OrgLink) -> Void) -> some View { | |
| 146 | alert(entry.wrappedValue.map { "@" + $0.key } ?? "", isPresented: Binding(get: { entry.wrappedValue != nil }, set: { if !$0 { entry.wrappedValue = nil } }), | |
| 147 | presenting: entry.wrappedValue) { shown in | |
| 148 | ForEach(shown.links.indices, id: \.self) { index in | |
| 149 | Button(shown.links[index].label) { open(shown.links[index].link) } | |
| 150 | } | |
| 151 | Button("Cancel", role: .cancel) {} | |
| 152 | } message: { shown in | |
| 153 | Text(shown.summary) | |
| 154 | } | |
| 155 | } | |
| 156 | } | |
Sources/OrgApp/CommandTitles.swift +1 · view
| @@ -140,6 +140,7 @@ enum CommandTitles { | ||
| 140 | 140 | String(localized: "Indent Item", comment: "Command title"), |
| 141 | 141 | String(localized: "Indent Item and Children", comment: "Command title"), |
| 142 | 142 | String(localized: "Insert Checkbox Item", comment: "Command title"), |
| 143 | String(localized: "Insert Citation…", comment: "Command title"), | |
| 143 | 144 | String(localized: "Insert Column View Table", comment: "Command title"), |
| 144 | 145 | String(localized: "Insert Denote Backlinks Block", comment: "Command title"), |
| 145 | 146 | String(localized: "Insert Denote Files Block", comment: "Command title"), |
Sources/OrgApp/CompletionSources.swift +4 · view
| @@ -19,6 +19,10 @@ public enum CompletionSources { | ||
| 19 | 19 | return CompletionResult(strings: values.allowed + values.used) |
| 20 | 20 | case .words(let prefix): |
| 21 | 21 | return CompletionResult(strings: (try? index.words(prefix, excluding: path)) ?? []) |
| 22 | case .citationKeys(let files): | |
| 23 | // With `org-cite-global-bibliography` as it is now, not as the buffer was parsed. | |
| 24 | let global = OrgPreferences.citeGlobalBibliography().map { OrgPaths.expandingTilde($0) } | |
| 25 | return CompletionResult(entries: BibliographyCache.shared.entries(files + global.filter { !files.contains($0) })) | |
| 22 | 26 | } |
| 23 | 27 | } |
| 24 | 28 | |
Sources/OrgApp/EmacsImport.swift +5 · view
| @@ -650,6 +650,11 @@ public struct EmacsImport: Sendable { | ||
| 650 | 650 | case "org-attach-id-dir": |
| 651 | 651 | guard let dir = value.string else { return note("not a string") } |
| 652 | 652 | add(name, .string(dir)) |
| 653 | case "org-cite-global-bibliography": | |
| 654 | guard let files = value.elements?.compactMap(\.string), files.count == value.elements?.count, !files.contains(where: { $0.contains(":") }) else { | |
| 655 | return note("not a list of files without :") | |
| 656 | } | |
| 657 | add(name, .string(files.joined(separator: ":"))) | |
| 653 | 658 | case "org-attach-use-inheritance": |
| 654 | 659 | if value.symbol == "selective" { add(name, .string("selective")) } else { add(name, .string(truthy ? "t" : "nil")) } |
| 655 | 660 | case "org-yank-image-save-method": |
Sources/OrgApp/LinkFollow.swift +8 −2 · view
| @@ -12,13 +12,15 @@ public enum LinkFollow: Equatable, Sendable { | ||
| 12 | 12 | case choose(prompt: String, paths: [String]) |
| 13 | 13 | /// An `elisp:` link's form, to run with `evaluateLink` once the user agrees. |
| 14 | 14 | case elisp(String) |
| 15 | /// A citation's keys, to show through `CitationActions.follow`. | |
| 16 | case citation([String]) | |
| 15 | 17 | } |
| 16 | 18 | |
| 17 | 19 | extension DocumentSession { |
| 18 | 20 | /// Follows a link as `org-link-open` does: files open as buffers (with a `::` search), |
| 19 | 21 | /// `id:`, `roam:` and `denote:` links through the index, internal and radio links in the current file, |
| 20 | /// `attachment:` links in their entry's attachment folder, and web and mail links go to | |
| 21 | /// their apps. | |
| 22 | /// `attachment:` links in their entry's attachment folder, and web, mail and `zotero:` links | |
| 23 | /// go to their apps. A citation (a `cite` link) comes back as its keys. | |
| 22 | 24 | public func follow(_ link: OrgLink, workspace: WorkspaceModel?, isText: (String) -> Bool) -> LinkFollow { |
| 23 | 25 | switch link.type { |
| 24 | 26 | case "http", "https", "ftp", "mailto", "news": |
| @@ -66,7 +68,11 @@ extension DocumentSession { | ||
| 66 | 68 | case "custom-id": |
| 67 | 69 | return searchCurrent("#" + link.path) |
| 68 | 70 | case "fuzzy": |
| 71 | // Zotero's `zotero://select/...` links, which Org doesn't know as a type. | |
| 72 | if link.path.lowercased().hasPrefix("zotero:") { return Self.url(link.path) } | |
| 69 | 73 | return searchCurrent(link.path) |
| 74 | case "cite": | |
| 75 | return .citation(link.path.components(separatedBy: ";")) | |
| 70 | 76 | case "radio": |
| 71 | 77 | guard let document else { return .message("No file is open") } |
| 72 | 78 | return shown(Links.searchRadio(link.path, tree: document.tree)) |
Sources/OrgApp/OrgPreferences.swift +5 · view
| @@ -18,6 +18,7 @@ public enum OrgPreferences { | ||
| 18 | 18 | settings.tagsExcludedFromInheritance = Set(string("tagsExcludedFromInheritance", defaults).split(whereSeparator: \.isWhitespace).map(String.init)) |
| 19 | 19 | settings.attachIDDir = attachIDDir(defaults) |
| 20 | 20 | settings.attachUseInheritance = attachUseInheritance(defaults) |
| 21 | settings.citeGlobalBibliography = citeGlobalBibliography(defaults) | |
| 21 | 22 | return settings |
| 22 | 23 | } |
| 23 | 24 | |
| @@ -223,6 +224,10 @@ public enum OrgPreferences { | ||
| 223 | 224 | default: nil |
| 224 | 225 | } |
| 225 | 226 | } |
| 227 | /// `org-cite-global-bibliography`: bibliography files, separated by `:`. | |
| 228 | public static func citeGlobalBibliography(_ defaults: UserDefaults = .standard) -> [String] { | |
| 229 | string("citeGlobalBibliography", defaults).split(separator: ":").map { $0.trimmingCharacters(in: .whitespaces) }.filter { !$0.isEmpty } | |
| 230 | } | |
| 226 | 231 | /// `org-yank-image-save-method`: "attach", or the folder pasted images go in. |
| 227 | 232 | public static func yankImageSaveMethod(_ defaults: UserDefaults = .standard) -> String { |
| 228 | 233 | string("yankImageSaveMethod", defaults).nonEmpty ?? "attach" |
Sources/OrgApp/UserConfig.swift +2 · view
| @@ -215,6 +215,8 @@ public enum UserConfig { | ||
| 215 | 215 | Setting(section: "", key: "org-attach-use-inheritance", defaultsKey: "attachUseInheritance", |
| 216 | 216 | kind: .choice([("selective", "selective"), ("t", "t"), ("nil", "nil")]), fallback: .string("selective"), |
| 217 | 217 | comment: "whether DIR and ID inherit for attachments: selective (as org-use-property-inheritance), t or nil", legacy: ""), |
| 218 | Setting(section: "", key: "org-cite-global-bibliography", defaultsKey: "citeGlobalBibliography", kind: .string, fallback: .string(""), | |
| 219 | comment: "bibliography files (.bib or CSL-JSON .json) every file's citations use, separated by :", legacy: ""), | |
| 218 | 220 | Setting(section: "", key: "org-yank-image-save-method", defaultsKey: "yankImageSaveMethod", kind: .string, fallback: .string("attach"), |
| 219 | 221 | comment: "where pasted images go: attach (the entry's attachments) or a folder, relative to the org file's folder unless absolute", legacy: ""), |
| 220 | 222 | Setting(section: "", key: "org-yank-dnd-method", defaultsKey: "yankDndMethod", |
Sources/OrgCore/Commands/CitationCommands.swift added +160 · view
| @@ -0,0 +1,160 @@ | ||
| 1 | import Foundation | |
| 2 | ||
| 3 | /// A citation in a buffer, with the parts `org-cite-insert` tells apart. | |
| 4 | public struct CitationAt: Sendable, Equatable { | |
| 5 | /// `[cite…]`, without the blanks after it. | |
| 6 | public var range: Range<Int> | |
| 7 | /// The `:` ending `[cite/style`. | |
| 8 | public var colon: Int | |
| 9 | /// Each reference, its `;` included, and its `@key`. | |
| 10 | public var references: [(range: Range<Int>, key: Range<Int>)] | |
| 11 | ||
| 12 | /// The style and variant as written (`t/c`); nil without one. | |
| 13 | public func style(in text: String) -> String? { | |
| 14 | let ns = text as NSString | |
| 15 | let written = ns.substring(with: NSRange(location: range.lowerBound + 5, length: colon - range.lowerBound - 5)) | |
| 16 | return written.hasPrefix("/") ? String(written.dropFirst()) : nil | |
| 17 | } | |
| 18 | ||
| 19 | public static func == (a: CitationAt, b: CitationAt) -> Bool { | |
| 20 | a.range == b.range && a.colon == b.colon && a.references.map(\.range) == b.references.map(\.range) && a.references.map(\.key) == b.references.map(\.key) | |
| 21 | } | |
| 22 | } | |
| 23 | ||
| 24 | public enum Citations { | |
| 25 | /// The citation holding `offset`: from just after its `[` to its `]`, as | |
| 26 | /// `org-cite-boundaries` bounds it. | |
| 27 | public static func citation(at offset: Int, tree: OrgTree) -> CitationAt? { | |
| 28 | var node = tree.root | |
| 29 | while let child = node.children.first(where: { $0.range.contains(offset) }) { | |
| 30 | if child.kind == .citation { return citation(child) } | |
| 31 | node = child | |
| 32 | } | |
| 33 | return nil | |
| 34 | } | |
| 35 | ||
| 36 | static func citation(_ node: SyntaxNode) -> CitationAt? { | |
| 37 | let text = node.text as NSString | |
| 38 | let colon = text.range(of: ":") | |
| 39 | guard colon.location != NSNotFound else { return nil } | |
| 40 | let key = try! NSRegularExpression(pattern: CiteProcessor.keyPattern) | |
| 41 | var references: [(range: Range<Int>, key: Range<Int>)] = [] | |
| 42 | func collect(_ node: SyntaxNode) { | |
| 43 | for child in node.children { | |
| 44 | if child.kind == .citationReference { | |
| 45 | let own = child.text | |
| 46 | guard let m = key.firstMatch(in: own, range: NSRange(location: 0, length: (own as NSString).length)) else { continue } | |
| 47 | let start = child.range.lowerBound + m.range.location | |
| 48 | references.append((child.range, start..<(start + m.range.length))) | |
| 49 | } else { | |
| 50 | collect(child) | |
| 51 | } | |
| 52 | } | |
| 53 | } | |
| 54 | collect(node) | |
| 55 | return CitationAt(range: node.range, colon: node.range.lowerBound + colon.location, references: references) | |
| 56 | } | |
| 57 | ||
| 58 | /// The citation keys a caret at `offset` follows, as `org-cite-basic-goto` picks them: the | |
| 59 | /// reference's, or every key of the citation. Nil off a citation. | |
| 60 | public static func keys(at offset: Int, text: String, tree: OrgTree) -> [String]? { | |
| 61 | guard let citation = citation(at: offset, tree: tree) else { return nil } | |
| 62 | let ns = text as NSString | |
| 63 | let keys = citation.references.map { ns.substring(with: NSRange(location: $0.key.lowerBound + 1, length: $0.key.count - 1)) } | |
| 64 | if let reference = citation.references.firstIndex(where: { $0.range.contains(offset) }) { return [keys[reference]] } | |
| 65 | var seen = Set<String>() | |
| 66 | return keys.filter { seen.insert($0).inserted } | |
| 67 | } | |
| 68 | ||
| 69 | /// What Insert Citation… does at `offset`, as `org-cite-make-insert-processor` decides. | |
| 70 | public enum Place: Sendable, Equatable { | |
| 71 | /// Outside a citation: a new one. | |
| 72 | case new | |
| 73 | /// On `[cite/style`: a new style. | |
| 74 | case style | |
| 75 | /// Elsewhere in a citation: a reference added before or after the caret. | |
| 76 | case reference | |
| 77 | /// Inside a key: the key replaced, its prefix and suffix kept. | |
| 78 | case key | |
| 79 | } | |
| 80 | ||
| 81 | public static func place(at offset: Int, tree: OrgTree) -> Place { | |
| 82 | guard let citation = citation(at: offset, tree: tree), offset > citation.range.lowerBound else { return .new } | |
| 83 | if offset <= citation.colon { return .style } | |
| 84 | if let current = citation.references.first(where: { $0.range.contains(offset) }), offset > current.key.lowerBound, offset < current.key.upperBound { | |
| 85 | return .key | |
| 86 | } | |
| 87 | return .reference | |
| 88 | } | |
| 89 | ||
| 90 | /// `@key` with a prefix and suffix around it, a blank between them unless they have one. | |
| 91 | static func reference(_ key: String, prefix: String, suffix: String) -> String { | |
| 92 | var out = "@" + key | |
| 93 | if !prefix.isEmpty { out = prefix + (prefix.last!.isWhitespace ? "" : " ") + out } | |
| 94 | if !suffix.isEmpty { out += (suffix.first!.isWhitespace || ",.:".contains(suffix.first!) ? "" : " ") + suffix } | |
| 95 | return out | |
| 96 | } | |
| 97 | } | |
| 98 | ||
| 99 | /// Insert Citation…'s edit, once the key and style are chosen: `org-cite-insert` with the | |
| 100 | /// basic processor. Outside a citation, `[cite/style:@key]`; on a citation's style, the style | |
| 101 | /// replaced; on its common prefix or before a reference's `@`, a reference before; on its | |
| 102 | /// common suffix or a reference's suffix, one after; on a key, that key replaced. A prefix | |
| 103 | /// and suffix go around the new reference. | |
| 104 | public struct InsertCitation: OrgCommand { | |
| 105 | public var key: String? | |
| 106 | public var style: String? | |
| 107 | public var prefix: String | |
| 108 | public var suffix: String | |
| 109 | ||
| 110 | public init(key: String?, style: String? = nil, prefix: String = "", suffix: String = "") { | |
| 111 | self.key = key | |
| 112 | self.style = style | |
| 113 | self.prefix = prefix | |
| 114 | self.suffix = suffix | |
| 115 | } | |
| 116 | ||
| 117 | public var id: String { "internal.insert-citation" } | |
| 118 | public var title: String { "Insert Citation" } | |
| 119 | ||
| 120 | public func applies(in context: EditContext) -> Bool { true } | |
| 121 | ||
| 122 | public func run(in context: EditContext) -> CommandStep { | |
| 123 | let caret = context.caret | |
| 124 | let styleText = (style?.trimmingCharacters(in: .whitespaces)).flatMap { $0.isEmpty ? nil : "/" + $0 } ?? "" | |
| 125 | func commit(_ range: Range<Int>, _ replacement: String, caret: Int) -> CommandStep { | |
| 126 | .commit(EditResult(baseRevision: context.revision, edits: [TextEdit(range: range, replacement: replacement)], selection: [caret..<caret])) | |
| 127 | } | |
| 128 | let place = Citations.place(at: caret, tree: context.tree) | |
| 129 | if place == .style, let citation = Citations.citation(at: caret, tree: context.tree) { | |
| 130 | guard style != nil else { return .failed("Aborted") } | |
| 131 | // A point in the old style ends up where the deletion leaves it, at the style's start. | |
| 132 | let start = citation.range.lowerBound + 5 | |
| 133 | return commit(start..<citation.colon, styleText, caret: min(caret, start)) | |
| 134 | } | |
| 135 | guard let key, !key.isEmpty else { return .failed("Aborted") } | |
| 136 | let reference = Citations.reference(key, prefix: prefix, suffix: suffix) | |
| 137 | guard place != .new, let citation = Citations.citation(at: caret, tree: context.tree), let first = citation.references.first, | |
| 138 | let last = citation.references.last else { | |
| 139 | let text = "[cite\(styleText):\(reference)]" | |
| 140 | return commit(caret..<caret, text, caret: caret + (text as NSString).length) | |
| 141 | } | |
| 142 | let ns = context.text as NSString | |
| 143 | func before(_ r: (range: Range<Int>, key: Range<Int>)) -> CommandStep { | |
| 144 | let inserted = reference + ";" | |
| 145 | return commit(r.range.lowerBound..<r.range.lowerBound, inserted, caret: caret > r.range.lowerBound ? caret + (inserted as NSString).length : caret) | |
| 146 | } | |
| 147 | func after(_ r: (range: Range<Int>, key: Range<Int>)) -> CommandStep { | |
| 148 | let end = r.range.upperBound | |
| 149 | let inserted = ns.character(at: end - 1) == 59 ? reference + ";" : ";" + reference | |
| 150 | return commit(end..<end, inserted, caret: caret >= end ? caret + (inserted as NSString).length : caret) | |
| 151 | } | |
| 152 | guard let current = citation.references.first(where: { $0.range.contains(caret) }) else { | |
| 153 | // On the common prefix or suffix. | |
| 154 | return caret < first.range.lowerBound ? before(first) : after(last) | |
| 155 | } | |
| 156 | if caret <= current.key.lowerBound { return before(current) } | |
| 157 | if caret >= current.key.upperBound { return after(current) } | |
| 158 | return commit(current.key, "@" + key, caret: current.key.lowerBound) | |
| 159 | } | |
| 160 | } | |
Sources/OrgCore/Commands/Dwim.swift +4 −2 · view
| @@ -12,8 +12,10 @@ public struct OrgDwim: OrgCommand { | ||
| 12 | 12 | public func applies(in context: EditContext) -> Bool { true } |
| 13 | 13 | |
| 14 | 14 | public func run(in context: EditContext) -> CommandStep { |
| 15 | // `+org/dwim-at-point` follows a link first. | |
| 16 | if Links.link(at: context.caret, text: context.text, tree: context.tree) != nil { return OpenLinkAtPoint().run(in: context) } | |
| 15 | // `+org/dwim-at-point` follows a link or citation first. | |
| 16 | if Links.link(at: context.caret, text: context.text, tree: context.tree) != nil || Links.citation(at: context.caret, text: context.text, tree: context.tree) != nil { | |
| 17 | return OpenLinkAtPoint().run(in: context) | |
| 18 | } | |
| 17 | 19 | if TableRecalculate.tblfmLine(in: context) != nil { return TableRecalculate(all: true).run(in: context) } |
| 18 | 20 | if KeyContext.holds("src", in: context) { return ExecuteSrcBlock().run(in: context) } |
| 19 | 21 | if KeyContext.holds("table", in: context) { |
Sources/OrgCore/Completion/IndexCompletion.swift +17 −1 · view
| @@ -30,16 +30,28 @@ public enum CompletionQuery: Sendable, Hashable { | ||
| 30 | 30 | case propertyValues(String) |
| 31 | 31 | /// Words starting with the abbreviation. |
| 32 | 32 | case words(String) |
| 33 | /// The keys of these bibliography files, for `@` in a citation. | |
| 34 | case citationKeys([String]) | |
| 33 | 35 | } |
| 34 | 36 | |
| 35 | 37 | /// What the index answers. |
| 36 | 38 | public struct CompletionResult: Sendable, Equatable { |
| 37 | 39 | public var items: [CompletionItem] = [] |
| 38 | 40 | public var strings: [String] = [] |
| 41 | /// Text shown after each string, by string. | |
| 42 | public var annotations: [String: String] = [:] | |
| 39 | 43 | |
| 40 | public init(items: [CompletionItem] = [], strings: [String] = []) { | |
| 44 | public init(items: [CompletionItem] = [], strings: [String] = [], annotations: [String: String] = [:]) { | |
| 41 | 45 | self.items = items |
| 42 | 46 | self.strings = strings |
| 47 | self.annotations = annotations | |
| 48 | } | |
| 49 | ||
| 50 | /// The keys of bibliography entries, each with its authors, year and title. | |
| 51 | public init(entries: [BibEntry]) { | |
| 52 | self.init(strings: entries.map(\.key), annotations: Dictionary(entries.map { entry in | |
| 53 | (entry.key, [entry.authors, entry.year, entry.title].compactMap { $0 }.joined(separator: " ")) | |
| 54 | }) { a, _ in a }) | |
| 43 | 55 | } |
| 44 | 56 | } |
| 45 | 57 | |
| @@ -57,6 +69,10 @@ extension OrgCompletion { | ||
| 57 | 69 | filled.candidates = matching(filled.pool, completion.typed, fuzzy: fuzzy, ignoringCase: true, sorted: false) |
| 58 | 70 | case .word: |
| 59 | 71 | filled = Dabbrev.adding(result.strings, to: completion) |
| 72 | case .citationKey: | |
| 73 | filled.pool = result.strings | |
| 74 | filled.annotations = result.annotations | |
| 75 | filled.candidates = matching(result.strings, completion.typed, fuzzy: fuzzy) | |
| 60 | 76 | default: |
| 61 | 77 | break |
| 62 | 78 | } |
Sources/OrgCore/Completion/OrgCompletion.swift +23 −2 · view
| @@ -5,12 +5,12 @@ import Foundation | ||
| 5 | 5 | // after `[[`, workspace tags and org-tempo's `<` templates are added, and snippet triggers |
| 6 | 6 | // where no org context offers anything. Headings after `[[id:`, notes after `[[denote:` and |
| 7 | 7 | // property values come from the buffer at once and from the index when it answers |
| 8 | // `Completion.query`. | |
| 8 | // `Completion.query`; keys after `@` in a citation come from the bibliography files. | |
| 9 | 9 | |
| 10 | 10 | public struct Completion: Sendable, Equatable { |
| 11 | 11 | public enum Kind: String, Sendable { |
| 12 | 12 | case keyword, keywordValue, link, entity, tag, todo, heading, drawer, property, srcLanguage, srcHeader, clocktable, template, snippet |
| 13 | case idLink, denoteLink, propertyValue, word | |
| 13 | case idLink, denoteLink, propertyValue, word, citationKey | |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | public var kind: Kind |
| @@ -34,9 +34,12 @@ public struct Completion: Sendable, Equatable { | ||
| 34 | 34 | public var templates: [StructureTemplate] = [] |
| 35 | 35 | /// The snippets whose triggers are the candidates, for `.snippet`; choosing one expands it. |
| 36 | 36 | public var snippets: [Snippet] = [] |
| 37 | /// What the list shows after a candidate: a citation key's authors, year and title. | |
| 38 | public var annotations: [String: String] = [:] | |
| 37 | 39 | |
| 38 | 40 | /// How the list shows `candidate`: a template with the block it makes. |
| 39 | 41 | public func label(_ candidate: String) -> String { |
| 42 | if let annotation = annotations[candidate], !annotation.isEmpty { return candidate + " " + annotation } | |
| 40 | 43 | if kind == .idLink || kind == .denoteLink, let item = item(candidate), candidate == item.title, !item.path.isEmpty { |
| 41 | 44 | return candidate + " " + (item.path as NSString).lastPathComponent |
| 42 | 45 | } |
| @@ -186,6 +189,15 @@ public enum OrgCompletion { | ||
| 186 | 189 | let from = start + NSMaxRange((line as NSString).range(of: "#+")) |
| 187 | 190 | return make(.keyword, from: from, caseDouble(fileOptions)) |
| 188 | 191 | } |
| 192 | // Keys after `@` in a citation, from its bibliography files. | |
| 193 | if let typed = citationKeyTyped(toHere) { | |
| 194 | let directory = context.options.filePath.map { ($0 as NSString).deletingLastPathComponent } | |
| 195 | let files = Bibliography.files(in: context.text, directory: directory, global: context.tree.settings.citeGlobalBibliography) | |
| 196 | var completion = Completion(kind: .citationKey, range: (caret - typed.utf16.count)..<caret, candidates: []) | |
| 197 | completion.typed = typed | |
| 198 | completion.query = .citationKeys(files) | |
| 199 | return completion | |
| 200 | } | |
| 189 | 201 | // Headings after `[[id:`, Denote's notes after `[[denote:`. |
| 190 | 202 | if let target = linkTarget(context, lineStart: start, toHere: toHere) { |
| 191 | 203 | var completion = Completion(kind: target.type == "id" ? .idLink : .denoteLink, range: target.typed, candidates: []) |
| @@ -272,6 +284,15 @@ public enum OrgCompletion { | ||
| 272 | 284 | |
| 273 | 285 | // MARK: - Sources |
| 274 | 286 | |
| 287 | private static let citationKeyBefore = try! NSRegularExpression(pattern: "\\[cite(?:/[-/_\\p{L}\\p{N}]*)?:[^\\[\\]]*@([-.:?!`'/*+|(){}<>&_^$#%~\\p{L}\\p{N}]*)$") | |
| 288 | ||
| 289 | /// What's typed of a citation key: the key characters after the last `@` of a citation | |
| 290 | /// that isn't closed before the caret. | |
| 291 | static func citationKeyTyped(_ toHere: String) -> String? { | |
| 292 | guard toHere.contains("[cite"), let m = citationKeyBefore.firstMatch(in: toHere, range: NSRange(location: 0, length: (toHere as NSString).length)) else { return nil } | |
| 293 | return (toHere as NSString).substring(with: m.range(at: 1)) | |
| 294 | } | |
| 295 | ||
| 275 | 296 | /// Upper and lower case of each, as `org-pcomplete-case-double`. |
| 276 | 297 | static func caseDouble(_ list: [String]) -> [String] { list.flatMap { [$0.uppercased(), $0.lowercased()] } } |
| 277 | 298 | |
Sources/OrgCore/Export/Citations.swift +8 −11 · view
| @@ -381,20 +381,17 @@ struct CiteProcessor { | ||
| 381 | 381 | // MARK: - Building |
| 382 | 382 | |
| 383 | 383 | /// The citations of `text` (as written, nocite citations included) worked out in document |
| 384 | /// order, then the bibliography; nil when the export leaves citations alone. | |
| 385 | init?(text: String, directory: URL?) { | |
| 384 | /// order, then the bibliography; nil when the export leaves citations alone. `global` is | |
| 385 | /// `org-cite-global-bibliography`, read after the file's own `#+bibliography:` files. | |
| 386 | init?(text: String, directory: URL?, global: [String] = []) { | |
| 386 | 387 | guard text.containsIgnoringASCIICase("[cite") else { return nil } |
| 387 | 388 | let settings = Self.exportSettings(text) |
| 388 | 389 | if let settings, settings.processor != "basic" { return nil } |
| 389 | // Each `#+bibliography:` names one file. | |
| 390 | for m in text.matches(of: #/(?mi)^[ \t]*#\+bibliography:[ \t]*(.*?)[ \t]*$/#) { | |
| 391 | for name in [String(m.1)].map({ $0.count > 1 && $0.hasPrefix("\"") && $0.hasSuffix("\"") ? String($0.dropFirst().dropLast()) : $0 }) where !name.isEmpty { | |
| 392 | let path = OrgPaths.expandingTilde(name) | |
| 393 | let url = path.hasPrefix("/") ? URL(fileURLWithPath: path) : (directory ?? URL(fileURLWithPath: "/")).appendingPathComponent(path) | |
| 394 | guard let data = try? Data(contentsOf: url) else { continue } | |
| 395 | let parsed = url.pathExtension.lowercased() == "json" ? Self.parseJSON(data) : Self.parseBibTeX(String(decoding: data, as: UTF8.self)) | |
| 396 | for (key, entry) in parsed where entries[key] == nil { entries[key] = entry } | |
| 397 | } | |
| 390 | for path in Bibliography.files(in: text, directory: directory?.path, global: global) { | |
| 391 | let url = URL(fileURLWithPath: path) | |
| 392 | guard let data = try? Data(contentsOf: url) else { continue } | |
| 393 | let parsed = url.pathExtension.lowercased() == "json" ? Self.parseJSON(data) : Self.parseBibTeX(String(decoding: data, as: UTF8.self)) | |
| 394 | for (key, entry) in parsed where entries[key] == nil { entries[key] = entry } | |
| 398 | 395 | } |
| 399 | 396 | let tree = OrgParser.parse(text) |
| 400 | 397 | // Keywords (`#+TITLE`) aren't part of the document Org processes citations in. |
Sources/OrgCore/Export/HTMLExport.swift +1 −1 · view
| @@ -64,7 +64,7 @@ public enum HTMLExport { | ||
| 64 | 64 | renderer.inTitle = true |
| 65 | 65 | let titleHTML = renderer.inlineString(title) |
| 66 | 66 | renderer.inTitle = false |
| 67 | renderer.citations = CiteProcessor(text: text, directory: directory) | |
| 67 | renderer.citations = CiteProcessor(text: text, directory: directory, global: settings.citeGlobalBibliography) | |
| 68 | 68 | var header = options.title ? "<h1 class=\"title\">\(titleHTML)</h1>\n" : "" |
| 69 | 69 | let byline = [options.author ? meta.author : nil, options.date ? meta.date : nil].compactMap { $0 }.filter { !$0.isEmpty } |
| 70 | 70 | if !byline.isEmpty { header += "<p class=\"byline\">\(byline.map(HTMLRenderer.escape).joined(separator: " · "))</p>\n" } |
Sources/OrgCore/Export/MarkdownExport.swift +1 −1 · view
| @@ -17,7 +17,7 @@ public enum MarkdownExport { | ||
| 17 | 17 | renderer.inTitle = true |
| 18 | 18 | if options.title, !bodyOnly, let title = HTMLExport.metadata(text, settings: settings).title { out = "# " + renderer.inlineString(title) + "\n\n" } |
| 19 | 19 | renderer.inTitle = false |
| 20 | renderer.citations = CiteProcessor(text: text, directory: directory) | |
| 20 | renderer.citations = CiteProcessor(text: text, directory: directory, global: settings.citeGlobalBibliography) | |
| 21 | 21 | out += renderer.document(renderer.citations == nil ? text : renderer.citations!.inliningNotes(CiteProcessor.removingNocite(text))) |
| 22 | 22 | return out.trimmingCharacters(in: .newlines) + "\n" |
| 23 | 23 | } |
Sources/OrgCore/Export/ODTExport.swift +1 −1 · view
| @@ -64,7 +64,7 @@ public enum ODTExport { | ||
| 64 | 64 | renderer.inTitle = false |
| 65 | 65 | renderer.author = authorName |
| 66 | 66 | renderer.dated = !(meta.date ?? "").isEmpty |
| 67 | renderer.citations = CiteProcessor(text: text, directory: directory) | |
| 67 | renderer.citations = CiteProcessor(text: text, directory: directory, global: settings.citeGlobalBibliography) | |
| 68 | 68 | let body = renderer.document(renderer.citations == nil ? text : renderer.citations!.inliningNotes(CiteProcessor.removingNocite(text))) |
| 69 | 69 | let date = options.date ? meta.date.flatMap { $0.isEmpty ? nil : renderer.inlineString($0) } : nil |
| 70 | 70 | if let failure = renderer.failure { throw failure } |
Sources/OrgCore/Keymap/PresetDoom.swift +4 · view
| @@ -356,6 +356,10 @@ extension KeymapPreset { | ||
| 356 | 356 | command = "org.link.insert" |
| 357 | 357 | mode = "normal" |
| 358 | 358 | [[bind]] |
| 359 | keys = "SPC m @" | |
| 360 | command = "app.cite.insert" | |
| 361 | mode = "normal" | |
| 362 | [[bind]] | |
| 359 | 363 | keys = "SPC m l s" |
| 360 | 364 | command = "org.link.store" |
| 361 | 365 | mode = "normal" |
Sources/OrgCore/Keymap/PresetEmacs.swift +3 · view
| @@ -118,6 +118,9 @@ extension KeymapPreset { | ||
| 118 | 118 | keys = "C-c C-l" |
| 119 | 119 | command = "org.link.insert" |
| 120 | 120 | [[bind]] |
| 121 | keys = "C-c C-x @" | |
| 122 | command = "app.cite.insert" | |
| 123 | [[bind]] | |
| 121 | 124 | keys = "C-c l" |
| 122 | 125 | command = "org.link.store" |
| 123 | 126 | [[bind]] |
Sources/OrgCore/Links/Bibliography.swift added +217 · view
| @@ -0,0 +1,217 @@ | ||
| 1 | import Foundation | |
| 2 | ||
| 3 | /// An entry of a bibliography file, as Insert Citation… offers it and following a citation | |
| 4 | /// shows it. | |
| 5 | public struct BibEntry: Sendable, Equatable { | |
| 6 | public var key: String | |
| 7 | /// Field names in lower case; values as `org-cite-basic` reads them, braces kept. | |
| 8 | public var fields: [String: String] | |
| 9 | /// The bibliography file the entry is in. | |
| 10 | public var file: String | |
| 11 | ||
| 12 | public init(key: String, fields: [String: String], file: String) { | |
| 13 | self.key = key | |
| 14 | self.fields = fields | |
| 15 | self.file = file | |
| 16 | } | |
| 17 | ||
| 18 | public var author: String? { field("author") ?? field("editor") } | |
| 19 | public var title: String? { field("title") } | |
| 20 | ||
| 21 | /// The `year` field, else the year of `date`, as `org-cite-basic--get-year` reads them. | |
| 22 | public var year: String? { | |
| 23 | if let year = field("year") { return year } | |
| 24 | return fields["date"].flatMap { $0.firstMatch(of: /^([0-9]{4})(?:[^0-9]|$)/) }.map { String($0.1) } | |
| 25 | } | |
| 26 | ||
| 27 | /// A field without braces and with blanks collapsed; nil when missing or empty. | |
| 28 | public func field(_ name: String) -> String? { | |
| 29 | fields[name].flatMap(Self.clean) | |
| 30 | } | |
| 31 | ||
| 32 | static func clean(_ value: String) -> String? { | |
| 33 | let clean = value.replacingOccurrences(of: "[{}]", with: "", options: .regularExpression) | |
| 34 | .replacingOccurrences(of: "\\s+", with: " ", options: .regularExpression).trimmingCharacters(in: .whitespaces) | |
| 35 | return clean.isEmpty ? nil : clean | |
| 36 | } | |
| 37 | ||
| 38 | /// The line a chooser shows: the key, then the authors (`;` between them), the year and | |
| 39 | /// the title, as `org-cite-basic`'s completion table has them. | |
| 40 | public var label: String { | |
| 41 | [key, authors, year, title].compactMap { $0 }.joined(separator: " ") | |
| 42 | } | |
| 43 | ||
| 44 | /// The authors (else the editors) separated by `;`: split at each `and` outside braces. | |
| 45 | public var authors: String? { | |
| 46 | guard let raw = fields["author"] ?? fields["editor"] else { return nil } | |
| 47 | var names: [String] = [] | |
| 48 | var current = "" | |
| 49 | var depth = 0 | |
| 50 | var rest = Substring(raw) | |
| 51 | while let c = rest.first { | |
| 52 | if depth == 0, rest.hasPrefix(" and ") { | |
| 53 | names.append(current) | |
| 54 | current = "" | |
| 55 | rest = rest.dropFirst(5) | |
| 56 | continue | |
| 57 | } | |
| 58 | if c == "{" { depth += 1 } else if c == "}" { depth = max(0, depth - 1) } | |
| 59 | current.append(c) | |
| 60 | rest = rest.dropFirst() | |
| 61 | } | |
| 62 | names.append(current) | |
| 63 | let clean = names.compactMap(Self.clean) | |
| 64 | return clean.isEmpty ? nil : clean.joined(separator: "; ") | |
| 65 | } | |
| 66 | ||
| 67 | /// Authors, year, title and where it was published, for showing the entry. | |
| 68 | public var summary: String { | |
| 69 | var parts: [String] = [] | |
| 70 | let who = [author, year.map { "(\($0))" }].compactMap { $0 }.joined(separator: " ") | |
| 71 | if !who.isEmpty { parts.append(who) } | |
| 72 | if let title { parts.append(title) } | |
| 73 | if let from = field("journal") ?? field("journaltitle") ?? field("booktitle") ?? field("container-title") ?? field("publisher") | |
| 74 | ?? field("institution") ?? field("school") { | |
| 75 | parts.append(from) | |
| 76 | } | |
| 77 | return parts.map { $0.hasSuffix(".") ? $0 : $0 + "." }.joined(separator: " ") | |
| 78 | } | |
| 79 | ||
| 80 | /// The `file` field's files: separated by `;`, each a path or JabRef's and Zotero's | |
| 81 | /// `description:path:type`, relative to the bibliography's folder unless absolute. | |
| 82 | public var files: [String] { | |
| 83 | guard let value = fields["file"] else { return [] } | |
| 84 | let folder = (file as NSString).deletingLastPathComponent | |
| 85 | return value.components(separatedBy: ";").compactMap { part in | |
| 86 | var path = part.trimmingCharacters(in: .whitespaces) | |
| 87 | if !FileManager.default.fileExists(atPath: OrgPaths.expandingTilde(path)), let m = path.firstMatch(of: /^[^:]*:(.+):[^:]*$/) { | |
| 88 | path = String(m.1) | |
| 89 | } | |
| 90 | path = path.replacingOccurrences(of: "\\:", with: ":") | |
| 91 | guard !path.isEmpty else { return nil } | |
| 92 | let expanded = OrgPaths.expandingTilde(path) | |
| 93 | return expanded.hasPrefix("/") ? expanded : ((folder as NSString).appendingPathComponent(expanded) as NSString).standardizingPath | |
| 94 | } | |
| 95 | } | |
| 96 | ||
| 97 | /// The DOI without a resolver in front. | |
| 98 | public var doi: String? { | |
| 99 | field("doi").map { $0.replacingOccurrences(of: "^(?:https?://(?:dx\\.)?doi\\.org/|doi:)", with: "", options: [.regularExpression, .caseInsensitive]) } | |
| 100 | } | |
| 101 | ||
| 102 | public var url: String? { field("url") } | |
| 103 | } | |
| 104 | ||
| 105 | /// Bibliography files (BibTeX, BibLaTeX and CSL-JSON) read for Insert Citation…, key | |
| 106 | /// completion and following citations. | |
| 107 | public enum Bibliography { | |
| 108 | /// The files a buffer's `#+bibliography:` lines name, one each, quotes removed and | |
| 109 | /// relative to `directory`, then the global ones, each once, as | |
| 110 | /// `org-cite-list-bibliography-files` lists them. | |
| 111 | public static func files(in text: String, directory: String?, global: [String] = []) -> [String] { | |
| 112 | var files: [String] = [] | |
| 113 | if text.containsIgnoringASCIICase("#+bibliography") { | |
| 114 | for m in text.matches(of: #/(?mi)^[ \t]*#\+bibliography:[ \t]*(.*?)[ \t]*$/#) { | |
| 115 | var name = String(m.1) | |
| 116 | if name.count > 1, name.hasPrefix("\""), name.hasSuffix("\"") { name = String(name.dropFirst().dropLast()) } | |
| 117 | guard !name.isEmpty else { continue } | |
| 118 | let path = OrgPaths.expandingTilde(name) | |
| 119 | files.append(path.hasPrefix("/") ? path : ((directory ?? "/") as NSString).appendingPathComponent(path)) | |
| 120 | } | |
| 121 | } | |
| 122 | var seen = Set<String>() | |
| 123 | return (files + global.map { OrgPaths.expandingTilde($0) }).filter { seen.insert($0).inserted } | |
| 124 | } | |
| 125 | ||
| 126 | /// The entries of a file: CSL-JSON for `.json`, BibTeX otherwise, with `@string`s expanded | |
| 127 | /// and `crossref` fields filled in, sorted by key. | |
| 128 | public static func entries(_ data: Data, path: String) -> [BibEntry] { | |
| 129 | if (path as NSString).pathExtension.lowercased() == "json" { | |
| 130 | return CiteProcessor.parseJSON(data).map { key, fields in | |
| 131 | BibEntry(key: key, fields: Dictionary(fields.map { ($0.key.lowercased(), $0.value) }) { a, _ in a }, file: path) | |
| 132 | }.sorted { $0.key < $1.key } | |
| 133 | } | |
| 134 | let parsed = resolvingCrossrefs(CiteProcessor.parseBibTeX(String(decoding: data, as: UTF8.self))) | |
| 135 | return parsed.map { BibEntry(key: $0.key, fields: $0.value, file: path) }.sorted { $0.key < $1.key } | |
| 136 | } | |
| 137 | ||
| 138 | /// BibTeX's `crossref`: fields an entry lacks come from the entry it names; that entry's | |
| 139 | /// `title` becomes `booktitle`, as BibLaTeX maps it. | |
| 140 | static func resolvingCrossrefs(_ entries: [String: CiteProcessor.Entry]) -> [String: CiteProcessor.Entry] { | |
| 141 | var result = entries | |
| 142 | let lowered = Dictionary(entries.map { ($0.key.lowercased(), $0.value) }) { a, _ in a } | |
| 143 | for (key, entry) in entries { | |
| 144 | guard let target = entry["crossref"]?.trimmingCharacters(in: CharacterSet(charactersIn: "{} ")), let parent = lowered[target.lowercased()] else { continue } | |
| 145 | var filled = entry | |
| 146 | for (field, value) in parent where !["id", "type", "crossref"].contains(field) { | |
| 147 | if field == "title" { | |
| 148 | if filled["booktitle"] == nil { filled["booktitle"] = value } | |
| 149 | if filled["title"] == nil { filled["title"] = value } | |
| 150 | } else if filled[field] == nil { | |
| 151 | filled[field] = value | |
| 152 | } | |
| 153 | } | |
| 154 | result[key] = filled | |
| 155 | } | |
| 156 | return result | |
| 157 | } | |
| 158 | ||
| 159 | /// The line (from 1) an entry starts on in a BibTeX file's text, or `"id"`'s object in a | |
| 160 | /// CSL-JSON file, as `org-cite-basic-goto` finds it. | |
| 161 | public static func line(of key: String, in text: String, json: Bool) -> Int? { | |
| 162 | let quoted = NSRegularExpression.escapedPattern(for: key) | |
| 163 | let pattern = json ? "\"id\":[ \\t]*\"\(quoted)\"" : "@[A-Za-z]+[ \\t\\n]*[{(][ \\t\\n]*\(quoted)[ \\t\\n]*," | |
| 164 | guard let range = text.range(of: pattern, options: .regularExpression) else { return nil } | |
| 165 | return text[..<range.lowerBound].reduce(1) { $1 == "\n" ? $0 + 1 : $0 } | |
| 166 | } | |
| 167 | } | |
| 168 | ||
| 169 | /// Parsed bibliography files kept by modification date, so a file is read again only when it | |
| 170 | /// changes. | |
| 171 | public final class BibliographyCache: @unchecked Sendable { | |
| 172 | public static let shared = BibliographyCache() | |
| 173 | ||
| 174 | private let lock = NSLock() | |
| 175 | private var files: [String: (modified: Date, entries: [BibEntry])] = [:] | |
| 176 | private let modified: (String) -> Date? | |
| 177 | private let read: (String) -> Data? | |
| 178 | ||
| 179 | public init( | |
| 180 | modified: @escaping (String) -> Date? = { try? FileManager.default.attributesOfItem(atPath: $0)[.modificationDate] as? Date }, | |
| 181 | read: @escaping (String) -> Data? = { FileManager.default.contents(atPath: $0) } | |
| 182 | ) { | |
| 183 | self.modified = modified | |
| 184 | self.read = read | |
| 185 | } | |
| 186 | ||
| 187 | /// The entries of `paths`, the first file's entry winning for a key in several. Files that | |
| 188 | /// can't be read are left out. Reads files, so callers run it off the main thread. | |
| 189 | public func entries(_ paths: [String]) -> [BibEntry] { | |
| 190 | var seen = Set<String>() | |
| 191 | var all: [BibEntry] = [] | |
| 192 | for path in paths { | |
| 193 | for entry in entries(of: (path as NSString).resolvingSymlinksInPath, as: path) where seen.insert(entry.key).inserted { all.append(entry) } | |
| 194 | } | |
| 195 | return all | |
| 196 | } | |
| 197 | ||
| 198 | /// `entries` on another thread. | |
| 199 | @concurrent | |
| 200 | public func load(_ paths: [String]) async -> [BibEntry] { | |
| 201 | entries(paths) | |
| 202 | } | |
| 203 | ||
| 204 | private func entries(of real: String, as path: String) -> [BibEntry] { | |
| 205 | guard let date = modified(real) else { return [] } | |
| 206 | lock.lock() | |
| 207 | let cached = files[real] | |
| 208 | lock.unlock() | |
| 209 | if let cached, cached.modified == date { return cached.entries.map { var e = $0; e.file = path; return e } } | |
| 210 | guard let data = read(real) else { return [] } | |
| 211 | let parsed = Bibliography.entries(data, path: real) | |
| 212 | lock.lock() | |
| 213 | files[real] = (date, parsed) | |
| 214 | lock.unlock() | |
| 215 | return parsed.map { var e = $0; e.file = path; return e } | |
| 216 | } | |
| 217 | } | |
Sources/OrgCore/Links/Links.swift +15 −1 · view
| @@ -256,19 +256,24 @@ public enum Links { | ||
| 256 | 256 | } |
| 257 | 257 | } |
| 258 | 258 | |
| 259 | /// `org-open-at-point` on a link or a timestamp (C-c C-o). | |
| 259 | /// `org-open-at-point` on a link, a citation or a timestamp (C-c C-o). A citation is followed | |
| 260 | /// as a `cite` link whose path is its keys, separated by `;`. | |
| 260 | 261 | public struct OpenLinkAtPoint: OrgCommand { |
| 261 | 262 | public init() {} |
| 262 | 263 | public var id: String { "org.link.open" } |
| 263 | 264 | public var title: String { "Open Link" } |
| 264 | 265 | public func applies(in context: EditContext) -> Bool { |
| 265 | 266 | Links.link(at: context.caret, text: context.text, tree: context.tree) != nil |
| 267 | || Citations.keys(at: context.caret, text: context.text, tree: context.tree) != nil | |
| 266 | 268 | || Links.timestampDays(at: context.caret, text: context.text) != nil |
| 267 | 269 | } |
| 268 | 270 | public func run(in context: EditContext) -> CommandStep { |
| 269 | 271 | if let found = Links.link(at: context.caret, text: context.text, tree: context.tree) { |
| 270 | 272 | return .external(.openLink(found.link)) |
| 271 | 273 | } |
| 274 | if let link = Links.citation(at: context.caret, text: context.text, tree: context.tree) { | |
| 275 | return .external(.openLink(link)) | |
| 276 | } | |
| 272 | 277 | if let days = Links.timestampDays(at: context.caret, text: context.text) { |
| 273 | 278 | return .external(.agenda(start: days.start, days: days.count)) |
| 274 | 279 | } |
| @@ -276,6 +281,15 @@ public struct OpenLinkAtPoint: OrgCommand { | ||
| 276 | 281 | } |
| 277 | 282 | } |
| 278 | 283 | |
| 284 | extension Links { | |
| 285 | /// The citation at `offset` as a `cite` link to follow: its keys, separated by `;`. | |
| 286 | public static func citation(at offset: Int, text: String, tree: OrgTree) -> OrgLink? { | |
| 287 | guard let keys = Citations.keys(at: offset, text: text, tree: tree), !keys.isEmpty else { return nil } | |
| 288 | let path = keys.joined(separator: ";") | |
| 289 | return OrgLink(type: "cite", path: path, raw: "cite:" + path) | |
| 290 | } | |
| 291 | } | |
| 292 | ||
| 279 | 293 | extension Links { |
| 280 | 294 | /// An `elisp:` link's form evaluated in `Elisp`: `org-link--open-elisp`'s message, the |
| 281 | 295 | /// error's, or why it needs Emacs. |
Sources/OrgCore/Parser/Settings.swift +3 · view
| @@ -57,6 +57,8 @@ public struct OrgSettings: Sendable, Equatable { | ||
| 57 | 57 | /// `org-attach-id-dir` and `org-attach-use-inheritance` (nil for `selective`), for export. |
| 58 | 58 | public var attachIDDir = "data/" |
| 59 | 59 | public var attachUseInheritance: Bool? |
| 60 | /// `org-cite-global-bibliography`: files every document's citations are read from. | |
| 61 | public var citeGlobalBibliography: [String] = [] | |
| 60 | 62 | |
| 61 | 63 | /// `org-remove-uninherited-tags` for one tag. |
| 62 | 64 | public func inheritsTag(_ tag: String) -> Bool { |
| @@ -154,6 +156,7 @@ enum SettingsScanner { | ||
| 154 | 156 | settings.tagsExcludedFromInheritance = defaults.tagsExcludedFromInheritance |
| 155 | 157 | settings.attachIDDir = defaults.attachIDDir |
| 156 | 158 | settings.attachUseInheritance = defaults.attachUseInheritance |
| 159 | settings.citeGlobalBibliography = defaults.citeGlobalBibliography | |
| 157 | 160 | settings.setupKeywords = defaults.setupKeywords |
| 158 | 161 | settings.startup = startup |
| 159 | 162 | return settings |
Sources/OrgEditorAppKit/EditorCommands.swift +1 · view
| @@ -75,6 +75,7 @@ public enum EditorCommands { | ||
| 75 | 75 | EditorCommand(id: "org.table.shrink", title: "Shrink Table Columns with Widths", action: .view), |
| 76 | 76 | EditorCommand(id: "org.table.expand", title: "Expand Table Columns", action: .view), |
| 77 | 77 | EditorCommand(id: "org.link.insert", title: "Insert Link…", action: .app), |
| 78 | EditorCommand(id: "app.cite.insert", title: "Insert Citation…", action: .app), | |
| 78 | 79 | EditorCommand(id: "org.link.store", title: "Store Link", action: .app), |
| 79 | 80 | EditorCommand(id: "org.id.store-link", title: "Store ID Link", action: .app), |
| 80 | 81 | EditorCommand(id: "org.subtree.paste", title: "Paste Subtree", action: .app), |
Sources/OrgEditorAppKit/OrgEditor.swift +1 · view
| @@ -169,6 +169,7 @@ public final class OrgEditor: NSObject { | ||
| 169 | 169 | } |
| 170 | 170 | view.onCommandClick = { [weak self, unowned view] offset in |
| 171 | 171 | guard let self, Links.link(at: offset, text: self.document.text, tree: self.document.tree) != nil |
| 172 | || Links.citation(at: offset, text: self.document.text, tree: self.document.tree) != nil | |
| 172 | 173 | || Links.timestampDays(at: offset, text: self.document.text) != nil else { return false } |
| 173 | 174 | self.active = view |
| 174 | 175 | self.setCaret(offset) |
Sources/Orgstar/ContentView.swift +23 −1 · view
| @@ -131,6 +131,8 @@ struct ContentView: View { | ||
| 131 | 131 | @State private var showingTemplate = false |
| 132 | 132 | /// Replace in Files, Rename Tag or Rename TODO Keyword, with the text to start from. |
| 133 | 133 | @State private var replacing: (kind: ReplaceKind, initial: String)? |
| 134 | /// A followed citation's bibliography entry. | |
| 135 | @State private var citationEntry: CitationEntry? | |
| 134 | 136 | @AppStorage("showTabBar") private var showTabBar = false |
| 135 | 137 | /// This window's panes. |
| 136 | 138 | @State private var window: WindowModel? |
| @@ -549,6 +551,9 @@ struct ContentView: View { | ||
| 549 | 551 | } |
| 550 | 552 | } |
| 551 | 553 | } |
| 554 | .citationAlert($citationEntry) { [session, workspace, commands] link in | |
| 555 | if let message = LinkOpener.open(link, session: session, workspace: workspace, ask: commands.ask) { commands.show(message) } | |
| 556 | } | |
| 552 | 557 | .alert(errorTitle, isPresented: errorShown) { |
| 553 | 558 | Button("OK") { |
| 554 | 559 | workspace.lastError = nil |
| @@ -961,6 +966,19 @@ struct ContentView: View { | ||
| 961 | 966 | return actions |
| 962 | 967 | } |
| 963 | 968 | |
| 969 | /// Insert Citation… and following citations. | |
| 970 | private var citationActions: CitationActions { | |
| 971 | var actions = CitationActions( | |
| 972 | session: session, context: { [commands] in commands.editor?.context() }, | |
| 973 | perform: { [commands] in _ = commands.editor?.perform($0) }, | |
| 974 | show: { [commands] in commands.show($0) }, ask: { [commands] in commands.ask($0, reply: $1) }, | |
| 975 | present: { citationEntry = $0 }) | |
| 976 | #if APPSTORE | |
| 977 | actions.reach = { [workspace] in GrantAccess.reach($0, workspace: workspace) } | |
| 978 | #endif | |
| 979 | return actions | |
| 980 | } | |
| 981 | ||
| 964 | 982 | /// org-attach's commands for the entry at the caret. |
| 965 | 983 | private var attachActions: AttachActions { |
| 966 | 984 | AttachActions( |
| @@ -1136,7 +1154,9 @@ struct ContentView: View { | ||
| 1136 | 1154 | private func runExternal(_ request: ExternalRequest) { |
| 1137 | 1155 | switch request { |
| 1138 | 1156 | case .openLink(let link): |
| 1139 | if let message = LinkOpener.open(link, session: session, workspace: workspace, ask: commands.ask, elisp: runElispLink) { commands.show(message) } | |
| 1157 | if let message = LinkOpener.open(link, session: session, workspace: workspace, ask: commands.ask, elisp: runElispLink, citation: citationActions.follow) { | |
| 1158 | commands.show(message) | |
| 1159 | } | |
| 1140 | 1160 | // `org-occur` for a regexp link, once the editor shows the file. |
| 1141 | 1161 | if let regexp = Links.regexpSearch(link) { |
| 1142 | 1162 | DispatchQueue.main.async { commands.editor?.perform(SparseTreeCommand(), answers: ["sparse": "/", "regexp": regexp]) } |
| @@ -1581,6 +1601,8 @@ struct ContentView: View { | ||
| 1581 | 1601 | roamActions.follow(request) |
| 1582 | 1602 | case let id where id.hasPrefix("app.dailies.") || id.hasPrefix("app.node."): |
| 1583 | 1603 | roamActions.run(id) |
| 1604 | case "app.cite.insert": | |
| 1605 | citationActions.insert() | |
| 1584 | 1606 | default: |
| 1585 | 1607 | if let editor = commands.editor { editor.run(id) } else { commands.show(String(localized: "No file is open")) } |
| 1586 | 1608 | } |
Sources/Orgstar/LinkOpener.swift +7 −2 · view
| @@ -6,9 +6,10 @@ import OrgCore | ||
| 6 | 6 | @MainActor |
| 7 | 7 | enum LinkOpener { |
| 8 | 8 | /// Returns a message when the link can't be followed. |
| 9 | /// `ask` picks among a query link's matches; `elisp` runs an `elisp:` link's form. | |
| 9 | /// `ask` picks among a query link's matches; `elisp` runs an `elisp:` link's form; | |
| 10 | /// `citation` shows a citation's entry. | |
| 10 | 11 | static func open(_ link: OrgLink, session: DocumentSession, workspace: WorkspaceModel, ask: @escaping (Prompt, @escaping (String?) -> Void) -> Void, |
| 11 | elisp: ((String) -> Void)? = nil) -> String? { | |
| 12 | elisp: ((String) -> Void)? = nil, citation: (([String]) -> Void)? = nil) -> String? { | |
| 12 | 13 | #if APPSTORE |
| 13 | 14 | // A file outside the sidebar's folders needs access to its folder first. |
| 14 | 15 | if link.type == "file", !link.path.isEmpty, |
| @@ -31,6 +32,10 @@ enum LinkOpener { | ||
| 31 | 32 | guard let elisp else { return "orgstar doesn't run elisp links here" } |
| 32 | 33 | elisp(form) |
| 33 | 34 | return nil |
| 35 | case .citation(let keys): | |
| 36 | guard let citation else { return "orgstar doesn't follow citations here" } | |
| 37 | citation(keys) | |
| 38 | return nil | |
| 34 | 39 | } |
| 35 | 40 | } |
| 36 | 41 | } |
Sources/Orgstar/OrgstarApp.swift +1 −1 · view
| @@ -762,7 +762,7 @@ struct OrgMenuItems: View { | ||
| 762 | 762 | ("Dates and Timers", ["org.schedule", "org.deadline", "org.timestamp.", "org.timer."]), |
| 763 | 763 | ("Lists", ["org.item.", "org.checkbox."]), |
| 764 | 764 | ("Tables", ["org.table", "app.table-", "app.plot"]), |
| 765 | ("Links and Footnotes", ["org.link.", "org.id.", "org.footnote."]), | |
| 765 | ("Links and Footnotes", ["org.link.", "org.id.", "org.footnote.", "app.cite."]), | |
| 766 | 766 | ("Blocks", ["org.babel.", "org.structure-template", "org.edit-special", "org.dblock.", "org.clock.report", "org.denote."]), |
| 767 | 767 | ("Text", ["org.emphasize", "org.fill-"]), |
| 768 | 768 | ("Attachments", ["app.attach."]), |
Sources/OrgstarMobile/EditorScreen.swift +15 · view
| @@ -72,6 +72,8 @@ struct EditorScreen: View { | ||
| 72 | 72 | @State private var photos: [PhotosPickerItem] = [] |
| 73 | 73 | /// A file shown in Quick Look. |
| 74 | 74 | @State private var previewed: URL? |
| 75 | /// A followed citation's bibliography entry. | |
| 76 | @State private var citationEntry: CitationEntry? | |
| 75 | 77 | /// The project whose publishing folder the folder picker is choosing. |
| 76 | 78 | @State private var publishFolder: PublishFolderRequest? |
| 77 | 79 | @State private var choosingPublishFolder = false |
| @@ -332,6 +334,7 @@ struct EditorScreen: View { | ||
| 332 | 334 | attachPhotos(items) |
| 333 | 335 | } |
| 334 | 336 | .quickLookPreview($previewed) |
| 337 | .citationAlert($citationEntry) { follow($0) } | |
| 335 | 338 | .fileExporter(isPresented: Binding(get: { exportedTable != nil }, set: { if !$0 { exportedTable = nil } }), |
| 336 | 339 | document: exportedTable, contentType: exportedTable?.type ?? .commaSeparatedText, |
| 337 | 340 | defaultFilename: exportedTable?.type == .tabSeparatedText ? "table.tsv" : "table.csv") { result in |
| @@ -579,6 +582,8 @@ struct EditorScreen: View { | ||
| 579 | 582 | } |
| 580 | 583 | } else if id == "app.toggle-markup" { |
| 581 | 584 | model.showMarkup.toggle() |
| 585 | } else if id == "app.cite.insert" { | |
| 586 | citationActions.insert() | |
| 582 | 587 | } else if MobileEditor.linkCommands.contains(id) { |
| 583 | 588 | link(id) |
| 584 | 589 | } else if !MobileClock.run(id, model: model, workspace: workspace, show: { message = $0 }) { |
| @@ -606,6 +611,8 @@ extension EditorScreen { | ||
| 606 | 611 | guard let answer, let index = labels.firstIndex(of: answer) else { return } |
| 607 | 612 | follow(OrgLink(type: "file", path: paths[index], raw: "file:" + paths[index])) |
| 608 | 613 | } |
| 614 | case .citation(let keys): | |
| 615 | citationActions.follow(keys) | |
| 609 | 616 | case .elisp(let form): |
| 610 | 617 | // Once trusted, as `org-link-elisp-confirm-function` asks. |
| 611 | 618 | let go = { _ = Task { message = await session.evaluateLink(form) } } |
| @@ -646,6 +653,13 @@ extension EditorScreen { | ||
| 646 | 653 | return actions |
| 647 | 654 | } |
| 648 | 655 | |
| 656 | /// Insert Citation… and following citations. | |
| 657 | private var citationActions: CitationActions { | |
| 658 | CitationActions( | |
| 659 | session: session, context: { editor?.editContext() }, perform: { _ = editor?.perform($0) }, | |
| 660 | show: { message = $0 }, ask: { prompt = PromptRequest(prompt: $0, reply: $1) }, present: { citationEntry = $0 }) | |
| 661 | } | |
| 662 | ||
| 649 | 663 | /// org-attach's commands for the entry at the caret. |
| 650 | 664 | private var attachActions: AttachActions { |
| 651 | 665 | AttachActions( |
| @@ -1120,6 +1134,7 @@ struct CommandPalette: View { | ||
| 1120 | 1134 | ("org.snippet.next-field", "Next Snippet Field"), ("org.snippet.previous-field", "Previous Snippet Field"), |
| 1121 | 1135 | ("app.recovery", "Recovery Versions…"), ("app.sync-conflicts", "Resolve Sync Conflicts…"), ("app.lint", "Lint File"), ("app.lint-folders", "Lint All Folders"), |
| 1122 | 1136 | ("app.working-copy.sync", "Sync with Working Copy"), |
| 1137 | ("app.cite.insert", "Insert Citation…"), | |
| 1123 | 1138 | ("org.toggle-inline-images", "Show or Hide Inline Images"), ("org.toggle-inline-images-linked", "Show or Hide Inline Images, Including Described Links"), ("org.latex-preview", "Show or Hide LaTeX Previews"), ("editor.toggle-truncate-lines", "Truncate or Wrap Long Lines"), ("editor.toggle-auto-fill", "Turn Auto Fill On or Off"), |
| 1124 | 1139 | ("editor.complete", "Complete at Point"), ("editor.dabbrev-expand", "Expand Word"), ("editor.dabbrev-completion", "Complete Word"), |
| 1125 | 1140 | ("edit.isearch-forward", "Incremental Search"), ("edit.isearch-backward", "Incremental Search Backward"), |
Sources/OrgstarMobile/MobileEditor.swift +2 −2 · view
| @@ -513,7 +513,7 @@ final class MobileEditor: NSObject, DocumentBuffer { | ||
| 513 | 513 | case "app.refile", "app.refile.copy", "app.archive": return onAppCommand != nil && Presentation.heading(containing: context.caret, in: context.tree) != nil |
| 514 | 514 | case "app.export-dialog", "app.export-subtree-dialog", "app.share-subtree", "app.copy-rich-text", "app.export.html-open", "app.export-body-only", "app.export.icalendar-agenda", "app.export.icalendar-combined": return onAppCommand != nil |
| 515 | 515 | case _ where id.hasPrefix("app.publish"): return onAppCommand != nil |
| 516 | case "app.working-copy.sync": return onAppCommand != nil | |
| 516 | case "app.working-copy.sync", "app.cite.insert": return onAppCommand != nil | |
| 517 | 517 | case _ where Self.linkCommands.contains(id): return onAppCommand != nil |
| 518 | 518 | case "org.link.open": return OpenLinkAtPoint().applies(in: context) |
| 519 | 519 | case "org.table.toggle-column-width", "org.table.shrink", "org.table.expand": |
| @@ -614,7 +614,7 @@ final class MobileEditor: NSObject, DocumentBuffer { | ||
| 614 | 614 | |
| 615 | 615 | private func openLinkAtCaret() { |
| 616 | 616 | let caret = textView.selectedRange.location |
| 617 | if let link = Links.link(at: caret, text: document.text, tree: document.tree)?.link { | |
| 617 | if let link = Links.link(at: caret, text: document.text, tree: document.tree)?.link ?? Links.citation(at: caret, text: document.text, tree: document.tree) { | |
| 618 | 618 | onLink?(link) |
| 619 | 619 | } else if let days = Links.timestampDays(at: caret, text: document.text) { |
| 620 | 620 | onAgenda?(days.start, days.count) |
Sources/OrgstarMobile/ReaderScreen.swift +2 · view
| @@ -562,6 +562,8 @@ struct ReaderScreen: View { | ||
| 562 | 562 | case .message(let text): message = text |
| 563 | 563 | case .choose(let question, let paths): message = question + paths.map { ($0 as NSString).lastPathComponent }.joined(separator: ", ") |
| 564 | 564 | case .elisp: message = "Open the file in the editor to run elisp links." |
| 565 | // `Links.link` doesn't read citations, so none come here. | |
| 566 | case .citation: break | |
| 565 | 567 | } |
| 566 | 568 | return .handled |
| 567 | 569 | } |
Tests/OrgAppTests/AppTests.swift +2 · view
| @@ -1420,6 +1420,8 @@ struct LinkFollowTests { | ||
| 1420 | 1420 | #expect(follow("file:pic.png") == .message("No file " + (notes.url.appendingPathComponent("sub/pic.png").path as NSString).standardizingPath)) |
| 1421 | 1421 | #expect(follow("https://orgmode.org/a b") == .openExternally(URL(string: "https://orgmode.org/a%20b")!)) |
| 1422 | 1422 | #expect(follow("doi:10.1000/182") == .openExternally(URL(string: "https://doi.org/10.1000/182")!)) |
| 1423 | #expect(follow("zotero://select/items/@doe2020") == .openExternally(URL(string: "zotero://select/items/@doe2020")!)) | |
| 1424 | #expect(session.follow(OrgLink(type: "cite", path: "a;b", raw: "cite:a;b"), workspace: workspace, isText: { _ in false }) == .citation(["a", "b"])) | |
| 1423 | 1425 | #expect(follow("shell:rm -rf x") == .message("orgstar doesn't run shell links")) |
| 1424 | 1426 | #expect(follow("elisp:(+ 1 2)") == .elisp("(+ 1 2)")) |
| 1425 | 1427 | #expect(follow("elisp:org-agenda") == .message("orgstar doesn't run Emacs commands from elisp: links")) |
Tests/OrgAppTests/CitationActionsTests.swift added +143 · view
| @@ -0,0 +1,143 @@ | ||
| 1 | import Foundation | |
| 2 | import OrgCore | |
| 3 | import OrgDocument | |
| 4 | import Testing | |
| 5 | @testable import OrgApp | |
| 6 | ||
| 7 | /// Insert Citation… and following citations, with the questions answered here. | |
| 8 | @MainActor | |
| 9 | struct CitationActionsTests { | |
| 10 | static let bib = #""" | |
| 11 | @book{smith1999, | |
| 12 | author = {Smith, John}, | |
| 13 | title = {The Book}, | |
| 14 | publisher = {Pub House}, | |
| 15 | year = 1999, | |
| 16 | url = {https://example.org/book}, | |
| 17 | doi = {10.1000/book}, | |
| 18 | file = {:papers/smith.pdf:PDF} | |
| 19 | } | |
| 20 | @article{doe2020, | |
| 21 | author = {Doe, Jane}, | |
| 22 | title = {A Study}, | |
| 23 | year = {2020} | |
| 24 | } | |
| 25 | """# | |
| 26 | ||
| 27 | final class Log { | |
| 28 | var prompts: [Prompt] = [] | |
| 29 | var messages: [String] = [] | |
| 30 | } | |
| 31 | ||
| 32 | func setUp(_ text: String, caret: Int? = nil) throws -> (Folder, DocumentSession, () -> EditContext) { | |
| 33 | let folder = try Folder() | |
| 34 | try folder.write("refs.bib", Self.bib) | |
| 35 | let doc = try folder.write("doc.org", text) | |
| 36 | let session = DocumentSession(recovery: FileRecoveryStore(directory: folder.url.appendingPathComponent(".r"))) | |
| 37 | session.open(doc.path) | |
| 38 | let context = { | |
| 39 | let caret = caret ?? text.utf16.count | |
| 40 | return EditContext(revision: 0, text: text, tree: OrgParser.parse(text), selection: [caret..<caret]) | |
| 41 | } | |
| 42 | return (folder, session, context) | |
| 43 | } | |
| 44 | ||
| 45 | /// The text after `command` runs in `context`. | |
| 46 | func applying(_ command: any OrgCommand, _ context: EditContext) -> String? { | |
| 47 | guard case .commit(let result) = command.run(in: context) else { return nil } | |
| 48 | var text = context.text | |
| 49 | for edit in result.edits.sorted(by: { $0.range.lowerBound > $1.range.lowerBound }) { text = edit.apply(to: text) } | |
| 50 | return text | |
| 51 | } | |
| 52 | ||
| 53 | @Test func insertsAKeyChosenFromTheBibliography() async throws { | |
| 54 | let (folder, session, context) = try setUp("#+bibliography: refs.bib\nSee ") | |
| 55 | defer { withExtendedLifetime(folder) {} } | |
| 56 | let log = Log() | |
| 57 | let command: (any OrgCommand)? = await withCheckedContinuation { done in | |
| 58 | let actions = CitationActions( | |
| 59 | session: session, context: { context() }, perform: { done.resume(returning: $0) }, show: { log.messages.append($0) }, | |
| 60 | ask: { prompt, reply in | |
| 61 | log.prompts.append(prompt) | |
| 62 | switch prompt.key { | |
| 63 | case "key": reply(prompt.choices.first { $0.hasPrefix("smith1999") }) | |
| 64 | case "prefix": reply("see") | |
| 65 | case "suffix": reply("p. 5") | |
| 66 | default: reply("t") | |
| 67 | } | |
| 68 | }, present: { _ in }) | |
| 69 | actions.insert() | |
| 70 | } | |
| 71 | #expect(log.prompts.map(\.key) == ["key", "prefix", "suffix", "style"]) | |
| 72 | #expect(log.prompts[0].choices == ["doe2020 Doe, Jane 2020 A Study", "smith1999 Smith, John 1999 The Book"]) | |
| 73 | #expect(log.prompts[3].choices == ["author", "noauthor", "nocite", "note", "numeric", "text", "nil"]) | |
| 74 | #expect(applying(try #require(command), context()) == "#+bibliography: refs.bib\nSee [cite/t:see @smith1999 p. 5]") | |
| 75 | } | |
| 76 | ||
| 77 | @Test func onAKeyReplacesItWithoutAskingMore() async throws { | |
| 78 | let text = "#+bibliography: refs.bib\nSee [cite:@doe2020]" | |
| 79 | let (folder, session, context) = try setUp(text, caret: text.utf16.count - 3) | |
| 80 | defer { withExtendedLifetime(folder) {} } | |
| 81 | let log = Log() | |
| 82 | let command: (any OrgCommand)? = await withCheckedContinuation { done in | |
| 83 | CitationActions( | |
| 84 | session: session, context: { context() }, perform: { done.resume(returning: $0) }, show: { log.messages.append($0) }, | |
| 85 | ask: { prompt, reply in | |
| 86 | log.prompts.append(prompt) | |
| 87 | reply(prompt.choices.first { $0.hasPrefix("smith1999") }) | |
| 88 | }, present: { _ in }).insert() | |
| 89 | } | |
| 90 | #expect(log.prompts.map(\.key) == ["key"]) | |
| 91 | #expect(applying(try #require(command), context()) == "#+bibliography: refs.bib\nSee [cite:@smith1999]") | |
| 92 | } | |
| 93 | ||
| 94 | @Test func withoutABibliographySaysSo() throws { | |
| 95 | let (folder, session, context) = try setUp("No keywords here ") | |
| 96 | defer { withExtendedLifetime(folder) {} } | |
| 97 | let log = Log() | |
| 98 | CitationActions(session: session, context: { context() }, perform: { _ in }, show: { log.messages.append($0) }, | |
| 99 | ask: { prompt, _ in log.prompts.append(prompt) }, present: { _ in }).insert() | |
| 100 | #expect(log.messages == ["No bibliography set"]) | |
| 101 | #expect(log.prompts.isEmpty) | |
| 102 | } | |
| 103 | ||
| 104 | @Test func followingShowsTheEntryAndWhatItOffers() async throws { | |
| 105 | let (folder, session, context) = try setUp("#+bibliography: refs.bib\nSee [cite:@smith1999; @doe2020]") | |
| 106 | let log = Log() | |
| 107 | let entry: CitationEntry = await withCheckedContinuation { done in | |
| 108 | CitationActions(session: session, context: { context() }, perform: { _ in }, show: { log.messages.append($0) }, | |
| 109 | ask: { prompt, reply in | |
| 110 | log.prompts.append(prompt) | |
| 111 | reply("smith1999") | |
| 112 | }, present: { done.resume(returning: $0) }).follow(["smith1999", "doe2020"]) | |
| 113 | } | |
| 114 | #expect(log.prompts.map(\.choices) == [["smith1999", "doe2020"]]) | |
| 115 | #expect(entry.key == "smith1999") | |
| 116 | #expect(entry.summary == "Smith, John (1999). The Book. Pub House.") | |
| 117 | let bib = folder.url.appendingPathComponent("refs.bib").path | |
| 118 | #expect(entry.links.map(\.label) == ["Open smith.pdf", "Open DOI", "Open URL", "Show in Bibliography"]) | |
| 119 | #expect(entry.links.map(\.link) == [ | |
| 120 | OrgLink(type: "file", path: folder.url.appendingPathComponent("papers/smith.pdf").path, raw: "file:" + folder.url.appendingPathComponent("papers/smith.pdf").path), | |
| 121 | OrgLink(type: "doi", path: "10.1000/book", raw: "doi:10.1000/book"), | |
| 122 | Links.parse(plain: "https://example.org/book"), | |
| 123 | OrgLink(type: "file", path: bib, searchOption: "1", raw: "file:" + bib), | |
| 124 | ]) | |
| 125 | #expect(session.follow(entry.links[1].link, workspace: nil, isText: { _ in false }) == .openExternally(URL(string: "https://doi.org/10.1000/book")!)) | |
| 126 | ||
| 127 | let missing: String = await withCheckedContinuation { done in | |
| 128 | CitationActions(session: session, context: { context() }, perform: { _ in }, show: { done.resume(returning: $0) }, | |
| 129 | ask: { _, _ in }, present: { _ in }).follow(["nope"]) | |
| 130 | } | |
| 131 | #expect(missing == "Cannot find citation key: nope") | |
| 132 | } | |
| 133 | ||
| 134 | @Test func completionAnswersWithTheKeys() async throws { | |
| 135 | let folder = try Folder() | |
| 136 | defer { withExtendedLifetime(folder) {} } | |
| 137 | let bib = try folder.write("refs.bib", Self.bib) | |
| 138 | let workspace = try WorkspaceModel(directory: nil) | |
| 139 | let result = await CompletionSources.answer(.citationKeys([bib.path]), index: workspace.index, excluding: nil) | |
| 140 | #expect(result.strings == ["doe2020", "smith1999"]) | |
| 141 | #expect(result.annotations["smith1999"] == "Smith, John 1999 The Book") | |
| 142 | } | |
| 143 | } | |
Tests/OrgAppTests/EmacsImportTests.swift +11 · view
| @@ -197,6 +197,17 @@ struct EmacsImportTests { | ||
| 197 | 197 | #expect(s["org-yank-dnd-method"] == .string("attach")) |
| 198 | 198 | } |
| 199 | 199 | |
| 200 | @Test func readsTheGlobalBibliography() throws { | |
| 201 | let folder = FileManager.default.temporaryDirectory.appendingPathComponent("orgstar-import-\(UUID().uuidString)") | |
| 202 | try FileManager.default.createDirectory(at: folder, withIntermediateDirectories: true) | |
| 203 | defer { try? FileManager.default.removeItem(at: folder) } | |
| 204 | try #""" | |
| 205 | (setq org-cite-global-bibliography '("~/refs/zotero.bib" "/data/more.json")) | |
| 206 | """#.write(to: folder.appendingPathComponent("init.el"), atomically: true, encoding: .utf8) | |
| 207 | let s = settings(EmacsImport.scan(EmacsImport.files(in: folder))) | |
| 208 | #expect(s["org-cite-global-bibliography"] == .string("~/refs/zotero.bib:/data/more.json")) | |
| 209 | } | |
| 210 | ||
| 200 | 211 | @Test func readsLiterateConfig() throws { |
| 201 | 212 | let folder = FileManager.default.temporaryDirectory.appendingPathComponent("orgstar-import-\(UUID().uuidString)") |
| 202 | 213 | try FileManager.default.createDirectory(at: folder, withIntermediateDirectories: true) |
Tests/OrgCoreTests/CitationInsertTests.swift added +288 · view
| @@ -0,0 +1,288 @@ | ||
| 1 | import Foundation | |
| 2 | import Testing | |
| 3 | @testable import OrgCore | |
| 4 | ||
| 5 | /// Bibliography files as Insert Citation… reads them, `org-cite-insert`'s edits, key | |
| 6 | /// completion and following citations. | |
| 7 | struct CitationInsertTests { | |
| 8 | static let oracle = ProcessInfo.processInfo.environment["ORGSTAR_SKIP_ORACLE"] == nil | |
| 9 | ||
| 10 | static let bib = #""" | |
| 11 | % A comment line. | |
| 12 | @String{jos = "Journal of " # "Stuff"} | |
| 13 | @Article{doe2020, | |
| 14 | Author = {Doe, Jane and {Roe and Sons}}, | |
| 15 | title = {A {Study} of {{Nested}} Things}, | |
| 16 | journal = jos, | |
| 17 | year = 2020, | |
| 18 | doi = {https://doi.org/10.1000/xyz}, | |
| 19 | file = {Full Text:papers/doe.pdf:application/pdf;/abs/other.pdf} | |
| 20 | } | |
| 21 | @comment{@book{hidden, title = {No}}} | |
| 22 | @book(smith1999, | |
| 23 | author = "Smith, John", | |
| 24 | title = "The {"}Book{"}", | |
| 25 | url = {https://example.org/book}, | |
| 26 | date = {1999-04-01} | |
| 27 | ) | |
| 28 | @proceedings{conf2021, | |
| 29 | title = {Proceedings of the Conference}, | |
| 30 | editor = {Park, Min}, | |
| 31 | publisher = {ACM}, | |
| 32 | year = {2021} | |
| 33 | } | |
| 34 | @inproceedings{talk, | |
| 35 | author = {Lee, Kim}, | |
| 36 | title = {A Talk}, | |
| 37 | crossref = {Conf2021} | |
| 38 | } | |
| 39 | """# | |
| 40 | ||
| 41 | static let json = #""" | |
| 42 | [{"id": "csl1", "author": [{"family": "Zed", "given": "Ann"}], "title": "From JSON", "issued": {"date-parts": [[2018]]}, "DOI": "10.1/j", "URL": "https://j.example"}] | |
| 43 | """# | |
| 44 | ||
| 45 | func folder() throws -> URL { | |
| 46 | let folder = FileManager.default.temporaryDirectory.appendingPathComponent("orgstar-bib-\(UUID().uuidString)") | |
| 47 | try FileManager.default.createDirectory(at: folder, withIntermediateDirectories: true) | |
| 48 | try Self.bib.write(to: folder.appendingPathComponent("refs.bib"), atomically: true, encoding: .utf8) | |
| 49 | try Self.json.write(to: folder.appendingPathComponent("more.json"), atomically: true, encoding: .utf8) | |
| 50 | return folder | |
| 51 | } | |
| 52 | ||
| 53 | // MARK: - Reading | |
| 54 | ||
| 55 | @Test func readsBibTeXWithBracesStringsAndCrossrefs() throws { | |
| 56 | let entries = Bibliography.entries(Data(Self.bib.utf8), path: "/refs/refs.bib") | |
| 57 | #expect(entries.map(\.key) == ["conf2021", "doe2020", "smith1999", "talk"]) | |
| 58 | let doe = try #require(entries.first { $0.key == "doe2020" }) | |
| 59 | #expect(doe.fields["author"] == "Doe, Jane and {Roe and Sons}") | |
| 60 | #expect(doe.author == "Doe, Jane and Roe and Sons") | |
| 61 | #expect(doe.fields["title"] == "A {Study} of {{Nested}} Things") | |
| 62 | #expect(doe.title == "A Study of Nested Things") | |
| 63 | #expect(doe.fields["journal"] == "Journal of Stuff") | |
| 64 | #expect(doe.year == "2020") | |
| 65 | #expect(doe.doi == "10.1000/xyz") | |
| 66 | #expect(doe.files == ["/refs/papers/doe.pdf", "/abs/other.pdf"]) | |
| 67 | #expect(doe.label == "doe2020 Doe, Jane; Roe and Sons 2020 A Study of Nested Things") | |
| 68 | #expect(doe.summary == "Doe, Jane and Roe and Sons (2020). A Study of Nested Things. Journal of Stuff.") | |
| 69 | let smith = try #require(entries.first { $0.key == "smith1999" }) | |
| 70 | #expect(smith.title == "The \"Book\"") | |
| 71 | #expect(smith.year == "1999") | |
| 72 | #expect(smith.url == "https://example.org/book") | |
| 73 | // Fields the entry lacks come from the one it cross-references; its title is the book's. | |
| 74 | let talk = try #require(entries.first { $0.key == "talk" }) | |
| 75 | #expect(talk.title == "A Talk") | |
| 76 | #expect(talk.field("booktitle") == "Proceedings of the Conference") | |
| 77 | #expect(talk.field("publisher") == "ACM") | |
| 78 | #expect(talk.year == "2021") | |
| 79 | #expect(talk.fields["crossref"] == "Conf2021") | |
| 80 | } | |
| 81 | ||
| 82 | @Test func readsCSLJSON() throws { | |
| 83 | let entries = Bibliography.entries(Data(Self.json.utf8), path: "/refs/more.json") | |
| 84 | let entry = try #require(entries.first) | |
| 85 | #expect(entry.key == "csl1") | |
| 86 | #expect(entry.author == "Zed Ann") | |
| 87 | #expect(entry.year == "2018") | |
| 88 | #expect(entry.doi == "10.1/j") | |
| 89 | #expect(entry.url == "https://j.example") | |
| 90 | } | |
| 91 | ||
| 92 | @Test func listsTheFilesBibliographyKeywordsAndTheGlobalSettingName() { | |
| 93 | let text = "#+BIBLIOGRAPHY: refs.bib\n#+bibliography: \"with space.bib\"\n#+bibliography: /abs/a.bib\n #+bibliography: refs.bib\n" | |
| 94 | #expect(Bibliography.files(in: text, directory: "/notes", global: ["/abs/a.bib", "/g/global.json"]) | |
| 95 | == ["/notes/refs.bib", "/notes/with space.bib", "/abs/a.bib", "/g/global.json"]) | |
| 96 | #expect(Bibliography.files(in: "No keywords\n", directory: "/notes", global: ["~/g.bib"]) == [OrgPaths.home + "/g.bib"]) | |
| 97 | } | |
| 98 | ||
| 99 | @Test func findsTheLineAnEntryStartsOn() { | |
| 100 | #expect(Bibliography.line(of: "smith1999", in: Self.bib, json: false) == 12) | |
| 101 | #expect(Bibliography.line(of: "doe2020", in: Self.bib, json: false) == 3) | |
| 102 | #expect(Bibliography.line(of: "csl1", in: Self.json, json: true) == 1) | |
| 103 | #expect(Bibliography.line(of: "hidden2", in: Self.bib, json: false) == nil) | |
| 104 | } | |
| 105 | ||
| 106 | /// A file is parsed again only when its modification date changes; the first file wins | |
| 107 | /// for a key in two. | |
| 108 | @Test func cachesFilesByModificationDate() throws { | |
| 109 | final class Disk: @unchecked Sendable { | |
| 110 | var dates: [String: Date] = [:] | |
| 111 | var texts: [String: String] = [:] | |
| 112 | var reads = 0 | |
| 113 | } | |
| 114 | let disk = Disk() | |
| 115 | disk.dates = ["/a.bib": Date(timeIntervalSince1970: 1), "/b.bib": Date(timeIntervalSince1970: 1)] | |
| 116 | disk.texts = ["/a.bib": "@misc{one, title = {A}}", "/b.bib": "@misc{one, title = {B}}\n@misc{two, title = {Two}}"] | |
| 117 | let cache = BibliographyCache(modified: { disk.dates[$0] }, read: { disk.reads += 1; return disk.texts[$0].map { Data($0.utf8) } }) | |
| 118 | #expect(cache.entries(["/a.bib", "/b.bib", "/missing.bib"]).map { "\($0.key) \($0.title ?? "")" } == ["one A", "two Two"]) | |
| 119 | #expect(disk.reads == 2) | |
| 120 | _ = cache.entries(["/a.bib", "/b.bib"]) | |
| 121 | #expect(disk.reads == 2) | |
| 122 | disk.texts["/a.bib"] = "@misc{three, title = {C}}" | |
| 123 | disk.dates["/a.bib"] = Date(timeIntervalSince1970: 2) | |
| 124 | #expect(cache.entries(["/a.bib"]).map(\.key) == ["three"]) | |
| 125 | #expect(disk.reads == 3) | |
| 126 | } | |
| 127 | ||
| 128 | @Test func loadsOffTheMainThread() async throws { | |
| 129 | let folder = try folder() | |
| 130 | defer { try? FileManager.default.removeItem(at: folder) } | |
| 131 | final class Seen: @unchecked Sendable { var main: Bool? } | |
| 132 | let seen = Seen() | |
| 133 | let cache = BibliographyCache(read: { seen.main = Thread.isMainThread; return FileManager.default.contents(atPath: $0) }) | |
| 134 | let entries = await Self.loadOnMain(cache, [folder.appendingPathComponent("refs.bib").path]) | |
| 135 | #expect(entries.count == 4) | |
| 136 | #expect(seen.main == false) | |
| 137 | } | |
| 138 | ||
| 139 | @MainActor | |
| 140 | static func loadOnMain(_ cache: BibliographyCache, _ paths: [String]) async -> [BibEntry] { | |
| 141 | await cache.load(paths) | |
| 142 | } | |
| 143 | ||
| 144 | // MARK: - Inserting | |
| 145 | ||
| 146 | /// Text with `|` at the caret, Insert Citation… of `key` with `style`, and the result | |
| 147 | /// with `|` at the caret. | |
| 148 | func insert(_ marked: String, key: String? = "k2", style: String? = nil, prefix: String = "", suffix: String = "") -> String { | |
| 149 | let caret = (marked as NSString).range(of: "|").location | |
| 150 | let text = marked.replacingOccurrences(of: "|", with: "") | |
| 151 | let result = runCommand(InsertCitation(key: key, style: style, prefix: prefix, suffix: suffix), text, caret: caret) | |
| 152 | if let failure = result.failure { return "failed: " + failure } | |
| 153 | return (result.text as NSString).replacingCharacters(in: NSRange(location: result.caret, length: 0), with: "|") | |
| 154 | } | |
| 155 | ||
| 156 | /// Cases where orgstar and `org-cite-insert` do the same, with the style asked (Emacs's | |
| 157 | /// prefix argument) or not. | |
| 158 | static let cases: [(text: String, styled: Bool, expected: String)] = [ | |
| 159 | ("Text | more", false, "Text [cite:@k2]| more"), | |
| 160 | ("Text |", true, "Text [cite/text:@k2]|"), | |
| 161 | ("|[cite:@a]", false, "[cite:@k2]|[cite:@a]"), | |
| 162 | ("[cite:@a] |", false, "[cite:@a] [cite:@k2]|"), | |
| 163 | ("[cite:@a|]", false, "[cite:@a;@k2|]"), | |
| 164 | ("[cite:|@a]", false, "[cite:|@k2;@a]"), | |
| 165 | ("[cite:@a|b]", false, "[cite:|@k2]"), | |
| 166 | ("[cite:see @a p. |4; @b]", false, "[cite:see @a p. |4;@k2; @b]"), | |
| 167 | ("[cite:@a; @b|]", false, "[cite:@a; @b;@k2|]"), | |
| 168 | ("[cite:@a;| @b]", false, "[cite:@a;|@k2; @b]"), | |
| 169 | ("[cite:pre|; @a; post]", false, "[cite:pre|;@k2; @a; post]"), | |
| 170 | ("[cite:pre; @a; po|st]", false, "[cite:pre; @a;@k2; po|st]"), | |
| 171 | ("[cite/t|:@a]", true, "[cite|/text:@a]"), | |
| 172 | ("[ci|te:@a]", true, "[ci|te/text:@a]"), | |
| 173 | ] | |
| 174 | ||
| 175 | @Test func insertsAsOrgCiteInsert() { | |
| 176 | for c in Self.cases { | |
| 177 | #expect(insert(c.text, style: c.styled ? "text" : nil) == c.expected, "\(c.text)") | |
| 178 | } | |
| 179 | } | |
| 180 | ||
| 181 | @Test(.enabled(if: oracle)) | |
| 182 | func insertionMatchesEmacs() throws { | |
| 183 | let oracleCases = Self.cases.map { c in | |
| 184 | let caret = (c.text as NSString).range(of: "|").location | |
| 185 | let text = c.text.replacingOccurrences(of: "|", with: "") | |
| 186 | let form = """ | |
| 187 | (progn (require 'oc-basic) | |
| 188 | (let ((org-cite-insert-processor 'basic)) | |
| 189 | (cl-letf (((symbol-function 'org-cite-basic--complete-key) (lambda (&optional multiple) (if multiple (list "k2") "k2"))) | |
| 190 | ((symbol-function 'org-cite-basic--complete-style) (lambda (_) "text"))) | |
| 191 | (org-cite-insert \(c.styled && Citations.place(at: caret, tree: OrgParser.parse(text)) == .new ? "'(4)" : "nil"))))) | |
| 192 | """ | |
| 193 | return EmacsOracle.Case(text: text, point: EmacsOracle.point(caret, in: text), form: form) | |
| 194 | } | |
| 195 | let results = try EmacsOracle.run(oracleCases) | |
| 196 | for (c, result) in zip(Self.cases, results) { | |
| 197 | let emacs = (result.text as NSString).replacingCharacters(in: NSRange(location: EmacsOracle.offset(result.point, in: result.text), length: 0), with: "|") | |
| 198 | #expect(result.error.isEmpty, "\(c.text): \(result.error)") | |
| 199 | #expect(insert(c.text, style: c.styled ? "text" : nil) == emacs, "\(c.text)") | |
| 200 | } | |
| 201 | } | |
| 202 | ||
| 203 | @Test func putsThePrefixAndSuffixAroundTheKey() { | |
| 204 | #expect(insert("A |", prefix: "see", suffix: "p. 4") == "A [cite:see @k2 p. 4]|") | |
| 205 | #expect(insert("A |", style: "t", prefix: "see ", suffix: ", ch. 2") == "A [cite/t:see @k2, ch. 2]|") | |
| 206 | #expect(insert("[cite:@a|]", prefix: "cf.") == "[cite:@a;cf. @k2|]") | |
| 207 | // A key replaced keeps the reference's own prefix and suffix. | |
| 208 | #expect(insert("[cite:see @a|b p. 4]", prefix: "x", suffix: "y") == "[cite:see |@k2 p. 4]") | |
| 209 | // An empty style is the default. | |
| 210 | #expect(insert("[cite/t|:@a]", style: "") == "[cite|:@a]") | |
| 211 | #expect(insert("[cite/t|:@a]", key: nil, style: nil) == "failed: Aborted") | |
| 212 | #expect(insert("A |", key: nil) == "failed: Aborted") | |
| 213 | } | |
| 214 | ||
| 215 | @Test func keysRunInsertCitation() { | |
| 216 | #expect(KeymapPreset.emacs.keymap.candidates(for: KeySequence.parse("C-c C-x @")!).first?.command == "app.cite.insert") | |
| 217 | #expect(KeymapPreset.doom.keymap.candidates(for: KeySequence.parse("SPC m @")!, mode: "normal").first?.command == "app.cite.insert") | |
| 218 | } | |
| 219 | ||
| 220 | @Test func tellsWhereTheCaretIs() { | |
| 221 | func place(_ marked: String) -> Citations.Place { | |
| 222 | let caret = (marked as NSString).range(of: "|").location | |
| 223 | return Citations.place(at: caret, tree: OrgParser.parse(marked.replacingOccurrences(of: "|", with: ""))) | |
| 224 | } | |
| 225 | #expect(place("x |") == .new) | |
| 226 | #expect(place("|[cite:@a]") == .new) | |
| 227 | #expect(place("[cite:@a]|") == .new) | |
| 228 | #expect(place("[|cite:@a]") == .style) | |
| 229 | #expect(place("[cite/t|:@a]") == .style) | |
| 230 | #expect(place("[cite:|@a]") == .reference) | |
| 231 | #expect(place("[cite:@|a]") == .key) | |
| 232 | #expect(place("[cite:@a|]") == .reference) | |
| 233 | #expect(place("* Heading [cite:@a|b]") == .key) | |
| 234 | } | |
| 235 | ||
| 236 | // MARK: - Following and completing | |
| 237 | ||
| 238 | @Test func followsTheReferenceOrEveryKey() { | |
| 239 | func link(_ marked: String) -> OrgLink? { | |
| 240 | let caret = (marked as NSString).range(of: "|").location | |
| 241 | let text = marked.replacingOccurrences(of: "|", with: "") | |
| 242 | let context = EditContext(revision: 0, text: text, tree: OrgParser.parse(text), selection: [caret..<caret]) | |
| 243 | guard case .external(.openLink(let link)) = OpenLinkAtPoint().run(in: context) else { return nil } | |
| 244 | return link | |
| 245 | } | |
| 246 | #expect(link("See [cite:@a; @|b]")?.raw == "cite:b") | |
| 247 | #expect(link("See [cite:pre; @a; @b; @a; po|st]")?.raw == "cite:a;b") | |
| 248 | #expect(link("See |[cite/t:@a]")?.path == "a") | |
| 249 | #expect(link("See [cite:@a]| x") == nil) | |
| 250 | let text = "x [cite:@a]" | |
| 251 | #expect(OrgDwim().run(in: EditContext(revision: 0, text: text, tree: OrgParser.parse(text), selection: [4..<4])) == .external(.openLink(OrgLink(type: "cite", path: "a", raw: "cite:a")))) | |
| 252 | } | |
| 253 | ||
| 254 | @Test func completesKeysAfterTheAtSign() throws { | |
| 255 | func complete(_ text: String, path: String? = "/notes/doc.org", global: [String] = []) -> Completion? { | |
| 256 | var options = EditingOptions.org | |
| 257 | options.filePath = path | |
| 258 | var settings = OrgSettings.default | |
| 259 | settings.citeGlobalBibliography = global | |
| 260 | let tree = OrgParser.parse(text, defaults: settings) | |
| 261 | return OrgCompletion.at(EditContext(revision: 0, text: text, tree: tree, selection: [text.utf16.count..<text.utf16.count], options: options)) | |
| 262 | } | |
| 263 | let completion = try #require(complete("#+bibliography: refs.bib\nSee [cite:@do")) | |
| 264 | #expect(completion.kind == .citationKey) | |
| 265 | #expect(completion.typed == "do") | |
| 266 | #expect(completion.range == 36..<38) | |
| 267 | #expect(completion.query == .citationKeys(["/notes/refs.bib"])) | |
| 268 | #expect(complete("[cite/t:see @a; @", global: ["/g.bib"])?.query == .citationKeys(["/g.bib"])) | |
| 269 | #expect(complete("[cite:@")?.typed == "") | |
| 270 | #expect(complete("[cite:@a] and @b")?.kind != .citationKey) | |
| 271 | #expect(complete("mail me@ho")?.kind != .citationKey) | |
| 272 | ||
| 273 | let entries = Bibliography.entries(Data(Self.bib.utf8), path: "/notes/refs.bib") | |
| 274 | let filled = OrgCompletion.filled(completion, with: CompletionResult(entries: entries), fuzzy: false) | |
| 275 | #expect(filled.candidates == ["doe2020"]) | |
| 276 | #expect(filled.label("doe2020") == "doe2020 Doe, Jane; Roe and Sons 2020 A Study of Nested Things") | |
| 277 | #expect(OrgCompletion.filled(completion, with: CompletionResult(entries: entries), fuzzy: true).candidates.first == "doe2020") | |
| 278 | } | |
| 279 | ||
| 280 | @Test func exportReadsTheGlobalBibliography() throws { | |
| 281 | let folder = try folder() | |
| 282 | defer { try? FileManager.default.removeItem(at: folder) } | |
| 283 | var settings = OrgSettings.default | |
| 284 | settings.citeGlobalBibliography = [folder.appendingPathComponent("refs.bib").path] | |
| 285 | let markdown = MarkdownExport.document("See [cite/t:@smith1999].\n", settings: settings, path: folder.appendingPathComponent("doc.org").path) | |
| 286 | #expect(markdown.contains("See Smith, John (1999).")) | |
| 287 | } | |
| 288 | } | |
docs/manual/guide/03-keys.org +3 −1 · view
| @@ -644,6 +644,7 @@ Besides the leader, the preset binds these evil-org and Doom keys in normal stat | ||
| 644 | 644 | | =SPC z t= | Clock Report (=app.clock.report=) | |
| 645 | 645 | | =SPC m '= | Edit Block (=org.edit-special=) | |
| 646 | 646 | | =SPC m .= | Go to Heading… (=org.goto=) | |
| 647 | | =SPC m @= | Insert Citation… (=app.cite.insert=) | | |
| 647 | 648 | | =SPC m A= | Archive Subtree (=app.archive=) | |
| 648 | 649 | | =SPC m b -= | Insert Table Rule (=org.table.insert-hline=) | |
| 649 | 650 | | =SPC m b a= | Align Table (=org.table.align=) | |
| @@ -1022,12 +1023,13 @@ When a key appears in several rows, it runs the command whose condition holds at | ||
| 1022 | 1023 | |
| 1023 | 1024 | | Command | Emacs | Mac | Doom | What it does | |
| 1024 | 1025 | |-+-+-+-+-| |
| 1025 | | Open Link (=org.link.open=) | =C-c C-o= | =⌃⌘O= | — | Follows the link or timestamp at the caret (=org-open-at-point=). | | |
| 1026 | | Open Link (=org.link.open=) | =C-c C-o= | =⌃⌘O= | — | Follows the link, citation or timestamp at the caret (=org-open-at-point=). | | |
| 1026 | 1027 | | Emphasize… (=org.emphasize=) | =C-c C-x C-f= | — | — | Asks for a marker and wraps the selection in it, or inserts a pair with the caret between (=org-emphasize=). | |
| 1027 | 1028 | | Bold (=org.emphasize.bold=) | — | =⌘B= | — | =org-emphasize= with =*=. | |
| 1028 | 1029 | | Italic (=org.emphasize.italic=) | — | =⌘I= | — | =org-emphasize= with =/=. | |
| 1029 | 1030 | | Underline (=org.emphasize.underline=) | — | =⌘U= | — | =org-emphasize= with =_=. | |
| 1030 | 1031 | | Insert Link… (=org.link.insert=) | =C-c C-l= | =⌘K= | =SPC m l l= (N) | Asks for a link and description and inserts it, offering stored links (=org-insert-link=). | |
| 1032 | | Insert Citation… (=app.cite.insert=) | =C-c C-x @= | — | =SPC m @= (N) | Inserts a citation of a bibliography entry, or adds a key to the citation at the caret (=org-cite-insert=). | | |
| 1031 | 1033 | | Store Link (=org.link.store=) | =C-c l= | =⌃⌘L= | =SPC m l s= (N), =SPC n l= (N) | Stores a link to the current entry for a later Insert Link (=org-store-link=). | |
| 1032 | 1034 | | Store ID Link (=org.id.store-link=) | — | — | =SPC m l i= (N) | Gives the entry an =ID= if needed and stores an =id:= link to it (=org-id-store-link=). | |
| 1033 | 1035 | | Footnote Action (=org.footnote.action=) | =C-c C-x f= | =⌃⇧⌘F= | — | On a reference, goes to its definition; on a definition, back to a reference; elsewhere inserts a footnote (=org-footnote-action=). | |
docs/manual/guide/09-links.org +78 −3 · view
| @@ -37,7 +37,7 @@ file into a link, matched case-insensitively, as in Org. | ||
| 37 | 37 | |
| 38 | 38 | * Following links |
| 39 | 39 | |
| 40 | =org-open-at-point= follows the link at the caret, or opens the agenda for a timestamp. | |
| 40 | =org-open-at-point= follows the link at the caret, shows the entry of a citation (see /Citations/ below), or opens the agenda for a timestamp. | |
| 41 | 41 | |
| 42 | 42 | | Preset | Key | |
| 43 | 43 | |--------+---------------------------------------------------------------------------------------| |
| @@ -62,6 +62,7 @@ A message in the echo area explains a link that can't be followed. | ||
| 62 | 62 | | Text | =[[budget table]]= | Searches this file: a =<<budget table>>= target, then =#+NAME: budget table=, then a heading. | |
| 63 | 63 | | Coderef | =[[(ref)]]= | Moves to the label =(ref:ref)= in a src or example block; see /Code references/ below. | |
| 64 | 64 | | Regexp | =[[/TODO.*soon/]]= | Shows a sparse tree of the regular expression's matches, as =org-occur=; iOS moves to the first match. | |
| 65 | | =zotero= | =[[zotero://select/items/@doe2020]]= | Opens Zotero at the item. Org has no =zotero= link type, so write it in brackets. | | |
| 65 | 66 | | =shell= | =[[shell:ls]]= | Not run. orgstar never executes these links. | |
| 66 | 67 | | =elisp= | =[[elisp:(+ 1 2)]]= | Runs the form once you agree; see /Emacs Lisp links/ below. | |
| 67 | 68 | | =attachment= | =[[attachment:scan.pdf]]= | Opens the file in the entry's attachment folder; see /Attachment links/ below. | |
| @@ -212,6 +213,7 @@ When the inserted link is a =file:= link, orgstar rewrites it as | ||
| 212 | 213 | You can also type a link by hand. With the caret right after =[[=, completion at point |
| 213 | 214 | offers =attachment:=, =doi:=, =file:=, =http:=, =https:=, =id:= and =mailto:=, plus |
| 214 | 215 | the file's link abbreviations. After =[[*=, it offers the headings of the current file. |
| 216 | After =@= in a citation, it offers the keys of the file's bibliographies (see /Citations/). | |
| 215 | 217 | Completion at point is =C-M-i= in the Emacs preset and =C-SPC= in Doom's insert state; |
| 216 | 218 | see [[file:02-the-editor.org][The editor]]. |
| 217 | 219 | |
| @@ -686,13 +688,86 @@ the title as its description, and is also copied to the clipboard. Insert it wit | ||
| 686 | 688 | Insert Link. Setting up a browser bookmarklet, and =org-protocol://capture=, are in |
| 687 | 689 | [[file:08-capture.org][Capture]]. |
| 688 | 690 | |
| 691 | * Citations | |
| 692 | ||
| 693 | A citation, =[cite:@key]=, names an entry of the bibliography files the file lists with | |
| 694 | =#+bibliography:= lines, or of those =org-cite-global-bibliography= lists for every file | |
| 695 | (see [[file:13-configuration.org][Configuration]]). The citation syntax and how citations | |
| 696 | export are in [[file:12-export.org][Export]]. A file ending in =.json= is read as CSL-JSON; | |
| 697 | anything else as BibTeX or BibLaTeX, with =@string= abbreviations expanded and the fields an | |
| 698 | entry lacks taken from the entry its =crossref= field names (whose =title= becomes the | |
| 699 | =booktitle=). Bibliography files are read in the background, and read again only when they | |
| 700 | change. In the Mac App Store version, a bibliography outside your sidebar folders asks for | |
| 701 | access to its folder the first time. | |
| 702 | ||
| 703 | ** Inserting citations | |
| 704 | ||
| 705 | Insert Citation… (Org ▸ Links and Footnotes on the Mac, Commands on iOS) is =org-cite-insert= | |
| 706 | with the basic processor. | |
| 707 | ||
| 708 | | Preset | Key | | |
| 709 | |--------+-----------------------------| | |
| 710 | | Emacs | =C-c C-x @= | | |
| 711 | | Mac | none; Org menu or palette | | |
| 712 | | Doom | =SPC m @= | | |
| 713 | ||
| 714 | What it does depends on where the caret is: | |
| 715 | ||
| 716 | - Outside a citation, it asks for an entry (=Key:=, each key with its authors, year and | |
| 717 | title), then a prefix, a suffix and a style (=author=, =noauthor=, =nocite=, =note=, | |
| 718 | =numeric=, =text= or =nil=), and inserts =[cite/style:prefix @key suffix]=. An empty answer | |
| 719 | leaves out the prefix, the suffix or the style. | |
| 720 | - On a citation's =[cite/style= part, it asks only for a style and puts it in place of the | |
| 721 | old one; an empty answer removes it. | |
| 722 | - On the citation's common prefix or before a reference's =@=, it adds the chosen key, with | |
| 723 | the prefix and suffix around it, before that reference; on a reference's suffix or the | |
| 724 | common suffix, after it. References are separated by =;=. | |
| 725 | - Inside a key, the chosen key replaces it; the reference's prefix and suffix stay. | |
| 726 | ||
| 727 | Without bibliography files, the echo area says =No bibliography set=. Where orgstar differs | |
| 728 | from Emacs: | |
| 729 | ||
| 730 | - It inserts one key at a time. Run it again inside the citation to add another; Emacs asks | |
| 731 | for keys until an empty answer. | |
| 732 | - It always asks for a style for a new citation; Emacs asks only after =C-u=. The prefix and | |
| 733 | suffix questions are orgstar's. | |
| 734 | - =C-u= doesn't delete the citation or reference at the caret. | |
| 735 | ||
| 736 | ** Completing keys | |
| 737 | ||
| 738 | Inside a citation, completion at point after =@= offers the keys of the file's | |
| 739 | bibliographies, each with its authors, year and title. | |
| 740 | ||
| 741 | ** Following citations | |
| 742 | ||
| 743 | =C-c C-o= (Mac =⌃⌘O=), =⌘=-click, and =RET= in Doom's normal state show a citation's entry: | |
| 744 | its authors, year, title and where it was published. Its buttons open the files in the | |
| 745 | entry's =file= field, its DOI and its URL, and Show in Bibliography opens the bibliography | |
| 746 | file at the entry, which is what =org-cite-basic-goto= does in Emacs. On a reference the | |
| 747 | entry is that key's; elsewhere in a citation with several keys, you choose a key first. A key | |
| 748 | no bibliography has shows =Cannot find citation key:= and the key. | |
| 749 | ||
| 750 | The =file= field may list several files, separated by =;=. Each is a path or JabRef's and | |
| 751 | Zotero's =description:path:type=, relative to the bibliography's folder unless absolute. | |
| 752 | ||
| 753 | ** Zotero | |
| 754 | ||
| 755 | Better BibTeX for Zotero can keep a =.bib= file exported from your library up to date | |
| 756 | (Export Library, with Keep updated). List that file in =#+bibliography:= or | |
| 757 | =org-cite-global-bibliography= like any other; orgstar reads it again when Zotero rewrites | |
| 758 | it. =[[zotero://select/items/@key]]= links, with Better BibTeX's citation keys, open the | |
| 759 | item in Zotero on the Mac; on iOS the link is handed to the system, which opens the Zotero | |
| 760 | app if it is installed and handles the address. | |
| 761 | ||
| 689 | 762 | * On iOS |
| 690 | 763 | |
| 691 | 764 | The iOS app follows links: tap a link in the reader. Org files open in the app, and |
| 692 | 765 | web, mail and other files go to the system. The iOS editor shows inline images as the |
| 693 | Mac does, and so does the reader, except in headings. In the editor, Store Link, Store ID Link and Insert Link… | |
| 766 | Mac does, and so does the reader, except in headings. In the editor, Store Link, Store ID Link, Insert Link… and Insert Citation… | |
| 694 | 767 | are in Commands, and on a hardware keyboard the Emacs keys run them; they work as |
| 695 | described above, and stored links last until the app quits. =org-protocol://store-link= | |
| 768 | described above, and stored links last until the app quits. Open Link in Commands shows | |
| 769 | the entry of the citation at the caret. The app reads only bibliography files in its | |
| 770 | folders. =org-protocol://store-link= | |
| 696 | 771 | links opened on the device are stored and copied too. Show Backlinks in Commands lists the same |
| 697 | 772 | links as the Mac's backlinks pane, for the heading at the caret and the file. See |
| 698 | 773 | [[file:14-ios.org][iOS]]. |
docs/manual/guide/12-export.org +1 −1 · view
| @@ -429,7 +429,7 @@ As shown in [cite:@smith2020], and again [cite/t:@smith2020; see @lee2019 p. 4]. | ||
| 429 | 429 | |
| 430 | 430 | ** Bibliography files |
| 431 | 431 | |
| 432 | Each =#+bibliography:= line names one file, relative to the Org file, optionally in quotes. A file ending in =.json= is read as CSL-JSON; anything else is read as BibTeX, with =@string= abbreviations expanded and =@comment= and =@preamble= skipped. You can have several =#+bibliography:= lines; for a key in more than one file, the first file wins. | |
| 432 | Each =#+bibliography:= line names one file, relative to the Org file, optionally in quotes. A file ending in =.json= is read as CSL-JSON; anything else is read as BibTeX, with =@string= abbreviations expanded and =@comment= and =@preamble= skipped. You can have several =#+bibliography:= lines; for a key in more than one file, the first file wins. The files of =org-cite-global-bibliography= (see [[file:13-configuration.org][Configuration]]) come after the file's own. Inserting and following citations are in [[file:09-links.org][Links]]. | |
| 433 | 433 | |
| 434 | 434 | ** =#+cite_export:= |
| 435 | 435 | |
docs/manual/guide/13-configuration.org +3 · view
| @@ -228,6 +228,7 @@ These settings have no control in the Settings window. Some are in the View menu | ||
| 228 | 228 | | =org-roam-directory=, =org-roam-dailies-directory=, =org-roam-dailies-file=, =org-roam-dailies-head=, =org-roam-dailies-entry= | | |
| 229 | 229 | | =notes-package=, =denote-directory=, =denote-prompts=, =denote-silo-directories=, =denote-sequence-scheme=, =denote-journal-directory=, =denote-journal-keyword=, =denote-journal-interval=, =denote-journal-title-format= | | |
| 230 | 230 | | =org-attach-id-dir=, =org-attach-use-inheritance= | | |
| 231 | | =org-cite-global-bibliography= | | | |
| 231 | 232 | | =org-yank-image-save-method=, =org-yank-dnd-method= | | |
| 232 | 233 | | =org-crypt-tag-matcher=, =org-crypt-use-before-save-magic= | | |
| 233 | 234 | | =org-agenda-start-on-weekday= | | |
| @@ -299,6 +300,7 @@ A key you remove from the file goes back to its default. A key that isn't in the | ||
| 299 | 300 | | =org-timer-default-timer= | string | ="0"= | The countdown Set Countdown Timer… offers, in minutes or =h:mm:ss=; ="0"= offers none. Mirrors =org-timer-default-timer=. | |
| 300 | 301 | | =org-attach-id-dir= | string | ="data/"= | The folder ID-based attachment folders go in, relative to the org file's folder unless absolute. See [[file:04-outlines.org][Outlines]]. Mirrors =org-attach-id-dir=. | |
| 301 | 302 | | =org-attach-use-inheritance= | string | ="selective"= | Whether attachment folders come from an ancestor's =DIR= or =ID=: =selective=, ="t"= or ="nil"=. Mirrors =org-attach-use-inheritance=. | |
| 303 | | =org-cite-global-bibliography= | string | =""= | Bibliography files, =.bib= or CSL-JSON =.json=, that every file's citations use after its own =#+bibliography:= files, separated by =:=. =~= is your home folder. Insert Citation…, key completion, following citations and export read them. See [[file:09-links.org][Links]]. Mirrors =org-cite-global-bibliography=. | | |
| 302 | 304 | | =org-yank-image-save-method= | string | ="attach"= | Where a pasted image goes: =attach= for the entry's attachment folder, or a folder, relative to the org file's folder unless absolute. See [[file:09-links.org][Links]]. Mirrors =org-yank-image-save-method=. | |
| 303 | 305 | | =org-yank-dnd-method= | string | ="ask"= | What dropping files on the editor does: =ask=, =attach=, =open= or =file-link=. See [[file:09-links.org][Links]]. Mirrors =org-yank-dnd-method=. | |
| 304 | 306 | | =org-crypt-tag-matcher= | string | ="crypt"= | The tag Encrypt Tagged Entries… encrypts. A single tag. See [[file:04-outlines.org][Outlines]]. Mirrors =org-crypt-tag-matcher=. | |
| @@ -838,6 +840,7 @@ Only variables whose names start with =org-=, =appt-=, =display-line-numbers=, = | ||
| 838 | 840 | | =org-timer-format=, =org-timer-default-timer= | The same keys; a number becomes a string | |
| 839 | 841 | | =org-attach-id-dir= | The same key, when the value is a string or an =expand-file-name= form | |
| 840 | 842 | | =org-attach-use-inheritance= | =selective=, or =t= / =nil= as ="t"= / ="nil"= | |
| 843 | | =org-cite-global-bibliography= | The same key, the files separated by =:= | | |
| 841 | 844 | | =org-yank-image-save-method= | =attach=, or a folder name | |
| 842 | 845 | | =org-yank-dnd-method= | =ask=, =attach=, =open= or =file-link= | |
| 843 | 846 | | =org-crypt-tag-matcher= | The same key, when the value is a single tag | |
docs/manual/guide/14-ios.org +3 · view
| @@ -192,6 +192,8 @@ Cancel answers nothing, as =C-g= does. | ||
| 192 | 192 | |
| 193 | 193 | Show Backlinks in Commands lists the links to the heading at the caret and to the file; the daily note commands, Find Node…, Find Ref…, Insert Node Link… and Show Node Graph, all in Commands, work with org-roam-style notes, and the Folders tab's calendar menu opens today's, yesterday's and tomorrow's note. A new node and a daily-note capture open the capture sheet, whose Template picker lists the org-roam templates. See [[file:09-links.org][Links]]. |
| 194 | 194 | |
| 195 | Insert Citation… in Commands asks for a bibliography entry in a list you can search, then the prefix, suffix and style, as on the Mac; completion offers citation keys after =@= in a citation. Open Link in Commands, on a citation, shows its entry with buttons for its file, DOI, URL and place in the bibliography file. =zotero://= links go to the system, which opens Zotero if it is installed. Only bibliography files in the app's folders can be read. See [[file:09-links.org][Links]]. | |
| 196 | ||
| 195 | 197 | Incremental Search is in Commands, and on =C-s= and =C-r= with a hardware keyboard; see [[file:02-the-editor.org][The editor]]. =auto-fill-mode= works as on the Mac. |
| 196 | 198 | |
| 197 | 199 | The org-timer commands are in Commands; a running timer shows above the text. See [[file:06-dates-and-clocking.org][Dates and clocking]]. |
| @@ -530,6 +532,7 @@ These settings from =config.toml= apply on iOS: | ||
| 530 | 532 | - =org-enforce-todo-dependencies=, =org-enforce-todo-checkbox-dependencies=, =org-track-ordered-property-with-tag=, =org-agenda-dim-blocked-tasks= |
| 531 | 533 | - =org-roam-directory=, =org-roam-dailies-directory=, =org-roam-dailies-file=, =org-roam-dailies-head=, =org-roam-dailies-entry= |
| 532 | 534 | - =org-crypt-tag-matcher=, =org-crypt-use-before-save-magic=, =org-attach-id-dir=, =org-attach-use-inheritance=, =org-yank-image-save-method=, =org-timer-format=, =org-timer-default-timer= |
| 535 | - =org-cite-global-bibliography=, for files in the app's folders | |
| 533 | 536 | - =org-archive-location=, =[org-structure-template-alist]= |
| 534 | 537 | - =org-use-tag-inheritance=, =org-tags-exclude-from-inheritance=, =org-tag-alist= |
| 535 | 538 | - =org-use-speed-commands=, with a hardware keyboard |
l10n/Localizable.xcstrings +420 · view
| @@ -8767,6 +8767,41 @@ | ||
| 8767 | 8767 | } |
| 8768 | 8768 | } |
| 8769 | 8769 | }, |
| 8770 | "Cannot find citation key: %@": { | |
| 8771 | "comment": "Following a citation whose key no bibliography has", | |
| 8772 | "localizations": { | |
| 8773 | "de": { | |
| 8774 | "stringUnit": { | |
| 8775 | "state": "translated", | |
| 8776 | "value": "Zitierschlüssel nicht gefunden: %@" | |
| 8777 | } | |
| 8778 | }, | |
| 8779 | "es": { | |
| 8780 | "stringUnit": { | |
| 8781 | "state": "translated", | |
| 8782 | "value": "No se encuentra la clave de cita: %@" | |
| 8783 | } | |
| 8784 | }, | |
| 8785 | "fr": { | |
| 8786 | "stringUnit": { | |
| 8787 | "state": "translated", | |
| 8788 | "value": "Clé de citation introuvable : %@" | |
| 8789 | } | |
| 8790 | }, | |
| 8791 | "ja": { | |
| 8792 | "stringUnit": { | |
| 8793 | "state": "translated", | |
| 8794 | "value": "引用キーが見つかりません:%@" | |
| 8795 | } | |
| 8796 | }, | |
| 8797 | "pt-BR": { | |
| 8798 | "stringUnit": { | |
| 8799 | "state": "translated", | |
| 8800 | "value": "Chave de citação não encontrada: %@" | |
| 8801 | } | |
| 8802 | } | |
| 8803 | } | |
| 8804 | }, | |
| 8770 | 8805 | "Capture": { |
| 8771 | 8806 | "localizations": { |
| 8772 | 8807 | "de": { |
| @@ -22578,6 +22613,41 @@ | ||
| 22578 | 22613 | } |
| 22579 | 22614 | } |
| 22580 | 22615 | }, |
| 22616 | "Insert Citation…": { | |
| 22617 | "comment": "Command title", | |
| 22618 | "localizations": { | |
| 22619 | "de": { | |
| 22620 | "stringUnit": { | |
| 22621 | "state": "translated", | |
| 22622 | "value": "Zitat einfügen …" | |
| 22623 | } | |
| 22624 | }, | |
| 22625 | "es": { | |
| 22626 | "stringUnit": { | |
| 22627 | "state": "translated", | |
| 22628 | "value": "Insertar cita…" | |
| 22629 | } | |
| 22630 | }, | |
| 22631 | "fr": { | |
| 22632 | "stringUnit": { | |
| 22633 | "state": "translated", | |
| 22634 | "value": "Insérer une citation…" | |
| 22635 | } | |
| 22636 | }, | |
| 22637 | "ja": { | |
| 22638 | "stringUnit": { | |
| 22639 | "state": "translated", | |
| 22640 | "value": "引用を挿入…" | |
| 22641 | } | |
| 22642 | }, | |
| 22643 | "pt-BR": { | |
| 22644 | "stringUnit": { | |
| 22645 | "state": "translated", | |
| 22646 | "value": "Inserir Citação…" | |
| 22647 | } | |
| 22648 | } | |
| 22649 | } | |
| 22650 | }, | |
| 22581 | 22651 | "Insert Column View Table": { |
| 22582 | 22652 | "comment": "Command title", |
| 22583 | 22653 | "localizations": { |
| @@ -23867,6 +23937,41 @@ | ||
| 23867 | 23937 | } |
| 23868 | 23938 | } |
| 23869 | 23939 | }, |
| 23940 | "Key: ": { | |
| 23941 | "comment": "Insert Citation… asks for a bibliography entry", | |
| 23942 | "localizations": { | |
| 23943 | "de": { | |
| 23944 | "stringUnit": { | |
| 23945 | "state": "translated", | |
| 23946 | "value": "Schlüssel: " | |
| 23947 | } | |
| 23948 | }, | |
| 23949 | "es": { | |
| 23950 | "stringUnit": { | |
| 23951 | "state": "translated", | |
| 23952 | "value": "Clave: " | |
| 23953 | } | |
| 23954 | }, | |
| 23955 | "fr": { | |
| 23956 | "stringUnit": { | |
| 23957 | "state": "translated", | |
| 23958 | "value": "Clé : " | |
| 23959 | } | |
| 23960 | }, | |
| 23961 | "ja": { | |
| 23962 | "stringUnit": { | |
| 23963 | "state": "translated", | |
| 23964 | "value": "キー:" | |
| 23965 | } | |
| 23966 | }, | |
| 23967 | "pt-BR": { | |
| 23968 | "stringUnit": { | |
| 23969 | "state": "translated", | |
| 23970 | "value": "Chave: " | |
| 23971 | } | |
| 23972 | } | |
| 23973 | } | |
| 23974 | }, | |
| 23870 | 23975 | "Keyboard macros": { |
| 23871 | 23976 | "localizations": { |
| 23872 | 23977 | "de": { |
| @@ -29349,6 +29454,41 @@ | ||
| 29349 | 29454 | } |
| 29350 | 29455 | } |
| 29351 | 29456 | }, |
| 29457 | "No bibliography set": { | |
| 29458 | "comment": "Insert Citation… in a file without #+bibliography", | |
| 29459 | "localizations": { | |
| 29460 | "de": { | |
| 29461 | "stringUnit": { | |
| 29462 | "state": "translated", | |
| 29463 | "value": "Keine Bibliografie festgelegt" | |
| 29464 | } | |
| 29465 | }, | |
| 29466 | "es": { | |
| 29467 | "stringUnit": { | |
| 29468 | "state": "translated", | |
| 29469 | "value": "No hay bibliografía definida" | |
| 29470 | } | |
| 29471 | }, | |
| 29472 | "fr": { | |
| 29473 | "stringUnit": { | |
| 29474 | "state": "translated", | |
| 29475 | "value": "Aucune bibliographie définie" | |
| 29476 | } | |
| 29477 | }, | |
| 29478 | "ja": { | |
| 29479 | "stringUnit": { | |
| 29480 | "state": "translated", | |
| 29481 | "value": "参考文献が設定されていません" | |
| 29482 | } | |
| 29483 | }, | |
| 29484 | "pt-BR": { | |
| 29485 | "stringUnit": { | |
| 29486 | "state": "translated", | |
| 29487 | "value": "Nenhuma bibliografia definida" | |
| 29488 | } | |
| 29489 | } | |
| 29490 | } | |
| 29491 | }, | |
| 29352 | 29492 | "No body-only export": { |
| 29353 | 29493 | "localizations": { |
| 29354 | 29494 | "de": { |
| @@ -31743,6 +31883,41 @@ | ||
| 31743 | 31883 | } |
| 31744 | 31884 | } |
| 31745 | 31885 | }, |
| 31886 | "Open %@": { | |
| 31887 | "comment": "Opens a citation's file", | |
| 31888 | "localizations": { | |
| 31889 | "de": { | |
| 31890 | "stringUnit": { | |
| 31891 | "state": "translated", | |
| 31892 | "value": "%@ öffnen" | |
| 31893 | } | |
| 31894 | }, | |
| 31895 | "es": { | |
| 31896 | "stringUnit": { | |
| 31897 | "state": "translated", | |
| 31898 | "value": "Abrir %@" | |
| 31899 | } | |
| 31900 | }, | |
| 31901 | "fr": { | |
| 31902 | "stringUnit": { | |
| 31903 | "state": "translated", | |
| 31904 | "value": "Ouvrir %@" | |
| 31905 | } | |
| 31906 | }, | |
| 31907 | "ja": { | |
| 31908 | "stringUnit": { | |
| 31909 | "state": "translated", | |
| 31910 | "value": "%@を開く" | |
| 31911 | } | |
| 31912 | }, | |
| 31913 | "pt-BR": { | |
| 31914 | "stringUnit": { | |
| 31915 | "state": "translated", | |
| 31916 | "value": "Abrir %@" | |
| 31917 | } | |
| 31918 | } | |
| 31919 | } | |
| 31920 | }, | |
| 31746 | 31921 | "Open Agenda Window": { |
| 31747 | 31922 | "localizations": { |
| 31748 | 31923 | "de": { |
| @@ -31847,6 +32022,41 @@ | ||
| 31847 | 32022 | } |
| 31848 | 32023 | } |
| 31849 | 32024 | }, |
| 32025 | "Open DOI": { | |
| 32026 | "comment": "Opens a citation's DOI", | |
| 32027 | "localizations": { | |
| 32028 | "de": { | |
| 32029 | "stringUnit": { | |
| 32030 | "state": "translated", | |
| 32031 | "value": "DOI öffnen" | |
| 32032 | } | |
| 32033 | }, | |
| 32034 | "es": { | |
| 32035 | "stringUnit": { | |
| 32036 | "state": "translated", | |
| 32037 | "value": "Abrir DOI" | |
| 32038 | } | |
| 32039 | }, | |
| 32040 | "fr": { | |
| 32041 | "stringUnit": { | |
| 32042 | "state": "translated", | |
| 32043 | "value": "Ouvrir le DOI" | |
| 32044 | } | |
| 32045 | }, | |
| 32046 | "ja": { | |
| 32047 | "stringUnit": { | |
| 32048 | "state": "translated", | |
| 32049 | "value": "DOIを開く" | |
| 32050 | } | |
| 32051 | }, | |
| 32052 | "pt-BR": { | |
| 32053 | "stringUnit": { | |
| 32054 | "state": "translated", | |
| 32055 | "value": "Abrir DOI" | |
| 32056 | } | |
| 32057 | } | |
| 32058 | } | |
| 32059 | }, | |
| 31850 | 32060 | "Open Fold": { |
| 31851 | 32061 | "comment": "Command title", |
| 31852 | 32062 | "localizations": { |
| @@ -31952,6 +32162,41 @@ | ||
| 31952 | 32162 | } |
| 31953 | 32163 | } |
| 31954 | 32164 | }, |
| 32165 | "Open URL": { | |
| 32166 | "comment": "Opens a citation's URL", | |
| 32167 | "localizations": { | |
| 32168 | "de": { | |
| 32169 | "stringUnit": { | |
| 32170 | "state": "translated", | |
| 32171 | "value": "URL öffnen" | |
| 32172 | } | |
| 32173 | }, | |
| 32174 | "es": { | |
| 32175 | "stringUnit": { | |
| 32176 | "state": "translated", | |
| 32177 | "value": "Abrir URL" | |
| 32178 | } | |
| 32179 | }, | |
| 32180 | "fr": { | |
| 32181 | "stringUnit": { | |
| 32182 | "state": "translated", | |
| 32183 | "value": "Ouvrir l'URL" | |
| 32184 | } | |
| 32185 | }, | |
| 32186 | "ja": { | |
| 32187 | "stringUnit": { | |
| 32188 | "state": "translated", | |
| 32189 | "value": "URLを開く" | |
| 32190 | } | |
| 32191 | }, | |
| 32192 | "pt-BR": { | |
| 32193 | "stringUnit": { | |
| 32194 | "state": "translated", | |
| 32195 | "value": "Abrir URL" | |
| 32196 | } | |
| 32197 | } | |
| 32198 | } | |
| 32199 | }, | |
| 31955 | 32200 | "Open after export": { |
| 31956 | 32201 | "localizations": { |
| 31957 | 32202 | "de": { |
| @@ -33678,6 +33923,41 @@ | ||
| 33678 | 33923 | } |
| 33679 | 33924 | } |
| 33680 | 33925 | }, |
| 33926 | "Prefix (empty for none): ": { | |
| 33927 | "comment": "Insert Citation… asks for text before the key", | |
| 33928 | "localizations": { | |
| 33929 | "de": { | |
| 33930 | "stringUnit": { | |
| 33931 | "state": "translated", | |
| 33932 | "value": "Präfix (leer für keins): " | |
| 33933 | } | |
| 33934 | }, | |
| 33935 | "es": { | |
| 33936 | "stringUnit": { | |
| 33937 | "state": "translated", | |
| 33938 | "value": "Prefijo (vacío para ninguno): " | |
| 33939 | } | |
| 33940 | }, | |
| 33941 | "fr": { | |
| 33942 | "stringUnit": { | |
| 33943 | "state": "translated", | |
| 33944 | "value": "Préfixe (vide pour aucun) : " | |
| 33945 | } | |
| 33946 | }, | |
| 33947 | "ja": { | |
| 33948 | "stringUnit": { | |
| 33949 | "state": "translated", | |
| 33950 | "value": "前置き(空欄でなし):" | |
| 33951 | } | |
| 33952 | }, | |
| 33953 | "pt-BR": { | |
| 33954 | "stringUnit": { | |
| 33955 | "state": "translated", | |
| 33956 | "value": "Prefixo (vazio para nenhum): " | |
| 33957 | } | |
| 33958 | } | |
| 33959 | } | |
| 33960 | }, | |
| 33681 | 33961 | "Previous Allowed Value": { |
| 33682 | 33962 | "comment": "Command title", |
| 33683 | 33963 | "localizations": { |
| @@ -39491,6 +39771,41 @@ | ||
| 39491 | 39771 | } |
| 39492 | 39772 | } |
| 39493 | 39773 | }, |
| 39774 | "Select citation key: ": { | |
| 39775 | "comment": "Following a citation with several keys", | |
| 39776 | "localizations": { | |
| 39777 | "de": { | |
| 39778 | "stringUnit": { | |
| 39779 | "state": "translated", | |
| 39780 | "value": "Zitierschlüssel wählen: " | |
| 39781 | } | |
| 39782 | }, | |
| 39783 | "es": { | |
| 39784 | "stringUnit": { | |
| 39785 | "state": "translated", | |
| 39786 | "value": "Seleccionar clave de cita: " | |
| 39787 | } | |
| 39788 | }, | |
| 39789 | "fr": { | |
| 39790 | "stringUnit": { | |
| 39791 | "state": "translated", | |
| 39792 | "value": "Choisir la clé de citation : " | |
| 39793 | } | |
| 39794 | }, | |
| 39795 | "ja": { | |
| 39796 | "stringUnit": { | |
| 39797 | "state": "translated", | |
| 39798 | "value": "引用キーを選択:" | |
| 39799 | } | |
| 39800 | }, | |
| 39801 | "pt-BR": { | |
| 39802 | "stringUnit": { | |
| 39803 | "state": "translated", | |
| 39804 | "value": "Selecionar chave de citação: " | |
| 39805 | } | |
| 39806 | } | |
| 39807 | } | |
| 39808 | }, | |
| 39494 | 39809 | "Selection (count-words-region)": { |
| 39495 | 39810 | "localizations": { |
| 39496 | 39811 | "de": { |
| @@ -41487,6 +41802,41 @@ | ||
| 41487 | 41802 | } |
| 41488 | 41803 | } |
| 41489 | 41804 | }, |
| 41805 | "Show in Bibliography": { | |
| 41806 | "comment": "Opens the bibliography file at a citation's entry", | |
| 41807 | "localizations": { | |
| 41808 | "de": { | |
| 41809 | "stringUnit": { | |
| 41810 | "state": "translated", | |
| 41811 | "value": "In Bibliografie zeigen" | |
| 41812 | } | |
| 41813 | }, | |
| 41814 | "es": { | |
| 41815 | "stringUnit": { | |
| 41816 | "state": "translated", | |
| 41817 | "value": "Mostrar en la bibliografía" | |
| 41818 | } | |
| 41819 | }, | |
| 41820 | "fr": { | |
| 41821 | "stringUnit": { | |
| 41822 | "state": "translated", | |
| 41823 | "value": "Afficher dans la bibliographie" | |
| 41824 | } | |
| 41825 | }, | |
| 41826 | "ja": { | |
| 41827 | "stringUnit": { | |
| 41828 | "state": "translated", | |
| 41829 | "value": "参考文献ファイルで表示" | |
| 41830 | } | |
| 41831 | }, | |
| 41832 | "pt-BR": { | |
| 41833 | "stringUnit": { | |
| 41834 | "state": "translated", | |
| 41835 | "value": "Mostrar na Bibliografia" | |
| 41836 | } | |
| 41837 | } | |
| 41838 | } | |
| 41839 | }, | |
| 41490 | 41840 | "Show in Calendar": { |
| 41491 | 41841 | "localizations": { |
| 41492 | 41842 | "de": { |
| @@ -43631,6 +43981,41 @@ | ||
| 43631 | 43981 | } |
| 43632 | 43982 | } |
| 43633 | 43983 | }, |
| 43984 | "Style (empty for default): ": { | |
| 43985 | "comment": "Insert Citation… asks for a citation style", | |
| 43986 | "localizations": { | |
| 43987 | "de": { | |
| 43988 | "stringUnit": { | |
| 43989 | "state": "translated", | |
| 43990 | "value": "Stil (leer für Standard): " | |
| 43991 | } | |
| 43992 | }, | |
| 43993 | "es": { | |
| 43994 | "stringUnit": { | |
| 43995 | "state": "translated", | |
| 43996 | "value": "Estilo (vacío para el predeterminado): " | |
| 43997 | } | |
| 43998 | }, | |
| 43999 | "fr": { | |
| 44000 | "stringUnit": { | |
| 44001 | "state": "translated", | |
| 44002 | "value": "Style (vide pour celui par défaut) : " | |
| 44003 | } | |
| 44004 | }, | |
| 44005 | "ja": { | |
| 44006 | "stringUnit": { | |
| 44007 | "state": "translated", | |
| 44008 | "value": "スタイル(空欄で既定):" | |
| 44009 | } | |
| 44010 | }, | |
| 44011 | "pt-BR": { | |
| 44012 | "stringUnit": { | |
| 44013 | "state": "translated", | |
| 44014 | "value": "Estilo (vazio para o padrão): " | |
| 44015 | } | |
| 44016 | } | |
| 44017 | } | |
| 44018 | }, | |
| 43634 | 44019 | "Subscriptions renew automatically until cancelled in your Apple Account settings, at least 24 hours before the period ends.": { |
| 43635 | 44020 | "localizations": { |
| 43636 | 44021 | "de": { |
| @@ -43733,6 +44118,41 @@ | ||
| 43733 | 44118 | } |
| 43734 | 44119 | } |
| 43735 | 44120 | }, |
| 44121 | "Suffix (empty for none): ": { | |
| 44122 | "comment": "Insert Citation… asks for text after the key", | |
| 44123 | "localizations": { | |
| 44124 | "de": { | |
| 44125 | "stringUnit": { | |
| 44126 | "state": "translated", | |
| 44127 | "value": "Suffix (leer für keins): " | |
| 44128 | } | |
| 44129 | }, | |
| 44130 | "es": { | |
| 44131 | "stringUnit": { | |
| 44132 | "state": "translated", | |
| 44133 | "value": "Sufijo (vacío para ninguno): " | |
| 44134 | } | |
| 44135 | }, | |
| 44136 | "fr": { | |
| 44137 | "stringUnit": { | |
| 44138 | "state": "translated", | |
| 44139 | "value": "Suffixe (vide pour aucun) : " | |
| 44140 | } | |
| 44141 | }, | |
| 44142 | "ja": { | |
| 44143 | "stringUnit": { | |
| 44144 | "state": "translated", | |
| 44145 | "value": "後置き(空欄でなし):" | |
| 44146 | } | |
| 44147 | }, | |
| 44148 | "pt-BR": { | |
| 44149 | "stringUnit": { | |
| 44150 | "state": "translated", | |
| 44151 | "value": "Sufixo (vazio para nenhum): " | |
| 44152 | } | |
| 44153 | } | |
| 44154 | } | |
| 44155 | }, | |
| 43736 | 44156 | "Sunset": { |
| 43737 | 44157 | "localizations": { |
| 43738 | 44158 | "de": { |