Stuck projects view !265
15 files changed, +238 −15
Layout: unified · split
Sources/OrgApp/AgendaModel.swift +2
| @@ -98,6 +98,8 @@ public final class AgendaModel { | ||
| 98 | 98 | list = Agenda.tagsMatch(all, match: match, todoOnly: todoOnly, now: now, calendar: calendar, options: options) |
| 99 | 99 | case .search(let string, let todoOnly): |
| 100 | 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 | 104 | return (days, list, events) |
| 103 | 105 | }.value |
Sources/OrgApp/AgendaViews.swift +18 −2
| @@ -11,6 +11,8 @@ public enum AgendaMode: Hashable, Sendable { | ||
| 11 | 11 | case match(String, todoOnly: Bool) |
| 12 | 12 | /// `org-search-view`. |
| 13 | 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 | 17 | /// The key `org-agenda-prefix-format` and `org-agenda-sorting-strategy` use for this kind |
| 16 | 18 | /// of view. |
| @@ -18,7 +20,7 @@ public enum AgendaMode: Hashable, Sendable { | ||
| 18 | 20 | switch self { |
| 19 | 21 | case .agenda: "agenda" |
| 20 | 22 | case .todo: "todo" |
| 21 | case .match: "tags" | |
| 23 | case .match, .stuck: "tags" | |
| 22 | 24 | case .search: "search" |
| 23 | 25 | } |
| 24 | 26 | } |
| @@ -67,7 +69,9 @@ public struct AgendaViewDefinition: Hashable, Sendable, Identifiable { | ||
| 67 | 69 | /// ``` |
| 68 | 70 | /// |
| 69 | 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 | 75 | /// `prefix-format` and `sorting-strategy` (keys separated by spaces) for itself. |
| 72 | 76 | @MainActor |
| 73 | 77 | public enum AgendaViewLoader { |
| @@ -76,6 +80,7 @@ public enum AgendaViewLoader { | ||
| 76 | 80 | public static let builtIn = [ |
| 77 | 81 | AgendaViewDefinition(name: "Agenda", mode: .agenda(span: nil, startOffset: nil)), |
| 78 | 82 | AgendaViewDefinition(name: "TODO List", mode: .todo(keywords: nil)), |
| 83 | AgendaViewDefinition(name: "Stuck Projects", mode: .stuck(nil)), | |
| 79 | 84 | ] |
| 80 | 85 | |
| 81 | 86 | /// The views' settings by mode; the first view with a mode wins. |
| @@ -126,6 +131,17 @@ public enum AgendaViewLoader { | ||
| 126 | 131 | continue |
| 127 | 132 | } |
| 128 | 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 | 145 | case let other: |
| 130 | 146 | problems.append("views.toml line \(table.line): unknown type \(other)") |
| 131 | 147 | continue |
Sources/OrgApp/EmacsImport.swift +7
| @@ -524,6 +524,13 @@ public struct EmacsImport: Sendable { | ||
| 524 | 524 | } else { |
| 525 | 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 | 534 | case "org-agenda-time-grid": |
| 528 | 535 | // `((daily today require-timed) (800 1000 …) "......" "----------------")`: the |
| 529 | 536 | // strings are how Emacs draws the lines. |
Sources/OrgApp/OrgPreferences.swift +8
| @@ -111,10 +111,18 @@ public enum OrgPreferences { | ||
| 111 | 111 | options.showCurrentTimeInGrid = bool("agendaShowCurrentTime", defaults) |
| 112 | 112 | options.gridWhen = Set(string("agendaTimeGridWhen", defaults).split(whereSeparator: \.isWhitespace).map(String.init)) |
| 113 | 113 | options.gridTimes = string("agendaTimeGridTimes", defaults).split(whereSeparator: \.isWhitespace).compactMap { Int($0) } |
| 114 | options.stuckProjects = stuckProjects(defaults) | |
| 114 | 115 | options.sortNotimeIsLate = bool("agendaSortNotimeIsLate", defaults) |
| 115 | 116 | options.sortNoeffortIsHigh = bool("agendaSortNoeffortIsHigh", defaults) |
| 116 | 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 | 126 | /// An `org-agenda-sorting-strategy` entry, keys separated by spaces; unknown keys are left out. |
| 119 | 127 | public static func sortingStrategy(_ text: String) -> [String] { |
| 120 | 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 | 225 | comment: "tag and property matches", legacy: ""), |
| 226 | 226 | Setting(section: "org-agenda-sorting-strategy", key: "search", defaultsKey: "agendaSortSearch", kind: .string, fallback: .string(AgendaSort.defaults["search"]!.joined(separator: " ")), |
| 227 | 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 | 236 | Setting(section: "org-agenda-time-grid", key: "when", defaultsKey: "agendaTimeGridWhen", kind: .string, fallback: .string("daily today require-timed"), |
| 229 | 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 | 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 | 91 | public var gridTimes = [800, 1000, 1200, 1400, 1600, 1800, 2000] |
| 92 | 92 | /// `org-agenda-show-current-time-in-grid`. |
| 93 | 93 | public var showCurrentTimeInGrid = true |
| 94 | /// `org-stuck-projects`, for views that don't give their own. | |
| 95 | public var stuckProjects = StuckProjects() | |
| 94 | 96 | public var gridTrailing = " ┄┄┄┄┄ " |
| 95 | 97 | public var gridLine = "┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄" |
| 96 | 98 | public var currentTimeLine = "← now ───────────────────────────────────────────────" |
Sources/OrgCore/Agenda/AgendaSearch.swift +2 −1
| @@ -32,7 +32,7 @@ extension Agenda { | ||
| 32 | 32 | /// unfinished TODO entries, as `M` does. |
| 33 | 33 | public static func tagsMatch( |
| 34 | 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 | 36 | ) -> [AgendaItem] { |
| 37 | 37 | let matcher = TagsMatcher(match, todoOnly: todoOnly) |
| 38 | 38 | let today = Days.absolute(now, calendar: calendar) |
| @@ -41,6 +41,7 @@ extension Agenda { | ||
| 41 | 41 | for (index, heading) in source.headings.enumerated() { |
| 42 | 42 | if matcher.todoOnly, heading.todo == nil { continue } |
| 43 | 43 | guard matcher.matches(heading, in: source, now: now, calendar: calendar), !heading.skipped else { continue } |
| 44 | if let skip, skip(source, index) { continue } | |
| 44 | 45 | if matcher.todoOnly, options.tagsTodoHonorIgnoreOptions, ignoresTodo(source, index, options: options, today: today) { continue } |
| 45 | 46 | var item = format( |
| 46 | 47 | source, heading, kind: .tagsMatch, marker: heading.start, extra: "", dotime: nil, removing: nil, |
Sources/OrgCore/Agenda/StuckProjects.swift added +65
| @@ -0,0 +1,65 @@ | ||
| 1 | import 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`. | |
| 7 | public 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 | ||
| 46 | extension 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 | 183 | case .todo(let keywords): "TODO items: \(keywords ?? "all")" |
| 184 | 184 | case .match(let match, let todoOnly): (todoOnly ? "TODO entries" : "Entries") + " matching \(match)" |
| 185 | 185 | case .search(let string, let todoOnly): (todoOnly ? "TODO entries" : "Entries") + " containing \(string)" |
| 186 | case .stuck: "Stuck projects" | |
| 186 | 187 | case .agenda: "" |
| 187 | 188 | } |
| 188 | 189 | } |
Sources/Orgstar/AgendaView.swift +7 −2
| @@ -85,6 +85,10 @@ struct AgendaView: View { | ||
| 85 | 85 | @AppStorage("agendaShowCurrentTime") private var showCurrentTime = true |
| 86 | 86 | @AppStorage("agendaTimeGridWhen") private var gridWhen = "" |
| 87 | 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 | 92 | @Environment(\.openWindow) var openWindow |
| 89 | 93 | |
| 90 | 94 | static let match = "Match…" |
| @@ -132,7 +136,7 @@ struct AgendaView: View { | ||
| 132 | 136 | var startOnWeekday: String |
| 133 | 137 | var includeSubfolders: Bool |
| 134 | 138 | var prefix: [String] |
| 135 | var sorting: [String] | |
| 139 | var settings: [String] | |
| 136 | 140 | var logMode: Bool |
| 137 | 141 | var calendars: [String] |
| 138 | 142 | var files: Int |
| @@ -147,7 +151,8 @@ struct AgendaView: View { | ||
| 147 | 151 | private var refreshKey: RefreshKey { |
| 148 | 152 | RefreshKey( |
| 149 | 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 | 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 | 651 | type = "match" |
| 652 | 652 | """) |
| 653 | 653 | let loaded = AgendaViewLoader.load(userFile: file) |
| 654 | #expect(loaded.views.map(\.name) == ["Agenda", "TODO List", "Work", "Week", "Waiting"]) | |
| 655 | #expect(loaded.views[2].mode == .match("+work", todoOnly: false)) | |
| 656 | #expect(loaded.views[3].mode == .agenda(span: 7, startOffset: -1)) | |
| 657 | #expect(loaded.views[4].mode == .todo(keywords: "WAIT|HOLD")) | |
| 654 | #expect(loaded.views.map(\.name) == ["Agenda", "TODO List", "Stuck Projects", "Work", "Week", "Waiting"]) | |
| 655 | #expect(loaded.views[3].mode == .match("+work", todoOnly: false)) | |
| 656 | #expect(loaded.views[4].mode == .agenda(span: 7, startOffset: -1)) | |
| 657 | #expect(loaded.views[5].mode == .todo(keywords: "WAIT|HOLD")) | |
| 658 | 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 | 671 | let loaded = AgendaViewLoader.load(userFile: file) |
| 672 | 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 | 674 | let model = try WorkspaceModel(directory: nil) |
| 675 | 675 | try await model.addRoot(notes.url) |
| 676 | 676 | let agenda = AgendaModel(workspace: model) |
| @@ -685,6 +685,34 @@ struct AgendaCommandTests { | ||
| 685 | 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 | 716 | @Test func todoListMode() async throws { |
| 689 | 717 | let notes = try Folder() |
| 690 | 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 | 22 | (setq org-agenda-prefix-format '((agenda . " %i %-12:c%?-12t% s%b") (todo . " %-8:c"))) |
| 23 | 23 | (setq org-agenda-sorting-strategy '((agenda time-up priority-down) (todo . (alpha-up))) org-agenda-sort-notime-is-late nil) |
| 24 | 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 | 26 | (setq fill-column (+ 70 2)) |
| 26 | 27 | (add-to-list 'org-structure-template-alist '("el" . "src emacs-lisp")) |
| 27 | 28 | (with-eval-after-load 'org (add-to-list 'org-structure-template-alist '("q" . "QUOTE"))) |
| @@ -100,6 +101,10 @@ struct EmacsImportTests { | ||
| 100 | 101 | #expect(s["org-agenda-time-grid.when"] == .string("daily today")) |
| 101 | 102 | #expect(s["org-agenda-time-grid.times"] == .string("800 1300")) |
| 102 | 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 | 108 | // after! org runs after the top-level setq. |
| 104 | 109 | #expect(s["org-tags-column"] == .integer(-80)) |
| 105 | 110 | #expect(s["org-agenda-span"] == .integer(10)) |
| @@ -203,7 +208,7 @@ struct EmacsImportTests { | ||
| 203 | 208 | let keymap = folder.appendingPathComponent("keymap.toml") |
| 204 | 209 | #expect(KeymapLoader.load(.doom, userFile: keymap).problems.isEmpty) |
| 205 | 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 | 212 | #expect(UserConfig.structureTemplates(defaults) == [.init(key: "el", type: "src emacs-lisp"), .init(key: "q", type: "QUOTE")]) |
| 208 | 213 | #expect(OrgPreferences.options(defaults).structureTemplates?.first { $0.key == "q" }?.type == "QUOTE") |
| 209 | 214 | #expect(defaults.string(forKey: "themeFont") == "JetBrains Mono") |
Tests/OrgCoreTests/StuckProjectsTests.swift added +48
| @@ -0,0 +1,48 @@ | ||
| 1 | import Foundation | |
| 2 | import Testing | |
| 3 | @testable import OrgCore | |
| 4 | ||
| 5 | /// `org-agenda-list-stuck-projects` against Emacs. | |
| 6 | struct 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 | 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 | ||
| 369 | The 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 | ||
| 378 | The 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 | 380 | * Text search |
| 368 | 381 | |
| 369 | 382 | Choose 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 | 408 | * Views |
| 396 | 409 | |
| 397 | The 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. | |
| 410 | The 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 | 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 | 442 | | Key | Applies to | Meaning | |
| 430 | 443 | |------------+--------------------+----------------------------------------------------------------------------| |
| 431 | 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 | 446 | | =span= | =agenda= | Days shown; the setting when omitted | |
| 434 | 447 | | =start= | =agenda= | First day as an integer number of days from today (=-3=, =0=); the setting when omitted | |
| 435 | 448 | | =keywords= | =todo= | Keywords separated by the vertical bar; all open TODOs when omitted | |
| 436 | 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 | 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 | 452 | | =prefix-format= | all | The view's =org-agenda-prefix-format=, in place of the one in =config.toml= for its kind | |
| 439 | 453 | |
| 440 | 454 | Note that =start= is a plain integer here, while =org-agenda-start-day= in =config.toml= is a string such as ="-3d"=. |
| 441 | 455 | |
| 442 | Not 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. | |
| 456 | Not 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 | 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 | 171 | | =[org-agenda-prefix-format]= | | |
| 172 | 172 | | =[org-agenda-sorting-strategy]=, =org-agenda-sort-notime-is-late=, =org-agenda-sort-noeffort-is-high= | | |
| 173 | 173 | | =[org-agenda-time-grid]=, =org-agenda-use-time-grid=, =org-agenda-show-current-time-in-grid= | | |
| 174 | | =[org-stuck-projects]= | | | |
| 174 | 175 | | =theme-file= | | |
| 175 | 176 | |
| 176 | 177 | * config.toml reference |
| 177 | 178 | |
| 178 | Settings 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]=. | |
| 179 | Settings 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 | |
| 180 | 181 | A 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 | |
| 272 | 273 | These 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 | ||
| 284 | These mirror the four elements of =org-stuck-projects=. See [[file:07-agenda.org][The agenda]]. | |
| 285 | ||
| 274 | 286 | ** [org-agenda-time-grid] |
| 275 | 287 | |
| 276 | 288 | | Key | Type | Default | Effect | |
| @@ -504,6 +516,7 @@ Only variables whose names start with =org-=, =appt-=, =display-line-numbers=, = | ||
| 504 | 516 | | =org-agenda-prefix-format= | =[org-agenda-prefix-format]=: a string sets all three views; an alist sets =agenda=, =todo= and =tags= | |
| 505 | 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 | 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 | 520 | | =org-agenda-time-grid= | =[org-agenda-time-grid]=: =when= from the first element, =times= from the second; the strings are left out | |
| 508 | 521 | | =org-log-done=, =org-log-reschedule=, =org-log-redeadline= | The same key: =nil=, =time= (also =t=) or =note= | |
| 509 | 522 | | =org-log-into-drawer= | A string as given; =t= becomes ="LOGBOOK"=; =nil= becomes =""= | |