org-use-property-inheritance !221

merged merged by cmc on 2026-10-10 21:22 UTC · krz/orgstar:property-inheritance into main

10 files changed, +89 −10

Layout: unified · split

Sources/OrgApp/OrgPreferences.swift +1
@@ -12,6 +12,7 @@ public enum OrgPreferences {
12 let line = defaults.string(forKey: "todoKeywords") ?? defaultTodoKeywords 12 let line = defaults.string(forKey: "todoKeywords") ?? defaultTodoKeywords
13 var settings = OrgSettings.default.withTodoKeywords(line) ?? .default 13 var settings = OrgSettings.default.withTodoKeywords(line) ?? .default
14 settings.listAllowAlphabetical = bool("alphabeticalLists", defaults) 14 settings.listAllowAlphabetical = bool("alphabeticalLists", defaults)
15 settings.propertyInheritance = .init(string("propertyInheritance", defaults))
15 return settings 16 return settings
16 } 17 }
17 18
Sources/OrgApp/UserConfig.swift +2
@@ -99,6 +99,8 @@ public enum UserConfig {
99 comment: "M-RET adds the new heading after the subtree", legacy: "editor.insert-heading-respect-content"), 99 comment: "M-RET adds the new heading after the subtree", legacy: "editor.insert-heading-respect-content"),
100 Setting(section: "", key: "org-M-RET-may-split-line", defaultsKey: "splitLine", kind: .bool, fallback: .bool(false), 100 Setting(section: "", key: "org-M-RET-may-split-line", defaultsKey: "splitLine", kind: .bool, fallback: .bool(false),
101 comment: "M-RET splits the line at the caret", legacy: "editor.meta-return-may-split-line"), 101 comment: "M-RET splits the line at the caret", legacy: "editor.meta-return-may-split-line"),
102 Setting(section: "", key: "org-use-property-inheritance", defaultsKey: "propertyInheritance", kind: .string, fallback: .string("nil"),
103 comment: "nil, t, or property names that inherit, separated by spaces, such as \"STYLE\"", legacy: ""),
102 Setting(section: "", key: "org-list-allow-alphabetical", defaultsKey: "alphabeticalLists", kind: .bool, fallback: .bool(true), 104 Setting(section: "", key: "org-list-allow-alphabetical", defaultsKey: "alphabeticalLists", kind: .bool, fallback: .bool(true),
103 comment: "lists can use a. b. c.", legacy: "editor.list-allow-alphabetical"), 105 comment: "lists can use a. b. c.", legacy: "editor.list-allow-alphabetical"),
104 Setting(section: "", key: "org-hide-emphasis-markers", defaultsKey: "hiddenMarkers", kind: .bool, fallback: .bool(true), 106 Setting(section: "", key: "org-hide-emphasis-markers", defaultsKey: "hiddenMarkers", kind: .bool, fallback: .bool(true),
Sources/OrgCore/Agenda/AgendaSearch.swift +1 −1
@@ -385,7 +385,7 @@ public struct TagsMatcher: Sendable {
385 case "SCHEDULED", "DEADLINE", "CLOSED": return heading.planning[name] 385 case "SCHEDULED", "DEADLINE", "CLOSED": return heading.planning[name]
386 case "TIMESTAMP": return heading.firstActive 386 case "TIMESTAMP": return heading.firstActive
387 case "TIMESTAMP_IA": return heading.firstInactive 387 case "TIMESTAMP_IA": return heading.firstInactive
388 default: return heading.properties[name] 388 default: return heading.matchProperties[name]
389 } 389 }
390 } 390 }
391 func evaluate(_ term: Term) -> Bool { 391 func evaluate(_ term: Term) -> Bool {
Sources/OrgCore/Agenda/AgendaSource.swift +13 −2
@@ -26,6 +26,8 @@ public struct AgendaSource: Sendable {
26 let localTags: [String] 26 let localTags: [String]
27 /// Upper-cased keys of the entry's own drawer. 27 /// Upper-cased keys of the entry's own drawer.
28 let properties: [String: String] 28 let properties: [String: String]
29 /// `properties` with inherited ones (`org-use-property-inheritance`), for matches.
30 let matchProperties: [String: String]
29 /// Planning timestamps with brackets, for property matches. 31 /// Planning timestamps with brackets, for property matches.
30 let planning: [String: String] 32 let planning: [String: String]
31 /// The first active and inactive timestamps in the entry (`TIMESTAMP`, `TIMESTAMP_IA`). 33 /// The first active and inactive timestamps in the entry (`TIMESTAMP`, `TIMESTAMP_IA`).
@@ -252,7 +254,16 @@ public struct AgendaSource: Sendable {
252 } 254 }
253 } 255 }
254 let ownStamps = sectionStamps(index) 256 let ownStamps = sectionStamps(index)
255 let isHabit = properties["STYLE"]?.trimmingCharacters(in: .whitespaces) == "habit" 257 // Matches and `org-is-habit-p` read properties with `org-use-property-inheritance`:
258 // inherited values first, the entry's own over them.
259 var matchProperties = properties
260 if model.settings.propertyInheritance != .none {
261 let keys = Set((model.fileProperties + model.ancestors(of: index).flatMap { model.headings[$0].properties }).map { $0.key.uppercased() })
262 for key in keys where matchProperties[key] == nil && model.inherits(key) {
263 if let value = model.property(key, of: index)?.value { matchProperties[key] = value }
264 }
265 }
266 let isHabit = matchProperties["STYLE"]?.trimmingCharacters(in: .whitespaces) == "habit"
256 var habit: Habit? 267 var habit: Habit?
257 if isHabit, let scheduled { 268 if isHabit, let scheduled {
258 let end = index + 1 < model.headings.count ? model.headings[index + 1].headingRange.lowerBound : ns.length 269 let end = index + 1 < model.headings.count ? model.headings[index + 1].headingRange.lowerBound : ns.length
@@ -269,7 +280,7 @@ public struct AgendaSource: Sendable {
269 headings.append(Heading( 280 headings.append(Heading(
270 start: info.headingRange.lowerBound, level: info.level, skipped: skipped[index], 281 start: info.headingRange.lowerBound, level: info.level, skipped: skipped[index],
271 title: info.title.trimmingCharacters(in: .whitespaces), priority: info.priority, localTags: info.localTags, 282 title: info.title.trimmingCharacters(in: .whitespaces), priority: info.priority, localTags: info.localTags,
272 properties: properties, planning: planningValues, 283 properties: properties, matchProperties: matchProperties, planning: planningValues,
273 firstActive: ownStamps.first { $0.hasPrefix("<") }, firstInactive: ownStamps.first { $0.hasPrefix("[") }, 284 firstActive: ownStamps.first { $0.hasPrefix("<") }, firstInactive: ownStamps.first { $0.hasPrefix("[") },
274 line: line.trimmingCharacters(in: .newlines), head: head, todo: info.todo, isDone: info.isDone, 285 line: line.trimmingCharacters(in: .newlines), head: head, todo: info.todo, isDone: info.isDone,
275 tags: tags, category: category, scheduled: scheduled, deadline: deadline, isHabit: isHabit, habit: habit, 286 tags: tags, category: category, scheduled: scheduled, deadline: deadline, isHabit: isHabit, habit: habit,
Sources/OrgCore/Parser/Settings.swift +3
@@ -47,6 +47,8 @@ public struct OrgSettings: Sendable, Equatable {
47 public var radioTargets: [String] = [] 47 public var radioTargets: [String] = []
48 /// `org-list-allow-alphabetical`: `a.` and `A)` are bullets. 48 /// `org-list-allow-alphabetical`: `a.` and `A)` are bullets.
49 public var listAllowAlphabetical = false 49 public var listAllowAlphabetical = false
50 /// `org-use-property-inheritance`.
51 public var propertyInheritance: SemanticSettings.PropertyInheritance = .none
50 /// Keyword lines from the file's `#+SETUPFILE`s, as `#+KEY: value` lines: they count as 52 /// Keyword lines from the file's `#+SETUPFILE`s, as `#+KEY: value` lines: they count as
51 /// the file's own, before them. 53 /// the file's own, before them.
52 public var setupKeywords = "" 54 public var setupKeywords = ""
@@ -133,6 +135,7 @@ enum SettingsScanner {
133 var settings = OrgSettings(todoSequences: sequences.isEmpty ? defaults.todoSequences : sequences, priorities: priorities, 135 var settings = OrgSettings(todoSequences: sequences.isEmpty ? defaults.todoSequences : sequences, priorities: priorities,
134 radioTargets: radio.sorted { $0.count > $1.count }) 136 radioTargets: radio.sorted { $0.count > $1.count })
135 settings.listAllowAlphabetical = defaults.listAllowAlphabetical 137 settings.listAllowAlphabetical = defaults.listAllowAlphabetical
138 settings.propertyInheritance = defaults.propertyInheritance
136 settings.setupKeywords = defaults.setupKeywords 139 settings.setupKeywords = defaults.setupKeywords
137 settings.startup = startup 140 settings.startup = startup
138 return settings 141 return settings
Sources/OrgCore/Semantic/DocumentModel.swift +3 −2
@@ -21,8 +21,9 @@ public struct DocumentModel: Sendable {
21 21
22 private typealias PendingBlock = (node: SyntaxNode, heading: Int?, affiliated: [SyntaxNode]) 22 private typealias PendingBlock = (node: SyntaxNode, heading: Int?, affiliated: [SyntaxNode])
23 23
24 public init(tree: OrgTree, settings: SemanticSettings = .default) { 24 /// `settings` default to the tree's property inheritance.
25 self.settings = settings 25 public init(tree: OrgTree, settings: SemanticSettings? = nil) {
26 self.settings = settings ?? SemanticSettings(propertyInheritance: tree.settings.propertyInheritance)
26 self.orgSettings = tree.settings 27 self.orgSettings = tree.settings
27 for (key, value) in SetupFile.keywords(tree.settings.setupKeywords) { fileKeyword(key, value.trimmingCharacters(in: .whitespaces)) } 28 for (key, value) in SetupFile.keywords(tree.settings.setupKeywords) { fileKeyword(key, value.trimmingCharacters(in: .whitespaces)) }
28 var pending: [PendingBlock] = [] 29 var pending: [PendingBlock] = []
Sources/OrgCore/Semantic/SemanticSettings.swift +13
@@ -6,6 +6,19 @@ public struct SemanticSettings: Sendable, Equatable {
6 case all 6 case all
7 /// Upper-cased property keys that inherit. 7 /// Upper-cased property keys that inherit.
8 case only(Set<String>) 8 case only(Set<String>)
9
10 /// `org-use-property-inheritance` as `config.toml` writes it: empty or `nil` for none,
11 /// `t` for all, or property names separated by spaces.
12 public init(_ text: String) {
13 let names = text.split(whereSeparator: \.isWhitespace).map { $0.uppercased() }
14 if names.isEmpty || names == ["NIL"] {
15 self = .none
16 } else if names == ["T"] {
17 self = .all
18 } else {
19 self = .only(Set(names))
20 }
21 }
9 } 22 }
10 23
11 public var tagInheritance: Bool 24 public var tagInheritance: Bool
Tests/OrgAppTests/WidgetDataTests.swift +43
@@ -47,3 +47,46 @@ struct WidgetDataTests {
47 #expect(ClockSnapshot.read(from: file)?.running == nil) 47 #expect(ClockSnapshot.read(from: file)?.running == nil)
48 } 48 }
49} 49}
50
51struct PropertyInheritanceTests {
52 static let file = """
53 #+PROPERTY: STYLE habit
54 * TODO Stretch
55 SCHEDULED: <2026-10-05 Mon .+1d>
56 * Work
57 :PROPERTIES:
58 :TEAM: ops
59 :END:
60 ** TODO Deploy
61 """
62
63 static func source(_ inheritance: String) -> AgendaSource {
64 var defaults = OrgSettings.default
65 defaults.propertyInheritance = .init(inheritance)
66 return AgendaSource(path: "/notes/habits.org", text: file, defaults: defaults)
67 }
68
69 /// `org-is-habit-p` reads STYLE with selective inheritance: a `#+PROPERTY` line counts only
70 /// when `org-use-property-inheritance` covers STYLE, as Emacs 31 does.
71 @Test func fileStyleMakesHabitsWhenStyleInherits() {
72 #expect(Self.source("nil").habits.isEmpty)
73 #expect(Self.source("STYLE").habits.map(\.title) == ["Stretch"])
74 #expect(Self.source("t").habits.map(\.title) == ["Stretch"])
75 #expect(Self.source("TEAM").habits.isEmpty)
76 }
77
78 @Test func matchesSeeInheritedProperties() {
79 func titles(_ inheritance: String) -> [String] {
80 Agenda.tagsMatch([Self.source(inheritance)], match: "TEAM=\"ops\"").map(\.text)
81 }
82 #expect(titles("nil").count == 1)
83 #expect(titles("TEAM").count == 2)
84 }
85
86 @Test func readsTheConfigValue() {
87 #expect(SemanticSettings.PropertyInheritance("") == .none)
88 #expect(SemanticSettings.PropertyInheritance("nil") == .none)
89 #expect(SemanticSettings.PropertyInheritance("t") == .all)
90 #expect(SemanticSettings.PropertyInheritance("style Team") == .only(["STYLE", "TEAM"]))
91 }
92}
docs/manual/guide/04-outlines.org +7 −4
@@ -584,9 +584,11 @@ whose value is =[ ]= or =[X]= toggles between them.
584 584
585** Inheritance 585** Inheritance
586 586
587orgstar inherits properties as Org does with =org-use-property-inheritance= at its 587orgstar inherits properties as Org does with =org-use-property-inheritance=, set in
588default of =nil=: a property applies only to the entry that has it, with these 588=config.toml=: =nil= (the default), =t= for all properties, or property names separated
589exceptions: 589by spaces, such as ="STYLE TEAM"=. An inherited property comes from the nearest ancestor
590that has it, or from a =#+PROPERTY:= line. At =nil=, a property applies only to the entry
591that has it, with these exceptions:
590 592
591- =CATEGORY=, =ARCHIVE=, =COLUMNS=, =LOGGING= and the =header-args= properties are 593- =CATEGORY=, =ARCHIVE=, =COLUMNS=, =LOGGING= and the =header-args= properties are
592 always inherited from ancestors and =#+PROPERTY:= lines. 594 always inherited from ancestors and =#+PROPERTY:= lines.
@@ -594,7 +596,8 @@ exceptions:
594- =KEY_ALL= allowed values and =COOKIE_DATA= for TODO statistics are looked up through 596- =KEY_ALL= allowed values and =COOKIE_DATA= for TODO statistics are looked up through
595 the ancestors. 597 the ancestors.
596 598
597orgstar has no setting for =org-use-property-inheritance=. 599The setting applies to property lookups, agenda matches and habits (=STYLE=), as
600Org's =selective= inheritance does.
598 601
599** Special properties 602** Special properties
600 603
docs/manual/guide/07-agenda.org +3 −1
@@ -243,6 +243,8 @@ SCHEDULED: <2026-10-05 Mon .+2d/4d>
243- State "DONE" from "TODO" [2026-10-01 Thu 07:05] 243- State "DONE" from "TODO" [2026-10-01 Thu 07:05]
244#+END_SRC 244#+END_SRC
245 245
246To make every entry of a file a habit, put =#+PROPERTY: STYLE habit= at the top of the file and set =org-use-property-inheritance = "STYLE"= in =config.toml=. As in Org, the =#+PROPERTY= line counts only when STYLE inherits; set the same variable in Emacs, =(setq org-use-property-inheritance '("STYLE"))=, for Emacs to agree.
247
246The repeater can be =+=, =++= or =.+=, with an optional =/Nd= maximum interval. Days the habit was done are read from =- State "DONE" … [date]= lines (for any done keyword) and =CLOSING NOTE [date]= lines in the entry. 248The repeater can be =+=, =++= or =.+=, with an optional =/Nd= maximum interval. Days the habit was done are read from =- State "DONE" … [date]= lines (for any done keyword) and =CLOSING NOTE [date]= lines in the entry.
247 249
248A habit appears only on today's agenda and not once it is done for the day. Its row carries the consistency graph: one cell per day for the 21 days before today and the 7 after (=org-habit-preceding-days= and =org-habit-following-days=). On the Mac the graph is at the right of the row, with =*= on days the habit was done and =!= on today; on iOS it is a strip under the title, with a dot on days it was done and today outlined. Cell colors follow org-habit's faces: 250A habit appears only on today's agenda and not once it is done for the day. Its row carries the consistency graph: one cell per day for the 21 days before today and the 7 after (=org-habit-preceding-days= and =org-habit-following-days=). On the Mac the graph is at the right of the row, with =*= on days the habit was done and =!= on today; on iOS it is a strip under the title, with a dot on days it was done and today outlined. Cell colors follow org-habit's faces:
@@ -323,7 +325,7 @@ Names are case-insensitive. Prefix a character in a name with =\= to use it lite
323| =SCHEDULED=, =DEADLINE=, =CLOSED= | The planning timestamp | 325| =SCHEDULED=, =DEADLINE=, =CLOSED= | The planning timestamp |
324| =TIMESTAMP=, =TIMESTAMP_IA= | The entry's first active or inactive timestamp | 326| =TIMESTAMP=, =TIMESTAMP_IA= | The entry's first active or inactive timestamp |
325 327
326Properties are not inherited in matches (=org-use-property-inheritance= is nil). With a date value, =<>= and its synonyms match dates that are equal, as orgstar's comparison mirrors =org-time<>= in Org 9.8.7; use =<= and =>= for date ranges. 328Properties inherit in matches as =org-use-property-inheritance= says: by default they don't, so =TEAM="ops"= matches only the entry with the property; with =org-use-property-inheritance = "TEAM"= it matches the entries under it too, and =#+PROPERTY= lines count. With a date value, =<>= and its synonyms match dates that are equal, as orgstar's comparison mirrors =org-time<>= in Org 9.8.7; use =<= and =>= for date ranges.
327 329
328** TODO keywords 330** TODO keywords
329 331