Commit 3cf0c16fe4

3cf0c16fe4e67f7e48d03ff5cd2212f5a2bd15c1

parent: b4eeefea9b

Verified · cmc

cmc <hello@cleberg.net> · 2026-10-11 10:25 UTC

Agenda time grid

Ports org-agenda-add-time-grid-maybe with org-agenda-time-grid's conditions (daily, weekly, today, require-timed, remove-match) and times, org-agenda-use-time-grid and org-agenda-show-current-time-in-grid. Mac and iOS draw the grid lines among the rows; the now line follows the same settings. iOS now applies org-agenda-prefix-format, which only the Mac read before. Imported from Emacs.

Closes #12

Layout: unified · split

Sources/OrgApp/EmacsImport.swift +7 −1
@@ -488,7 +488,7 @@ public struct EmacsImport: Sendable {
488 "org-startup-indented", "org-hide-leading-stars", "org-startup-align-all-tables", "org-startup-truncated", 488 "org-startup-indented", "org-hide-leading-stars", "org-startup-align-all-tables", "org-startup-truncated",
489 "org-enforce-todo-dependencies", "org-enforce-todo-checkbox-dependencies", 489 "org-enforce-todo-dependencies", "org-enforce-todo-checkbox-dependencies",
490 "org-agenda-todo-ignore-with-date", "org-agenda-tags-todo-honor-ignore-options", "org-clock-out-remove-zero-time-clocks", 490 "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":
492 add(name, .bool(truthy)) 492 add(name, .bool(truthy))
493 case "org-archive-location": 493 case "org-archive-location":
494 guard let location = value.string, location.contains("::") else { return note("not a file::heading location") } 494 guard let location = value.string, location.contains("::") else { return note("not a file::heading location") }
@@ -524,6 +524,12 @@ public struct EmacsImport: Sendable {
524 } else { 524 } else {
525 add(name, .bool(truthy)) 525 add(name, .bool(truthy))
526 } 526 }
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: " ")))
527 case "org-agenda-sorting-strategy": 533 case "org-agenda-sorting-strategy":
528 // `((agenda habit-down time-up) (todo urgency-down))`, or one list for every view. 534 // `((agenda habit-down time-up) (todo urgency-down))`, or one list for every view.
529 func keys(_ items: [Sexp]) -> String? { 535 func keys(_ items: [Sexp]) -> String? {
Sources/OrgApp/OrgPreferences.swift +7
@@ -101,9 +101,16 @@ public enum OrgPreferences {
101 options.todoIgnoreDeadlines = AgendaOptions.TodoIgnore(string("agendaTodoIgnoreDeadlines", defaults), deadlines: true) ?? .off 101 options.todoIgnoreDeadlines = AgendaOptions.TodoIgnore(string("agendaTodoIgnoreDeadlines", defaults), deadlines: true) ?? .off
102 options.todoIgnoreTimestamp = AgendaOptions.TodoIgnore(string("agendaTodoIgnoreTimestamp", defaults)) ?? .off 102 options.todoIgnoreTimestamp = AgendaOptions.TodoIgnore(string("agendaTodoIgnoreTimestamp", defaults)) ?? .off
103 options.tagsTodoHonorIgnoreOptions = bool("agendaTagsTodoHonorIgnore", defaults) 103 options.tagsTodoHonorIgnoreOptions = bool("agendaTagsTodoHonorIgnore", defaults)
104 for (view, key) in [("agenda", "agendaPrefixAgenda"), ("todo", "agendaPrefixTodo"), ("tags", "agendaPrefixTags")] {
105 options.prefixFormat[view] = string(key, defaults)
106 }
104 for (view, key) in [("agenda", "agendaSortAgenda"), ("todo", "agendaSortTodo"), ("tags", "agendaSortTags"), ("search", "agendaSortSearch")] { 107 for (view, key) in [("agenda", "agendaSortAgenda"), ("todo", "agendaSortTodo"), ("tags", "agendaSortTags"), ("search", "agendaSortSearch")] {
105 options.sortingStrategy[view] = sortingStrategy(string(key, defaults)) 108 options.sortingStrategy[view] = sortingStrategy(string(key, defaults))
106 } 109 }
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) }
107 options.sortNotimeIsLate = bool("agendaSortNotimeIsLate", defaults) 114 options.sortNotimeIsLate = bool("agendaSortNotimeIsLate", defaults)
108 options.sortNoeffortIsHigh = bool("agendaSortNoeffortIsHigh", defaults) 115 options.sortNoeffortIsHigh = bool("agendaSortNoeffortIsHigh", defaults)
109 return options 116 return options
Sources/OrgApp/UserConfig.swift +8
@@ -203,6 +203,10 @@ public enum UserConfig {
203 comment: "t: marking the clocked entry done clocks out; nil: it doesn't; or keywords that clock out, separated by spaces", legacy: ""), 203 comment: "t: marking the clocked entry done clocks out; nil: it doesn't; or keywords that clock out, separated by spaces", legacy: ""),
204 Setting(section: "", key: "org-clock-history-length", defaultsKey: "clockHistoryLength", kind: .integer, fallback: .integer(5), 204 Setting(section: "", key: "org-clock-history-length", defaultsKey: "clockHistoryLength", kind: .integer, fallback: .integer(5),
205 comment: "recently clocked entries to remember", legacy: ""), 205 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: ""),
206 Setting(section: "", key: "org-agenda-sort-notime-is-late", defaultsKey: "agendaSortNotimeIsLate", kind: .bool, fallback: .bool(true), 210 Setting(section: "", key: "org-agenda-sort-notime-is-late", defaultsKey: "agendaSortNotimeIsLate", kind: .bool, fallback: .bool(true),
207 comment: "lines without a time sort after timed ones for time-up, and without a date after dated ones", legacy: ""), 211 comment: "lines without a time sort after timed ones for time-up, and without a date after dated ones", legacy: ""),
208 Setting(section: "", key: "org-agenda-sort-noeffort-is-high", defaultsKey: "agendaSortNoeffortIsHigh", kind: .bool, fallback: .bool(true), 212 Setting(section: "", key: "org-agenda-sort-noeffort-is-high", defaultsKey: "agendaSortNoeffortIsHigh", kind: .bool, fallback: .bool(true),
@@ -221,6 +225,10 @@ public enum UserConfig {
221 comment: "tag and property matches", legacy: ""), 225 comment: "tag and property matches", legacy: ""),
222 Setting(section: "org-agenda-sorting-strategy", key: "search", defaultsKey: "agendaSortSearch", kind: .string, fallback: .string(AgendaSort.defaults["search"]!.joined(separator: " ")), 226 Setting(section: "org-agenda-sorting-strategy", key: "search", defaultsKey: "agendaSortSearch", kind: .string, fallback: .string(AgendaSort.defaults["search"]!.joined(separator: " ")),
223 comment: "text search", legacy: ""), 227 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: ""),
224 Setting(section: "theme", key: "font", defaultsKey: "themeFont", kind: .string, fallback: .string(""), 232 Setting(section: "theme", key: "font", defaultsKey: "themeFont", kind: .string, fallback: .string(""),
225 comment: "a monospaced font family; \"\" for the system's", legacy: ""), 233 comment: "a monospaced font family; \"\" for the system's", legacy: ""),
226 Setting(section: "theme", key: "font-size", defaultsKey: "themeFontSize", kind: .integer, fallback: .integer(13), 234 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 {
84 84
85public struct AgendaOptions: Sendable, Equatable { 85public struct AgendaOptions: Sendable, Equatable {
86 public var deadlineWarningDays = 14 86 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"]
87 public var gridTimes = [800, 1000, 1200, 1400, 1600, 1800, 2000] 91 public var gridTimes = [800, 1000, 1200, 1400, 1600, 1800, 2000]
92 /// `org-agenda-show-current-time-in-grid`.
93 public var showCurrentTimeInGrid = true
88 public var gridTrailing = " ┄┄┄┄┄ " 94 public var gridTrailing = " ┄┄┄┄┄ "
89 public var gridLine = "┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄" 95 public var gridLine = "┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄"
90 public var currentTimeLine = "← now ───────────────────────────────────────────────" 96 public var currentTimeLine = "← now ───────────────────────────────────────────────"
@@ -184,8 +190,7 @@ public enum Agenda {
184 var items: [AgendaItem] = [] 190 var items: [AgendaItem] = []
185 for source in sources { items += entries(source, day: day, today: today, options: options) } 191 for source in sources { items += entries(source, day: day, today: today, options: options) }
186 let isToday = day == today 192 let isToday = day == today
187 if (isToday || days == 1), items.contains(where: { $0.timeOfDay != nil }) { 193 if let grid = grid(items, days: days, isToday: isToday, now: now, options: options) {
188 let grid = grid(day: day, isToday: isToday, now: now, options: options)
189 items = options.strategy("agenda").contains("time-up") ? grid + items : items + grid 194 items = options.strategy("agenda").contains("time-up") ? grid + items : items + grid
190 } 195 }
191 return AgendaDay(day: day, isToday: isToday, header: header(day), items: AgendaSort.sort(markBlocked(items, options: options), view: "agenda", options: options)) 196 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 {
634 639
635 // MARK: - Grid, sorting, headers 640 // MARK: - Grid, sorting, headers
636 641
637 /// `org-agenda-add-time-grid-maybe`. 642 /// `org-agenda-add-time-grid-maybe`: the grid lines for a day with `items`, or nil when
638 static func grid(day: Int, isToday: Bool, now: (hour: Int, minute: Int), options: AgendaOptions) -> [AgendaItem] { 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")
639 func item(_ kind: AgendaItem.Kind, _ text: String, _ dotime: String) -> AgendaItem { 650 func item(_ kind: AgendaItem.Kind, _ text: String, _ dotime: String) -> AgendaItem {
640 var txt = text 651 var txt = text
641 let timed = timeFields(&txt, tagString: "", dotime: .string(dotime), trailing: options.gridTrailing) 652 let timed = timeFields(&txt, tagString: "", dotime: .string(dotime), trailing: options.gridTrailing)
@@ -648,10 +659,10 @@ public enum Agenda {
648 grid.alpha = AgendaSort.alpha(txt, keywords: []) 659 grid.alpha = AgendaSort.alpha(txt, keywords: [])
649 return grid 660 return grid
650 } 661 }
651 var new = options.gridTimes.reversed().map { t in 662 var new = options.gridTimes.filter { !(remove && have.contains($0)) }.reversed().map { t in
652 item(.timeGrid, options.gridLine, String(format: "%02d:%02d", t / 100, t % 100)) 663 item(.timeGrid, options.gridLine, String(format: "%02d:%02d", t / 100, t % 100))
653 } 664 }
654 if isToday { 665 if isToday, options.showCurrentTimeInGrid {
655 new.insert(item(.currentTime, options.currentTimeLine, String(format: "%02d:%02d ", now.hour, now.minute)), at: 0) 666 new.insert(item(.currentTime, options.currentTimeLine, String(format: "%02d:%02d ", now.hour, now.minute)), at: 0)
656 } 667 }
657 return new 668 return new
Sources/OrgPresentation/AgendaRows.swift +47 −5
@@ -241,6 +241,24 @@ public struct AgendaDayGroup: Sendable, Equatable, Identifiable {
241 /// Today only: deadlines and scheduled entries from before today, oldest first. 241 /// Today only: deadlines and scheduled entries from before today, oldest first.
242 public let overdue: [AgendaRow] 242 public let overdue: [AgendaRow]
243 public let rows: [AgendaRow] 243 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 }
244 262
245 public var id: Int { day } 263 public var id: Int { day }
246 public var isEmpty: Bool { overdue.isEmpty && rows.isEmpty } 264 public var isEmpty: Bool { overdue.isEmpty && rows.isEmpty }
@@ -265,8 +283,24 @@ public struct AgendaDayGroup: Sendable, Equatable, Identifiable {
265 /// `now` (`HHMM`), or after the last timed row when all have started. Nil on other days 283 /// `now` (`HHMM`), or after the last timed row when all have started. Nil on other days
266 /// and when no row is timed, as Org adds the line only among timed entries. 284 /// and when no row is timed, as Org adds the line only among timed entries.
267 public func nowIndex(now: Int) -> Int? { 285 public func nowIndex(now: Int) -> Int? {
268 guard isToday else { return nil } 286 guard isToday, showsNow else { return nil }
269 return AgendaRows.nowIndex(rows, now: now) 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
270 } 304 }
271} 305}
272 306
@@ -290,8 +324,13 @@ public enum AgendaRows {
290 for day in days { 324 for day in days {
291 var overdue: [AgendaRow] = [] 325 var overdue: [AgendaRow] = []
292 var rows: [AgendaRow] = [] 326 var rows: [AgendaRow] = []
293 for item in day.items where keep(item) { 327 // Grid lines by the number of Org rows before them; filters leave them.
294 guard let row = AgendaRow(item: item, day: day.day, today: today) else { continue } 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 }
295 if day.day == today, item.habit == nil, let planning = row.planningDay, planning < today { 334 if day.day == today, item.habit == nil, let planning = row.planningDay, planning < today {
296 overdue.append(row) 335 overdue.append(row)
297 } else { 336 } else {
@@ -303,7 +342,10 @@ public enum AgendaRows {
303 }.map(\.element) 342 }.map(\.element)
304 let dayEvents = eventDays.filter { $0.1.contains(day.day) }.map { AgendaRow(event: $0.0, day: day.day, calendar: calendar) } 343 let dayEvents = eventDays.filter { $0.1.contains(day.day) }.map { AgendaRow(event: $0.0, day: day.day, calendar: calendar) }
305 rows = merge(rows, events: dayEvents) 344 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
307 if group.isEmpty, !group.isToday, !showAllDates { continue } 349 if group.isEmpty, !group.isToday, !showAllDates { continue }
308 groups.append(group) 350 groups.append(group)
309 } 351 }
Sources/Orgstar/AgendaView.swift +35 −6
@@ -81,6 +81,10 @@ struct AgendaView: View {
81 @AppStorage("agendaSortTodo") private var sortTodo = "" 81 @AppStorage("agendaSortTodo") private var sortTodo = ""
82 @AppStorage("agendaSortTags") private var sortTags = "" 82 @AppStorage("agendaSortTags") private var sortTags = ""
83 @AppStorage("agendaSortSearch") private var sortSearch = "" 83 @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 = ""
84 @Environment(\.openWindow) var openWindow 88 @Environment(\.openWindow) var openWindow
85 89
86 static let match = "Match…" 90 static let match = "Match…"
@@ -143,7 +147,7 @@ struct AgendaView: View {
143 private var refreshKey: RefreshKey { 147 private var refreshKey: RefreshKey {
144 RefreshKey( 148 RefreshKey(
145 mode: agenda.mode, start: agenda.start, span: span, startOffset: startOffset, startOnWeekday: startOnWeekday, includeSubfolders: includeSubfolders, prefix: [prefixAgenda, prefixTodo, prefixTags], 149 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,
147 calendars: calendarEventsOn ? [calendarNames] : [], files: 0, changed: nil, edits: 0, path: nil, tick: tick 151 calendars: calendarEventsOn ? [calendarNames] : [], files: 0, changed: nil, edits: 0, path: nil, tick: tick
148 ) 152 )
149 } 153 }
@@ -368,12 +372,27 @@ struct AgendaView: View {
368 .padding(.horizontal, 16) 372 .padding(.horizontal, 16)
369 .padding(.vertical, 10) 373 .padding(.vertical, 10)
370 } 374 }
371 let nowAt = group.nowIndex(now: Self.hhmm(now)) 375 ForEach(Array(group.lines(now: Self.hhmm(now)).enumerated()), id: \.offset) { _, line in
372 ForEach(Array(group.rows.enumerated()), id: \.element.id) { index, row in 376 switch line {
373 if index == nowAt { nowLine } 377 case .row(let index): rowView(Line(id: "\(group.day):\(index)", row: group.rows[index], day: group.day))
374 rowView(Line(id: "\(group.day):\(index)", row: row, 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)
375 } 391 }
376 if let nowAt, nowAt == group.rows.count { nowLine } 392 .foregroundStyle(.tertiary)
393 .padding(.horizontal, 16)
394 .frame(height: 10)
395 .accessibilityHidden(true)
377 } 396 }
378 397
379 private func header(@ViewBuilder _ content: () -> some View) -> some View { 398 private func header(@ViewBuilder _ content: () -> some View) -> some View {
@@ -524,3 +543,13 @@ struct AgendaView: View {
524 selection = all[next].id 543 selection = all[next].id
525 } 544 }
526} 545}
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 {
297 ForEach(lines(group)) { line in 297 ForEach(lines(group)) { line in
298 switch line { 298 switch line {
299 case .now: NowLine(time: now, color: todayColor) 299 case .now: NowLine(time: now, color: todayColor)
300 case .grid(let time): GridLineRow(time: time)
300 case .row(let item): Deferred { row(item, day: group.day) } 301 case .row(let item): Deferred { row(item, day: group.day) }
301 } 302 }
302 } 303 }
303 } 304 }
304 } 305 }
305 306
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.
307 private enum DayLine: Identifiable { 308 private enum DayLine: Identifiable {
308 case now 309 case now
310 case grid(Int)
309 case row(AgendaRow) 311 case row(AgendaRow)
310 312
311 var id: String { 313 var id: String {
312 if case .row(let row) = self { return row.id } 314 switch self {
313 return "now" 315 case .row(let row): row.id
316 case .grid(let time): "grid \(time)"
317 case .now: "now"
318 }
314 } 319 }
315 } 320 }
316 321
317 private func lines(_ group: AgendaDayGroup) -> [DayLine] { 322 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? {
324 let c = Calendar.current.dateComponents([.hour, .minute], from: now) 323 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 }
326 } 331 }
327 332
328 private var todayColor: Color { themed(theme.color("agenda-today", dark: isDark), .accentColor) } 333 private var todayColor: Color { themed(theme.color("agenda-today", dark: isDark), .accentColor) }
@@ -753,6 +758,24 @@ struct AgendaRowView: View {
753 } 758 }
754} 759}
755 760
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
756/// The current time between timed rows, as Org's `now - - -` line. 779/// The current time between timed rows, as Org's `now - - -` line.
757struct NowLine: View { 780struct NowLine: View {
758 let time: Date 781 let time: Date
Tests/OrgAppTests/EmacsImportTests.swift +5 −1
@@ -21,6 +21,7 @@ struct EmacsImportTests {
21 (setq org-log-done 'note org-log-into-drawer t org-log-reschedule 'time) 21 (setq org-log-done 'note org-log-into-drawer t org-log-reschedule 'time)
22 (setq org-agenda-prefix-format '((agenda . " %i %-12:c%?-12t% s%b") (todo . " %-8:c"))) 22 (setq org-agenda-prefix-format '((agenda . " %i %-12:c%?-12t% s%b") (todo . " %-8:c")))
23 (setq org-agenda-sorting-strategy '((agenda time-up priority-down) (todo . (alpha-up))) org-agenda-sort-notime-is-late nil) 23 (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)
24 (setq fill-column (+ 70 2)) 25 (setq fill-column (+ 70 2))
25 (add-to-list 'org-structure-template-alist '("el" . "src emacs-lisp")) 26 (add-to-list 'org-structure-template-alist '("el" . "src emacs-lisp"))
26 (with-eval-after-load 'org (add-to-list 'org-structure-template-alist '("q" . "QUOTE"))) 27 (with-eval-after-load 'org (add-to-list 'org-structure-template-alist '("q" . "QUOTE")))
@@ -96,6 +97,9 @@ struct EmacsImportTests {
96 #expect(s["org-agenda-sorting-strategy.agenda"] == .string("time-up priority-down")) 97 #expect(s["org-agenda-sorting-strategy.agenda"] == .string("time-up priority-down"))
97 #expect(s["org-agenda-sorting-strategy.todo"] == .string("alpha-up")) 98 #expect(s["org-agenda-sorting-strategy.todo"] == .string("alpha-up"))
98 #expect(s["org-agenda-sort-notime-is-late"] == .bool(false)) 99 #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))
99 // after! org runs after the top-level setq. 103 // after! org runs after the top-level setq.
100 #expect(s["org-tags-column"] == .integer(-80)) 104 #expect(s["org-tags-column"] == .integer(-80))
101 #expect(s["org-agenda-span"] == .integer(10)) 105 #expect(s["org-agenda-span"] == .integer(10))
@@ -199,7 +203,7 @@ struct EmacsImportTests {
199 let keymap = folder.appendingPathComponent("keymap.toml") 203 let keymap = folder.appendingPathComponent("keymap.toml")
200 #expect(KeymapLoader.load(.doom, userFile: keymap).problems.isEmpty) 204 #expect(KeymapLoader.load(.doom, userFile: keymap).problems.isEmpty)
201 #expect(KeymapLoader.load(.doom, userFile: keymap).keymap.keyLabels(for: "app.agenda", modes: ["normal"]).contains("C-c a")) 205 #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)")
203 #expect(UserConfig.structureTemplates(defaults) == [.init(key: "el", type: "src emacs-lisp"), .init(key: "q", type: "QUOTE")]) 207 #expect(UserConfig.structureTemplates(defaults) == [.init(key: "el", type: "src emacs-lisp"), .init(key: "q", type: "QUOTE")])
204 #expect(OrgPreferences.options(defaults).structureTemplates?.first { $0.key == "q" }?.type == "QUOTE") 208 #expect(OrgPreferences.options(defaults).structureTemplates?.first { $0.key == "q" }?.type == "QUOTE")
205 #expect(defaults.string(forKey: "themeFont") == "JetBrains Mono") 209 #expect(defaults.string(forKey: "themeFont") == "JetBrains Mono")
Tests/OrgCoreTests/AgendaSortTests.swift +50
@@ -104,3 +104,53 @@ struct AgendaSortTests {
104 } 104 }
105 } 105 }
106} 106}
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 {
164 let later = AgendaRows.groups(Self.days(start: Self.today + 4), today: Self.today)[0] 164 let later = AgendaRows.groups(Self.days(start: Self.today + 4), today: Self.today)[0]
165 #expect(later.nowIndex(now: 900) == nil) 165 #expect(later.nowIndex(now: 900) == nil)
166 } 166 }
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 }
167} 191}
168 192
169struct AgendaThemeTests { 193struct AgendaThemeTests {
docs/manual/guide/07-agenda.org +1 −1
@@ -114,7 +114,7 @@ org-agenda-show-all-dates = true
114 114
115Today'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. 115Today'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.
116 116
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.
118 118
119** Sorting 119** Sorting
120 120
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
170| =org-agenda-search-view-force-full-words= | | 170| =org-agenda-search-view-force-full-words= | |
171| =[org-agenda-prefix-format]= | | 171| =[org-agenda-prefix-format]= | |
172| =[org-agenda-sorting-strategy]=, =org-agenda-sort-notime-is-late=, =org-agenda-sort-noeffort-is-high= | | 172| =[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= | |
173| =theme-file= | | 174| =theme-file= | |
174 175
175* config.toml reference 176* config.toml reference
176 177
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]=.
178 179
179A key you remove from the file goes back to its default. A key that isn't in the table below is reported as unknown. 180A key you remove from the file goes back to its default. A key that isn't in the table below is reported as unknown.
180 181
@@ -227,6 +228,8 @@ A key you remove from the file goes back to its default. A key that isn't in the
227| =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=. | 228| =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=. |
228| =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=. | 229| =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=. |
229| =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=. | 230| =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=. |
230| =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=. | 233| =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=. |
231| =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=. | 234| =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=. |
232| =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=. | 235| =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,
268 271
269These 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]]. 272These 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]].
270 273
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
271** [org-structure-template-alist] 283** [org-structure-template-alist]
272 284
273Block 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. 285Block 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=, =
491| =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 | 503| =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 |
492| =org-agenda-prefix-format= | =[org-agenda-prefix-format]=: a string sets all three views; an alist sets =agenda=, =todo= and =tags= | 504| =org-agenda-prefix-format= | =[org-agenda-prefix-format]=: a string sets all three views; an alist sets =agenda=, =todo= and =tags= |
493| =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 | 505| =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 |
495| =org-log-done=, =org-log-reschedule=, =org-log-redeadline= | The same key: =nil=, =time= (also =t=) or =note= | 508| =org-log-done=, =org-log-reschedule=, =org-log-redeadline= | The same key: =nil=, =time= (also =t=) or =note= |
496| =org-log-into-drawer= | A string as given; =t= becomes ="LOGBOOK"=; =nil= becomes =""= | 509| =org-log-into-drawer= | A string as given; =t= becomes ="LOGBOOK"=; =nil= becomes =""= |
497| =display-line-numbers-type= | =true= unless =nil=; =relative= and =visual= become absolute numbers | 510| =display-line-numbers-type= | =true= unless =nil=; =relative= and =visual= become absolute numbers |