Commit 1e56a2e00d
Verified · cmc
Layout: unified · split
Sources/OrgApp/EmacsImport.swift +33 −1
| @@ -1095,6 +1095,30 @@ extension EmacsImport { | |||
| 1095 | } | 1095 | } |
| 1096 | } | 1096 | } |
| 1097 | 1097 | ||
| 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 | |||
| 1098 | @MainActor | 1122 | @MainActor |
| 1099 | static func isRoot(_ url: URL, in workspace: WorkspaceModel) -> Bool { | 1123 | static func isRoot(_ url: URL, in workspace: WorkspaceModel) -> Bool { |
| 1100 | workspace.roots.contains { URL(fileURLWithPath: $0.path).standardizedFileURL.path == url.path } | 1124 | workspace.roots.contains { URL(fileURLWithPath: $0.path).standardizedFileURL.path == url.path } |
| @@ -1108,6 +1132,7 @@ extension EmacsImport { | |||
| 1108 | /// With `writeConfig`, settings and structure templates are written into `config.toml` too, | 1132 | /// With `writeConfig`, settings and structure templates are written into `config.toml` too, |
| 1109 | /// for where nothing syncs user defaults into it (iOS). With `chosenFolders`, folders chosen in | 1133 | /// for where nothing syncs user defaults into it (iOS). With `chosenFolders`, folders chosen in |
| 1110 | /// open panels by the path of their item, a folder item is added only as the folder chosen for it. | 1134 | /// 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`. | ||
| 1111 | public static func apply( | 1136 | public static func apply( |
| 1112 | _ items: [Item], defaults: UserDefaults = .standard, workspace: WorkspaceModel?, directory: URL = UserConfig.directory, | 1137 | _ items: [Item], defaults: UserDefaults = .standard, workspace: WorkspaceModel?, directory: URL = UserConfig.directory, |
| 1113 | writeConfig: Bool = false, chosenFolders: [String: URL]? = nil | 1138 | writeConfig: Bool = false, chosenFolders: [String: URL]? = nil |
| @@ -1116,8 +1141,15 @@ extension EmacsImport { | |||
| 1116 | var settings = 0, folders = 0, templates = 0, bindings = 0, blocks = 0, views = 0, projects = 0 | 1141 | var settings = 0, folders = 0, templates = 0, bindings = 0, blocks = 0, views = 0, projects = 0 |
| 1117 | var problems: [String] = [] | 1142 | var problems: [String] = [] |
| 1118 | for item in items { | 1143 | for item in items { |
| 1119 | guard case .setting(let key, let value) = item.change, | 1144 | guard case .setting(let key, var value) = item.change, |
| 1120 | let setting = UserConfig.settings.first(where: { $0.path == key || $0.key == key }) else { continue } | 1145 | 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 | } | ||
| 1121 | if let problem = UserConfig.store(value, setting, in: defaults) { | 1153 | if let problem = UserConfig.store(value, setting, in: defaults) { |
| 1122 | problems.append(problem) | 1154 | problems.append(problem) |
| 1123 | } else { | 1155 | } else { |
Tests/OrgAppTests/EmacsImportFoldersTests.swift +22
| @@ -32,6 +32,28 @@ struct EmacsImportFoldersTests { | |||
| 32 | #expect(!summary.contains(first), "\(summary)") | 32 | #expect(!summary.contains(first), "\(summary)") |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 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 | |||
| 35 | @Test func withoutChosenFoldersAddsWhatsWritten() async throws { | 57 | @Test func withoutChosenFoldersAddsWhatsWritten() async throws { |
| 36 | let notes = try Folder() | 58 | let notes = try Folder() |
| 37 | let config = try Folder() | 59 | 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 | |||
| 315 | 315 | ||
| 316 | Clock 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. | 316 | Clock 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. |
| 317 | 317 | ||
| 318 | With =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. | 318 | With =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. |
| 319 | 319 | ||
| 320 | Clock 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. | 320 | Clock 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. |
| 321 | 321 | ||
| @@ -393,7 +393,7 @@ Import from Emacs reads an Emacs or Doom configuration folder, such as a synced | |||
| 393 | 393 | ||
| 394 | With 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. | 394 | With 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. |
| 395 | 395 | ||
| 396 | Folders 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. | 396 | Folders 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. |
| 397 | 397 | ||
| 398 | The Agenda, TODO Dependencies, Calendar and Reminders sections are the only places the app changes a setting itself, besides Import from Emacs: | 398 | The Agenda, TODO Dependencies, Calendar and Reminders sections are the only places the app changes a setting itself, besides Import from Emacs: |
| 399 | 399 | ||