Stuck projects view !265

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

15 files changed, +238 −15

Layout: unified · split

Sources/OrgApp/AgendaModel.swift +2
@@ -98,6 +98,8 @@ public final class AgendaModel {
98 list = Agenda.tagsMatch(all, match: match, todoOnly: todoOnly, now: now, calendar: calendar, options: options) 98 list = Agenda.tagsMatch(all, match: match, todoOnly: todoOnly, now: now, calendar: calendar, options: options)
99 case .search(let string, let todoOnly): 99 case .search(let string, let todoOnly):
100 list = Agenda.textSearch(all, string: string, todoOnly: todoOnly, options: options) 100 list = Agenda.textSearch(all, string: string, todoOnly: todoOnly, options: options)
101 case .stuck(let definition):
102 list = Agenda.stuckProjects(all, definition ?? options.stuckProjects, now: now, calendar: calendar, options: options)
101 } 103 }
102 return (days, list, events) 104 return (days, list, events)
103 }.value 105 }.value
Sources/OrgApp/AgendaViews.swift +18 −2
@@ -11,6 +11,8 @@ public enum AgendaMode: Hashable, Sendable {
11 case match(String, todoOnly: Bool) 11 case match(String, todoOnly: Bool)
12 /// `org-search-view`. 12 /// `org-search-view`.
13 case search(String, todoOnly: Bool) 13 case search(String, todoOnly: Bool)
14 /// `org-agenda-list-stuck-projects`; nil uses the `org-stuck-projects` setting.
15 case stuck(StuckProjects?)
14 16
15 /// The key `org-agenda-prefix-format` and `org-agenda-sorting-strategy` use for this kind 17 /// The key `org-agenda-prefix-format` and `org-agenda-sorting-strategy` use for this kind
16 /// of view. 18 /// of view.
@@ -18,7 +20,7 @@ public enum AgendaMode: Hashable, Sendable {
18 switch self { 20 switch self {
19 case .agenda: "agenda" 21 case .agenda: "agenda"
20 case .todo: "todo" 22 case .todo: "todo"
21 case .match: "tags" 23 case .match, .stuck: "tags"
22 case .search: "search" 24 case .search: "search"
23 } 25 }
24 } 26 }
@@ -67,7 +69,9 @@ public struct AgendaViewDefinition: Hashable, Sendable, Identifiable {
67/// ``` 69/// ```
68/// 70///
69/// `agenda` views take `span` and `start` (days from today), `todo` views `keywords` 71/// `agenda` views take `span` and `start` (days from today), `todo` views `keywords`
70/// (`WAIT|HOLD`); a `search` view's `match` is its search string. Any view can set 72/// (`WAIT|HOLD`); a `search` view's `match` is its search string. `stuck` views take
73/// `match`, `keywords`, `tags` and `regexp` as `[org-stuck-projects]` does, each defaulting
74/// to that setting. Any view can set
71/// `prefix-format` and `sorting-strategy` (keys separated by spaces) for itself. 75/// `prefix-format` and `sorting-strategy` (keys separated by spaces) for itself.
72@MainActor 76@MainActor
73public enum AgendaViewLoader { 77public enum AgendaViewLoader {
@@ -76,6 +80,7 @@ public enum AgendaViewLoader {
76 public static let builtIn = [ 80 public static let builtIn = [
77 AgendaViewDefinition(name: "Agenda", mode: .agenda(span: nil, startOffset: nil)), 81 AgendaViewDefinition(name: "Agenda", mode: .agenda(span: nil, startOffset: nil)),
78 AgendaViewDefinition(name: "TODO List", mode: .todo(keywords: nil)), 82 AgendaViewDefinition(name: "TODO List", mode: .todo(keywords: nil)),
83 AgendaViewDefinition(name: "Stuck Projects", mode: .stuck(nil)),
79 ] 84 ]
80 85
81 /// The views' settings by mode; the first view with a mode wins. 86 /// The views' settings by mode; the first view with a mode wins.
@@ -126,6 +131,17 @@ public enum AgendaViewLoader {
126 continue 131 continue
127 } 132 }
128 mode = .search(match, todoOnly: table.values["type"]?.string == "todo-search") 133 mode = .search(match, todoOnly: table.values["type"]?.string == "todo-search")
134 case "stuck":
135 if ["match", "keywords", "tags", "regexp"].allSatisfy({ table.values[$0] == nil }) {
136 mode = .stuck(nil)
137 } else {
138 var definition = OrgPreferences.stuckProjects()
139 if let match { definition.match = match }
140 if let keywords = table.values["keywords"]?.string { definition.todo = OrgPreferences.words(keywords) }
141 if let tags = table.values["tags"]?.string { definition.tags = OrgPreferences.words(tags) }
142 if let regexp = table.values["regexp"]?.string { definition.regexp = regexp }
143 mode = .stuck(definition)
144 }
129 case let other: 145 case let other:
130 problems.append("views.toml line \(table.line): unknown type \(other)") 146 problems.append("views.toml line \(table.line): unknown type \(other)")
131 continue 147 continue
Sources/OrgApp/EmacsImport.swift +7
@@ -524,6 +524,13 @@ public struct EmacsImport: Sendable {
524 } else { 524 } else {
525 add(name, .bool(truthy)) 525 add(name, .bool(truthy))
526 } 526 }
527 case "org-stuck-projects":
528 // `("+LEVEL=2/-DONE" ("TODO" "NEXT") nil "")`.
529 guard let parts = value.elements, parts.count == 4, let match = parts[0].string else { return note("not a stuck-projects definition") }
530 add("org-stuck-projects.match", .string(match))
531 add("org-stuck-projects.todo", .string((parts[1].elements ?? []).compactMap(\.string).joined(separator: " ")))
532 add("org-stuck-projects.tags", .string((parts[2].elements ?? []).compactMap(\.string).joined(separator: " ")))
533 add("org-stuck-projects.regexp", .string(parts[3].string ?? ""))
527 case "org-agenda-time-grid": 534 case "org-agenda-time-grid":
528 // `((daily today require-timed) (800 1000 …) "......" "----------------")`: the 535 // `((daily today require-timed) (800 1000 …) "......" "----------------")`: the
529 // strings are how Emacs draws the lines. 536 // strings are how Emacs draws the lines.
Sources/OrgApp/OrgPreferences.swift +8
@@ -111,10 +111,18 @@ public enum OrgPreferences {
111 options.showCurrentTimeInGrid = bool("agendaShowCurrentTime", defaults) 111 options.showCurrentTimeInGrid = bool("agendaShowCurrentTime", defaults)
112 options.gridWhen = Set(string("agendaTimeGridWhen", defaults).split(whereSeparator: \.isWhitespace).map(String.init)) 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) } 113 options.gridTimes = string("agendaTimeGridTimes", defaults).split(whereSeparator: \.isWhitespace).compactMap { Int($0) }
114 options.stuckProjects = stuckProjects(defaults)
114 options.sortNotimeIsLate = bool("agendaSortNotimeIsLate", defaults) 115 options.sortNotimeIsLate = bool("agendaSortNotimeIsLate", defaults)
115 options.sortNoeffortIsHigh = bool("agendaSortNoeffortIsHigh", defaults) 116 options.sortNoeffortIsHigh = bool("agendaSortNoeffortIsHigh", defaults)
116 return options 117 return options
117 } 118 }
119 /// `org-stuck-projects`.
120 public static func stuckProjects(_ defaults: UserDefaults = .standard) -> StuckProjects {
121 StuckProjects(match: string("stuckProjectsMatch", defaults), todo: words(string("stuckProjectsTodo", defaults)),
122 tags: words(string("stuckProjectsTags", defaults)), regexp: string("stuckProjectsRegexp", defaults))
123 }
124 /// Words separated by spaces.
125 public static func words(_ text: String) -> [String] { text.split(whereSeparator: \.isWhitespace).map(String.init) }
118 /// An `org-agenda-sorting-strategy` entry, keys separated by spaces; unknown keys are left out. 126 /// An `org-agenda-sorting-strategy` entry, keys separated by spaces; unknown keys are left out.
119 public static func sortingStrategy(_ text: String) -> [String] { 127 public static func sortingStrategy(_ text: String) -> [String] {
120 text.split(whereSeparator: \.isWhitespace).map(String.init).filter(AgendaSort.keys.contains) 128 text.split(whereSeparator: \.isWhitespace).map(String.init).filter(AgendaSort.keys.contains)
Sources/OrgApp/UserConfig.swift +8
@@ -225,6 +225,14 @@ public enum UserConfig {
225 comment: "tag and property matches", legacy: ""), 225 comment: "tag and property matches", legacy: ""),
226 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: " ")),
227 comment: "text search", legacy: ""), 227 comment: "text search", legacy: ""),
228 Setting(section: "org-stuck-projects", key: "match", defaultsKey: "stuckProjectsMatch", kind: .string, fallback: .string("+LEVEL=2/-DONE"),
229 comment: "the entries that are projects, as a tag and property match", legacy: ""),
230 Setting(section: "org-stuck-projects", key: "todo", defaultsKey: "stuckProjectsTodo", kind: .string, fallback: .string("TODO NEXT NEXTACTION"),
231 comment: "a heading in the project with one of these keywords unsticks it; * for any open keyword", legacy: ""),
232 Setting(section: "org-stuck-projects", key: "tags", defaultsKey: "stuckProjectsTags", kind: .string, fallback: .string(""),
233 comment: "a heading in the project with one of these tags unsticks it; * for any tag", legacy: ""),
234 Setting(section: "org-stuck-projects", key: "regexp", defaultsKey: "stuckProjectsRegexp", kind: .string, fallback: .string(""),
235 comment: "text in the project matching this Emacs regexp unsticks it", legacy: ""),
228 Setting(section: "org-agenda-time-grid", key: "when", defaultsKey: "agendaTimeGridWhen", kind: .string, fallback: .string("daily today require-timed"), 236 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: ""), 237 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"), 238 Setting(section: "org-agenda-time-grid", key: "times", defaultsKey: "agendaTimeGridTimes", kind: .string, fallback: .string("800 1000 1200 1400 1600 1800 2000"),
Sources/OrgCore/Agenda/Agenda.swift +2
@@ -91,6 +91,8 @@ public struct AgendaOptions: Sendable, Equatable {
91 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`. 92 /// `org-agenda-show-current-time-in-grid`.
93 public var showCurrentTimeInGrid = true 93 public var showCurrentTimeInGrid = true
94 /// `org-stuck-projects`, for views that don't give their own.
95 public var stuckProjects = StuckProjects()
94 public var gridTrailing = " ┄┄┄┄┄ " 96 public var gridTrailing = " ┄┄┄┄┄ "
95 public var gridLine = "┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄" 97 public var gridLine = "┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄"
96 public var currentTimeLine = "← now ───────────────────────────────────────────────" 98 public var currentTimeLine = "← now ───────────────────────────────────────────────"
Sources/OrgCore/Agenda/AgendaSearch.swift +2 −1
@@ -32,7 +32,7 @@ extension Agenda {
32 /// unfinished TODO entries, as `M` does. 32 /// unfinished TODO entries, as `M` does.
33 public static func tagsMatch( 33 public static func tagsMatch(
34 _ sources: [AgendaSource], match: String, todoOnly: Bool = false, now: Date = Date(), calendar: Calendar = .current, 34 _ sources: [AgendaSource], match: String, todoOnly: Bool = false, now: Date = Date(), calendar: Calendar = .current,
35 options: AgendaOptions = AgendaOptions() 35 options: AgendaOptions = AgendaOptions(), skip: ((AgendaSource, Int) -> Bool)? = nil
36 ) -> [AgendaItem] { 36 ) -> [AgendaItem] {
37 let matcher = TagsMatcher(match, todoOnly: todoOnly) 37 let matcher = TagsMatcher(match, todoOnly: todoOnly)
38 let today = Days.absolute(now, calendar: calendar) 38 let today = Days.absolute(now, calendar: calendar)
@@ -41,6 +41,7 @@ extension Agenda {
41 for (index, heading) in source.headings.enumerated() { 41 for (index, heading) in source.headings.enumerated() {
42 if matcher.todoOnly, heading.todo == nil { continue } 42 if matcher.todoOnly, heading.todo == nil { continue }
43 guard matcher.matches(heading, in: source, now: now, calendar: calendar), !heading.skipped else { continue } 43 guard matcher.matches(heading, in: source, now: now, calendar: calendar), !heading.skipped else { continue }
44 if let skip, skip(source, index) { continue }
44 if matcher.todoOnly, options.tagsTodoHonorIgnoreOptions, ignoresTodo(source, index, options: options, today: today) { continue } 45 if matcher.todoOnly, options.tagsTodoHonorIgnoreOptions, ignoresTodo(source, index, options: options, today: today) { continue }
45 var item = format( 46 var item = format(
46 source, heading, kind: .tagsMatch, marker: heading.start, extra: "", dotime: nil, removing: nil, 47 source, heading, kind: .tagsMatch, marker: heading.start, extra: "", dotime: nil, removing: nil,
Sources/OrgCore/Agenda/StuckProjects.swift added +65
@@ -0,0 +1,65 @@
1import Foundation
2
3/// `org-stuck-projects` (Org 9.8.7): projects are the entries `match` finds; one is not stuck
4/// when its subtree, its own heading included, has a heading with one of `todo` (`*` for any
5/// open keyword), a heading with one of `tags` set on it (`*` for any tag), or text matching
6/// `regexp`.
7public struct StuckProjects: Sendable, Hashable {
8 public var match: String
9 public var todo: [String]
10 public var tags: [String]
11 /// In Emacs syntax; empty for none.
12 public var regexp: String
13
14 public init(match: String = "+LEVEL=2/-DONE", todo: [String] = ["TODO", "NEXT", "NEXTACTION"], tags: [String] = [], regexp: String = "") {
15 self.match = match
16 self.todo = todo
17 self.tags = tags
18 self.regexp = regexp
19 }
20
21 /// The `skip-re` of `org-agenda-list-stuck-projects`, compiled; nil when the definition
22 /// names nothing that unsticks a project.
23 func unstuck(_ sources: [AgendaSource]) -> NSRegularExpression? {
24 var parts: [String] = []
25 if !todo.isEmpty {
26 var words = todo
27 if words.contains("*") {
28 var open: [String] = []
29 for source in sources { for k in source.notDoneKeywords where !open.contains(k) { open.append(k) } }
30 words = open
31 }
32 parts.append("^\\*+[ \\t]+(" + words.map(NSRegularExpression.escapedPattern(for:)).joined(separator: "|") + ")(?:[ \\t]|$)")
33 }
34 if tags.contains("*") {
35 parts.append(SetTags.tagLine)
36 } else if !tags.isEmpty {
37 let other = "(?:[[:alnum:]_@#%]+:)*"
38 parts.append("^\\*+ .*?[ \\t]:" + other + "(" + tags.map(NSRegularExpression.escapedPattern(for:)).joined(separator: "|") + "):" + other + "[ \\t]*$")
39 }
40 if regexp.contains(where: { !$0.isWhitespace }) { parts.append(EmacsRegex.translate(regexp)) }
41 guard !parts.isEmpty else { return nil }
42 return try? NSRegularExpression(pattern: parts.map { "(?:" + $0 + ")" }.joined(separator: "|"), options: .anchorsMatchLines)
43 }
44}
45
46extension Agenda {
47 /// `org-agenda-list-stuck-projects`: the tags view of `definition.match`, without the
48 /// projects that something in their subtree unsticks. With nothing to unstick them (Org
49 /// signals an error), every match is listed.
50 public static func stuckProjects(
51 _ sources: [AgendaSource], _ definition: StuckProjects, now: Date = Date(), calendar: Calendar = .current, options: AgendaOptions = AgendaOptions()
52 ) -> [AgendaItem] {
53 let unstuck = definition.unstuck(sources)
54 return tagsMatch(sources, match: definition.match, now: now, calendar: calendar, options: options) { source, index in
55 guard let unstuck else { return false }
56 let heading = source.headings[index]
57 let next = source.headings[(index + 1)...].first { $0.level <= heading.level }?.start
58 let ns = source.text as NSString
59 // `org-end-of-subtree`: before the line break ending the subtree's last line.
60 var end = next ?? ns.length
61 if end > heading.start, ns.character(at: end - 1) == 10 { end -= 1 }
62 return unstuck.firstMatch(in: source.text, range: NSRange(location: heading.start, length: end - heading.start)) != nil
63 }
64 }
65}
Sources/Orgstar/AgendaView+Toolbar.swift +1
@@ -183,6 +183,7 @@ extension AgendaView {
183 case .todo(let keywords): "TODO items: \(keywords ?? "all")" 183 case .todo(let keywords): "TODO items: \(keywords ?? "all")"
184 case .match(let match, let todoOnly): (todoOnly ? "TODO entries" : "Entries") + " matching \(match)" 184 case .match(let match, let todoOnly): (todoOnly ? "TODO entries" : "Entries") + " matching \(match)"
185 case .search(let string, let todoOnly): (todoOnly ? "TODO entries" : "Entries") + " containing \(string)" 185 case .search(let string, let todoOnly): (todoOnly ? "TODO entries" : "Entries") + " containing \(string)"
186 case .stuck: "Stuck projects"
186 case .agenda: "" 187 case .agenda: ""
187 } 188 }
188 } 189 }
Sources/Orgstar/AgendaView.swift +7 −2
@@ -85,6 +85,10 @@ struct AgendaView: View {
85 @AppStorage("agendaShowCurrentTime") private var showCurrentTime = true 85 @AppStorage("agendaShowCurrentTime") private var showCurrentTime = true
86 @AppStorage("agendaTimeGridWhen") private var gridWhen = "" 86 @AppStorage("agendaTimeGridWhen") private var gridWhen = ""
87 @AppStorage("agendaTimeGridTimes") private var gridTimes = "" 87 @AppStorage("agendaTimeGridTimes") private var gridTimes = ""
88 @AppStorage("stuckProjectsMatch") private var stuckMatch = ""
89 @AppStorage("stuckProjectsTodo") private var stuckTodo = ""
90 @AppStorage("stuckProjectsTags") private var stuckTags = ""
91 @AppStorage("stuckProjectsRegexp") private var stuckRegexp = ""
88 @Environment(\.openWindow) var openWindow 92 @Environment(\.openWindow) var openWindow
89 93
90 static let match = "Match…" 94 static let match = "Match…"
@@ -132,7 +136,7 @@ struct AgendaView: View {
132 var startOnWeekday: String 136 var startOnWeekday: String
133 var includeSubfolders: Bool 137 var includeSubfolders: Bool
134 var prefix: [String] 138 var prefix: [String]
135 var sorting: [String] 139 var settings: [String]
136 var logMode: Bool 140 var logMode: Bool
137 var calendars: [String] 141 var calendars: [String]
138 var files: Int 142 var files: Int
@@ -147,7 +151,8 @@ struct AgendaView: View {
147 private var refreshKey: RefreshKey { 151 private var refreshKey: RefreshKey {
148 RefreshKey( 152 RefreshKey(
149 mode: agenda.mode, start: agenda.start, span: span, startOffset: startOffset, startOnWeekday: startOnWeekday, includeSubfolders: includeSubfolders, prefix: [prefixAgenda, prefixTodo, prefixTags], 153 mode: agenda.mode, start: agenda.start, span: span, startOffset: startOffset, startOnWeekday: startOnWeekday, includeSubfolders: includeSubfolders, prefix: [prefixAgenda, prefixTodo, prefixTags],
150 sorting: [sortAgenda, sortTodo, sortTags, sortSearch, gridWhen, gridTimes, "\(useTimeGrid) \(showCurrentTime)"], logMode: logMode, 154 settings: [sortAgenda, sortTodo, sortTags, sortSearch, gridWhen, gridTimes, "\(useTimeGrid) \(showCurrentTime)", stuckMatch, stuckTodo, stuckTags, stuckRegexp],
155 logMode: logMode,
151 calendars: calendarEventsOn ? [calendarNames] : [], files: 0, changed: nil, edits: 0, path: nil, tick: tick 156 calendars: calendarEventsOn ? [calendarNames] : [], files: 0, changed: nil, edits: 0, path: nil, tick: tick
152 ) 157 )
153 } 158 }
Tests/OrgAppTests/AppTests.swift +33 −5
@@ -651,10 +651,10 @@ struct AgendaCommandTests {
651 type = "match" 651 type = "match"
652 """) 652 """)
653 let loaded = AgendaViewLoader.load(userFile: file) 653 let loaded = AgendaViewLoader.load(userFile: file)
654 #expect(loaded.views.map(\.name) == ["Agenda", "TODO List", "Work", "Week", "Waiting"]) 654 #expect(loaded.views.map(\.name) == ["Agenda", "TODO List", "Stuck Projects", "Work", "Week", "Waiting"])
655 #expect(loaded.views[2].mode == .match("+work", todoOnly: false)) 655 #expect(loaded.views[3].mode == .match("+work", todoOnly: false))
656 #expect(loaded.views[3].mode == .agenda(span: 7, startOffset: -1)) 656 #expect(loaded.views[4].mode == .agenda(span: 7, startOffset: -1))
657 #expect(loaded.views[4].mode == .todo(keywords: "WAIT|HOLD")) 657 #expect(loaded.views[5].mode == .todo(keywords: "WAIT|HOLD"))
658 #expect(loaded.problems == ["views.toml line 13: Broken needs a match"]) 658 #expect(loaded.problems == ["views.toml line 13: Broken needs a match"])
659 } 659 }
660 660
@@ -670,7 +670,7 @@ struct AgendaCommandTests {
670 """) 670 """)
671 let loaded = AgendaViewLoader.load(userFile: file) 671 let loaded = AgendaViewLoader.load(userFile: file)
672 #expect(loaded.problems == ["views.toml line 1: unknown sorting key bogus"]) 672 #expect(loaded.problems == ["views.toml line 1: unknown sorting key bogus"])
673 #expect(loaded.views[2].settings == AgendaViewSettings(prefixFormat: "%e", sortingStrategy: ["alpha-up"])) 673 #expect(loaded.views[3].settings == AgendaViewSettings(prefixFormat: "%e", sortingStrategy: ["alpha-up"]))
674 let model = try WorkspaceModel(directory: nil) 674 let model = try WorkspaceModel(directory: nil)
675 try await model.addRoot(notes.url) 675 try await model.addRoot(notes.url)
676 let agenda = AgendaModel(workspace: model) 676 let agenda = AgendaModel(workspace: model)
@@ -685,6 +685,34 @@ struct AgendaCommandTests {
685 #expect(agenda.list.map(\.text) == ["TODO [#A] c", "TODO b", "TODO a"]) 685 #expect(agenda.list.map(\.text) == ["TODO [#A] c", "TODO b", "TODO a"])
686 } 686 }
687 687
688 @Test func stuckProjectViews() async throws {
689 let notes = try Folder()
690 try notes.write("a.org", "* Projects\n** Website\n*** TODO Draft\n** Garden\n*** WAIT Seeds\n")
691 let file = try notes.write("views.toml", """
692 [[view]]
693 name = "Stuck"
694 type = "stuck"
695 [[view]]
696 name = "Waiting counts"
697 type = "stuck"
698 keywords = "TODO WAIT"
699 """)
700 let loaded = AgendaViewLoader.load(userFile: file)
701 #expect(loaded.problems.isEmpty)
702 #expect(loaded.views[3].mode == .stuck(nil))
703 guard case .stuck(let definition?) = loaded.views[4].mode else { Issue.record("no definition"); return }
704 #expect(definition.todo == ["TODO", "WAIT"] && definition.match == "+LEVEL=2/-DONE")
705 let model = try WorkspaceModel(directory: nil)
706 try await model.addRoot(notes.url)
707 let agenda = AgendaModel(workspace: model)
708 agenda.mode = loaded.views[3].mode
709 await agenda.refresh(open: [:])
710 #expect(agenda.list.map(\.text) == ["Garden"])
711 agenda.mode = loaded.views[4].mode
712 await agenda.refresh(open: [:])
713 #expect(agenda.list.isEmpty)
714 }
715
688 @Test func todoListMode() async throws { 716 @Test func todoListMode() async throws {
689 let notes = try Folder() 717 let notes = try Folder()
690 try notes.write("a.org", "* TODO One :work:\n* DONE Two\n* TODO Three\n") 718 try notes.write("a.org", "* TODO One :work:\n* DONE Two\n* TODO Three\n")
Tests/OrgAppTests/EmacsImportTests.swift +6 −1
@@ -22,6 +22,7 @@ struct EmacsImportTests {
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 org-agenda-time-grid '((daily today) (800 1300) "......" "----") org-agenda-use-time-grid nil)
25 (setq org-stuck-projects '("+project/-DONE" ("NEXT" "TODO") ("errand") "\\<IGNORE\\>"))
25 (setq fill-column (+ 70 2)) 26 (setq fill-column (+ 70 2))
26 (add-to-list 'org-structure-template-alist '("el" . "src emacs-lisp")) 27 (add-to-list 'org-structure-template-alist '("el" . "src emacs-lisp"))
27 (with-eval-after-load 'org (add-to-list 'org-structure-template-alist '("q" . "QUOTE"))) 28 (with-eval-after-load 'org (add-to-list 'org-structure-template-alist '("q" . "QUOTE")))
@@ -100,6 +101,10 @@ struct EmacsImportTests {
100 #expect(s["org-agenda-time-grid.when"] == .string("daily today")) 101 #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-time-grid.times"] == .string("800 1300"))
102 #expect(s["org-agenda-use-time-grid"] == .bool(false)) 103 #expect(s["org-agenda-use-time-grid"] == .bool(false))
104 #expect(s["org-stuck-projects.match"] == .string("+project/-DONE"))
105 #expect(s["org-stuck-projects.todo"] == .string("NEXT TODO"))
106 #expect(s["org-stuck-projects.tags"] == .string("errand"))
107 #expect(s["org-stuck-projects.regexp"] == .string("\\<IGNORE\\>"))
103 // after! org runs after the top-level setq. 108 // after! org runs after the top-level setq.
104 #expect(s["org-tags-column"] == .integer(-80)) 109 #expect(s["org-tags-column"] == .integer(-80))
105 #expect(s["org-agenda-span"] == .integer(10)) 110 #expect(s["org-agenda-span"] == .integer(10))
@@ -203,7 +208,7 @@ struct EmacsImportTests {
203 let keymap = folder.appendingPathComponent("keymap.toml") 208 let keymap = folder.appendingPathComponent("keymap.toml")
204 #expect(KeymapLoader.load(.doom, userFile: keymap).problems.isEmpty) 209 #expect(KeymapLoader.load(.doom, userFile: keymap).problems.isEmpty)
205 #expect(KeymapLoader.load(.doom, userFile: keymap).keymap.keyLabels(for: "app.agenda", modes: ["normal"]).contains("C-c a")) 210 #expect(KeymapLoader.load(.doom, userFile: keymap).keymap.keyLabels(for: "app.agenda", modes: ["normal"]).contains("C-c a"))
206 #expect(summary.hasPrefix("Imported 38 settings, 3 capture templates, 3 key bindings, 2 structure templates."), "\(summary)") 211 #expect(summary.hasPrefix("Imported 42 settings, 3 capture templates, 3 key bindings, 2 structure templates."), "\(summary)")
207 #expect(UserConfig.structureTemplates(defaults) == [.init(key: "el", type: "src emacs-lisp"), .init(key: "q", type: "QUOTE")]) 212 #expect(UserConfig.structureTemplates(defaults) == [.init(key: "el", type: "src emacs-lisp"), .init(key: "q", type: "QUOTE")])
208 #expect(OrgPreferences.options(defaults).structureTemplates?.first { $0.key == "q" }?.type == "QUOTE") 213 #expect(OrgPreferences.options(defaults).structureTemplates?.first { $0.key == "q" }?.type == "QUOTE")
209 #expect(defaults.string(forKey: "themeFont") == "JetBrains Mono") 214 #expect(defaults.string(forKey: "themeFont") == "JetBrains Mono")
Tests/OrgCoreTests/StuckProjectsTests.swift added +48
@@ -0,0 +1,48 @@
1import Foundation
2import Testing
3@testable import OrgCore
4
5/// `org-agenda-list-stuck-projects` against Emacs.
6struct StuckProjectsTests {
7 static let file = """
8 * Projects
9 ** Website
10 *** TODO Draft the copy
11 ** Garden :outdoor:
12 *** WAIT Seeds
13 *** Notes
14 ** TODO Taxes
15 ** Kitchen
16 *** Buy tiles :errand:
17 ** DONE Old project
18 ** Reading
19 Waiting for the library. NEXT week.
20 ** IDEA Novel
21 *** HOLD Outline :@home:
22 * Areas
23 ** Health
24 *** STRT Running
25
26 """
27
28 @Test(.enabled(if: ProcessInfo.processInfo.environment["ORGSTAR_SKIP_ORACLE"] == nil))
29 func listsLikeOrg() throws {
30 let today = Days.absolute(year: 2026, month: 10, day: 5)
31 let cases: [(String, StuckProjects)] = [
32 ("'(\"+LEVEL=2/-DONE\" (\"TODO\" \"NEXT\" \"NEXTACTION\") nil \"\")", StuckProjects()),
33 ("'(\"+LEVEL=2/-DONE\" (\"*\") nil \"\")", StuckProjects(todo: ["*"])),
34 ("'(\"+LEVEL=2/-DONE\" nil (\"errand\" \"@home\") \"\")", StuckProjects(todo: [], tags: ["errand", "@home"])),
35 ("'(\"+LEVEL=2/-DONE\" nil (\"*\") \"\")", StuckProjects(todo: [], tags: ["*"])),
36 ("'(\"+LEVEL=2/-DONE\" (\"WAIT\") nil \"\\\\<NEXT\\\\>\")", StuckProjects(todo: ["WAIT"], regexp: "\\<NEXT\\>")),
37 ("'(\"LEVEL=2-outdoor\" (\"TODO\" \"STRT\") nil \"library\")", StuckProjects(match: "LEVEL=2-outdoor", todo: ["TODO", "STRT"], regexp: "library")),
38 ]
39 var utc = Calendar(identifier: .gregorian)
40 utc.timeZone = TimeZone(identifier: "UTC")!
41 let now = Date(timeIntervalSince1970: Double((today - 719163) * 86400 + 9 * 3600 + 30 * 60))
42 for (lisp, definition) in cases {
43 try AgendaOracle.compareList(files: [("p.org", Self.file)], form: "(let ((org-stuck-projects \(lisp))) (org-agenda-list-stuck-projects))", today: today) {
44 Agenda.stuckProjects($0, definition, now: now, calendar: utc)
45 }
46 }
47 }
48}
docs/manual/guide/07-agenda.org +17 −3
@@ -364,6 +364,19 @@ After the last =/= (one not followed by a quote), the match restricts TODO keywo
364 364
365=/TODO|NEXT= matches either keyword, and =/!NEXT|WAIT= either one while open. =/!= has the same effect as choosing TODO Match…. 365=/TODO|NEXT= matches either keyword, and =/!NEXT|WAIT= either one while open. =/!= has the same effect as choosing TODO Match….
366 366
367* Stuck projects
368
369The built-in view Stuck Projects is =org-agenda-list-stuck-projects= (=#=): the projects that have no next action. =[org-stuck-projects]= in =config.toml= says what a project is and what makes one active, as =org-stuck-projects= does:
370
371| Key | Default | Meaning |
372|----------+---------------------------+----------------------------------------------------------------------------------|
373| =match= | ="+LEVEL=2/-DONE"= | A match as in [[*Tag and property matches][Tag and property matches]]: the entries that are projects |
374| =todo= | ="TODO NEXT NEXTACTION"= | A heading with one of these keywords makes its project active; =*= for any open keyword |
375| =tags= | =""= | A heading with one of these tags set on it (not inherited) makes its project active; =*= for any tag |
376| =regexp= | =""= | Text matching this Emacs regular expression makes its project active |
377
378The project's own heading counts: a project whose heading has a =todo= keyword is not stuck. Keywords, tags and the regexp are case-sensitive. A project that isn't stuck can still contain stuck subprojects, which are listed. When =todo=, =tags= and =regexp= are all empty, every project is listed; Org signals an error instead. Lines sort as tag matches do.
379
367* Text search 380* Text search
368 381
369Choose Search… from the view menu to list entries containing some text, as =org-search-view= (=s=) does, or TODO Search… to list only entries with an open TODO keyword (=S=, or =C-u s=). Type the search string in the toolbar field and press Return. An entry is its heading and the text up to the next heading; text before the first heading of a file is not searched. Entries show in file order, with the rows of the TODO list. 382Choose Search… from the view menu to list entries containing some text, as =org-search-view= (=s=) does, or TODO Search… to list only entries with an open TODO keyword (=S=, or =C-u s=). Type the search string in the toolbar field and press Return. An entry is its heading and the text up to the next heading; text before the first heading of a file is not searched. Entries show in file order, with the rows of the TODO list.
@@ -394,7 +407,7 @@ The search covers the agenda files only, not =org-agenda-text-search-extra-files
394 407
395* Views 408* Views
396 409
397The view menu lists the built-in views, Agenda and TODO List, then the views in =views.toml=, then Match…, TODO Match…, Search… and TODO Search…. Saved views mirror =org-agenda-custom-commands=, with fewer options. 410The view menu lists the built-in views, Agenda, TODO List and Stuck Projects, then the views in =views.toml=, then Match…, TODO Match…, Search… and TODO Search…. Saved views mirror =org-agenda-custom-commands=, with fewer options.
398 411
399=views.toml= lives in the configuration folder beside =config.toml= (=~/.config/orgstar/= by default; see [[file:13-configuration.org][Configuration]]). Each view is a =[[view]]= table: 412=views.toml= lives in the configuration folder beside =config.toml= (=~/.config/orgstar/= by default; see [[file:13-configuration.org][Configuration]]). Each view is a =[[view]]= table:
400 413
@@ -429,17 +442,18 @@ match = "+invoice -paid"
429| Key | Applies to | Meaning | 442| Key | Applies to | Meaning |
430|------------+--------------------+----------------------------------------------------------------------------| 443|------------+--------------------+----------------------------------------------------------------------------|
431| =name= | all, required | The name in the view menu | 444| =name= | all, required | The name in the view menu |
432| =type= | all | =agenda= (the default), =todo=, =match=, =todo-match=, =search= or =todo-search= | 445| =type= | all | =agenda= (the default), =todo=, =match=, =todo-match=, =search=, =todo-search= or =stuck= |
433| =span= | =agenda= | Days shown; the setting when omitted | 446| =span= | =agenda= | Days shown; the setting when omitted |
434| =start= | =agenda= | First day as an integer number of days from today (=-3=, =0=); the setting when omitted | 447| =start= | =agenda= | First day as an integer number of days from today (=-3=, =0=); the setting when omitted |
435| =keywords= | =todo= | Keywords separated by the vertical bar; all open TODOs when omitted | 448| =keywords= | =todo= | Keywords separated by the vertical bar; all open TODOs when omitted |
436| =match= | =match=, =todo-match=, =search=, =todo-search=, required | A match string as in [[*Tag and property matches][Tag and property matches]], or for =search= a search string as in [[*Text search][Text search]]; the =todo-= types keep only open TODO entries | 449| =match= | =match=, =todo-match=, =search=, =todo-search=, required | A match string as in [[*Tag and property matches][Tag and property matches]], or for =search= a search string as in [[*Text search][Text search]]; the =todo-= types keep only open TODO entries |
450| =keywords=, =tags=, =regexp= | =stuck= | The =todo=, =tags= (separated by spaces) and =regexp= of =[org-stuck-projects]=; with =match= they replace the setting's values for this view, and the ones left out keep them |
437| =sorting-strategy= | all | The view's =org-agenda-sorting-strategy=, keys separated by spaces, in place of the one in =config.toml= for its kind | 451| =sorting-strategy= | all | The view's =org-agenda-sorting-strategy=, keys separated by spaces, in place of the one in =config.toml= for its kind |
438| =prefix-format= | all | The view's =org-agenda-prefix-format=, in place of the one in =config.toml= for its kind | 452| =prefix-format= | all | The view's =org-agenda-prefix-format=, in place of the one in =config.toml= for its kind |
439 453
440Note that =start= is a plain integer here, while =org-agenda-start-day= in =config.toml= is a string such as ="-3d"=. 454Note that =start= is a plain integer here, while =org-agenda-start-day= in =config.toml= is a string such as ="-3d"=.
441 455
442Not supported: block agendas (several views in one), =org-agenda-skip-function=, and =stuck= projects. The views load when the window opens and again on =g= or =r=. A problem in the file, such as a missing =name= or an unknown =type=, shows in the status line at the bottom of the window, and the remaining views still load. 456Not supported: block agendas (several views in one) and =org-agenda-skip-function=. The views load when the window opens and again on =g= or =r=. A problem in the file, such as a missing =name= or an unknown =type=, shows in the status line at the bottom of the window, and the remaining views still load.
443 457
444* Filters 458* Filters
445 459
docs/manual/guide/13-configuration.org +14 −1
@@ -171,11 +171,12 @@ These settings have no control in the Settings window. Some are in the View menu
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| =[org-agenda-time-grid]=, =org-agenda-use-time-grid=, =org-agenda-show-current-time-in-grid= | |
174| =[org-stuck-projects]= | |
174| =theme-file= | | 175| =theme-file= | |
175 176
176* config.toml reference 177* config.toml reference
177 178
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]=. 179Settings 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]=, stuck projects in =[org-stuck-projects]=, type and theme in =[theme]=, and the settings Emacs has no variable for in =[orgstar]=.
179 180
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. 181A key you remove from the file goes back to its default. A key that isn't in the table below is reported as unknown.
181 182
@@ -271,6 +272,17 @@ These mirror the entries of =org-agenda-prefix-format=. Rows show the category,
271 272
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]]. 273These 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]].
273 274
275** [org-stuck-projects]
276
277| Key | Type | Default | Effect |
278|----------+--------+--------------------------+-----------------------------------------------------------------|
279| =match= | string | ="+LEVEL=2/-DONE"= | The entries that are projects |
280| =todo= | string | ="TODO NEXT NEXTACTION"= | Keywords, separated by spaces, that make a project active; =*= for any open one |
281| =tags= | string | =""= | Tags, separated by spaces, that make a project active; =*= for any |
282| =regexp= | string | =""= | An Emacs regular expression that makes a project active |
283
284These mirror the four elements of =org-stuck-projects=. See [[file:07-agenda.org][The agenda]].
285
274** [org-agenda-time-grid] 286** [org-agenda-time-grid]
275 287
276| Key | Type | Default | Effect | 288| Key | Type | Default | Effect |
@@ -504,6 +516,7 @@ Only variables whose names start with =org-=, =appt-=, =display-line-numbers=, =
504| =org-agenda-prefix-format= | =[org-agenda-prefix-format]=: a string sets all three views; an alist sets =agenda=, =todo= and =tags= | 516| =org-agenda-prefix-format= | =[org-agenda-prefix-format]=: a string sets all three views; an alist sets =agenda=, =todo= and =tags= |
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 | 517| =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 |
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 | 518| =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 |
519| =org-stuck-projects= | =[org-stuck-projects]=: =match=, =todo=, =tags= and =regexp= from the four elements |
507| =org-agenda-time-grid= | =[org-agenda-time-grid]=: =when= from the first element, =times= from the second; the strings are left out | 520| =org-agenda-time-grid= | =[org-agenda-time-grid]=: =when= from the first element, =times= from the second; the strings are left out |
508| =org-log-done=, =org-log-reschedule=, =org-log-redeadline= | The same key: =nil=, =time= (also =t=) or =note= | 521| =org-log-done=, =org-log-reschedule=, =org-log-redeadline= | The same key: =nil=, =time= (also =t=) or =note= |
509| =org-log-into-drawer= | A string as given; =t= becomes ="LOGBOOK"=; =nil= becomes =""= | 522| =org-log-into-drawer= | A string as given; =t= becomes ="LOGBOOK"=; =nil= becomes =""= |