Commit 8fa7e99e67

8fa7e99e67428d4d706c9b6db611f7847dfdbb02

parent: 8d1ab6bd94

Verified · cmc

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

org-use-property-inheritance

config.toml's org-use-property-inheritance (nil, t, or property names) applies to property lookups, agenda matches and habits, as Org's selective inheritance does. A file's #+PROPERTY: STYLE habit makes its entries habits when STYLE inherits.

Layout: unified · split

Sources/OrgApp/OrgPreferences.swift +1
@@ -12,6 +12,7 @@ public enum OrgPreferences {
1212 let line = defaults.string(forKey: "todoKeywords") ?? defaultTodoKeywords
1313 var settings = OrgSettings.default.withTodoKeywords(line) ?? .default
1414 settings.listAllowAlphabetical = bool("alphabeticalLists", defaults)
15 settings.propertyInheritance = .init(string("propertyInheritance", defaults))
1516 return settings
1617 }
1718
Sources/OrgApp/UserConfig.swift +2
@@ -99,6 +99,8 @@ public enum UserConfig {
9999 comment: "M-RET adds the new heading after the subtree", legacy: "editor.insert-heading-respect-content"),
100100 Setting(section: "", key: "org-M-RET-may-split-line", defaultsKey: "splitLine", kind: .bool, fallback: .bool(false),
101101 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: ""),
102104 Setting(section: "", key: "org-list-allow-alphabetical", defaultsKey: "alphabeticalLists", kind: .bool, fallback: .bool(true),
103105 comment: "lists can use a. b. c.", legacy: "editor.list-allow-alphabetical"),
104106 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 {
385385 case "SCHEDULED", "DEADLINE", "CLOSED": return heading.planning[name]
386386 case "TIMESTAMP": return heading.firstActive
387387 case "TIMESTAMP_IA": return heading.firstInactive
388 default: return heading.properties[name]
388 default: return heading.matchProperties[name]
389389 }
390390 }
391391 func evaluate(_ term: Term) -> Bool {
Sources/OrgCore/Agenda/AgendaSource.swift +13 −2
@@ -26,6 +26,8 @@ public struct AgendaSource: Sendable {
2626 let localTags: [String]
2727 /// Upper-cased keys of the entry's own drawer.
2828 let properties: [String: String]
29 /// `properties` with inherited ones (`org-use-property-inheritance`), for matches.
30 let matchProperties: [String: String]
2931 /// Planning timestamps with brackets, for property matches.
3032 let planning: [String: String]
3133 /// The first active and inactive timestamps in the entry (`TIMESTAMP`, `TIMESTAMP_IA`).
@@ -252,7 +254,16 @@ public struct AgendaSource: Sendable {
252254 }
253255 }
254256 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"
256267 var habit: Habit?
257268 if isHabit, let scheduled {
258269 let end = index + 1 < model.headings.count ? model.headings[index + 1].headingRange.lowerBound : ns.length
@@ -269,7 +280,7 @@ public struct AgendaSource: Sendable {
269280 headings.append(Heading(
270281 start: info.headingRange.lowerBound, level: info.level, skipped: skipped[index],
271282 title: info.title.trimmingCharacters(in: .whitespaces), priority: info.priority, localTags: info.localTags,
272 properties: properties, planning: planningValues,
283 properties: properties, matchProperties: matchProperties, planning: planningValues,
273284 firstActive: ownStamps.first { $0.hasPrefix("<") }, firstInactive: ownStamps.first { $0.hasPrefix("[") },
274285 line: line.trimmingCharacters(in: .newlines), head: head, todo: info.todo, isDone: info.isDone,
275286 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 {
4747 public var radioTargets: [String] = []
4848 /// `org-list-allow-alphabetical`: `a.` and `A)` are bullets.
4949 public var listAllowAlphabetical = false
50 /// `org-use-property-inheritance`.
51 public var propertyInheritance: SemanticSettings.PropertyInheritance = .none
5052 /// Keyword lines from the file's `#+SETUPFILE`s, as `#+KEY: value` lines: they count as
5153 /// the file's own, before them.
5254 public var setupKeywords = ""
@@ -133,6 +135,7 @@ enum SettingsScanner {
133135 var settings = OrgSettings(todoSequences: sequences.isEmpty ? defaults.todoSequences : sequences, priorities: priorities,
134136 radioTargets: radio.sorted { $0.count > $1.count })
135137 settings.listAllowAlphabetical = defaults.listAllowAlphabetical
138 settings.propertyInheritance = defaults.propertyInheritance
136139 settings.setupKeywords = defaults.setupKeywords
137140 settings.startup = startup
138141 return settings
Sources/OrgCore/Semantic/DocumentModel.swift +3 −2
@@ -21,8 +21,9 @@ public struct DocumentModel: Sendable {
2121
2222 private typealias PendingBlock = (node: SyntaxNode, heading: Int?, affiliated: [SyntaxNode])
2323
24 public init(tree: OrgTree, settings: SemanticSettings = .default) {
25 self.settings = settings
24 /// `settings` default to the tree's property inheritance.
25 public init(tree: OrgTree, settings: SemanticSettings? = nil) {
26 self.settings = settings ?? SemanticSettings(propertyInheritance: tree.settings.propertyInheritance)
2627 self.orgSettings = tree.settings
2728 for (key, value) in SetupFile.keywords(tree.settings.setupKeywords) { fileKeyword(key, value.trimmingCharacters(in: .whitespaces)) }
2829 var pending: [PendingBlock] = []
Sources/OrgCore/Semantic/SemanticSettings.swift +13
@@ -6,6 +6,19 @@ public struct SemanticSettings: Sendable, Equatable {
66 case all
77 /// Upper-cased property keys that inherit.
88 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 }
922 }
1023
1124 public var tagInheritance: Bool
Tests/OrgAppTests/WidgetDataTests.swift +43
@@ -47,3 +47,46 @@ struct WidgetDataTests {
4747 #expect(ClockSnapshot.read(from: file)?.running == nil)
4848 }
4949}
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.
584584
585585** Inheritance
586586
587orgstar inherits properties as Org does with =org-use-property-inheritance= at its
588default of =nil=: a property applies only to the entry that has it, with these
589exceptions:
587orgstar inherits properties as Org does with =org-use-property-inheritance=, set in
588=config.toml=: =nil= (the default), =t= for all properties, or property names separated
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:
590592
591593- =CATEGORY=, =ARCHIVE=, =COLUMNS=, =LOGGING= and the =header-args= properties are
592594 always inherited from ancestors and =#+PROPERTY:= lines.
@@ -594,7 +596,8 @@ exceptions:
594596- =KEY_ALL= allowed values and =COOKIE_DATA= for TODO statistics are looked up through
595597 the ancestors.
596598
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.
598601
599602** Special properties
600603
docs/manual/guide/07-agenda.org +3 −1
@@ -243,6 +243,8 @@ SCHEDULED: <2026-10-05 Mon .+2d/4d>
243243- State "DONE" from "TODO" [2026-10-01 Thu 07:05]
244244#+END_SRC
245245
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
246248The 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.
247249
248250A 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
323325| =SCHEDULED=, =DEADLINE=, =CLOSED= | The planning timestamp |
324326| =TIMESTAMP=, =TIMESTAMP_IA= | The entry's first active or inactive timestamp |
325327
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.
327329
328330** TODO keywords
329331