Sources/OrgApp/ProgramRunning.swift
21 lines · 959 bytes
1import Foundation
2import OrgCore
3
4/// Runs Babel jobs and Emacs as processes, for an app allowed to start them.
5public protocol ProgramRunning: Sendable {
6 /// Runs `job` in `fileDirectory`, or its `:dir`.
7 func runBabel(_ job: BabelJob, fileDirectory: URL) async throws -> BabelOutput
8 /// Runs `form` in Emacs on a copy of `text`; returns the table that starts at `table.lowerBound`.
9 func recalculateTable(text: String, directory: URL, table: Range<Int>, point: Int, form: String) async throws -> String
10}
11
12extension DocumentSession {
13 /// The runner for programs, set at launch by an app that may start them. Without one,
14 /// only what runs natively runs.
15 public static var programs: (any ProgramRunning)?
16
17 /// Overrides `programs` for the current task and the tasks it starts.
18 @TaskLocal public static var scopedPrograms: (any ProgramRunning)?
19
20 static var runner: (any ProgramRunning)? { scopedPrograms ?? programs }
21}