Agenda time grid !264

merged merged by cmc on 2026-10-11 10:25 UTC · krz/orgstar:issue-12 into main

12 files changed, +249 −32

Layout: unified · split

Sources/OrgApp/EmacsImport.swift +7 −1
@@ -488,7 +488,7 @@ public struct EmacsImport: Sendable {
488488 "org-startup-indented", "org-hide-leading-stars", "org-startup-align-all-tables", "org-startup-truncated",
489489 "org-enforce-todo-dependencies", "org-enforce-todo-checkbox-dependencies",
490490 "org-agenda-todo-ignore-with-date", "org-agenda-tags-todo-honor-ignore-options", "org-clock-out-remove-zero-time-clocks",
491 "org-agenda-sort-notime-is-late", "org-agenda-sort-noeffort-is-high":
491 "org-agenda-sort-notime-is-late", "org-agenda-sort-noeffort-is-high", "org-agenda-use-time-grid", "org-agenda-show-current-time-in-grid":
492492 add(name, .bool(truthy))
493493 case "org-archive-location":
494494 guard let location = value.string, location.contains("::") else { return note("not a file::heading location") }
@@ -524,6 +524,12 @@ public struct EmacsImport: Sendable {
524524 } else {
525525 add(name, .bool(truthy))
526526 }
527 case "org-agenda-time-grid":
528 // `((daily today require-timed) (800 1000 …) "......" "----------------")`: the
529 // strings are how Emacs draws the lines.
530 guard let parts = value.elements, parts.count >= 2, let when = parts[0].elements, let times = parts[1].elements else { return note("not a time grid") }
531 add("org-agenda-time-grid.when", .string(when.compactMap(\.symbol).joined(separator: " ")))
532 add("org-agenda-time-grid.times", .string(times.compactMap { $0.integer.map(String.init) ?? $0.string }.joined(separator: " ")))
527533 case "org-agenda-sorting-strategy":
528534 // `((agenda habit-down time-up) (todo urgency-down))`, or one list for every view.
529535 func keys(_ items: [Sexp]) -> String? {
Sources/OrgApp/OrgPreferences.swift +7
@@ -101,9 +101,16 @@ public enum OrgPreferences {
101101 options.todoIgnoreDeadlines = AgendaOptions.TodoIgnore(string("agendaTodoIgnoreDeadlines", defaults), deadlines: true) ?? .off
102102 options.todoIgnoreTimestamp = AgendaOptions.TodoIgnore(string("agendaTodoIgnoreTimestamp", defaults)) ?? .off
103103 options.tagsTodoHonorIgnoreOptions = bool("agendaTagsTodoHonorIgnore", defaults)
104 for (view, key) in [("agenda", "agendaPrefixAgenda"), ("todo", "agendaPrefixTodo"), ("tags", "agendaPrefixTags")] {
105 options.prefixFormat[view] = string(key, defaults)
106 }
104107 for (view, key) in [("agenda", "agendaSortAgenda"), ("todo", "agendaSortTodo"), ("tags", "agendaSortTags"), ("search", "agendaSortSearch")] {
105108 options.sortingStrategy[view] = sortingStrategy(string(key, defaults))
106109 }
110 options.useTimeGrid = bool("agendaUseTimeGrid", defaults)
111 options.showCurrentTimeInGrid = bool("agendaShowCurrentTime", defaults)
112 options.gridWhen = Set(string("agendaTimeGridWhen", defaults).split(whereSeparator: \.isWhitespace).map(String.init))
113 options.gridTimes = string("agendaTimeGridTimes", defaults).split(whereSeparator: \.isWhitespace).compactMap { Int($0) }
107114 options.sortNotimeIsLate = bool("agendaSortNotimeIsLate", defaults)
108115 options.sortNoeffortIsHigh = bool("agendaSortNoeffortIsHigh", defaults)
109116 return options
Sources/OrgApp/UserConfig.swift +8
@@ -203,6 +203,10 @@ public enum UserConfig {
203203 comment: "t: marking the clocked entry done clocks out; nil: it doesn't; or keywords that clock out, separated by spaces", legacy: ""),
204204 Setting(section: "", key: "org-clock-history-length", defaultsKey: "clockHistoryLength", kind: .integer, fallback: .integer(5),
205205 comment: "recently clocked entries to remember", legacy: ""),
206 Setting(section: "", key: "org-agenda-use-time-grid", defaultsKey: "agendaUseTimeGrid", kind: .bool, fallback: .bool(true),
207 comment: "time grid lines among timed entries, as [org-agenda-time-grid] says", legacy: ""),
208 Setting(section: "", key: "org-agenda-show-current-time-in-grid", defaultsKey: "agendaShowCurrentTime", kind: .bool, fallback: .bool(true),
209 comment: "the now line on today's grid", legacy: ""),
206210 Setting(section: "", key: "org-agenda-sort-notime-is-late", defaultsKey: "agendaSortNotimeIsLate", kind: .bool, fallback: .bool(true),
207211 comment: "lines without a time sort after timed ones for time-up, and without a date after dated ones", legacy: ""),
208212 Setting(section: "", key: "org-agenda-sort-noeffort-is-high", defaultsKey: "agendaSortNoeffortIsHigh", kind: .bool, fallback: .bool(true),
@@ -221,6 +225,10 @@ public enum UserConfig {
221225 comment: "tag and property matches", legacy: ""),
222226 Setting(section: "org-agenda-sorting-strategy", key: "search", defaultsKey: "agendaSortSearch", kind: .string, fallback: .string(AgendaSort.defaults["search"]!.joined(separator: " ")),
223227 comment: "text search", legacy: ""),
228 Setting(section: "org-agenda-time-grid", key: "when", defaultsKey: "agendaTimeGridWhen", kind: .string, fallback: .string("daily today require-timed"),
229 comment: "daily (one-day views), today, weekly (every day), require-timed (only with timed entries), remove-match (no line at an entry's time)", legacy: ""),
230 Setting(section: "org-agenda-time-grid", key: "times", defaultsKey: "agendaTimeGridTimes", kind: .string, fallback: .string("800 1000 1200 1400 1600 1800 2000"),
231 comment: "the grid's times as HHMM, separated by spaces", legacy: ""),
224232 Setting(section: "theme", key: "font", defaultsKey: "themeFont", kind: .string, fallback: .string(""),
225233 comment: "a monospaced font family; \"\" for the system's", legacy: ""),
226234 Setting(section: "theme", key: "font-size", defaultsKey: "themeFontSize", kind: .integer, fallback: .integer(13),
Sources/OrgCore/Agenda/Agenda.swift +17 −6
@@ -84,7 +84,13 @@ public struct AgendaDay: Sendable, Equatable {
8484
8585public struct AgendaOptions: Sendable, Equatable {
8686 public var deadlineWarningDays = 14
87 /// `org-agenda-use-time-grid`, and `org-agenda-time-grid`'s conditions (`daily`, `weekly`,
88 /// `today`, `require-timed`, `remove-match`) and times.
89 public var useTimeGrid = true
90 public var gridWhen: Set<String> = ["daily", "today", "require-timed"]
8791 public var gridTimes = [800, 1000, 1200, 1400, 1600, 1800, 2000]
92 /// `org-agenda-show-current-time-in-grid`.
93 public var showCurrentTimeInGrid = true
8894 public var gridTrailing = " ┄┄┄┄┄ "
8995 public var gridLine = "┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄"
9096 public var currentTimeLine = "← now ───────────────────────────────────────────────"
@@ -184,8 +190,7 @@ public enum Agenda {
184190 var items: [AgendaItem] = []
185191 for source in sources { items += entries(source, day: day, today: today, options: options) }
186192 let isToday = day == today
187 if (isToday || days == 1), items.contains(where: { $0.timeOfDay != nil }) {
188 let grid = grid(day: day, isToday: isToday, now: now, options: options)
193 if let grid = grid(items, days: days, isToday: isToday, now: now, options: options) {
189194 items = options.strategy("agenda").contains("time-up") ? grid + items : items + grid
190195 }
191196 return AgendaDay(day: day, isToday: isToday, header: header(day), items: AgendaSort.sort(markBlocked(items, options: options), view: "agenda", options: options))
@@ -634,8 +639,14 @@ public enum Agenda {
634639
635640 // MARK: - Grid, sorting, headers
636641
637 /// `org-agenda-add-time-grid-maybe`.
638 static func grid(day: Int, isToday: Bool, now: (hour: Int, minute: Int), options: AgendaOptions) -> [AgendaItem] {
642 /// `org-agenda-add-time-grid-maybe`: the grid lines for a day with `items`, or nil when
643 /// the day has no grid.
644 static func grid(_ items: [AgendaItem], days: Int, isToday: Bool, now: (hour: Int, minute: Int), options: AgendaOptions) -> [AgendaItem]? {
645 let when = options.gridWhen
646 guard options.useTimeGrid, (isToday && when.contains("today")) || (days == 1 && when.contains("daily")) || when.contains("weekly") else { return nil }
647 let have = Set(items.compactMap(\.timeOfDay))
648 if when.contains("require-timed"), have.isEmpty { return nil }
649 let remove = when.contains("remove-match")
639650 func item(_ kind: AgendaItem.Kind, _ text: String, _ dotime: String) -> AgendaItem {
640651 var txt = text
641652 let timed = timeFields(&txt, tagString: "", dotime: .string(dotime), trailing: options.gridTrailing)
@@ -648,10 +659,10 @@ public enum Agenda {
648659 grid.alpha = AgendaSort.alpha(txt, keywords: [])
649660 return grid
650661 }
651 var new = options.gridTimes.reversed().map { t in
662 var new = options.gridTimes.filter { !(remove && have.contains($0)) }.reversed().map { t in
652663 item(.timeGrid, options.gridLine, String(format: "%02d:%02d", t / 100, t % 100))
653664 }
654 if isToday {
665 if isToday, options.showCurrentTimeInGrid {
655666 new.insert(item(.currentTime, options.currentTimeLine, String(format: "%02d:%02d ", now.hour, now.minute)), at: 0)
656667 }
657668 return new
Sources/OrgPresentation/AgendaRows.swift +47 −5
@@ -241,6 +241,24 @@ public struct AgendaDayGroup: Sendable, Equatable, Identifiable {
241241 /// Today only: deadlines and scheduled entries from before today, oldest first.
242242 public let overdue: [AgendaRow]
243243 public let rows: [AgendaRow]
244 /// `org-agenda-time-grid` lines: each time, before the row it precedes in Org's order
245 /// (`rows.count` for after the last).
246 public var grid: [GridLine] = []
247 /// Org puts the current-time line on this day.
248 public var showsNow = false
249
250 public struct GridLine: Sendable, Equatable {
251 public let before: Int
252 /// `HHMM`.
253 public let time: Int
254 }
255
256 /// What a day shows, in order: rows by index, grid lines and the now line.
257 public enum Line: Sendable, Equatable {
258 case row(Int)
259 case grid(Int)
260 case now
261 }
244262
245263 public var id: Int { day }
246264 public var isEmpty: Bool { overdue.isEmpty && rows.isEmpty }
@@ -265,8 +283,24 @@ public struct AgendaDayGroup: Sendable, Equatable, Identifiable {
265283 /// `now` (`HHMM`), or after the last timed row when all have started. Nil on other days
266284 /// and when no row is timed, as Org adds the line only among timed entries.
267285 public func nowIndex(now: Int) -> Int? {
268 guard isToday else { return nil }
269 return AgendaRows.nowIndex(rows, now: now)
286 guard isToday, showsNow else { return nil }
287 return AgendaRows.nowIndex(rows, now: now) ?? (grid.isEmpty ? nil : 0)
288 }
289
290 /// The rows with the grid lines and, at `now` (`HHMM`), the now line among them; lines
291 /// before the same row go by time.
292 public func lines(now: Int) -> [Line] {
293 let nowAt = nowIndex(now: now)
294 var lines: [Line] = []
295 for index in 0...rows.count {
296 var marks = grid.filter { $0.before == index }.map { ($0.time, Line.grid($0.time)) }
297 if index == nowAt { marks.append((now, .now)) }
298 lines += marks.enumerated().sorted { a, b in
299 a.element.0 != b.element.0 ? a.element.0 < b.element.0 : a.offset < b.offset
300 }.map(\.element.1)
301 if index < rows.count { lines.append(.row(index)) }
302 }
303 return lines
270304 }
271305}
272306
@@ -290,8 +324,13 @@ public enum AgendaRows {
290324 for day in days {
291325 var overdue: [AgendaRow] = []
292326 var rows: [AgendaRow] = []
293 for item in day.items where keep(item) {
294 guard let row = AgendaRow(item: item, day: day.day, today: today) else { continue }
327 // Grid lines by the number of Org rows before them; filters leave them.
328 var grid: [(ordinal: Int, time: Int)] = []
329 var showsNow = false
330 for item in day.items {
331 if item.kind == .timeGrid, let time = item.timeOfDay { grid.append((rows.count, time)) }
332 if item.kind == .currentTime { showsNow = true }
333 guard keep(item), let row = AgendaRow(item: item, day: day.day, today: today) else { continue }
295334 if day.day == today, item.habit == nil, let planning = row.planningDay, planning < today {
296335 overdue.append(row)
297336 } else {
@@ -303,7 +342,10 @@ public enum AgendaRows {
303342 }.map(\.element)
304343 let dayEvents = eventDays.filter { $0.1.contains(day.day) }.map { AgendaRow(event: $0.0, day: day.day, calendar: calendar) }
305344 rows = merge(rows, events: dayEvents)
306 let group = AgendaDayGroup(day: day.day, isToday: day.day == today, header: day.header, overdue: unique(overdue), rows: unique(rows))
345 let orgIndices = rows.indices.filter { !rows[$0].isEvent }
346 var group = AgendaDayGroup(day: day.day, isToday: day.day == today, header: day.header, overdue: unique(overdue), rows: unique(rows))
347 group.grid = grid.map { .init(before: $0.ordinal < orgIndices.count ? orgIndices[$0.ordinal] : rows.count, time: $0.time) }
348 group.showsNow = showsNow
307349 if group.isEmpty, !group.isToday, !showAllDates { continue }
308350 groups.append(group)
309351 }
Sources/Orgstar/AgendaView.swift +35 −6
@@ -81,6 +81,10 @@ struct AgendaView: View {
8181 @AppStorage("agendaSortTodo") private var sortTodo = ""
8282 @AppStorage("agendaSortTags") private var sortTags = ""
8383 @AppStorage("agendaSortSearch") private var sortSearch = ""
84 @AppStorage("agendaUseTimeGrid") private var useTimeGrid = true
85 @AppStorage("agendaShowCurrentTime") private var showCurrentTime = true
86 @AppStorage("agendaTimeGridWhen") private var gridWhen = ""
87 @AppStorage("agendaTimeGridTimes") private var gridTimes = ""
8488 @Environment(\.openWindow) var openWindow
8589
8690 static let match = "Match…"
@@ -143,7 +147,7 @@ struct AgendaView: View {
143147 private var refreshKey: RefreshKey {
144148 RefreshKey(
145149 mode: agenda.mode, start: agenda.start, span: span, startOffset: startOffset, startOnWeekday: startOnWeekday, includeSubfolders: includeSubfolders, prefix: [prefixAgenda, prefixTodo, prefixTags],
146 sorting: [sortAgenda, sortTodo, sortTags, sortSearch], logMode: logMode,
150 sorting: [sortAgenda, sortTodo, sortTags, sortSearch, gridWhen, gridTimes, "\(useTimeGrid) \(showCurrentTime)"], logMode: logMode,
147151 calendars: calendarEventsOn ? [calendarNames] : [], files: 0, changed: nil, edits: 0, path: nil, tick: tick
148152 )
149153 }
@@ -368,12 +372,27 @@ struct AgendaView: View {
368372 .padding(.horizontal, 16)
369373 .padding(.vertical, 10)
370374 }
371 let nowAt = group.nowIndex(now: Self.hhmm(now))
372 ForEach(Array(group.rows.enumerated()), id: \.element.id) { index, row in
373 if index == nowAt { nowLine }
374 rowView(Line(id: "\(group.day):\(index)", row: row, day: group.day))
375 ForEach(Array(group.lines(now: Self.hhmm(now)).enumerated()), id: \.offset) { _, line in
376 switch line {
377 case .row(let index): rowView(Line(id: "\(group.day):\(index)", row: group.rows[index], day: group.day))
378 case .grid(let time): gridLine(time)
379 case .now: nowLine
380 }
381 }
382 }
383
384 /// An `org-agenda-time-grid` line.
385 private func gridLine(_ time: Int) -> some View {
386 HStack(spacing: 6) {
387 Text(String(format: "%02d:%02d", time / 100, time % 100))
388 .font(.system(size: 10).monospacedDigit())
389 .frame(width: AgendaRowView.gutterWidth, alignment: .leading)
390 GridRule().stroke(style: StrokeStyle(lineWidth: 0.5, dash: [2, 3])).frame(height: 1)
375391 }
376 if let nowAt, nowAt == group.rows.count { nowLine }
392 .foregroundStyle(.tertiary)
393 .padding(.horizontal, 16)
394 .frame(height: 10)
395 .accessibilityHidden(true)
377396 }
378397
379398 private func header(@ViewBuilder _ content: () -> some View) -> some View {
@@ -524,3 +543,13 @@ struct AgendaView: View {
524543 selection = all[next].id
525544 }
526545}
546
547/// A horizontal line through the middle of its frame.
548struct GridRule: Shape {
549 func path(in rect: CGRect) -> Path {
550 Path { path in
551 path.move(to: CGPoint(x: rect.minX, y: rect.midY))
552 path.addLine(to: CGPoint(x: rect.maxX, y: rect.midY))
553 }
554 }
555}
Sources/OrgstarMobile/AgendaScreen.swift +33 −10
@@ -297,32 +297,37 @@ struct AgendaScreen: View, Equatable {
297297 ForEach(lines(group)) { line in
298298 switch line {
299299 case .now: NowLine(time: now, color: todayColor)
300 case .grid(let time): GridLineRow(time: time)
300301 case .row(let item): Deferred { row(item, day: group.day) }
301302 }
302303 }
303304 }
304305 }
305306
306 /// A day's rows, with the now line among them as a line of its own.
307 /// A day's rows, with the grid and now lines among them as lines of their own.
307308 private enum DayLine: Identifiable {
308309 case now
310 case grid(Int)
309311 case row(AgendaRow)
310312
311313 var id: String {
312 if case .row(let row) = self { return row.id }
313 return "now"
314 switch self {
315 case .row(let row): row.id
316 case .grid(let time): "grid \(time)"
317 case .now: "now"
318 }
314319 }
315320 }
316321
317322 private func lines(_ group: AgendaDayGroup) -> [DayLine] {
318 var lines = group.rows.map(DayLine.row)
319 if let at = nowIndex(group) { lines.insert(.now, at: at) }
320 return lines
321 }
322
323 private func nowIndex(_ group: AgendaDayGroup) -> Int? {
324323 let c = Calendar.current.dateComponents([.hour, .minute], from: now)
325 return group.nowIndex(now: (c.hour ?? 0) * 100 + (c.minute ?? 0))
324 return group.lines(now: (c.hour ?? 0) * 100 + (c.minute ?? 0)).map { line in
325 switch line {
326 case .row(let index): .row(group.rows[index])
327 case .grid(let time): .grid(time)
328 case .now: .now
329 }
330 }
326331 }
327332
328333 private var todayColor: Color { themed(theme.color("agenda-today", dark: isDark), .accentColor) }
@@ -753,6 +758,24 @@ struct AgendaRowView: View {
753758 }
754759}
755760
761/// An `org-agenda-time-grid` line.
762struct GridLineRow: View {
763 let time: Int
764
765 var body: some View {
766 HStack(spacing: 6) {
767 Text(String(format: "%02d:%02d", time / 100, time % 100))
768 .font(.caption2.monospacedDigit())
769 Rectangle().fill(Color(.separator)).frame(height: 0.5)
770 }
771 .foregroundStyle(.tertiary)
772 .listRowInsets(EdgeInsets(top: 0, leading: 16, bottom: 0, trailing: 16))
773 .listRowSeparator(.hidden)
774 .frame(height: 14)
775 .accessibilityHidden(true)
776 }
777}
778
756779/// The current time between timed rows, as Org's `now - - -` line.
757780struct NowLine: View {
758781 let time: Date
Tests/OrgAppTests/EmacsImportTests.swift +5 −1
@@ -21,6 +21,7 @@ struct EmacsImportTests {
2121 (setq org-log-done 'note org-log-into-drawer t org-log-reschedule 'time)
2222 (setq org-agenda-prefix-format '((agenda . " %i %-12:c%?-12t% s%b") (todo . " %-8:c")))
2323 (setq org-agenda-sorting-strategy '((agenda time-up priority-down) (todo . (alpha-up))) org-agenda-sort-notime-is-late nil)
24 (setq org-agenda-time-grid '((daily today) (800 1300) "......" "----") org-agenda-use-time-grid nil)
2425 (setq fill-column (+ 70 2))
2526 (add-to-list 'org-structure-template-alist '("el" . "src emacs-lisp"))
2627 (with-eval-after-load 'org (add-to-list 'org-structure-template-alist '("q" . "QUOTE")))
@@ -96,6 +97,9 @@ struct EmacsImportTests {
9697 #expect(s["org-agenda-sorting-strategy.agenda"] == .string("time-up priority-down"))
9798 #expect(s["org-agenda-sorting-strategy.todo"] == .string("alpha-up"))
9899 #expect(s["org-agenda-sort-notime-is-late"] == .bool(false))
100 #expect(s["org-agenda-time-grid.when"] == .string("daily today"))
101 #expect(s["org-agenda-time-grid.times"] == .string("800 1300"))
102 #expect(s["org-agenda-use-time-grid"] == .bool(false))
99103 // after! org runs after the top-level setq.
100104 #expect(s["org-tags-column"] == .integer(-80))
101105 #expect(s["org-agenda-span"] == .integer(10))
@@ -199,7 +203,7 @@ struct EmacsImportTests {
199203 let keymap = folder.appendingPathComponent("keymap.toml")
200204 #expect(KeymapLoader.load(.doom, userFile: keymap).problems.isEmpty)
201205 #expect(KeymapLoader.load(.doom, userFile: keymap).keymap.keyLabels(for: "app.agenda", modes: ["normal"]).contains("C-c a"))
202 #expect(summary.hasPrefix("Imported 35 settings, 3 capture templates, 3 key bindings, 2 structure templates."), "\(summary)")
206 #expect(summary.hasPrefix("Imported 38 settings, 3 capture templates, 3 key bindings, 2 structure templates."), "\(summary)")
203207 #expect(UserConfig.structureTemplates(defaults) == [.init(key: "el", type: "src emacs-lisp"), .init(key: "q", type: "QUOTE")])
204208 #expect(OrgPreferences.options(defaults).structureTemplates?.first { $0.key == "q" }?.type == "QUOTE")
205209 #expect(defaults.string(forKey: "themeFont") == "JetBrains Mono")
Tests/OrgCoreTests/AgendaSortTests.swift +50
@@ -104,3 +104,53 @@ struct AgendaSortTests {
104104 }
105105 }
106106}
107
108/// `org-agenda-time-grid` and `org-agenda-use-time-grid` against Emacs.
109struct AgendaTimeGridTests {
110 static let file = """
111 * Breakfast
112 <2026-10-05 Mon 09:00>
113 * Lunch
114 <2026-10-05 Mon 14:00>
115 * Untimed today
116 SCHEDULED: <2026-10-05 Mon>
117 * Tomorrow untimed
118 SCHEDULED: <2026-10-06 Tue>
119 * Yesterday timed
120 <2026-10-04 Sun 10:30>
121
122 """
123
124 @Test(.enabled(if: ProcessInfo.processInfo.environment["ORGSTAR_SKIP_ORACLE"] == nil))
125 func gridsLikeOrg() throws {
126 let today = Days.absolute(year: 2026, month: 10, day: 5)
127 let cases: [(use: Bool, when: [String], times: [Int], now: Bool, span: Int, start: Int)] = [
128 (true, ["daily", "today", "require-timed"], [800, 1000, 1200, 1400, 1600, 1800, 2000], true, 3, -1),
129 (false, ["daily", "today", "require-timed"], [800, 1000], true, 3, -1),
130 (true, ["weekly", "require-timed"], [900, 1200], true, 3, -1),
131 (true, ["weekly"], [900, 1200], false, 3, -1),
132 (true, ["daily", "today", "remove-match"], [900, 1000, 1100, 1400], true, 3, -1),
133 (true, ["daily"], [800, 1300], true, 1, 1),
134 (true, ["daily", "require-timed"], [800, 1300], true, 1, 1),
135 (true, ["today"], [800, 1300], true, 1, 0),
136 ]
137 for c in cases {
138 let date = Days.date(today + c.start)
139 let grid = "'((\(c.when.joined(separator: " "))) (\(c.times.map(String.init).joined(separator: " "))) \"......\" \"----------------\")"
140 let form = "(let ((org-agenda-use-time-grid \(c.use ? "t" : "nil")) (org-agenda-time-grid \(grid)) (org-agenda-show-current-time-in-grid \(c.now ? "t" : "nil"))) (org-agenda-list nil \"\(String(format: "%04d-%02d-%02d", date.year, date.month, date.day))\" \(c.span)))"
141 let emacs = try AgendaOracle.run(files: [("g.org", Self.file)], form: form, today: today, hour: 9, minute: 30)
142 let defaults = OrgSettings.default.withTodoKeywords(AgendaOracle.keywords)!
143 var options = AgendaOptions.terminal
144 options.useTimeGrid = c.use
145 options.gridWhen = Set(c.when)
146 options.gridTimes = c.times
147 options.showCurrentTimeInGrid = c.now
148 let ours = Agenda.list([AgendaSource(path: "g.org", text: Self.file, defaults: defaults)], start: today + c.start, days: c.span,
149 today: today, now: (9, 30), options: options)
150 #expect(ours.count == emacs.count)
151 for (o, e) in zip(ours, emacs) {
152 #expect(AgendaOracle.describe(o.items, today: today) == AgendaOracle.describe(e.items), "\(form) \(e.header)")
153 }
154 }
155 }
156}
Tests/OrgPresentationTests/AgendaRowsTests.swift +24
@@ -164,6 +164,30 @@ struct AgendaRowsTests {
164164 let later = AgendaRows.groups(Self.days(start: Self.today + 4), today: Self.today)[0]
165165 #expect(later.nowIndex(now: 900) == nil)
166166 }
167
168 @Test func gridLinesGoBeforeLaterRows() {
169 let today = AgendaRows.groups(Self.days(), today: Self.today)[0]
170 #expect(today.grid.map(\.time) == [800, 1000, 1200, 1400, 1600, 1800, 2000])
171 let lines = today.lines(now: 1100)
172 // Each grid line comes before the first timed row after its time, entries at the same
173 // time first, as `time-up urgency-down` orders them; the rest after the last timed row.
174 var last = -1
175 for line in lines {
176 switch line {
177 case .row(let index):
178 if let start = today.rows[index].start, today.rows[index].item?.habit == nil { #expect(start >= last) ; last = start }
179 case .grid(let time): #expect(time >= last); last = time
180 case .now: #expect(1100 >= last); last = 1100
181 }
182 }
183 #expect(lines.filter { if case .row = $0 { return true } else { return false } }.count == today.rows.count)
184 #expect(lines.contains(.now))
185 var options = AgendaOptions()
186 options.useTimeGrid = false
187 let source = AgendaSource(path: "life.org", text: Self.file, defaults: OrgSettings.default.withTodoKeywords("TODO | DONE")!)
188 let plain = AgendaRows.groups(Agenda.list([source], start: Self.today, days: 1, today: Self.today, now: (10, 0), options: options), today: Self.today)[0]
189 #expect(plain.grid.isEmpty && plain.nowIndex(now: 1100) == nil)
190 }
167191}
168192
169193struct AgendaThemeTests {
docs/manual/guide/07-agenda.org +1 −1
@@ -114,7 +114,7 @@ org-agenda-show-all-dates = true
114114
115115Today's past deadlines and entries scheduled on earlier days, habits excepted, go in a group headed =Overdue= with their count, above today's other entries. The oldest date comes first; entries with the same date keep Org's order. Click or tap the header to collapse or expand the group; it stays as you left it.
116116
117On today, a line marked with the current time sits between the timed entries: before the first entry that starts later, or after the last one when all have started. It shows only when today has timed entries, as Org's =now= line does. Org's time grid (the lines at 8:00, 10:00 and so on) isn't shown.
117Days with a time grid show dotted lines at the grid's times among the timed entries, as =org-agenda-time-grid= does: by default at 8:00, 10:00 and every two hours to 20:00, on today and in one-day views, when the day has a timed entry. An entry at a grid line's time comes before the line. On today, a line marked with the current time sits among them: before the first entry that starts later, or after the last one when all have started. The grid's days and times are set in =[org-agenda-time-grid]= in =config.toml=, =org-agenda-use-time-grid= turns the grid off, and =org-agenda-show-current-time-in-grid= the now line (see [[file:13-configuration.org][Configuration]]). With the grid off there is no now line, as in Org.
118118
119119** Sorting
120120
docs/manual/guide/13-configuration.org +15 −2
@@ -170,11 +170,12 @@ These settings have no control in the Settings window. Some are in the View menu
170170| =org-agenda-search-view-force-full-words= | |
171171| =[org-agenda-prefix-format]= | |
172172| =[org-agenda-sorting-strategy]=, =org-agenda-sort-notime-is-late=, =org-agenda-sort-noeffort-is-high= | |
173| =[org-agenda-time-grid]=, =org-agenda-use-time-grid=, =org-agenda-show-current-time-in-grid= | |
173174| =theme-file= | |
174175
175176* config.toml reference
176177
177Settings that mirror an Emacs variable sit at the top of the file under that variable's name. The agenda prefix formats are in =[org-agenda-prefix-format]=, the sorting strategies in =[org-agenda-sorting-strategy]=, type and theme in =[theme]=, and the settings Emacs has no variable for in =[orgstar]=.
178Settings that mirror an Emacs variable sit at the top of the file under that variable's name. The agenda prefix formats are in =[org-agenda-prefix-format]=, the sorting strategies in =[org-agenda-sorting-strategy]=, the time grid in =[org-agenda-time-grid]=, type and theme in =[theme]=, and the settings Emacs has no variable for in =[orgstar]=.
178179
179180A key you remove from the file goes back to its default. A key that isn't in the table below is reported as unknown.
180181
@@ -227,6 +228,8 @@ A key you remove from the file goes back to its default. A key that isn't in the
227228| =org-agenda-tags-todo-honor-ignore-options= | boolean | =false= | The four settings above apply to TODO-only matches (=M=) too. Mirrors =org-agenda-tags-todo-honor-ignore-options=. |
228229| =org-agenda-search-view-always-boolean= | boolean | =false= | The agenda's text search reads every string as =+word -word {regexp}= snippets, never as a phrase. Mirrors =org-agenda-search-view-always-boolean=. |
229230| =org-agenda-search-view-force-full-words= | boolean | =false= | Text search snippets match whole words only, as a leading =:= does. Mirrors =org-agenda-search-view-force-full-words=. |
231| =org-agenda-use-time-grid= | boolean | =true= | Grid lines at the times in =[org-agenda-time-grid]=, on the days it names. Mirrors =org-agenda-use-time-grid=. |
232| =org-agenda-show-current-time-in-grid= | boolean | =true= | The now line on today's grid. Mirrors =org-agenda-show-current-time-in-grid=. |
230233| =org-agenda-sort-notime-is-late= | boolean | =true= | Lines without a time sort after timed ones for =time-up=, and lines without a date after dated ones for the date keys. Mirrors =org-agenda-sort-notime-is-late=. |
231234| =org-agenda-sort-noeffort-is-high= | boolean | =true= | Entries without an =Effort= sort as the longest for =effort-up=. Mirrors =org-agenda-sort-noeffort-is-high=. |
232235| =org-agenda-dim-blocked-tasks= | string | ="t"= | =t= dims entries the two enforce settings block, =invisible= hides them (entries blocked only by checkboxes are still dimmed), =nil= shows them as usual. Mirrors =org-agenda-dim-blocked-tasks=. |
@@ -268,6 +271,15 @@ These mirror the entries of =org-agenda-prefix-format=. Rows show the category,
268271
269272These mirror the entries of =org-agenda-sorting-strategy=, keys separated by spaces. Unknown keys are ignored. A view in =views.toml= can set its own with =sorting-strategy=. The keys are listed in [[file:07-agenda.org][The agenda]].
270273
274** [org-agenda-time-grid]
275
276| Key | Type | Default | Effect |
277|---------+--------+----------------------------------------+-------------------------------------------|
278| =when= | string | ="daily today require-timed"= | Which days get a grid, separated by spaces |
279| =times= | string | ="800 1000 1200 1400 1600 1800 2000"= | The grid's times as =HHMM= |
280
281These mirror the first two elements of =org-agenda-time-grid=. =when= takes =daily= (views of one day), =today=, =weekly= (every day), =require-timed= (only days with a timed entry) and =remove-match= (no line at a time an entry has). orgstar draws the lines itself, so Emacs's third and fourth elements, the strings for the lines, have no equivalent.
282
271283** [org-structure-template-alist]
272284
273285Block templates for Insert Structure Template (=C-c C-,=) and =<= completion, each a key and the block type it inserts. They go over Org's default =org-structure-template-alist=: a key Org has (=s=, =q=, …) gets the new type, and other keys are added after Org's.
@@ -491,7 +503,8 @@ Only variables whose names start with =org-=, =appt-=, =display-line-numbers=, =
491503| =org-M-RET-may-split-line= | =org-M-RET-may-split-line=, from the =default= entry of an alist; other per-context entries aren't supported |
492504| =org-agenda-prefix-format= | =[org-agenda-prefix-format]=: a string sets all three views; an alist sets =agenda=, =todo= and =tags= |
493505| =org-agenda-sorting-strategy= | =[org-agenda-sorting-strategy]=: a list sets all four views; an alist sets =agenda=, =todo=, =tags= and =search=. A list with =user-defined-up= or =user-defined-down= isn't imported |
494| =org-agenda-sort-notime-is-late=, =org-agenda-sort-noeffort-is-high= | The same key, as booleans |
506| =org-agenda-sort-notime-is-late=, =org-agenda-sort-noeffort-is-high=, =org-agenda-use-time-grid=, =org-agenda-show-current-time-in-grid= | The same key, as booleans |
507| =org-agenda-time-grid= | =[org-agenda-time-grid]=: =when= from the first element, =times= from the second; the strings are left out |
495508| =org-log-done=, =org-log-reschedule=, =org-log-redeadline= | The same key: =nil=, =time= (also =t=) or =note= |
496509| =org-log-into-drawer= | A string as given; =t= becomes ="LOGBOOK"=; =nil= becomes =""= |
497510| =display-line-numbers-type= | =true= unless =nil=; =relative= and =visual= become absolute numbers |