Commit 1e56a2e00d

1e56a2e00dd480286c662c6b043a393f2947fbd7

parent: 586bad784d

Verified · cmc

cmc <hello@cleberg.net> · 2026-11-21 09:40 UTC

Move imported org-agenda-files to the folders chosen on iOS

Layout: unified · split

Sources/OrgApp/EmacsImport.swift +33 −1
@@ -1095,6 +1095,30 @@ extension EmacsImport {
10951095 }
10961096 }
10971097
1098 /// `org-agenda-files` (one path a line) with each path below a folder in `chosenFolders` moved
1099 /// to the folder chosen for it. Paths with no chosen folder that don't exist here are left
1100 /// out; nil when none remain. With `keepingOriginals`, for a config.toml the Mac reads too,
1101 /// the Mac's paths are all kept, a moved one beside its new path; each device skips the paths
1102 /// it doesn't have.
1103 static func agendaFiles(_ list: String, chosenFolders: [String: URL], keepingOriginals: Bool = false) -> String? {
1104 func standard(_ path: String) -> String { URL(fileURLWithPath: OrgPaths.expandingTilde(path)).standardizedFileURL.path }
1105 let folders = chosenFolders.map { (standard($0.key), $0.value.standardizedFileURL.path) }.sorted { $0.0.count > $1.0.count }
1106 var here: [String] = [], all: [String] = []
1107 for path in list.split(separator: "\n").map(String.init) {
1108 let full = standard(path)
1109 if let (mac, device) = folders.first(where: { full == $0.0 || full.hasPrefix($0.0 + "/") }) {
1110 let moved = device + full.dropFirst(mac.count)
1111 here.append(moved)
1112 all += moved == full ? [path] : [path, moved]
1113 } else {
1114 if FileManager.default.fileExists(atPath: full) { here.append(path) }
1115 all.append(path)
1116 }
1117 }
1118 guard !here.isEmpty else { return nil }
1119 return (keepingOriginals ? all : here).joined(separator: "\n")
1120 }
1121
10981122 @MainActor
10991123 static func isRoot(_ url: URL, in workspace: WorkspaceModel) -> Bool {
11001124 workspace.roots.contains { URL(fileURLWithPath: $0.path).standardizedFileURL.path == url.path }
@@ -1108,6 +1132,7 @@ extension EmacsImport {
11081132 /// With `writeConfig`, settings and structure templates are written into `config.toml` too,
11091133 /// for where nothing syncs user defaults into it (iOS). With `chosenFolders`, folders chosen in
11101134 /// open panels by the path of their item, a folder item is added only as the folder chosen for it.
1135 /// `org-agenda-files` paths below a chosen folder are moved into it; see `agendaFiles`.
11111136 public static func apply(
11121137 _ items: [Item], defaults: UserDefaults = .standard, workspace: WorkspaceModel?, directory: URL = UserConfig.directory,
11131138 writeConfig: Bool = false, chosenFolders: [String: URL]? = nil
@@ -1116,8 +1141,15 @@ extension EmacsImport {
11161141 var settings = 0, folders = 0, templates = 0, bindings = 0, blocks = 0, views = 0, projects = 0
11171142 var problems: [String] = []
11181143 for item in items {
1119 guard case .setting(let key, let value) = item.change,
1144 guard case .setting(let key, var value) = item.change,
11201145 let setting = UserConfig.settings.first(where: { $0.path == key || $0.key == key }) else { continue }
1146 if key == "org-agenda-files", let chosenFolders {
1147 guard let paths = Self.agendaFiles(value.string ?? "", chosenFolders: chosenFolders, keepingOriginals: writeConfig) else {
1148 problems.append("org-agenda-files wasn't set: no folder was chosen for its files")
1149 continue
1150 }
1151 value = .string(paths)
1152 }
11211153 if let problem = UserConfig.store(value, setting, in: defaults) {
11221154 problems.append(problem)
11231155 } else {
Tests/OrgAppTests/EmacsImportFoldersTests.swift +22
@@ -32,6 +32,28 @@ struct EmacsImportFoldersTests {
3232 #expect(!summary.contains(first), "\(summary)")
3333 }
3434
35 @Test func movesAgendaFilesToTheChosenFolders() async throws {
36 let picked = try Folder()
37 let config = try Folder()
38 let model = try WorkspaceModel(directory: nil)
39 let mac = "/nowhere-\(UUID().uuidString)/org", other = "/also-nowhere-\(UUID().uuidString)"
40 let files = EmacsImport.Item(id: 0, name: "org-agenda-files", summary: "", source: "config.el:1",
41 change: .setting(key: "org-agenda-files", value: .string("\(mac)/inbox.org\n\(mac)/work/a.org\n\(other)/b.org")))
42 let stored = defaults()
43 _ = await EmacsImport.apply([files] + items([mac, other]), defaults: stored, workspace: model, directory: config.url, chosenFolders: [mac: picked.url])
44 let dir = picked.url.standardizedFileURL.path
45 #expect(stored.string(forKey: "agendaFiles") == "\(dir)/inbox.org\n\(dir)/work/a.org")
46
47 let none = defaults()
48 let summary = await EmacsImport.apply([files], defaults: none, workspace: model, directory: config.url, chosenFolders: [:])
49 #expect(none.string(forKey: "agendaFiles") == nil)
50 #expect(summary.contains("org-agenda-files wasn't set"), "\(summary)")
51
52 // A config.toml the Mac reads too keeps the Mac's paths beside the device's.
53 let shared = EmacsImport.agendaFiles("\(mac)/inbox.org\n\(other)/b.org", chosenFolders: [mac: picked.url], keepingOriginals: true)
54 #expect(shared == "\(mac)/inbox.org\n\(dir)/inbox.org\n\(other)/b.org")
55 }
56
3557 @Test func withoutChosenFoldersAddsWhatsWritten() async throws {
3658 let notes = try Folder()
3759 let config = try Folder()
docs/manual/guide/14-ios.org +2 −2
@@ -315,7 +315,7 @@ Recent Entries, in the bar and in the editor's More menu, lists the recently clo
315315
316316Clock questions open in a sheet: the task selection and the resolution keys as lists to tap, and minutes or a date and time as a field. Cancel answers nothing, as =q= does. Clocking in with no clock running first asks about open clocks in your folders, from the editor, an agenda entry's Clock In or a capture template with =clock-in=; Resolve Open Clocks… asks about every open clock. Both work as on the Mac.
317317
318With =org-clock-idle-time= set, returning to the app while a clock runs asks what to do with the time away, if it was longer than that many minutes: iOS has no idle time, so time in other apps or with the device locked stands in for it. See [[file:06-dates-and-clocking.org][Dates and clocking]]. =org-clock-history-length= applies too.
318With =org-clock-idle-time= set, returning to the app while a clock runs asks what to do with the time away, if it was longer than that many minutes: iOS has no idle time, so time in other apps or with the device locked stands in for it. Time working in another orgstar window doesn't count. See [[file:06-dates-and-clocking.org][Dates and clocking]]. =org-clock-history-length= applies too.
319319
320320Clock Report shows the time per day and heading for the files you choose. It starts with the files that contain clock lines. Turn on Limit dates to choose a range. The share button sends the report as text.
321321
@@ -393,7 +393,7 @@ Import from Emacs reads an Emacs or Doom configuration folder, such as a synced
393393
394394With a configuration folder, settings and structure templates are written to its =config.toml=, and capture templates, key bindings and agenda views to its =capture.toml=, =keymap.toml= and =views.toml=, so the Mac reads them too. Without one, settings are kept on the device.
395395
396Folders from =org-directory= and =org-agenda-files= name the Mac's paths, so the screen lists them under Folders on this device. Tap each one and choose the folder on this device that holds the same files, such as its synced copy in iCloud Drive. Import adds the chosen folders to the Folders tab; folders not chosen aren't added, and the summary says so.
396Folders from =org-directory= and =org-agenda-files= name the Mac's paths, so the screen lists them under Folders on this device. Tap each one and choose the folder on this device that holds the same files, such as its synced copy in iCloud Drive. Import adds the chosen folders to the Folders tab; folders not chosen aren't added, and the summary says so. =org-agenda-files= entries in a chosen folder point to the same files in the folder chosen for it, and entries in folders not chosen are left out. With a configuration folder, =config.toml= keeps the Mac's entries as well, beside the device's; each device skips the files it doesn't have.
397397
398398The Agenda, TODO Dependencies, Calendar and Reminders sections are the only places the app changes a setting itself, besides Import from Emacs:
399399