Commit d4ccb12cca

d4ccb12cca1f5f07b8acf23dc1cac828bb6a1498

parent: b3ba6ca101

Verified · cmc

cmc <hello@cleberg.net> · 2026-10-16 17:10 UTC

Setting to leave archive files out of the agenda

agenda-exclude-archives (Settings ▸ Agenda ▸ Leave out archive files on
iOS) drops the files other agenda files archive to, by #+ARCHIVE:, an
:ARCHIVE: property or org-archive-location, from the agenda, reminders,
widgets and the board.

Layout: unified · split

Sources/OrgApp/AgendaModel.swift +9 −1
@@ -36,6 +36,8 @@ public final class AgendaModel {
3636 public var startOnWeekday: Int? = 1
3737 /// Files below the top level of each folder are agenda files too.
3838 public var includeSubfolders = false
39 /// Files other agenda files archive to are left out.
40 public var excludeArchives = OrgPreferences.agendaExcludeArchives()
3941 /// `org-agenda-files`: when not empty, the agenda reads these instead of the folders' files.
4042 public var agendaFiles = OrgPreferences.agendaFiles()
4143 public var options = AgendaOptions()
@@ -207,7 +209,13 @@ public final class AgendaModel {
207209 cache.open[source.path] = (defaults, blocking, source.source)
208210 }
209211 }
210 return loaded.map(\.source)
212 var sources = loaded.map(\.source)
213 if excludeArchives {
214 let location = OrgPreferences.options().archiveLocation ?? "%s_archive::"
215 let archives = Set(sources.flatMap { $0.archiveFiles(location: location) })
216 sources.removeAll { archives.contains($0.path) }
217 }
218 return sources
211219 }
212220
213221 /// The days as rows with the events, empty days hidden unless `showAllDates`; see
Sources/OrgApp/OrgPreferences.swift +2
@@ -95,6 +95,8 @@ public enum OrgPreferences {
9595 return words == ["t"] || words.isEmpty ? [] : Set(words)
9696 }
9797 public static func agendaSubfolders(_ defaults: UserDefaults = .standard) -> Bool { bool("agendaSubfolders", defaults) }
98 /// The agenda leaves out the files other agenda files archive to.
99 public static func agendaExcludeArchives(_ defaults: UserDefaults = .standard) -> Bool { bool("agendaExcludeArchives", defaults) }
98100 /// `org-agenda-show-all-dates`: days without entries show.
99101 public static func agendaShowAllDates(_ defaults: UserDefaults = .standard) -> Bool { bool("agendaShowAllDates", defaults) }
100102 public static func agendaSkipScheduledIfDone(_ defaults: UserDefaults = .standard) -> Bool { bool("agendaSkipScheduledIfDone", defaults) }
Sources/OrgApp/UserConfig.swift +2
@@ -348,6 +348,8 @@ public enum UserConfig {
348348 comment: "folder names never listed or searched, separated by spaces", legacy: ""),
349349 Setting(section: "orgstar", key: "agenda-include-subfolders", defaultsKey: "agendaSubfolders", kind: .bool, fallback: .bool(false),
350350 comment: "the agenda reads org files in subfolders too", legacy: "agenda.include-subfolders"),
351 Setting(section: "orgstar", key: "agenda-exclude-archives", defaultsKey: "agendaExcludeArchives", kind: .bool, fallback: .bool(false),
352 comment: "the agenda leaves out files that other agenda files archive to (#+ARCHIVE:, org-archive-location)", legacy: ""),
351353 Setting(section: "orgstar", key: "reminders", defaultsKey: "reminders", kind: .bool, fallback: .bool(true),
352354 comment: "notify before timed entries", legacy: "agenda.reminders"),
353355 Setting(section: "orgstar", key: "calendar-events", defaultsKey: "calendarEvents", kind: .bool, fallback: .bool(false),
Sources/OrgCore/Agenda/AgendaSource.swift +15
@@ -101,6 +101,12 @@ public struct AgendaSource: Sendable {
101101
102102 let headings: [Heading]
103103
104 /// The other files this one archives to, as `org-all-archive-files` names them, with
105 /// `location` (`org-archive-location`) when the file sets none.
106 public func archiveFiles(location: String) -> [String] {
107 ([archiveKeyword ?? location] + archiveProperties).compactMap { Archive.archiveFile($0, sourcePath: path) }.filter { $0 != path }
108 }
109
104110 /// The file's habits not done and not in skipped trees: their titles, heading offsets and
105111 /// what their consistency graphs are drawn from.
106112 public var habits: [(title: String, offset: Int, habit: Habit)] {
@@ -121,6 +127,9 @@ public struct AgendaSource: Sendable {
121127 let firstDone: [String: String]
122128 /// The file's text, for the search view.
123129 public let text: String
130 /// The archive locations the file names: its `#+ARCHIVE:`, then each `:ARCHIVE:` property's.
131 let archiveKeyword: String?
132 let archiveProperties: [String]
124133 let priorities: Priorities
125134
126135 /// `checksBlocking` false leaves every heading unblocked, for when neither enforce
@@ -159,6 +168,7 @@ public struct AgendaSource: Sendable {
159168 func sectionStamps(_ index: Int) -> [String] { stampsByHeading[index] ?? [] }
160169
161170 var keywordCategory = SetupFile.keywords(tree.settings.setupKeywords).last { $0.key == "CATEGORY" }?.value.trimmingCharacters(in: .whitespaces)
171 var archiveKeyword: String?
162172 var srcBodies: [Range<Int>] = []
163173 var planningLines: [Range<Int>] = []
164174 var timestampNodes: [Int] = []
@@ -170,6 +180,8 @@ public struct AgendaSource: Sendable {
170180 let line = child.text.trimmingCharacters(in: .whitespacesAndNewlines)
171181 if line.uppercased().hasPrefix("#+CATEGORY:") {
172182 keywordCategory = line.dropFirst("#+CATEGORY:".count).trimmingCharacters(in: .whitespaces)
183 } else if archiveKeyword == nil, line.uppercased().hasPrefix("#+ARCHIVE:") {
184 archiveKeyword = line.dropFirst("#+ARCHIVE:".count).trimmingCharacters(in: .whitespaces)
173185 }
174186 case .block:
175187 if DocumentModel.isSrcBlock(child) {
@@ -289,6 +301,9 @@ public struct AgendaSource: Sendable {
289301 ))
290302 }
291303 self.headings = headings
304 self.archiveKeyword = archiveKeyword
305 ?? SetupFile.keywords(tree.settings.setupKeywords).last { $0.key == "ARCHIVE" }?.value.trimmingCharacters(in: .whitespaces)
306 archiveProperties = (model.property("ARCHIVE", of: nil).map { [$0.value] } ?? []) + headings.compactMap { $0.properties["ARCHIVE"] }
292307
293308 let starts = model.headings.map(\.headingRange.lowerBound)
294309 func heading(at offset: Int) -> Int? {
Sources/Orgstar/AgendaView.swift +1
@@ -168,6 +168,7 @@ struct AgendaView: View {
168168 agenda.startOffset = startOffset
169169 agenda.startOnWeekday = Int(startOnWeekday)
170170 agenda.includeSubfolders = includeSubfolders
171 agenda.excludeArchives = OrgPreferences.agendaExcludeArchives()
171172 agenda.agendaFiles = OrgPreferences.agendaFiles()
172173 agenda.options.prefixFormat = ["agenda": prefixAgenda, "todo": prefixTodo, "tags": prefixTags]
173174 agenda.options.logMode = logMode
Sources/Orgstar/BoardView.swift +1
@@ -79,6 +79,7 @@ struct BoardView: View {
7979 .navigationTitle(kanban ? "Kanban" : "Entries")
8080 .task(id: RefreshKey(match: match, subfolders: includeSubfolders, files: workspace.files.count, changed: workspace.changedFile?.version, edits: session.editVersion, path: session.path, tick: tick)) {
8181 agenda.includeSubfolders = includeSubfolders
82 agenda.excludeArchives = OrgPreferences.agendaExcludeArchives()
8283 agenda.agendaFiles = OrgPreferences.agendaFiles()
8384 let open = session.openTexts
8485 let result = await agenda.board(open: open, match: match)
Sources/Orgstar/ContentView.swift +2
@@ -929,6 +929,7 @@ struct ContentView: View {
929929 let agenda = reminderAgenda ?? AgendaModel(workspace: workspace)
930930 reminderAgenda = agenda
931931 agenda.includeSubfolders = agendaSubfolders
932 agenda.excludeArchives = OrgPreferences.agendaExcludeArchives()
932933 let open = session.openTexts
933934 let reminders = await agenda.reminders(open: open, lead: reminderLead)
934935 guard !Task.isCancelled else { return }
@@ -944,6 +945,7 @@ struct ContentView: View {
944945 days.mode = .agenda(span: AgendaSnapshot.dayCount, startOffset: 0)
945946 days.startOnWeekday = nil
946947 days.includeSubfolders = agendaSubfolders
948 days.excludeArchives = OrgPreferences.agendaExcludeArchives()
947949 days.agendaFiles = OrgPreferences.agendaFiles()
948950 days.options = OrgPreferences.agendaOptions(days.options)
949951 days.options.logMode = false
Sources/OrgstarMobile/BoardScreen.swift +1
@@ -94,6 +94,7 @@ struct BoardScreen: View {
9494 .task(id: RefreshKey(match: match, files: workspace.files.count, changed: workspace.changedFile?.version, edits: session.editVersion,
9595 tick: tick, settings: model.settingsVersion)) {
9696 agenda.includeSubfolders = OrgPreferences.agendaSubfolders()
97 agenda.excludeArchives = OrgPreferences.agendaExcludeArchives()
9798 agenda.agendaFiles = OrgPreferences.agendaFiles()
9899 let result = await agenda.board(open: session.openTexts, match: match)
99100 entries = result.entries
Sources/OrgstarMobile/MobileModel.swift +2
@@ -153,6 +153,7 @@ final class MobileModel {
153153 agenda.startOffset = OrgPreferences.agendaStartOffset()
154154 agenda.startOnWeekday = OrgPreferences.agendaStartOnWeekday()
155155 agenda.includeSubfolders = OrgPreferences.agendaSubfolders()
156 agenda.excludeArchives = OrgPreferences.agendaExcludeArchives()
156157 agenda.agendaFiles = OrgPreferences.agendaFiles()
157158 agenda.options = OrgPreferences.agendaOptions(agenda.options)
158159 agenda.calendarEvents = OrgPreferences.calendarEvents() ? calendarEvents : nil
@@ -296,6 +297,7 @@ final class MobileModel {
296297 days.startOnWeekday = nil
297298 if let agenda {
298299 days.includeSubfolders = agenda.includeSubfolders
300 days.excludeArchives = agenda.excludeArchives
299301 days.options = agenda.options
300302 days.options.logMode = false
301303 days.calendarEvents = agenda.calendarEvents
Sources/OrgstarMobile/SettingsScreen.swift +8 −1
@@ -41,7 +41,7 @@ struct SettingsScreen: View {
4141 } footer: {
4242 Text("A folder with config.toml and capture.toml, such as a synced copy of ~/.config/orgstar from your Mac. Changes to them apply as they sync.")
4343 }
44 Section("Agenda") {
44 Section {
4545 let _ = model.settingsVersion
4646 Toggle("Show days without entries", isOn: Binding {
4747 OrgPreferences.agendaShowAllDates()
@@ -49,6 +49,9 @@ struct SettingsScreen: View {
4949 Toggle("Habits only today", isOn: Binding {
5050 OrgPreferences.habitsOnlyForToday()
5151 } set: { model.set("habitsOnlyForToday", to: .bool($0)) })
52 Toggle("Leave out archive files", isOn: Binding {
53 OrgPreferences.agendaExcludeArchives()
54 } set: { model.set("agendaExcludeArchives", to: .bool($0)) })
5255 Picker("Blocked entries", selection: Binding {
5356 UserDefaults.standard.string(forKey: "agendaDimBlockedTasks") ?? "t"
5457 } set: { model.set("agendaDimBlockedTasks", to: .string($0)) }) {
@@ -56,6 +59,10 @@ struct SettingsScreen: View {
5659 Text("Hidden").tag("invisible")
5760 Text("Shown as usual").tag("nil")
5861 }
62 } header: {
63 Text("Agenda")
64 } footer: {
65 Text("Archive files are the ones your agenda files archive to, named by #+ARCHIVE:, an :ARCHIVE: property or org-archive-location.")
5966 }
6067 Section {
6168 let _ = model.settingsVersion
Tests/OrgAppTests/AppTests.swift +24
@@ -630,6 +630,30 @@ struct AgendaModelTests {
630630 await agenda.refresh(open: [:], now: wednesday, calendar: utc)
631631 #expect(agenda.days.first?.day == Days.absolute(year: 2026, month: 10, day: 7))
632632 }
633
634 @Test func leavesOutArchiveFiles() async throws {
635 let notes = try Folder()
636 try notes.write("todo.org", "#+ARCHIVE: todo_archive.org::* %s\n* TODO Live\nSCHEDULED: <2026-10-05 Mon>\n")
637 try notes.write("todo_archive.org", "* DONE Old\nSCHEDULED: <2026-10-05 Mon>\n")
638 try notes.write("work.org", "* Project\n:PROPERTIES:\n:ARCHIVE: done/work.org::\n:END:\n** TODO Task\nSCHEDULED: <2026-10-05 Mon>\n")
639 try notes.write("self.org", "#+ARCHIVE: ::* Archived\n* TODO Mine\nSCHEDULED: <2026-10-05 Mon>\n")
640 try notes.write("done/work.org", "* DONE Older\nSCHEDULED: <2026-10-05 Mon>\n")
641 let model = try WorkspaceModel(directory: nil)
642 try await model.addRoot(notes.url)
643 let agenda = AgendaModel(workspace: model)
644 agenda.includeSubfolders = true
645 agenda.span = 1
646 var utc = Calendar(identifier: .gregorian)
647 utc.timeZone = TimeZone(identifier: "UTC")!
648 let now = try #require(utc.date(from: DateComponents(year: 2026, month: 10, day: 5, hour: 9)))
649
650 agenda.excludeArchives = false
651 await agenda.refresh(open: [:], now: now, calendar: utc)
652 #expect(Set(agenda.days[0].items.map(\.text)) == ["TODO Live", "DONE Old", "TODO Task", "TODO Mine", "DONE Older"])
653 agenda.excludeArchives = true
654 await agenda.refresh(open: [:], now: now, calendar: utc)
655 #expect(Set(agenda.days[0].items.map(\.text)) == ["TODO Live", "TODO Task", "TODO Mine"])
656 }
633657}
634658
635659@MainActor
docs/manual/guide/07-agenda.org +7
@@ -31,6 +31,13 @@ To include files in subfolders as well, turn on Settings ▸ Agenda ▸ Include
3131agenda-include-subfolders = true
3232#+END_SRC
3333
34To leave out archive files, the files your agenda files archive to by their =#+ARCHIVE:= keyword, an =:ARCHIVE:= property or =org-archive-location=, turn on Settings ▸ Agenda ▸ Leave out archive files on iOS, or set this in =config.toml=:
35
36#+BEGIN_SRC toml
37[orgstar]
38agenda-exclude-archives = true
39#+END_SRC
40
3441To read a list of files instead, as =org-agenda-files= does, set =org-agenda-files= in =config.toml=, entries separated by =\n=:
3542
3643#+BEGIN_SRC toml
docs/manual/guide/13-configuration.org +1
@@ -392,6 +392,7 @@ Any other key in =[theme]= is a color; see Themes below.
392392| =show-hidden-files= | boolean | =true= | List dotfiles and dot folders in your folders. |
393393| =ignored-folders= | string | see below | Folder names never listed or searched, separated by spaces. |
394394| =agenda-include-subfolders= | boolean | =false= | The agenda reads org files in subfolders too. |
395| =agenda-exclude-archives= | boolean | =false= | The agenda leaves out files that other agenda files archive to. |
395396| =reminders= | boolean | =true= | Notify before timed entries. |
396397| =calendar-events= | boolean | =false= | Show events from Calendar in the agenda. |
397398| =calendar-event-calendars= | string | =""= | The calendars whose events show, by title or identifier, separated by commas; =""= for all. |
docs/manual/guide/14-ios.org +2 −1
@@ -389,6 +389,7 @@ The Agenda, TODO Dependencies, Calendar and Reminders sections are the only plac
389389
390390- Show days without entries :: turns =org-agenda-show-all-dates= on or off.
391391- Habits only today :: turns =org-habit-show-habits-only-for-today= on or off.
392- Leave out archive files :: turns =agenda-exclude-archives= on or off: the agenda leaves out the files your agenda files archive to.
392393- Blocked entries :: Dimmed, Hidden or Shown as usual (=org-agenda-dim-blocked-tasks=).
393394- TODO Dependencies :: Not done before TODO children (=org-enforce-todo-dependencies=) and Not done with unchecked boxes (=org-enforce-todo-checkbox-dependencies=).
394395- Show Calendar Events :: turns on =calendar-events=, and asks for access to your calendars. iOS asks for full access, as Calendar has no read-only level; orgstar changes a calendar only when you edit an event or add an entry. While access is missing the section shows Allow Access to Calendars…; if you declined, allow it in the Settings app under Privacy & Security ▸ Calendars.
@@ -415,7 +416,7 @@ These settings from =config.toml= apply on iOS:
415416- =org-use-tag-inheritance=, =org-tags-exclude-from-inheritance=, =org-tag-alist=
416417- =org-use-speed-commands=, with a hardware keyboard
417418- =electric-pair-mode=, =spell-check=, =auto-fill-mode=
418- =org-agenda-span=, =org-agenda-start-day=, =org-agenda-start-on-weekday=, =org-deadline-warning-days=, =agenda-include-subfolders=, =org-agenda-show-all-dates=, =org-agenda-skip-scheduled-if-done=, =org-agenda-skip-deadline-if-done=, =org-habit-show-habits-only-for-today=, =org-agenda-search-view-always-boolean=, =org-agenda-search-view-force-full-words=, =org-agenda-log-mode-items=, the =org-agenda-todo-ignore-= settings, =org-agenda-tags-todo-honor-ignore-options=
419- =org-agenda-span=, =org-agenda-start-day=, =org-agenda-start-on-weekday=, =org-deadline-warning-days=, =agenda-include-subfolders=, =agenda-exclude-archives=, =org-agenda-show-all-dates=, =org-agenda-skip-scheduled-if-done=, =org-agenda-skip-deadline-if-done=, =org-habit-show-habits-only-for-today=, =org-agenda-search-view-always-boolean=, =org-agenda-search-view-force-full-words=, =org-agenda-log-mode-items=, the =org-agenda-todo-ignore-= settings, =org-agenda-tags-todo-honor-ignore-options=
419420- =calendar-events=, =calendar-event-calendars=, =agenda-reminders=, =agenda-reminder-lists=
420421- =reminders=, =appt-message-warning-time=
421422- =org-clock-history-length=, =org-clock-into-drawer=, =org-clock-rounding-minutes=, =org-clock-out-remove-zero-time-clocks=, =org-clock-in-switch-to-state=, =org-clock-out-when-done=