Sources/OrgApp/TangleWriter.swift

72f19c1f379646b2cfc45c5053a72e5997fbef36
orgstar/Sources/OrgApp/TangleWriter.swift

27 lines · 1036 bytes

 1import Foundation
 2import OrgConfig
 3import OrgCore
 4
 5extension DocumentSession {
 6    /// The files `tangle` would write.
 7    public func tangleFiles(_ scope: Tangle.Scope) -> [String] {
 8        guard let path, let document, case .success(let output) = Tangle.run(text: document.text, path: path, scope: scope, tree: document.tree) else { return [] }
 9        return output.files.map(\.path)
10    }
11
12    /// Tangles the open file: its text as it is now, written beside it.
13    public func tangle(_ scope: Tangle.Scope) -> String {
14        guard let path, let document else { return "No file is open" }
15        switch Tangle.run(text: document.text, path: path, scope: scope, tree: document.tree) {
16        case .failure(.message(let message)):
17            return message
18        case .success(let output):
19            do {
20                try TangleWriter.write(output, source: path)
21                return TangleWriter.message(output, source: path)
22            } catch {
23                return error.message
24            }
25        }
26    }
27}
Keyboard shortcuts

Global

⌘K
Command palette & jump
/
Focus search
?
Show this help
g d
Dashboard
g e
Explore repositories
g n
Notifications

Repository & editor

t
Find file in repository
y
Copy immutable SHA permalink
g c
Code tab
g i
Issues tab
g m
Merge requests tab
g b
Builds tab
⌘↵
Submit active form