org-track-ordered-property-with-tag !245
12 files changed, +83 −21
Layout: unified · split
Sources/OrgApp/EmacsImport.swift +2
| @@ -479,6 +479,8 @@ public struct EmacsImport: Sendable { | ||
| 479 | 479 | "org-startup-indented", "org-hide-leading-stars", "org-startup-align-all-tables", "org-startup-truncated", |
| 480 | 480 | "org-enforce-todo-dependencies", "org-enforce-todo-checkbox-dependencies": |
| 481 | 481 | add(name, .bool(truthy)) |
| 482 | case "org-track-ordered-property-with-tag": | |
| 483 | if let tag = value.string { add(name, .string(tag)) } else { add(name, .string(truthy ? "t" : "nil")) } | |
| 482 | 484 | case "org-agenda-dim-blocked-tasks": |
| 483 | 485 | add(name, .string(value.symbol == "invisible" ? "invisible" : truthy ? "t" : "nil")) |
| 484 | 486 | case "org-hide-drawer-startup", "org-hide-block-startup": |
Sources/OrgApp/OrgPreferences.swift +5
| @@ -35,6 +35,11 @@ public enum OrgPreferences { | ||
| 35 | 35 | options.electricPair = bool("electricPair", defaults) |
| 36 | 36 | options.enforceTodoDependencies = bool("enforceTodoDependencies", defaults) |
| 37 | 37 | options.enforceTodoCheckboxDependencies = bool("enforceTodoCheckboxDependencies", defaults) |
| 38 | options.trackOrderedPropertyWithTag = switch string("trackOrderedTag", defaults) { | |
| 39 | case "", "nil": nil | |
| 40 | case "t": "ORDERED" | |
| 41 | case let tag: tag | |
| 42 | } | |
| 38 | 43 | return options |
| 39 | 44 | } |
| 40 | 45 | |
Sources/OrgApp/UserConfig.swift +2
| @@ -121,6 +121,8 @@ public enum UserConfig { | ||
| 121 | 121 | comment: "an entry can't be done before its TODO children, or under an ORDERED parent before its earlier siblings", legacy: ""), |
| 122 | 122 | Setting(section: "", key: "org-enforce-todo-checkbox-dependencies", defaultsKey: "enforceTodoCheckboxDependencies", kind: .bool, fallback: .bool(false), |
| 123 | 123 | comment: "an entry can't be done while it has unchecked boxes", legacy: ""), |
| 124 | Setting(section: "", key: "org-track-ordered-property-with-tag", defaultsKey: "trackOrderedTag", kind: .string, fallback: .string("nil"), | |
| 125 | comment: "nil, t (the tag ORDERED) or a tag that Toggle ORDERED Property toggles too", legacy: ""), | |
| 124 | 126 | Setting(section: "", key: "org-startup-indented", defaultsKey: "startupIndented", kind: .bool, fallback: .bool(true), |
| 125 | 127 | comment: "indent bodies under their headings (org-indent-mode); #+STARTUP: (no)indent overrides", legacy: ""), |
| 126 | 128 | Setting(section: "", key: "org-hide-leading-stars", defaultsKey: "hideLeadingStars", kind: .bool, fallback: .bool(false), |
Sources/OrgCore/Commands/Command.swift +2
| @@ -27,6 +27,8 @@ public struct EditingOptions: Sendable, Equatable, Codable { | ||
| 27 | 27 | public var enforceTodoDependencies = false |
| 28 | 28 | /// `org-enforce-todo-checkbox-dependencies`: an entry can't become done with unchecked boxes. |
| 29 | 29 | public var enforceTodoCheckboxDependencies = false |
| 30 | /// `org-track-ordered-property-with-tag`: the tag toggling `ORDERED` toggles too; nil for none. | |
| 31 | public var trackOrderedPropertyWithTag: String? | |
| 30 | 32 | /// `org-use-speed-commands`: single keys at the start of a heading line run commands. |
| 31 | 33 | public var useSpeedCommands: Bool |
| 32 | 34 | /// `org-startup-with-inline-images`. |
Sources/OrgCore/Commands/TagCommands.swift +30 −16
| @@ -60,22 +60,7 @@ public struct SetTags: OrgCommand { | ||
| 60 | 60 | /// `org-set-tags`: the entry's tags become `tags`, realigned. |
| 61 | 61 | static func set(_ tags: [String], in context: EditContext) -> CommandStep { |
| 62 | 62 | commitBuffer(context) { buffer in |
| 63 | try buffer.saveExcursion { | |
| 64 | try buffer.backToHeading() | |
| 65 | buffer.saveExcursion { | |
| 66 | let line = buffer.saveExcursion { buffer.lookingAt(Self.tagLine) } | |
| 67 | let old = line.flatMap { $0[2] }.map { buffer.substring($0.lowerBound, $0.upperBound).split(separator: ":").map(String.init) } ?? [] | |
| 68 | if tags != old { | |
| 69 | buffer.point = line?[1]?.lowerBound ?? buffer.lineEnd(buffer.point) | |
| 70 | buffer.skipBackward(EmacsBuffer.blanks) | |
| 71 | buffer.deleteRegion(buffer.point, buffer.lineEnd(buffer.point)) | |
| 72 | if !buffer.atHeading { buffer.insert(" ") } | |
| 73 | if !tags.isEmpty { buffer.saveExcursion { buffer.insert(" :" + tags.joined(separator: ":") + ":") } } | |
| 74 | } | |
| 75 | // Org realigns whenever there are tags, changed or not. | |
| 76 | if !tags.isEmpty { buffer.alignTags(onLineAt: buffer.point) } | |
| 77 | } | |
| 78 | } | |
| 63 | try set(tags, in: buffer) | |
| 79 | 64 | let afterStars = buffer.saveExcursion { () -> Bool in |
| 80 | 65 | buffer.skipBackward([42]) |
| 81 | 66 | return buffer.bolp |
| @@ -83,6 +68,35 @@ public struct SetTags: OrgCommand { | ||
| 83 | 68 | if afterStars, buffer.character(at: buffer.point) == 32 { buffer.point += 1 } |
| 84 | 69 | } |
| 85 | 70 | } |
| 71 | ||
| 72 | /// The tags of the entry at point. | |
| 73 | static func tags(in buffer: EmacsBuffer) throws -> [String] { | |
| 74 | try buffer.saveExcursion { | |
| 75 | try buffer.backToHeading() | |
| 76 | let line = buffer.lookingAt(Self.tagLine) | |
| 77 | return line.flatMap { $0[2] }.map { buffer.substring($0.lowerBound, $0.upperBound).split(separator: ":").map(String.init) } ?? [] | |
| 78 | } | |
| 79 | } | |
| 80 | ||
| 81 | /// `org-set-tags` on the entry at point, which stays where it is. | |
| 82 | static func set(_ tags: [String], in buffer: EmacsBuffer) throws { | |
| 83 | try buffer.saveExcursion { | |
| 84 | try buffer.backToHeading() | |
| 85 | buffer.saveExcursion { | |
| 86 | let line = buffer.saveExcursion { buffer.lookingAt(Self.tagLine) } | |
| 87 | let old = line.flatMap { $0[2] }.map { buffer.substring($0.lowerBound, $0.upperBound).split(separator: ":").map(String.init) } ?? [] | |
| 88 | if tags != old { | |
| 89 | buffer.point = line?[1]?.lowerBound ?? buffer.lineEnd(buffer.point) | |
| 90 | buffer.skipBackward(EmacsBuffer.blanks) | |
| 91 | buffer.deleteRegion(buffer.point, buffer.lineEnd(buffer.point)) | |
| 92 | if !buffer.atHeading { buffer.insert(" ") } | |
| 93 | if !tags.isEmpty { buffer.saveExcursion { buffer.insert(" :" + tags.joined(separator: ":") + ":") } } | |
| 94 | } | |
| 95 | // Org realigns whenever there are tags, changed or not. | |
| 96 | if !tags.isEmpty { buffer.alignTags(onLineAt: buffer.point) } | |
| 97 | } | |
| 98 | } | |
| 99 | } | |
| 86 | 100 | } |
| 87 | 101 | |
| 88 | 102 | /// `org-toggle-tag` with `on` or `off`: adds or removes one tag, as the agenda's bulk tag |
Sources/OrgCore/Commands/TodoDependencies.swift +16 −2
| @@ -3,7 +3,7 @@ import Foundation | ||
| 3 | 3 | // TODO dependencies (Org 9.8.7): `org-block-todo-from-children-or-siblings-or-parent` with |
| 4 | 4 | // `org-enforce-todo-dependencies`, `org-block-todo-from-checkboxes` with |
| 5 | 5 | // `org-enforce-todo-checkbox-dependencies`, `org-entry-blocked-p` and |
| 6 | // `org-toggle-ordered-property` with `org-track-ordered-property-with-tag` nil. | |
| 6 | // `org-toggle-ordered-property` with `org-track-ordered-property-with-tag`. | |
| 7 | 7 | |
| 8 | 8 | extension EmacsBuffer { |
| 9 | 9 | /// `org-not-done-heading-regexp`. |
| @@ -141,14 +141,28 @@ public struct ToggleOrderedProperty: OrgCommand { | ||
| 141 | 141 | public var title: String { "Toggle ORDERED Property" } |
| 142 | 142 | public func applies(in context: EditContext) -> Bool { entryHeading(at: context.caret, in: context.tree) != nil } |
| 143 | 143 | public func run(in context: EditContext) -> CommandStep { |
| 144 | commitBuffer(context) { buffer in | |
| 144 | let tag = context.options.trackOrderedPropertyWithTag | |
| 145 | return commitBuffer(context) { buffer in | |
| 145 | 146 | try buffer.saveExcursion { |
| 146 | 147 | let heading = try buffer.backToHeading() |
| 148 | // `org-toggle-tag`: the tag goes on or off. | |
| 149 | func toggle(_ on: Bool) throws { | |
| 150 | guard let tag else { return } | |
| 151 | var tags = try SetTags.tags(in: buffer) | |
| 152 | if on { | |
| 153 | if !tags.contains(tag) { tags.append(tag) } | |
| 154 | } else { | |
| 155 | tags.removeAll { $0 == tag } | |
| 156 | } | |
| 157 | try SetTags.set(tags, in: buffer) | |
| 158 | } | |
| 147 | 159 | if buffer.localProperty("ORDERED", heading: heading).map({ $0 != "nil" }) ?? false { |
| 148 | 160 | buffer.entryDelete("ORDERED") |
| 161 | try toggle(false) | |
| 149 | 162 | buffer.message = "Subtasks can be completed in arbitrary order" |
| 150 | 163 | } else { |
| 151 | 164 | buffer.entryPut("ORDERED", "t") |
| 165 | try toggle(true) | |
| 152 | 166 | buffer.message = "Subtasks must be completed in sequence" |
| 153 | 167 | } |
| 154 | 168 | } |
Tests/OrgAppTests/EmacsImportTests.swift +3 −1
| @@ -41,6 +41,7 @@ struct EmacsImportTests { | ||
| 41 | 41 | org-agenda-span 10 |
| 42 | 42 | org-deadline-warning-days 7 |
| 43 | 43 | org-agenda-start-on-weekday 0 |
| 44 | org-track-ordered-property-with-tag t | |
| 44 | 45 | org-agenda-start-day "-3d" |
| 45 | 46 | org-clock-idle-time 15 |
| 46 | 47 | org-clock-history-length 10 |
| @@ -84,6 +85,7 @@ struct EmacsImportTests { | ||
| 84 | 85 | #expect(s["org-agenda-span"] == .integer(10)) |
| 85 | 86 | #expect(s["org-deadline-warning-days"] == .integer(7)) |
| 86 | 87 | #expect(s["org-agenda-start-on-weekday"] == .string("0")) |
| 88 | #expect(s["org-track-ordered-property-with-tag"] == .string("t")) | |
| 87 | 89 | #expect(s["org-agenda-start-day"] == .string("-3d")) |
| 88 | 90 | #expect(s["org-clock-idle-time"] == .integer(15)) |
| 89 | 91 | #expect(s["org-clock-history-length"] == .integer(10)) |
| @@ -175,7 +177,7 @@ struct EmacsImportTests { | ||
| 175 | 177 | let keymap = folder.appendingPathComponent("keymap.toml") |
| 176 | 178 | #expect(KeymapLoader.load(.doom, userFile: keymap).problems.isEmpty) |
| 177 | 179 | #expect(KeymapLoader.load(.doom, userFile: keymap).keymap.keyLabels(for: "app.agenda", modes: ["normal"]).contains("C-c a")) |
| 178 | #expect(summary.hasPrefix("Imported 21 settings, 3 capture templates, 3 key bindings."), "\(summary)") | |
| 180 | #expect(summary.hasPrefix("Imported 22 settings, 3 capture templates, 3 key bindings."), "\(summary)") | |
| 179 | 181 | #expect(defaults.string(forKey: "themeFont") == "JetBrains Mono") |
| 180 | 182 | #expect(defaults.integer(forKey: "themeFontSize") == 14) |
| 181 | 183 | |
Tests/OrgAppTests/OrgPreferencesTests.swift +3
| @@ -13,6 +13,7 @@ struct OrgPreferencesTests { | ||
| 13 | 13 | #expect(OrgPreferences.agendaSpan(defaults) == 10 && OrgPreferences.agendaStartOffset(defaults) == 0) |
| 14 | 14 | #expect(OrgPreferences.orgSettings(defaults).deadlineWarningDays == 14) |
| 15 | 15 | #expect(OrgPreferences.agendaStartOnWeekday(defaults) == 1) |
| 16 | #expect(OrgPreferences.options(defaults).trackOrderedPropertyWithTag == nil) | |
| 16 | 17 | #expect(OrgPreferences.agendaOptions(AgendaOptions(), defaults).deadlineWarningDays == 14) |
| 17 | 18 | #expect(OrgPreferences.reminders(defaults) && OrgPreferences.reminderLead(defaults) == 12) |
| 18 | 19 | let fallbacks = OrgPreferences.options(defaults) |
| @@ -28,6 +29,7 @@ struct OrgPreferencesTests { | ||
| 28 | 29 | appt-message-warning-time = 30 |
| 29 | 30 | org-deadline-warning-days = 5 |
| 30 | 31 | org-agenda-start-on-weekday = "nil" |
| 32 | org-track-ordered-property-with-tag = "t" | |
| 31 | 33 | org-M-RET-may-split-line = true |
| 32 | 34 | org-hide-emphasis-markers = false |
| 33 | 35 | org-pretty-entities = false |
| @@ -42,6 +44,7 @@ struct OrgPreferencesTests { | ||
| 42 | 44 | #expect(OrgPreferences.agendaSpan(defaults) == 7 && OrgPreferences.agendaStartOffset(defaults) == -1) |
| 43 | 45 | #expect(OrgPreferences.orgSettings(defaults).deadlineWarningDays == 5) |
| 44 | 46 | #expect(OrgPreferences.agendaStartOnWeekday(defaults) == nil) |
| 47 | #expect(OrgPreferences.options(defaults).trackOrderedPropertyWithTag == "ORDERED") | |
| 45 | 48 | #expect(OrgPreferences.agendaOptions(AgendaOptions(), defaults).deadlineWarningDays == 5) |
| 46 | 49 | #expect(!OrgPreferences.reminders(defaults) && OrgPreferences.reminderLead(defaults) == 30) |
| 47 | 50 | #expect(UserConfig.apply("org-agenda-start-on-weekday = \"0\"", to: defaults).isEmpty) |
Tests/OrgCoreTests/TodoDependencyTests.swift +16
| @@ -146,6 +146,22 @@ struct TodoDependencyTests { | ||
| 146 | 146 | form: Self.form("(org-toggle-ordered-property)", dependencies: false, checkboxes: false, keep: "Subtasks"))) |
| 147 | 147 | ours.append(Self.run(ToggleOrderedProperty(), text, caret: caret, options: .org)) |
| 148 | 148 | } |
| 149 | // org-track-ordered-property-with-tag: t is the tag ORDERED, a string names the tag. | |
| 150 | let tracked = [ | |
| 151 | "* A¶\n", "* A :x:¶\n", "* A :x:ORDERED:¶\n:PROPERTIES:\n:ORDERED: t\n:END:\n", | |
| 152 | "* TODO A :seq:¶\n:PROPERTIES:\n:ORDERED: t\n:END:\n", "* A :ORDERED:¶\n", | |
| 153 | ] | |
| 154 | for (lisp, tag) in [("t", "ORDERED"), ("\"seq\"", "seq")] { | |
| 155 | var options = EditingOptions.org | |
| 156 | options.trackOrderedPropertyWithTag = tag | |
| 157 | for marked in tracked { | |
| 158 | let (text, caret) = Self.place(marked) | |
| 159 | cases.append(EmacsOracle.Case(text: text, point: EmacsOracle.point(caret, in: text), | |
| 160 | form: Self.form("(let ((org-track-ordered-property-with-tag \(lisp))) (org-toggle-ordered-property))", | |
| 161 | dependencies: false, checkboxes: false, keep: "Subtasks"))) | |
| 162 | ours.append(Self.run(ToggleOrderedProperty(), text, caret: caret, options: options)) | |
| 163 | } | |
| 164 | } | |
| 149 | 165 | for (i, theirs) in try EmacsOracle.run(cases).enumerated() { |
| 150 | 166 | // Org's message also names the position it reached and the buffer. |
| 151 | 167 | let before = "Before first headline" |
docs/manual/guide/05-todos-and-tags.org +1 −1
| @@ -112,7 +112,7 @@ The =ORDERED= property adds an order. Under a parent with =:ORDERED: t=, an entr | ||
| 112 | 112 | ,** TODO Pack the kitchen |
| 113 | 113 | #+END_SRC |
| 114 | 114 | |
| 115 | Here Pack the kitchen can't be done until Hire a van is. Toggle ORDERED Property (=org-toggle-ordered-property=, =C-c C-x o= in Emacs and Doom) adds =:ORDERED: t= to the entry's property drawer, or removes the property when it is set. | |
| 115 | Here Pack the kitchen can't be done until Hire a van is. Toggle ORDERED Property (=org-toggle-ordered-property=, =C-c C-x o= in Emacs and Doom) adds =:ORDERED: t= to the entry's property drawer, or removes the property when it is set. With =org-track-ordered-property-with-tag= set in =config.toml=, it adds or removes that tag too (=ORDERED= for ="t"=), so ordered entries show in the heading line. | |
| 116 | 116 | |
| 117 | 117 | With =org-enforce-todo-checkbox-dependencies= on, an entry can't be done while its own text has an unchecked (=[ ]=) or partly checked (=[-]=) checkbox. Checkboxes in child entries and in src, example, export and verse blocks don't count. The message ends in =(by contained checkboxes)=; when both settings would refuse the change, it names the checkboxes. |
| 118 | 118 | |
docs/manual/guide/13-configuration.org +2
| @@ -155,6 +155,7 @@ These settings have no control in the Settings window. Some are in the View menu | ||
| 155 | 155 | | =tab-bar= | View ▸ Show Tab Bar | |
| 156 | 156 | | =show-markup= | View ▸ Show Markup (=⇧⌘M=) | |
| 157 | 157 | | =ignored-folders= | | |
| 158 | | =org-track-ordered-property-with-tag= | | | |
| 158 | 159 | | =org-agenda-start-on-weekday= | | |
| 159 | 160 | | =org-deadline-warning-days= | | |
| 160 | 161 | | =org-agenda-skip-scheduled-if-done= | | |
| @@ -188,6 +189,7 @@ A key you remove from the file goes back to its default. A key that isn't in the | ||
| 188 | 189 | | =org-log-into-drawer= | string | =""= | The drawer state notes go in. ="LOGBOOK"= is Emacs's =t=; =""= puts them under the heading. Mirrors =org-log-into-drawer=. | |
| 189 | 190 | | =org-enforce-todo-dependencies= | boolean | =false= | An entry can't become done while a descendant has an active TODO keyword, or under an =ORDERED= parent while an earlier sibling has one. Mirrors =org-enforce-todo-dependencies=. | |
| 190 | 191 | | =org-enforce-todo-checkbox-dependencies= | boolean | =false= | An entry can't become done while its text has an unchecked checkbox. Mirrors =org-enforce-todo-checkbox-dependencies=. | |
| 192 | | =org-track-ordered-property-with-tag= | string | ="nil"= | A tag that Toggle ORDERED Property adds and removes with the property: ="t"= for the tag =ORDERED=, or a tag name. Mirrors =org-track-ordered-property-with-tag=. | | |
| 191 | 193 | | =org-startup-indented= | boolean | =true= | Indent bodies under their headings, as =org-indent-mode=. =#+STARTUP: indent= / =noindent= override it. Mirrors =org-startup-indented=. | |
| 192 | 194 | | =org-hide-leading-stars= | boolean | =false= | Show only a heading's last star, without indentation. =#+STARTUP: hidestars= / =showstars= override it. Mirrors =org-hide-leading-stars=. | |
| 193 | 195 | | =org-startup-align-all-tables= | boolean | =false= | Align every table when a file opens. =#+STARTUP: align= / =noalign= override it. Mirrors =org-startup-align-all-tables=. | |
docs/manual/guide/14-ios.org +1 −1
| @@ -347,7 +347,7 @@ These settings from =config.toml= apply on iOS: | ||
| 347 | 347 | - =show-markup=, =org-startup-indented=, =org-hide-leading-stars=, =org-startup-with-inline-images=, =org-startup-align-all-tables=, =org-startup-truncated=, =org-cycle-hide-drawer-startup=, =org-cycle-hide-block-startup= |
| 348 | 348 | - =[theme]= (=font=, =font-size=, =line-spacing=, =heading-size-step=, =theme-file= and colours), =[theme.light]=, =[theme.dark]=, =[theme.todo]=, =[theme.category]= |
| 349 | 349 | - =org-log-done=, =org-log-reschedule=, =org-log-redeadline=, =org-log-into-drawer= |
| 350 | - =org-enforce-todo-dependencies=, =org-enforce-todo-checkbox-dependencies=, =org-agenda-dim-blocked-tasks= | |
| 350 | - =org-enforce-todo-dependencies=, =org-enforce-todo-checkbox-dependencies=, =org-track-ordered-property-with-tag=, =org-agenda-dim-blocked-tasks= | |
| 351 | 351 | - =org-use-speed-commands=, with a hardware keyboard |
| 352 | 352 | - =electric-pair-mode=, =spell-check= |
| 353 | 353 | - =org-agenda-span=, =org-agenda-start-day=, =org-agenda-start-on-weekday=, =org-deadline-warning-days=, =agenda-include-subfolders=, =org-agenda-show-all-dates=, =org-agenda-skip-scheduled-if-done=, =org-agenda-skip-deadline-if-done=, =org-agenda-search-view-always-boolean=, =org-agenda-search-view-force-full-words= |